dolibarr 21.0.0-alpha
commondocgenerator.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2016-2023 Charlene Benke <charlene@patas-monkey.com>
8 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
10 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Mélina Joum <melina.joum@altairis.fr>
12 * Copyright (C) 2024 Nick Fragoulis
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 * or see https://www.gnu.org/
27 */
28
39abstract class CommonDocGenerator
40{
44 public $name = '';
45
49 public $version = '';
50
54 public $error = '';
55
59 public $errors = array();
60
64 protected $db;
65
69 public $extrafieldsCache;
70
74 public $update_main_doc_field;
75
79 public $scandir;
80
84 public $description;
85
89 public $format;
90
94 public $type;
95
99 public $page_hauteur;
100
104 public $page_largeur;
105
109 public $marge_gauche;
110
114 public $marge_droite;
115
119 public $marge_haute;
120
124 public $marge_basse;
125
129 public $corner_radius;
130
134 public $option_logo;
138 public $option_tva;
142 public $option_multilang;
146 public $option_freetext;
150 public $option_draft_watermark;
154 public $watermark;
155
159 public $option_modereg;
163 public $option_condreg;
167 public $option_escompte;
171 public $option_credit_note;
172
176 public $tva;
180 public $tva_array;
186 public $localtax1;
187
193 public $localtax2;
194
198 public $tabTitleHeight;
199
203 public $defaultTitlesFieldsStyle;
204
208 public $defaultContentsFieldsStyle;
209
213 public $emetteur;
214
219 public $phpmin = array(7, 1);
220
224 public $cols;
225
229 public $result;
230
234 public $posxlabel;
238 public $posxup;
242 public $posxref;
246 public $posxpicture; // For picture
250 public $posxdesc; // For description
254 public $posxqty;
258 public $posxpuht;
262 public $posxtva;
266 public $posxtotalht;
270 public $postotalht;
274 public $posxunit;
278 public $posxdiscount;
282 public $posxworkload;
286 public $posxtimespent;
290 public $posxprogress;
294 public $atleastonephoto;
298 public $atleastoneratenotnull;
302 public $atleastonediscount;
303
309 public function __construct($db)
310 {
311 $this->db = $db;
312 }
313
314
315 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
323 public function get_substitutionarray_user($user, $outputlangs)
324 {
325 // phpcs:enable
326 global $conf, $extrafields;
327
328 $logotouse = $conf->user->dir_output . '/' . get_exdir(0, 0, 0, 0, $user, 'user') . 'photos/' . getImageFileNameForSize($user->photo, '_small');
329
330 $array_user = array(
331 'myuser_lastname' => $user->lastname,
332 'myuser_firstname' => $user->firstname,
333 'myuser_fullname' => $user->getFullName($outputlangs, 1),
334 'myuser_login' => $user->login,
335 'myuser_phone' => $user->office_phone,
336 'myuser_address' => $user->address,
337 'myuser_zip' => $user->zip,
338 'myuser_town' => $user->town,
339 'myuser_country' => $user->country,
340 'myuser_country_code' => $user->country_code,
341 'myuser_state' => $user->state,
342 'myuser_state_code' => $user->state_code,
343 'myuser_fax' => $user->office_fax,
344 'myuser_mobile' => $user->user_mobile,
345 'myuser_email' => $user->email,
346 'myuser_logo' => $logotouse,
347 'myuser_job' => $user->job,
348 'myuser_web' => '', // url not exist in $user object
349 'myuser_birth' => dol_print_date($user->birth, 'day', 'gmt'),
350 'myuser_dateemployment' => dol_print_date($user->dateemployment, 'day', 'tzuser'),
351 'myuser_dateemploymentend' => dol_print_date($user->dateemploymentend, 'day', 'tzuser'),
352 'myuser_gender' => $user->gender,
353 );
354 // Retrieve extrafields
355 if (is_array($user->array_options) && count($user->array_options)) {
356 if (empty($extrafields->attributes[$user->table_element])) {
357 $extrafields->fetch_name_optionals_label($user->table_element);
358 }
359 $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
360 }
361 return $array_user;
362 }
363
364
372 public function getSubstitutionarrayMember($member, $outputlangs)
373 {
374 global $conf, $extrafields;
375
376 if ($member->photo) {
377 $logotouse = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
378 } else {
379 $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
380 }
381
382 $array_member = array(
383 'mymember_lastname' => $member->lastname,
384 'mymember_firstname' => $member->firstname,
385 'mymember_fullname' => $member->getFullName($outputlangs, 1),
386 'mymember_login' => $member->login,
387 'mymember_address' => $member->address,
388 'mymember_zip' => $member->zip,
389 'mymember_town' => $member->town,
390 'mymember_country_code' => $member->country_code,
391 'mymember_country' => $member->country,
392 'mymember_state_code' => $member->state_code,
393 'mymember_state' => $member->state,
394 'mymember_phone_perso' => $member->phone_perso,
395 'mymember_phone_pro' => $member->phone,
396 'mymember_phone_mobile' => $member->phone_mobile,
397 'mymember_email' => $member->email,
398 'mymember_logo' => $logotouse,
399 'mymember_gender' => $member->gender,
400 'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
401 'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
402 );
403 // Retrieve extrafields
404 if (is_array($member->array_options) && count($member->array_options)) {
405 $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
406 }
407 return $array_member;
408 }
409
410
411 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
419 public function get_substitutionarray_mysoc($mysoc, $outputlangs)
420 {
421 // phpcs:enable
422 global $conf;
423
424 if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
425 $mysoc->forme_juridique = getFormeJuridiqueLabel((string) $mysoc->forme_juridique_code);
426 }
427 if (empty($mysoc->country) && !empty($mysoc->country_code)) {
428 $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
429 }
430 if (empty($mysoc->state) && !empty($mysoc->state_code)) {
431 $state_id = dol_getIdFromCode($this->db, $mysoc->state_code, 'c_departements', 'code_departement', 'rowid');
432 $mysoc->state = getState($state_id, '0');
433 }
434
435 $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
436
437 return array(
438 'mycompany_logo' => $logotouse,
439 'mycompany_name' => $mysoc->name,
440 'mycompany_email' => $mysoc->email,
441 'mycompany_phone' => $mysoc->phone,
442 'mycompany_fax' => $mysoc->fax,
443 'mycompany_address' => $mysoc->address,
444 'mycompany_zip' => $mysoc->zip,
445 'mycompany_town' => $mysoc->town,
446 'mycompany_country' => $mysoc->country,
447 'mycompany_country_code' => $mysoc->country_code,
448 'mycompany_state' => $mysoc->state,
449 'mycompany_state_code' => $mysoc->state_code,
450 'mycompany_web' => $mysoc->url,
451 'mycompany_juridicalstatus' => $mysoc->forme_juridique,
452 'mycompany_managers' => $mysoc->managers,
453 'mycompany_capital' => $mysoc->capital,
454 'mycompany_barcode' => $mysoc->barcode,
455 'mycompany_idprof1' => $mysoc->idprof1,
456 'mycompany_idprof2' => $mysoc->idprof2,
457 'mycompany_idprof3' => $mysoc->idprof3,
458 'mycompany_idprof4' => $mysoc->idprof4,
459 'mycompany_idprof5' => $mysoc->idprof5,
460 'mycompany_idprof6' => $mysoc->idprof6,
461 'mycompany_vatnumber' => $mysoc->tva_intra,
462 'mycompany_socialobject' => $mysoc->socialobject,
463 'mycompany_note_private' => $mysoc->note_private,
464 //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
465 );
466 }
467
468
469 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
479 public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
480 {
481 // phpcs:enable
482 global $extrafields;
483
484 if (!is_object($object)) {
485 return array();
486 }
487
488 if (empty($object->country) && !empty($object->country_code)) {
489 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
490 }
491 if (empty($object->state) && !empty($object->state_code)) {
492 $state_id = dol_getIdFromCode($this->db, $object->state_code, 'c_departements', 'code_departement', 'rowid');
493 $object->state = getState($state_id, '0');
494 }
495
496 $array_thirdparty = array(
497 'company_name' => $object->name,
498 'company_name_alias' => $object->name_alias,
499 'company_email' => $object->email,
500 'company_phone' => $object->phone,
501 'company_fax' => $object->fax,
502 'company_address' => $object->address,
503 'company_zip' => $object->zip,
504 'company_town' => $object->town,
505 'company_country' => $object->country,
506 'company_country_code' => $object->country_code,
507 'company_state' => $object->state,
508 'company_state_code' => $object->state_code,
509 'company_web' => $object->url,
510 'company_barcode' => $object->barcode,
511 'company_vatnumber' => $object->tva_intra,
512 'company_customercode' => $object->code_client,
513 'company_suppliercode' => $object->code_fournisseur,
514 'company_customeraccountancycode' => $object->code_compta_client,
515 'company_supplieraccountancycode' => $object->code_compta_fournisseur,
516 'company_juridicalstatus' => $object->forme_juridique,
517 'company_outstanding_limit' => $object->outstanding_limit,
518 'company_capital' => $object->capital,
519 'company_capital_formated' => price($object->capital, 0, '', 1, -1),
520 'company_idprof1' => $object->idprof1,
521 'company_idprof2' => $object->idprof2,
522 'company_idprof3' => $object->idprof3,
523 'company_idprof4' => $object->idprof4,
524 'company_idprof5' => $object->idprof5,
525 'company_idprof6' => $object->idprof6,
526 'company_note_public' => $object->note_public,
527 'company_note_private' => $object->note_private,
528 'company_default_bank_iban' => (is_object($object->bank_account) ? $object->bank_account->iban : ''),
529 'company_default_bank_bic' => (is_object($object->bank_account) ? $object->bank_account->bic : '')
530 );
531
532 // Retrieve extrafields
533 if (is_array($object->array_options) && count($object->array_options)) {
534 $object->fetch_optionals();
535
536 $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
537 }
538 return $array_thirdparty;
539 }
540
541 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
550 public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
551 {
552 // phpcs:enable
553 global $conf, $extrafields;
554
555 if (empty($object->country) && !empty($object->country_code)) {
556 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
557 }
558 if (empty($object->state) && !empty($object->state_code)) {
559 $state_id = dol_getIdFromCode($this->db, $object->state_code, 'c_departements', 'code_departement', 'rowid');
560 $object->state = getState($state_id, '0');
561 }
562
563 $array_contact = array(
564 $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
565 $array_key.'_lastname' => $object->lastname,
566 $array_key.'_firstname' => $object->firstname,
567 $array_key.'_address' => $object->address,
568 $array_key.'_zip' => $object->zip,
569 $array_key.'_town' => $object->town,
570 $array_key.'_state_id' => $object->state_id,
571 $array_key.'_state_code' => $object->state_code,
572 $array_key.'_state' => $object->state,
573 $array_key.'_country_id' => $object->country_id,
574 $array_key.'_country_code' => $object->country_code,
575 $array_key.'_country' => $object->country,
576 $array_key.'_poste' => $object->poste,
577 $array_key.'_socid' => $object->socid,
578 $array_key.'_statut' => $object->statut,
579 $array_key.'_code' => $object->code,
580 $array_key.'_email' => $object->email,
581 $array_key.'_phone_pro' => $object->phone_pro,
582 $array_key.'_phone_perso' => $object->phone_perso,
583 $array_key.'_phone_mobile' => $object->phone_mobile,
584 $array_key.'_fax' => $object->fax,
585 $array_key.'_birthday' => $object->birthday,
586 $array_key.'_default_lang' => $object->default_lang,
587 $array_key.'_note_public' => $object->note_public,
588 $array_key.'_note_private' => $object->note_private,
589 $array_key.'_civility' => $object->civility,
590 );
591
592 // Retrieve extrafields
593 if (is_array($object->array_options) && count($object->array_options)) {
594 $object->fetch_optionals();
595
596 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
597 }
598 return $array_contact;
599 }
600
601
602 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
609 public function get_substitutionarray_other($outputlangs)
610 {
611 // phpcs:enable
612 global $conf;
613
614 $now = dol_now('gmt'); // gmt
615 $array_other = array(
616 // Date in default language
617 'current_date' => dol_print_date($now, 'day', 'tzuser'),
618 'current_datehour' => dol_print_date($now, 'dayhour', 'tzuser'),
619 'current_server_date' => dol_print_date($now, 'day', 'tzserver'),
620 'current_server_datehour' => dol_print_date($now, 'dayhour', 'tzserver'),
621 // Date in requested output language
622 'current_date_locale' => dol_print_date($now, 'day', 'tzuser', $outputlangs),
623 'current_datehour_locale' => dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
624 'current_server_date_locale' => dol_print_date($now, 'day', 'tzserver', $outputlangs),
625 'current_server_datehour_locale' => dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
626 );
627
628
629 foreach ($conf->global as $key => $val) {
630 if (isASecretKey($key)) {
631 $newval = '*****forbidden*****';
632 } else {
633 $newval = $val;
634 }
635 $array_other['__['.$key.']__'] = $newval;
636 }
637
638 return $array_other;
639 }
640
641
642 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
652 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
653 {
654 // phpcs:enable
655 global $extrafields;
656
657 $sumpayed = $sumdeposit = $sumcreditnote = '';
658 $already_payed_all = 0;
659
660 if ($object->element == 'facture') {
662 '@phan-var-force Facture $object';
663 $invoice_source = new Facture($this->db);
664 if ($object->fk_facture_source > 0) {
665 $invoice_source->fetch($object->fk_facture_source);
666 }
667 $sumpayed = $object->getSommePaiement();
668 $sumdeposit = $object->getSumDepositsUsed();
669 $sumcreditnote = $object->getSumCreditNotesUsed();
670 $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
671 }
672
673 // Ignore notice for deprecated date - @phan-suppress-next-line PhanUndeclaredProperty
674 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
675
676 if ($object instanceof CommandeFournisseur) {
677 $object->date_validation = $object->date_valid;
678 $object->date_commande = $object->date;
679 }
680 $resarray = array(
681 $array_key.'_id' => $object->id,
682 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
683 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''), // @phan-suppress-current-line PhanUndeclaredProperty
684 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
685 $array_key.'_ref_customer' => (!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
686 $array_key.'_ref_supplier' => (!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), // @phan-suppress-current-line PhanUndeclaredProperty
687 $array_key.'_source_invoice_ref' => ((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
688 // Dates
689 $array_key.'_hour' => dol_print_date($date, 'hour'),
690 $array_key.'_date' => dol_print_date($date, 'day'),
691 $array_key.'_date_rfc' => dol_print_date($date, 'dayrfc'),
692 $array_key.'_date_limit' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
693 $array_key.'_date_limit_rfc' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
694 $array_key.'_date_end' => (!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''), // @phan-suppress-current-line PhanUndeclaredProperty
695 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
696 $array_key.'_date_modification' => (!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
697 $array_key.'_date_validation' => (!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
698 $array_key.'_date_approve' => (!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
699 $array_key.'_date_delivery_planed' => (!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
700 $array_key.'_date_close' => (!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
701
702 $array_key.'_payment_mode_code' => $object->mode_reglement_code,
703 $array_key.'_payment_mode' => ($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code) != 'PaymentType'.$object->mode_reglement_code ? $outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code) : $object->mode_reglement),
704 $array_key.'_payment_term_code' => $object->cond_reglement_code,
705 $array_key.'_payment_term' => ($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code) != 'PaymentCondition'.$object->cond_reglement_code ? $outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code) : ($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement)),
706
707 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
708
709 $array_key.'_total_ht_locale' => price($object->total_ht, 0, $outputlangs),
710 $array_key.'_total_vat_locale' => (!empty($object->total_vat) ? price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)), // @phan-suppress-current-line PhanUndeclaredProperty
711 $array_key.'_total_localtax1_locale' => price($object->total_localtax1, 0, $outputlangs),
712 $array_key.'_total_localtax2_locale' => price($object->total_localtax2, 0, $outputlangs),
713 $array_key.'_total_ttc_locale' => price($object->total_ttc, 0, $outputlangs),
714
715 $array_key.'_total_ht' => price2num($object->total_ht),
716 $array_key.'_total_vat' => (!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)), // @phan-suppress-current-line PhanUndeclaredProperty
717 $array_key.'_total_localtax1' => price2num($object->total_localtax1),
718 $array_key.'_total_localtax2' => price2num($object->total_localtax2),
719 $array_key.'_total_ttc' => price2num($object->total_ttc),
720
721 $array_key.'_multicurrency_code' => $object->multicurrency_code,
722 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
723 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
724 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
725 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
726 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
727 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
728 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
729
730 $array_key.'_note_private' => $object->note_private,
731 $array_key.'_note_public' => $object->note_public,
732 $array_key.'_note' => $object->note_public, // For backward compatibility
733
734 // Payments
735 $array_key.'_already_payed_locale' => price($sumpayed, 0, $outputlangs),
736 $array_key.'_already_payed' => price2num($sumpayed),
737 $array_key.'_already_deposit_locale' => price($sumdeposit, 0, $outputlangs),
738 $array_key.'_already_deposit' => price2num($sumdeposit),
739 $array_key.'_already_creditnote_locale' => price($sumcreditnote, 0, $outputlangs),
740 $array_key.'_already_creditnote' => price2num($sumcreditnote),
741
742 $array_key.'_already_payed_all_locale' => price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
743 $array_key.'_already_payed_all' => price2num($already_payed_all, 'MT'),
744
745 // Remain to pay with all known information (except open direct debit requests)
746 $array_key.'_remain_to_pay_locale' => price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
747 $array_key.'_remain_to_pay' => price2num($object->total_ttc - $already_payed_all, 'MT')
748 );
749
750 if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur'))) {
751 $bank_account = null;
752
753 if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
754 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
755 $bank_account = new Account($this->db);
756 $bank_account->fetch($object->fk_account);
757 }
758
759 $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
760 $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
761 $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
762 $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
763 $resarray[$array_key.'_bank_proprio'] = (empty($bank_account) ? '' : $bank_account->owner_name);
764 $resarray[$array_key.'_bank_address'] = (empty($bank_account) ? '' : $bank_account->address);
765 $resarray[$array_key.'_bank_state'] = (empty($bank_account) ? '' : $bank_account->state);
766 $resarray[$array_key.'_bank_country'] = (empty($bank_account) ? '' : $bank_account->country);
767 }
768
769 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
770 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
771 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
772 } else {
773 $resarray[$array_key.'_total_discount_ht_locale'] = '';
774 $resarray[$array_key.'_total_discount_ht'] = '';
775 }
776
777 // Fetch project information if there is a project assigned to this object
778 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
779 if (!is_object($object->project)) {
780 $object->fetchProject();
781 }
782
783 $resarray[$array_key.'_project_ref'] = $object->project->ref;
784 $resarray[$array_key.'_project_title'] = $object->project->title;
785 $resarray[$array_key.'_project_description'] = $object->project->description;
786 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
787 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
788 } else { // empty replacement
789 $resarray[$array_key.'_project_ref'] = '';
790 $resarray[$array_key.'_project_title'] = '';
791 $resarray[$array_key.'_project_description'] = '';
792 $resarray[$array_key.'_project_date_start'] = '';
793 $resarray[$array_key.'_project_date_end'] = '';
794 }
795
796 // Add vat by rates
797 if (is_array($object->lines) && count($object->lines) > 0) {
798 $totalUp = 0;
799 // Set substitution keys for different VAT rates
800 foreach ($object->lines as $line) {
801 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
802 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
803 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
804 }
805 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
806 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
807 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
808 $vatformated = vatrate($line->tva_tx);
809 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
810 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
811 }
812 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
813 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
814
815 $totalUp += $line->subprice * $line->qty;
816 }
817
818 // Calculate total up and total discount percentage
819 // Note that this added fields does not match a field into database in Dolibarr (Dolibarr manage discount on lines not as a global property of object)
820 $resarray['object_total_up'] = $totalUp;
821 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
822 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
823 $totalDiscount = $object->getTotalDiscount();
824 } else {
825 $totalDiscount = 0;
826 }
827 if (!empty($totalUp) && !empty($totalDiscount)) {
828 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
829 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
830 } else {
831 $resarray['object_total_discount'] = '';
832 $resarray['object_total_discount_locale'] = '';
833 }
834 }
835
836 // Retrieve extrafields
837 if (is_array($object->array_options) && count($object->array_options)) {
838 $object->fetch_optionals();
839
840 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
841 }
842
843 return $resarray;
844 }
845
846 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
856 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
857 {
858 // phpcs:enable
859 $resarray = array(
860 'line_pos' => $linenumber,
861 'line_fulldesc' => doc_getlinedesc($line, $outputlangs),
862
863 'line_product_ref' => (empty($line->product_ref) ? '' : $line->product_ref),
864 'line_product_label' => (empty($line->product_label) ? '' : $line->product_label),
865 'line_product_type' => (empty($line->product_type) ? '' : $line->product_type),
866 'line_product_barcode' => (empty($line->product_barcode) ? '' : $line->product_barcode),
867 'line_product_desc' => (empty($line->product_desc) ? '' : $line->product_desc),
868
869 'line_desc' => $line->desc,
870 'line_vatrate' => vatrate($line->tva_tx, true, $line->info_bits),
871 'line_up' => price2num($line->subprice),
872 'line_up_locale' => price($line->subprice, 0, $outputlangs),
873 'line_total_up' => price2num($line->subprice * (float) $line->qty),
874 'line_total_up_locale' => price($line->subprice * (float) $line->qty, 0, $outputlangs),
875 'line_qty' => $line->qty,
876 'line_discount_percent' => ($line->remise_percent ? $line->remise_percent.'%' : ''),
877 'line_price_ht' => price2num($line->total_ht),
878 'line_price_ttc' => price2num($line->total_ttc),
879 'line_price_vat' => price2num($line->total_tva),
880 'line_price_ht_locale' => price($line->total_ht, 0, $outputlangs),
881 'line_price_ttc_locale' => price($line->total_ttc, 0, $outputlangs),
882 'line_price_vat_locale' => price($line->total_tva, 0, $outputlangs),
883
884 'line_multicurrency_code' => price2num($line->multicurrency_code),
885 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
886 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
887 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
888 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
889 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
890 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
891 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
892 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
893 );
894
895 if (property_exists($line, 'ref_fourn')) {
896 $resarray['line_product_ref_fourn'] = $line->ref_fourn; // for supplier doc lines @phan-suppress-current-line PhanUndeclaredProperty
897 } else {
898 $resarray['line_product_ref_fourn'] = '';
899 }
900 $vat_specs = array(
901 'line_localtax1_rate' => 'localtax1_tx',
902 'line_localtax2_rate' => 'localtax2_tx',
903 );
904 foreach ($vat_specs as $vat_spec) {
905 if (property_exists($line, $vat_spec[1])) {
906 $resarray[$vat_spec[0]] = vatrate($line->${$vat_spec[1]});
907 }
908 }
909
910 // Dates (fields not available on all line classes)
911 $date_specs = array(
912 array('line_date_start', 'date_start', 'day', 'auto', null),
913 array('line_date_start_locale', 'date_start', 'day', 'tzserver', $outputlangs),
914 array('line_date_start_rfc', 'date_start', 'dayrfc', 'auto', null),
915 array('line_date_end', 'date_end', 'day', 'auto', null),
916 array('line_date_end_locale', 'date_end', 'day', 'tzserver', $outputlangs),
917 array('line_date_end_rfc', 'date_end', 'dayrfc', 'auto', null)
918 );
919 foreach ($date_specs as $date_spec) {
920 if (property_exists($line, $date_spec[1])) {
921 $resarray[$date_spec[0]] = dol_print_date($line->${$date_spec[1]}, $date_spec[2], $date_spec[3], $date_spec[4]);
922 }
923 }
924
925 // Units
926 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
927 $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
928 $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
929 }
930
931 // Retrieve extrafields
932 $extrafieldkey = $line->table_element;
933 $array_key = "line";
934 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
935 $extrafields = new ExtraFields($this->db);
936 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
937 $line->fetch_optionals();
938
939 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
940
941 // Check if the current line belongs to a supplier order
942 if (get_class($line) == 'CommandeFournisseurLigne') {
943 // Add the product supplier extrafields to the substitutions
944 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
945 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
946
947 if (!empty($extralabels) && is_array($extralabels)) {
948 $columns = "";
949
950 foreach ($extralabels as $key => $label) {
951 $columns .= "$key, ";
952 }
953
954 if ($columns != "") {
955 $columns = substr($columns, 0, strlen($columns) - 2);
956 $resql = $this->db->query("SELECT ".$columns." FROM ".$this->db->prefix()."product_fournisseur_price_extrafields AS ex INNER JOIN ".$this->db->prefix()."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'");
957
958 if ($this->db->num_rows($resql) > 0) {
959 $resql = $this->db->fetch_object($resql);
960
961 foreach ($extralabels as $key => $label) {
962 $resarray['line_product_supplier_'.$key] = $resql->$key;
963 }
964 }
965 }
966 }
967 }
968
969 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
970 if (isset($line->fk_product) && $line->fk_product > 0) {
971 $tmpproduct = new Product($this->db);
972 $result = $tmpproduct->fetch($line->fk_product);
973 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
974 foreach ($tmpproduct->array_options as $key => $label) {
975 $resarray["line_product_".$key] = $label;
976 }
977 }
978 } else {
979 // Set unused placeholders as blank
980 $extrafields->fetch_name_optionals_label("product");
981 if ($extrafields->attributes["product"]['count'] > 0) {
982 $extralabels = $extrafields->attributes["product"]['label'];
983
984 foreach ($extralabels as $key => $label) {
985 $resarray['line_product_options_'.$key] = '';
986 }
987 }
988 }
989
990 return $resarray;
991 }
992
993 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1003 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
1004 {
1005 // phpcs:enable
1006 global $extrafields;
1007
1008 include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
1009
1010 $object->list_delivery_methods($object->shipping_method_id);
1011 $calculatedVolume = ((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth);
1012
1013 $array_shipment = array(
1014 $array_key.'_id' => $object->id,
1015 $array_key.'_ref' => $object->ref,
1016 $array_key.'_ref_ext' => $object->ref_ext,
1017 $array_key.'_ref_customer' => $object->ref_customer,
1018 $array_key.'_date_delivery' => dol_print_date($object->date_delivery, 'day'),
1019 $array_key.'_hour_delivery' => dol_print_date($object->date_delivery, 'hour'),
1020 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
1021 $array_key.'_total_ht' => price($object->total_ht),
1022 $array_key.'_total_vat' => price($object->total_tva),
1023 $array_key.'_total_ttc' => price($object->total_ttc),
1024 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
1025 $array_key.'_note_private' => $object->note_private,
1026 $array_key.'_note' => $object->note_public,
1027 $array_key.'_tracking_number' => $object->tracking_number,
1028 $array_key.'_tracking_url' => $object->tracking_url,
1029 $array_key.'_shipping_method' => $object->listmeths[0]['libelle'],
1030 $array_key.'_weight' => $object->trueWeight.' '.measuringUnitString(0, 'weight', (string) $object->weight_units),
1031 $array_key.'_width' => $object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
1032 $array_key.'_height' => $object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
1033 $array_key.'_depth' => $object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
1034 $array_key.'_size' => $calculatedVolume.' '.measuringUnitString(0, 'volume'),
1035 );
1036
1037 // Add vat by rates
1038 foreach ($object->lines as $line) {
1039 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
1040 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
1041 }
1042 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
1043 }
1044
1045 // Retrieve extrafields
1046 if (is_array($object->array_options) && count($object->array_options)) {
1047 $object->fetch_optionals();
1048
1049 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
1050 }
1051
1052 // Add info from $object->xxx where xxx has been loaded by fetch_origin() of shipment
1053 if (is_object($object->commande) && !empty($object->commande->ref)) {
1054 $array_shipment['order_ref'] = $object->commande->ref;
1055 $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
1056 }
1057
1058 return $array_shipment;
1059 }
1060
1061
1062 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1071 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
1072 {
1073 // phpcs:enable
1074 $array_other = array();
1075 if (is_array($object) && count($object)) {
1076 foreach ($object as $key => $value) {
1077 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
1078 continue;
1079 }
1080 if (!empty($value)) {
1081 if (!is_array($value) && !is_object($value)) {
1082 $array_other['object_'.$key] = $value;
1083 } elseif (is_array($value) && $recursive) {
1084 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1085 if (!empty($tmparray) && is_array($tmparray)) {
1086 foreach ($tmparray as $key2 => $value2) {
1087 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1088 }
1089 }
1090 } elseif (is_object($value) && $recursive) {
1091 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1092 if (!empty($tmparray) && is_array($tmparray)) {
1093 foreach ($tmparray as $key2 => $value2) {
1094 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1095 }
1096 }
1097 }
1098 }
1099 }
1100 }
1101
1102 return $array_other;
1103 }
1104
1105
1106 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1118 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
1119 {
1120 // phpcs:enable
1121 global $conf;
1122
1123 if ($extrafields->attributes[$object->table_element]['count'] > 0) {
1124 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1125 $formatedarrayoption = $object->array_options;
1126
1127 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
1128 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
1129 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
1130 //Add value to store price with currency
1131 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
1132 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
1133 $valueofselectkey = $formatedarrayoption['options_'.$key];
1134 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
1135 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
1136 } else {
1137 $formatedarrayoption['options_'.$key] = '';
1138 }
1139 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
1140 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
1141 $output = array();
1142 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
1143 if (in_array($keyopt, $valArray)) {
1144 $output[] = $valopt;
1145 }
1146 }
1147 $formatedarrayoption['options_'.$key] = implode(', ', $output);
1148 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
1149 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
1150 $date = $formatedarrayoption['options_'.$key];
1151 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
1152 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
1153 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
1154 } else {
1155 $formatedarrayoption['options_'.$key] = '';
1156 $formatedarrayoption['options_'.$key.'_locale'] = '';
1157 $formatedarrayoption['options_'.$key.'_rfc'] = '';
1158 }
1159 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1160 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1161 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1162 $datetime = $formatedarrayoption['options_'.$key];
1163 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1164 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1165 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1166 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1167 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1168 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1169 $id = $formatedarrayoption['options_'.$key];
1170 if ($id != "") {
1171 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1172 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1173 $InfoFieldList = explode(":", $param_list[0]);
1174 $classname = $InfoFieldList[0];
1175 $classpath = $InfoFieldList[1];
1176 if (!empty($classpath)) {
1177 dol_include_once($InfoFieldList[1]);
1178 if ($classname && class_exists($classname)) {
1179 $tmpobject = new $classname($this->db);
1180 '@phan-var-force CommonObject $tmpobject';
1181 $tmpobject->fetch($id);
1182 // completely replace the id with the linked object name
1183 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1184 }
1185 }
1186 }
1187 }
1188
1189 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1190 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1191 } else {
1192 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1193 }
1194 }
1195 }
1196
1197 return $array_to_fill;
1198 }
1199
1200
1213 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1214 {
1215 if (empty($hidetop) || $hidetop == -1) {
1216 $pdf->line($x, $y, $x + $l, $y);
1217 }
1218 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1219 if (empty($hidebottom)) {
1220 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1221 }
1222 $pdf->line($x, $y + $h, $x, $y);
1223 }
1224
1239 public function printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop = 0, $hidebottom = 0, $style = 'D')
1240 {
1241 // Top line
1242 if (empty($hidetop) || $hidetop == -1) {
1243 $pdf->RoundedRect($x, $y, $w, $h, $r, '1111', $style);
1244 } else {
1245 // Draw rounded rectangle with hidden top side
1246 $pdf->RoundedRect($x, $y, $w, $h, $r, '0111', $style);
1247 }
1248 if (!empty($hidebottom)) {
1249 $pdf->RoundedRect($x, $y, $w, $h, $r, '1101', $style);
1250 }
1251 }
1252
1260 public function columnSort($a, $b)
1261 {
1262 if (empty($a['rank'])) {
1263 $a['rank'] = 0;
1264 }
1265 if (empty($b['rank'])) {
1266 $b['rank'] = 0;
1267 }
1268 if ($a['rank'] == $b['rank']) {
1269 return 0;
1270 }
1271 return ($a['rank'] > $b['rank']) ? -1 : 1;
1272 }
1273
1284 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1285 {
1286 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1287
1288
1289 // Sorting
1290 uasort($this->cols, array($this, 'columnSort'));
1291
1292 // Positioning
1293 $curX = $this->page_largeur - $this->marge_droite; // start from right
1294
1295 // Array width
1296 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1297
1298 // Count flexible column
1299 $totalDefinedColWidth = 0;
1300 $countFlexCol = 0;
1301 foreach ($this->cols as $colKey => & $colDef) {
1302 if (!$this->getColumnStatus($colKey)) {
1303 continue; // continue if disabled
1304 }
1305
1306 if (!empty($colDef['scale'])) {
1307 // In case of column width is defined by percentage
1308 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1309 }
1310
1311 if (empty($colDef['width'])) {
1312 $countFlexCol++;
1313 } else {
1314 $totalDefinedColWidth += $colDef['width'];
1315 }
1316 }
1317
1318 foreach ($this->cols as $colKey => & $colDef) {
1319 // setting empty conf with default
1320 if (!empty($colDef['title'])) {
1321 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1322 } else {
1323 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1324 }
1325
1326 // setting empty conf with default
1327 if (!empty($colDef['content'])) {
1328 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1329 } else {
1330 $colDef['content'] = $this->defaultContentsFieldsStyle;
1331 }
1332
1333 if ($this->getColumnStatus($colKey)) {
1334 // In case of flexible column
1335 if (empty($colDef['width'])) {
1336 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1337 }
1338
1339 // Set positions
1340 $lastX = $curX;
1341 $curX = $lastX - $colDef['width'];
1342 $colDef['xStartPos'] = $curX;
1343 $colDef['xEndPos'] = $lastX;
1344 }
1345 }
1346 }
1347
1354 public function getColumnContentWidth($colKey)
1355 {
1356 $colDef = $this->cols[$colKey];
1357 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1358 }
1359
1360
1367 public function getColumnContentXStart($colKey)
1368 {
1369 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1370 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1371 }
1372
1379 public function getColumnRank($colKey)
1380 {
1381 if (!isset($this->cols[$colKey]['rank'])) {
1382 return -1;
1383 }
1384 return $this->cols[$colKey]['rank'];
1385 }
1386
1396 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1397 {
1398 // prepare wanted rank
1399 $rank = -1;
1400
1401 // try to get rank from target column
1402 if (!empty($targetCol)) {
1403 $rank = $this->getColumnRank($targetCol);
1404 if ($rank >= 0 && $insertAfterTarget) {
1405 $rank++;
1406 }
1407 }
1408
1409 // get rank from new column definition
1410 if ($rank < 0 && !empty($defArray['rank'])) {
1411 $rank = $defArray['rank'];
1412 }
1413
1414 // error: no rank
1415 if ($rank < 0) {
1416 return -1;
1417 }
1418
1419 foreach ($this->cols as $colKey => & $colDef) {
1420 if ($rank <= $colDef['rank']) {
1421 $colDef['rank'] += 1;
1422 }
1423 }
1424
1425 $defArray['rank'] = $rank;
1426 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1427
1428 return $rank;
1429 }
1430
1431
1441 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1442 {
1443 global $hookmanager;
1444
1445 $parameters = array(
1446 'curY' => &$curY,
1447 'columnText' => $columnText,
1448 'colKey' => $colKey,
1449 'pdf' => &$pdf,
1450 );
1451 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1452 if ($reshook < 0) {
1453 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1454 }
1455 if (!$reshook) {
1456 if (empty($columnText)) {
1457 return 0;
1458 }
1459 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
1460 $colDef = $this->cols[$colKey];
1461 // save current cell padding
1462 $curentCellPaddinds = $pdf->getCellPaddings();
1463 // set cell padding with column content definition
1464 $pdf->setCellPaddings(isset($colDef['content']['padding'][3]) ? $colDef['content']['padding'][3] : 0, isset($colDef['content']['padding'][0]) ? $colDef['content']['padding'][0] : 0, isset($colDef['content']['padding'][1]) ? $colDef['content']['padding'][1] : 0, isset($colDef['content']['padding'][2]) ? $colDef['content']['padding'][2] : 0);
1465 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1466
1467 // restore cell padding
1468 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1469 }
1470
1471 return 0;
1472 }
1473
1474
1489 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1490 {
1491 // load desc col params
1492 $colDef = $this->cols[$colKey];
1493 // save current cell padding
1494 $curentCellPaddinds = $pdf->getCellPaddings();
1495 // set cell padding with column content definition
1496 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1497
1498 // line description
1499 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline, empty($colDef['content']['align']) ? 'J' : $colDef['content']['align']);
1500 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1501
1502 // restore cell padding
1503 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1504
1505 // Display extrafield if needed
1506 $params = array(
1507 'display' => 'list',
1508 'printableEnable' => array(3),
1509 'printableEnableNotEmpty' => array(4)
1510 );
1511 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1512 if (!empty($extrafieldDesc)) {
1513 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1514 }
1515 }
1516
1526 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1527 {
1528 global $hookmanager;
1529
1530 if (empty($object->table_element)) {
1531 return '';
1532 }
1533
1534 $extrafieldsKeyPrefix = "options_";
1535
1536 // Cleanup extrafield key to remove prefix if present
1537 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1538 if ($pos === 0) {
1539 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1540 }
1541
1542 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1543
1544
1545 // Load extra fields if they haven't been loaded already.
1546 if (is_null($this->extrafieldsCache)) {
1547 $this->extrafieldsCache = new ExtraFields($this->db);
1548 }
1549 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1550 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1551 }
1552 $extrafields = $this->extrafieldsCache;
1553
1554 $extrafieldOutputContent = '';
1555 if (isset($object->array_options[$extrafieldOptionsKey])) {
1556 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1557 }
1558
1559 // TODO : allow showOutputField to be pdf public friendly, ex: in a link to object, clean getNomUrl to remove link and images... like a getName methode ...
1560 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1561 // for lack of anything better we cleanup all html tags
1562 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1563 }
1564
1565 $parameters = array(
1566 'object' => $object,
1567 'extrafields' => $extrafields,
1568 'extrafieldKey' => $extrafieldKey,
1569 'extrafieldOutputContent' => & $extrafieldOutputContent
1570 );
1571 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1572 if ($reshook < 0) {
1573 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1574 }
1575 if ($reshook) {
1576 $extrafieldOutputContent = $hookmanager->resPrint;
1577 }
1578
1579 return $extrafieldOutputContent;
1580 }
1581
1582
1591 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1592 {
1593 global $hookmanager;
1594
1595 if (empty($object->table_element)) {
1596 return "";
1597 }
1598
1599 // Load extrafields if not already done
1600 if (is_null($this->extrafieldsCache)) {
1601 $this->extrafieldsCache = new ExtraFields($this->db);
1602 }
1603 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1604 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1605 }
1606 $extrafields = $this->extrafieldsCache;
1607
1608 $defaultParams = array(
1609 'style' => '',
1610 'display' => 'auto', // auto, table, list
1611 'printableEnable' => array(1),
1612 'printableEnableNotEmpty' => array(2),
1613
1614 'table' => array(
1615 'maxItemsInRow' => 2,
1616 'cellspacing' => 0,
1617 'cellpadding' => 0,
1618 'border' => 0,
1619 'labelcolwidth' => '25%',
1620 'arrayOfLineBreakType' => array('text', 'html')
1621 ),
1622
1623 'list' => array(
1624 'separator' => '<br>'
1625 ),
1626
1627 'auto' => array(
1628 'list' => 0, // 0 for default
1629 'table' => 4 // if there more than x extrafield to display
1630 ),
1631 );
1632
1633 $params += $defaultParams;
1634
1639 $html = '';
1640 $fields = array();
1641
1642 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1643 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1644 // Enable extrafield ?
1645 $enabled = 0;
1646 $disableOnEmpty = 0;
1647 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1648 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1649 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1650 $enabled = 1;
1651 }
1652
1653 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1654 $disableOnEmpty = 1;
1655 }
1656 }
1657
1658 if (empty($enabled)) {
1659 continue;
1660 }
1661
1662 // Load language if required
1663 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1664 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1665 }
1666
1667 $field = new stdClass();
1668 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1669 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1670 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1671 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1672 }
1673 $field->label = $outputlangs->transnoentities($label);
1674 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1675
1676 // don't display if empty
1677 if ($disableOnEmpty && empty($field->content)) {
1678 continue;
1679 }
1680
1681 $fields[] = $field;
1682 }
1683 }
1684
1685 if (!empty($fields)) {
1686 // Sort extrafields by rank
1687 uasort(
1688 $fields,
1694 static function ($a, $b) {
1695 return ($a->rank > $b->rank) ? 1 : -1;
1696 }
1697 );
1698
1699 // define some HTML content with style
1700 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1701
1702 // auto select display format
1703 if ($params['display'] == 'auto') {
1704 $lastNnumbItems = 0;
1705 foreach ($params['auto'] as $display => $numbItems) {
1706 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1707 $lastNnumbItems = $numbItems;
1708 $params['display'] = $display;
1709 }
1710 }
1711 }
1712
1713 if ($params['display'] == 'list') {
1714 // Display in list format
1715 $i = 0;
1716 foreach ($fields as $field) {
1717 $html .= !empty($i) ? $params['list']['separator'] : '';
1718 $html .= '<strong>'.$field->label.' : </strong>';
1719 $html .= $field->content;
1720 $i++;
1721 }
1722 } elseif ($params['display'] == 'table') {
1723 // Display in table format
1724 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1725
1726 $html .= "<tr>";
1727 $itemsInRow = 0;
1728 $maxItemsInRow = $params['table']['maxItemsInRow'];
1729 foreach ($fields as $field) {
1730 //$html.= !empty($html)?'<br>':'';
1731 if ($itemsInRow >= $maxItemsInRow) {
1732 // start a new line
1733 $html .= "</tr><tr>";
1734 $itemsInRow = 0;
1735 }
1736
1737 // for some type we need line break
1738 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1739 if ($itemsInRow > 0) {
1740 // close table row and empty cols
1741 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1742 $html .= "<td></td><td></td>";
1743 }
1744 $html .= "</tr>";
1745
1746 // start a new line
1747 $html .= "<tr>";
1748 }
1749
1750 $itemsInRow = $maxItemsInRow;
1751 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1752 $html .= '<strong>'.$field->label.' :</strong> ';
1753 $html .= $field->content;
1754 $html .= "</td>";
1755 } else {
1756 $itemsInRow++;
1757 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1758 $html .= '<strong>'.$field->label.' :</strong>';
1759 $html .= "</td>";
1760
1761
1762 $html .= '<td class="extrafield-content">';
1763 $html .= $field->content;
1764 $html .= "</td>";
1765 }
1766 }
1767 $html .= "</tr>";
1768
1769 $html .= '</table>';
1770 }
1771 }
1772
1773 return $html;
1774 }
1775
1776
1783 public function getColumnStatus($colKey)
1784 {
1785 if (!empty($this->cols[$colKey]['status'])) {
1786 return true;
1787 } else {
1788 return false;
1789 }
1790 }
1791
1802 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1803 {
1804 global $hookmanager, $conf;
1805
1806 foreach ($this->cols as $colKey => $colDef) {
1807 $parameters = array(
1808 'colKey' => $colKey,
1809 'pdf' => $pdf,
1810 'outputlangs' => $outputlangs,
1811 'tab_top' => $tab_top,
1812 'tab_height' => $tab_height,
1813 'hidetop' => $hidetop
1814 );
1815
1816 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1817 if ($reshook < 0) {
1818 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1819 } elseif (empty($reshook)) {
1820 if (!$this->getColumnStatus($colKey)) {
1821 continue;
1822 }
1823
1824 // get title label
1825 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1826
1827 // Add column separator
1828 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
1829 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1830 }
1831
1832 if (empty($hidetop)) {
1833 // save current cell padding
1834 $curentCellPaddinds = $pdf->getCellPaddings();
1835
1836 // Add space for lines (more if we need to show a second alternative language)
1837 global $outputlangsbis;
1838 if (is_object($outputlangsbis)) {
1839 // set cell padding with column title definition
1840 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1841 } else {
1842 // set cell padding with column title definition
1843 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1844 }
1845 if (isset($colDef['title']['align'])) {
1846 $align = $colDef['title']['align'];
1847 } else {
1848 $align = '';
1849 }
1850 $pdf->SetXY($colDef['xStartPos'], $tab_top);
1851 $textWidth = $colDef['width'];
1852 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
1853
1854 // Add variant of translation if $outputlangsbis is an object
1855 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1856 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1857 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1858 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1859 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
1860 }
1861
1862 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1863
1864 // restore cell padding
1865 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1866 }
1867 }
1868 }
1869
1870 return $this->tabTitleHeight;
1871 }
1872
1873
1874
1883 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1884 {
1885 if (!empty($hidedetails)) {
1886 return 0;
1887 }
1888
1889 if (empty($object->table_element)) {
1890 return 0;
1891 }
1892
1893 // Load extra fields if they haven't been loaded already.
1894 if (is_null($this->extrafieldsCache)) {
1895 $this->extrafieldsCache = new ExtraFields($this->db);
1896 }
1897 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1898 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1899 }
1900 $extrafields = $this->extrafieldsCache;
1901
1902
1903 if (!empty($extrafields->attributes[$object->table_element]) && is_array($extrafields->attributes[$object->table_element]) && array_key_exists('label', $extrafields->attributes[$object->table_element]) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1904 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1905 // Don't display separator yet even is set to be displayed (not compatible yet)
1906 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1907 continue;
1908 }
1909
1910 // Enable extrafield ?
1911 $enabled = 0;
1912 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1913 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1914 if ($printable === 1 || $printable === 2) {
1915 $enabled = 1;
1916 }
1917 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1918 }
1919
1920 if (!$enabled) {
1921 continue;
1922 } // don't waste resources if we don't need them...
1923
1924 // Load language if required
1925 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1926 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1927 }
1928
1929 // TODO : add more extrafield customisation capacities for PDF like width, rank...
1930
1931 // set column definition
1932 $def = array(
1933 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1934 'width' => 25, // in mm
1935 'status' => (bool) $enabled,
1936 'title' => array(
1937 'label' => $outputlangs->transnoentities($label)
1938 ),
1939 'content' => array(
1940 'align' => 'C'
1941 ),
1942 'border-left' => true, // add left line separator
1943 );
1944
1945 $alignTypeRight = array('double', 'int', 'price');
1946 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1947 $def['content']['align'] = 'R';
1948 }
1949
1950 $alignTypeLeft = array('text', 'html');
1951 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1952 $def['content']['align'] = 'L';
1953 }
1954
1955
1956 // for extrafields we use rank of extrafield to place it on PDF
1957 $this->insertNewColumnDef("options_".$key, $def);
1958 }
1959 }
1960
1961 return 1;
1962 }
1963
1975 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1976 {
1977 // Default field style for content
1978 $this->defaultContentsFieldsStyle = array(
1979 'align' => 'R', // R,C,L
1980 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1981 );
1982
1983 // Default field style for content
1984 $this->defaultTitlesFieldsStyle = array(
1985 'align' => 'C', // R,C,L
1986 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1987 );
1988
1989 // Example
1990 /*
1991 $rank = 0; // do not use negative rank
1992 $this->cols['desc'] = array(
1993 'rank' => $rank,
1994 'width' => false, // only for desc
1995 'status' => true,
1996 'title' => array(
1997 'textkey' => 'Designation', // use lang key is useful in somme case with module
1998 'align' => 'L',
1999 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2000 // 'label' => ' ', // the final label
2001 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2002 ),
2003 'content' => array(
2004 'align' => 'L',
2005 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2006 ),
2007 );
2008 */
2009 }
2010}
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$object ref
Definition info.php:79
Class to manage bank accounts.
Class to manage predefined suppliers products.
Parent class for documents (PDF, ODT, ...) generators.
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
insertNewColumnDef($newColKey, $defArray, $targetCol='', $insertAfterTarget=false)
get column position rank from column key
getSubstitutionarrayMember($member, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive=1)
Define array with couple substitution key => substitution value.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple substitution key => substitution value.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
get_substitutionarray_contact($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
get_substitutionarray_other($outputlangs)
Define array with couple substitution key => substitution value.
columnSort($a, $b)
uasort callback function to Sort columns fields
fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
Fill array with couple extrafield key => extrafield value Note that vars into substitutions array are...
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getColumnContentWidth($colKey)
get column content width from column key
getColumnRank($colKey)
get column position rank from column key
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
get_substitutionarray_lines($line, $outputlangs, $linenumber=0)
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field into $this->cols This method must be implemented by the module that generat...
get_substitutionarray_thirdparty($object, $outputlangs, $array_key='company')
Define array with couple substitution key => substitution value For example {company_name}...
get_substitutionarray_user($user, $outputlangs)
Define array with couple substitution key => substitution value.
Class to manage standard extra fields.
Class to manage invoices.
Class to manage products or services.
display_incoterms()
Return incoterms information TODO Use a cache for label get.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
doc_getlinedesc($line, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
Return line description translated in outputlangs and encoded into UTF8.
Definition doc.lib.php:41
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1442
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.