dolibarr 23.0.3
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-2025 Charlene Benke <charlene@patas-monkey.com>
8 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
10 * Copyright (C) 2024-2025 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 public $warnings = array();
65
69 protected $db;
70
74 public $extrafieldsCache;
75
79 public $update_main_doc_field;
80
84 public $scandir;
85
89 public $description;
90
94 public $format;
95
99 public $type;
100
104 public $page_hauteur;
105
109 public $page_largeur;
110
114 public $marge_gauche;
115
119 public $marge_droite;
120
124 public $marge_haute;
125
129 public $marge_basse;
130
134 public $corner_radius;
135
139 public $option_logo;
143 public $option_tva;
147 public $option_multilang;
151 public $option_freetext;
155 public $option_draft_watermark;
159 public $watermark;
160
164 public $option_modereg;
168 public $option_condreg;
172 public $option_escompte;
176 public $option_credit_note;
177
181 public $tva;
185 public $tva_array;
191 public $localtax1;
192
198 public $localtax2;
199
203 public $tabTitleHeight;
204
208 public $defaultTitlesFieldsStyle;
209
213 public $defaultContentsFieldsStyle;
214
218 public $emetteur;
219
224 public $phpmin = array(7, 1);
225
229 public $cols;
230
234 public $afterColsLinePositions;
235
239 public $result;
240
244 public $posxlabel;
248 public $posxup;
252 public $posxref;
256 public $posxpicture; // For picture
260 public $posxdesc; // For description
264 public $posxqty;
268 public $posxpuht;
272 public $posxtva;
276 public $posxtotalht;
280 public $postotalht;
284 public $posxunit;
288 public $posxdiscount;
292 public $posxworkload;
296 public $posxtimespent;
300 public $posxprogress;
304 public $atleastonephoto;
308 public $atleastoneratenotnull;
312 public $atleastonediscount;
313
319 public function __construct($db)
320 {
321 $this->db = $db;
322 }
323
324
325 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
333 public function get_substitutionarray_user($user, $outputlangs)
334 {
335 // phpcs:enable
336 global $conf, $extrafields;
337
338 $logotouse = $conf->user->dir_output . '/' . get_exdir(0, 0, 0, 0, $user, 'user') . 'photos/' . getImageFileNameForSize($user->photo, '_small');
339
340 $array_user = array(
341 'myuser_lastname' => $user->lastname,
342 'myuser_firstname' => $user->firstname,
343 'myuser_fullname' => $user->getFullName($outputlangs, 1),
344 'myuser_login' => $user->login,
345 'myuser_phone' => $user->office_phone,
346 'myuser_address' => $user->address,
347 'myuser_zip' => $user->zip,
348 'myuser_town' => $user->town,
349 'myuser_country' => $user->country,
350 'myuser_country_code' => $user->country_code,
351 'myuser_state' => $user->state,
352 'myuser_state_code' => $user->state_code,
353 'myuser_fax' => $user->office_fax,
354 'myuser_mobile' => $user->user_mobile,
355 'myuser_email' => $user->email,
356 'myuser_logo' => $logotouse,
357 'myuser_job' => $user->job,
358 'myuser_web' => '', // url not exist in $user object
359 'myuser_birth' => dol_print_date($user->birth, 'day', 'gmt'),
360 'myuser_dateemployment' => dol_print_date($user->dateemployment, 'day', 'tzuser'),
361 'myuser_dateemploymentend' => dol_print_date($user->dateemploymentend, 'day', 'tzuser'),
362 'myuser_gender' => $user->gender,
363 );
364 // Retrieve extrafields
365 if (is_array($user->array_options) && count($user->array_options)) {
366 if (empty($extrafields->attributes[$user->table_element])) {
367 $extrafields->fetch_name_optionals_label($user->table_element);
368 }
369 $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
370 }
371 return $array_user;
372 }
373
374
382 public function getSubstitutionarrayMember($member, $outputlangs)
383 {
384 global $conf, $extrafields;
385
386 if ($member->photo) {
387 $logotouse = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
388 } else {
389 $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
390 }
391
392 $array_member = array(
393 'mymember_lastname' => $member->lastname,
394 'mymember_firstname' => $member->firstname,
395 'mymember_fullname' => $member->getFullName($outputlangs, 1),
396 'mymember_login' => $member->login,
397 'mymember_address' => $member->address,
398 'mymember_zip' => $member->zip,
399 'mymember_town' => $member->town,
400 'mymember_country_code' => $member->country_code,
401 'mymember_country' => $member->country,
402 'mymember_state_code' => $member->state_code,
403 'mymember_state' => $member->state,
404 'mymember_phone_perso' => $member->phone_perso,
405 'mymember_phone_pro' => $member->phone,
406 'mymember_phone_mobile' => $member->phone_mobile,
407 'mymember_email' => $member->email,
408 'mymember_logo' => $logotouse,
409 'mymember_gender' => $member->gender,
410 'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
411 'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
412 );
413 // Retrieve extrafields
414 if (is_array($member->array_options) && count($member->array_options)) {
415 $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
416 }
417 return $array_member;
418 }
419
420
421 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
429 public function get_substitutionarray_mysoc($mysoc, $outputlangs)
430 {
431 // phpcs:enable
432 global $conf;
433
434 if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
435 $mysoc->forme_juridique = getFormeJuridiqueLabel((string) $mysoc->forme_juridique_code);
436 }
437 if (empty($mysoc->country) && !empty($mysoc->country_code)) {
438 $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
439 }
440 if (empty($mysoc->state) && !empty($mysoc->state_code)) {
441 $state_id = dol_getIdFromCode($this->db, $mysoc->state_code, 'c_departements', 'code_departement', 'rowid');
442 $mysoc->state = getState($state_id, '0');
443 }
444
445 $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
446
447 return array(
448 'mycompany_logo' => $logotouse,
449 'mycompany_name' => $mysoc->name,
450 'mycompany_email' => $mysoc->email,
451 'mycompany_phone' => $mysoc->phone,
452 'mycompany_fax' => $mysoc->fax,
453 'mycompany_address' => $mysoc->address,
454 'mycompany_zip' => $mysoc->zip,
455 'mycompany_town' => $mysoc->town,
456 'mycompany_country' => $mysoc->country,
457 'mycompany_country_code' => $mysoc->country_code,
458 'mycompany_state' => $mysoc->state,
459 'mycompany_state_code' => $mysoc->state_code,
460 'mycompany_web' => $mysoc->url,
461 'mycompany_juridicalstatus' => $mysoc->forme_juridique,
462 'mycompany_managers' => $mysoc->managers,
463 'mycompany_capital' => $mysoc->capital,
464 'mycompany_barcode' => $mysoc->barcode,
465 'mycompany_idprof1' => $mysoc->idprof1,
466 'mycompany_idprof2' => $mysoc->idprof2,
467 'mycompany_idprof3' => $mysoc->idprof3,
468 'mycompany_idprof4' => $mysoc->idprof4,
469 'mycompany_idprof5' => $mysoc->idprof5,
470 'mycompany_idprof6' => $mysoc->idprof6,
471 'mycompany_vatnumber' => $mysoc->tva_intra,
472 'mycompany_socialobject' => $mysoc->socialobject,
473 'mycompany_note_private' => $mysoc->note_private,
474 //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
475 );
476 }
477
478
479 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
489 public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
490 {
491 // phpcs:enable
492 global $extrafields;
493
494 if (!is_object($object)) {
495 return array();
496 }
497
498 if (empty($object->country) && !empty($object->country_code)) {
499 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
500 }
501 if (empty($object->state) && !empty($object->state_code)) {
502 $state_id = dol_getIdFromCode($this->db, $object->state_code, 'c_departements', 'code_departement', 'rowid');
503 $object->state = getState($state_id, '0');
504 }
505
506 $array_thirdparty = array(
507 'company_name' => $object->name,
508 'company_name_alias' => $object->name_alias,
509 'company_email' => $object->email,
510 'company_phone' => $object->phone,
511 'company_fax' => $object->fax,
512 'company_address' => $object->address,
513 'company_zip' => $object->zip,
514 'company_town' => $object->town,
515 'company_country' => $object->country,
516 'company_country_code' => $object->country_code,
517 'company_state' => $object->state,
518 'company_state_code' => $object->state_code,
519 'company_web' => $object->url,
520 'company_barcode' => $object->barcode,
521 'company_vatnumber' => $object->tva_intra,
522 'company_customercode' => $object->code_client,
523 'company_suppliercode' => $object->code_fournisseur,
524 'company_customeraccountancycode' => $object->code_compta_client,
525 'company_supplieraccountancycode' => $object->code_compta_fournisseur,
526 'company_juridicalstatus' => $object->forme_juridique,
527 'company_outstanding_limit' => $object->outstanding_limit,
528 'company_capital' => $object->capital,
529 'company_capital_formated' => price($object->capital, 0, '', 1, -1),
530 'company_idprof1' => $object->idprof1,
531 'company_idprof2' => $object->idprof2,
532 'company_idprof3' => $object->idprof3,
533 'company_idprof4' => $object->idprof4,
534 'company_idprof5' => $object->idprof5,
535 'company_idprof6' => $object->idprof6,
536 'company_note_public' => $object->note_public,
537 'company_note_private' => $object->note_private,
538 'company_default_bank_iban' => (is_object($object->bank_account) ? $object->bank_account->iban : ''),
539 'company_default_bank_bic' => (is_object($object->bank_account) ? $object->bank_account->bic : '')
540 );
541
542 // Retrieve extrafields
543 if (is_array($object->array_options) && count($object->array_options)) {
544 $object->fetch_optionals();
545
546 $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
547 }
548 return $array_thirdparty;
549 }
550
551 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
560 public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
561 {
562 // phpcs:enable
563 global $conf, $extrafields;
564
565 if (empty($object->country) && !empty($object->country_code)) {
566 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
567 }
568 if (empty($object->state) && !empty($object->state_code)) {
569 $state_id = dol_getIdFromCode($this->db, $object->state_code, 'c_departements', 'code_departement', 'rowid');
570 $object->state = getState($state_id, '0');
571 }
572
573 $array_contact = array(
574 $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
575 $array_key.'_lastname' => $object->lastname,
576 $array_key.'_firstname' => $object->firstname,
577 $array_key.'_address' => $object->address,
578 $array_key.'_zip' => $object->zip,
579 $array_key.'_town' => $object->town,
580 $array_key.'_state_id' => $object->state_id,
581 $array_key.'_state_code' => $object->state_code,
582 $array_key.'_state' => $object->state,
583 $array_key.'_country_id' => $object->country_id,
584 $array_key.'_country_code' => $object->country_code,
585 $array_key.'_country' => $object->country,
586 $array_key.'_poste' => $object->poste,
587 $array_key.'_socid' => $object->socid,
588 $array_key.'_statut' => $object->statut,
589 $array_key.'_code' => $object->code,
590 $array_key.'_email' => $object->email,
591 $array_key.'_phone_pro' => $object->phone_pro,
592 $array_key.'_phone_perso' => $object->phone_perso,
593 $array_key.'_phone_mobile' => $object->phone_mobile,
594 $array_key.'_fax' => $object->fax,
595 $array_key.'_birthday' => $object->birthday,
596 $array_key.'_default_lang' => $object->default_lang,
597 $array_key.'_note_public' => $object->note_public,
598 $array_key.'_note_private' => $object->note_private,
599 $array_key.'_civility' => $object->civility,
600 );
601
602 // Retrieve extrafields
603 if (is_array($object->array_options) && count($object->array_options)) {
604 $object->fetch_optionals();
605
606 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
607 }
608 return $array_contact;
609 }
610
611
612 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
619 public function get_substitutionarray_other($outputlangs)
620 {
621 // phpcs:enable
622 global $conf;
623
624 $now = dol_now('gmt'); // gmt
625 $array_other = array(
626 // Date in default language
627 'current_date' => dol_print_date($now, 'day', 'tzuser'),
628 'current_datehour' => dol_print_date($now, 'dayhour', 'tzuser'),
629 'current_server_date' => dol_print_date($now, 'day', 'tzserver'),
630 'current_server_datehour' => dol_print_date($now, 'dayhour', 'tzserver'),
631 // Date in requested output language
632 'current_date_locale' => dol_print_date($now, 'day', 'tzuser', $outputlangs),
633 'current_datehour_locale' => dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
634 'current_server_date_locale' => dol_print_date($now, 'day', 'tzserver', $outputlangs),
635 'current_server_datehour_locale' => dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
636 );
637
638
639 foreach ($conf->global as $key => $val) {
640 if (isASecretKey($key)) {
641 $newval = '*****forbidden*****';
642 } else {
643 $newval = $val;
644 }
645 $array_other['__['.$key.']__'] = $newval;
646 }
647
648 return $array_other;
649 }
650
651
652 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
662 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
663 {
664 // phpcs:enable
665 global $extrafields;
666
667 $totalpaid = $totaldeposits = $totalcreditnotes = '';
668 $already_payed_all = 0;
669
670 if ($object->element == 'facture') {
672 '@phan-var-force Facture $object';
673 $invoice_source = new Facture($this->db);
674 if ($object->fk_facture_source > 0) {
675 $invoice_source->fetch($object->fk_facture_source);
676 }
677 $totalpaid = $object->getSommePaiement();
678 $totaldeposits = $object->getSumDepositsUsed();
679 $totalcreditnotes = $object->getSumCreditNotesUsed();
680 $already_payed_all = $totalpaid + $totaldeposits + $totalcreditnotes;
681 }
682
683 // Ignore notice for deprecated date - @phan-suppress-next-line PhanUndeclaredProperty
684 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
685
686 if ($object instanceof CommandeFournisseur) {
687 $object->date_validation = $object->date_valid;
688 $object->date_commande = $object->date;
689 }
690 $resarray = array(
691 $array_key.'_id' => $object->id,
692 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
693 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''), // @phan-suppress-current-line PhanUndeclaredProperty
694 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
695 $array_key.'_ref_customer' => (!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
696 $array_key.'_ref_supplier' => (!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), // @phan-suppress-current-line PhanUndeclaredProperty
697 $array_key.'_source_invoice_ref' => ((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
698 // Dates
699 $array_key.'_hour' => dol_print_date($date, 'hour'),
700 $array_key.'_date' => dol_print_date($date, 'day'),
701 $array_key.'_date_rfc' => dol_print_date($date, 'dayrfc'),
702 $array_key.'_date_limit' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
703 $array_key.'_date_limit_rfc' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
704 $array_key.'_date_end' => (!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''), // @phan-suppress-current-line PhanUndeclaredProperty
705 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
706 $array_key.'_date_modification' => (!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
707 $array_key.'_date_validation' => (!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
708 $array_key.'_date_approve' => (!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
709 $array_key.'_date_delivery_planed' => (!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
710 $array_key.'_date_close' => (!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
711
712 $array_key.'_payment_mode_code' => $object->mode_reglement_code,
713 $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),
714 $array_key.'_payment_term_code' => $object->cond_reglement_code,
715 $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),
716
717 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
718
719 $array_key.'_total_ht_locale' => price($object->total_ht, 0, $outputlangs),
720 $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
721 $array_key.'_total_localtax1_locale' => price($object->total_localtax1, 0, $outputlangs),
722 $array_key.'_total_localtax2_locale' => price($object->total_localtax2, 0, $outputlangs),
723 $array_key.'_total_ttc_locale' => price($object->total_ttc, 0, $outputlangs),
724
725 $array_key.'_total_ht' => price2num($object->total_ht),
726 $array_key.'_total_vat' => (!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)), // @phan-suppress-current-line PhanUndeclaredProperty
727 $array_key.'_total_localtax1' => price2num($object->total_localtax1),
728 $array_key.'_total_localtax2' => price2num($object->total_localtax2),
729 $array_key.'_total_ttc' => price2num($object->total_ttc),
730
731 $array_key.'_multicurrency_code' => $object->multicurrency_code,
732 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
733 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
734 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
735 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
736 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
737 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
738 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
739
740 $array_key.'_note_private' => $object->note_private,
741 $array_key.'_note_public' => $object->note_public,
742 $array_key.'_note' => $object->note_public, // For backward compatibility
743
744 // Payments
745 $array_key.'_already_payed_locale' => price($totalpaid, 0, $outputlangs),
746 $array_key.'_already_payed' => price2num($totalpaid),
747 $array_key.'_already_deposit_locale' => price($totaldeposits, 0, $outputlangs),
748 $array_key.'_already_deposit' => price2num($totaldeposits),
749 $array_key.'_already_creditnote_locale' => price($totalcreditnotes, 0, $outputlangs),
750 $array_key.'_already_creditnote' => price2num($totalcreditnotes),
751
752 $array_key.'_already_payed_all_locale' => price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
753 $array_key.'_already_payed_all' => price2num($already_payed_all, 'MT'),
754
755 // Remain to pay with all known information (except open direct debit requests)
756 $array_key.'_remain_to_pay_locale' => price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
757 $array_key.'_remain_to_pay' => price2num($object->total_ttc - $already_payed_all, 'MT')
758 );
759
760 if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur'))) {
761 $bank_account = null;
762
763 if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
764 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
765 $bank_account = new Account($this->db);
766 $bank_account->fetch((int) $object->fk_account);
767 }
768
769 $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
770 $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
771 $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
772 $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
773 $resarray[$array_key.'_bank_proprio'] = (empty($bank_account) ? '' : $bank_account->owner_name);
774 $resarray[$array_key.'_bank_address'] = (empty($bank_account) ? '' : $bank_account->address);
775 $resarray[$array_key.'_bank_state'] = (empty($bank_account) ? '' : $bank_account->state);
776 $resarray[$array_key.'_bank_country'] = (empty($bank_account) ? '' : $bank_account->country);
777 }
778
779 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
780 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
781 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
782 } else {
783 $resarray[$array_key.'_total_discount_ht_locale'] = '';
784 $resarray[$array_key.'_total_discount_ht'] = '';
785 }
786
787 if ($object->element == 'facture' || $object->element == 'invoice_supplier') {
788 if ($object->type == 0) {
789 $resarray[$array_key.'_type_label'] = $outputlangs->transnoentities("PdfInvoiceTitle");
790 } else {
791 $resarray[$array_key.'_type_label'] = (empty($object)) ? '' : $object->getLibType(0);
792 }
793 }
794
795 // Fetch project information if there is a project assigned to this object
796 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
797 if (!is_object($object->project)) {
798 $object->fetchProject();
799 }
800
801 $resarray[$array_key.'_project_ref'] = $object->project->ref;
802 $resarray[$array_key.'_project_title'] = $object->project->title;
803 $resarray[$array_key.'_project_description'] = $object->project->description;
804 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
805 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
806 } else { // empty replacement
807 $resarray[$array_key.'_project_ref'] = '';
808 $resarray[$array_key.'_project_title'] = '';
809 $resarray[$array_key.'_project_description'] = '';
810 $resarray[$array_key.'_project_date_start'] = '';
811 $resarray[$array_key.'_project_date_end'] = '';
812 }
813
814 // Add vat by rates
815 if (is_array($object->lines) && count($object->lines) > 0) {
816 $totalUp = 0;
817 // Set substitution keys for different VAT rates
818 foreach ($object->lines as $line) {
819 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
820 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
821 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
822 }
823 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
824 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
825 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
826 $vatformated = vatrate($line->tva_tx);
827 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
828 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
829 }
830 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
831 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
832
833 $totalUp += $line->subprice * $line->qty;
834 }
835
836 // Calculate total up and total discount percentage
837 // 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)
838 $resarray['object_total_up'] = $totalUp;
839 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
840 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
841 $totalDiscount = $object->getTotalDiscount();
842 } else {
843 $totalDiscount = 0;
844 }
845 if (!empty($totalUp) && !empty($totalDiscount)) {
846 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
847 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
848 } else {
849 $resarray['object_total_discount'] = '';
850 $resarray['object_total_discount_locale'] = '';
851 }
852 }
853
854 // Retrieve extrafields
855 if (is_array($object->array_options) && count($object->array_options)) {
856 $object->fetch_optionals();
857
858 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
859 }
860
861 return $resarray;
862 }
863
864 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
874 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
875 {
876 // phpcs:enable
877 $resarray = array(
878 'line_pos' => $linenumber,
879 'line_fulldesc' => doc_getlinedesc($line, $outputlangs),
880
881 'line_product_ref' => (empty($line->product_ref) ? '' : $line->product_ref),
882 'line_product_label' => (empty($line->product_label) ? '' : $line->product_label),
883 'line_product_type' => (empty($line->product_type) ? '' : $line->product_type),
884 'line_product_barcode' => (empty($line->product_barcode) ? '' : $line->product_barcode),
885 'line_product_desc' => (empty($line->product_desc) ? '' : $line->product_desc),
886
887 'line_desc' => $line->desc,
888 'line_vatrate' => vatrate($line->tva_tx, true, (int) $line->info_bits),
889 'line_up' => price2num($line->subprice),
890 'line_up_locale' => price($line->subprice, 0, $outputlangs),
891 'line_total_up' => price2num($line->subprice * (float) $line->qty),
892 'line_total_up_locale' => price($line->subprice * (float) $line->qty, 0, $outputlangs),
893 'line_qty' => $line->qty,
894 'line_qty_locale' => price($line->qty),
895 'line_discount_percent' => ($line->remise_percent ? $line->remise_percent.'%' : ''),
896 'line_price_ht' => price2num($line->total_ht),
897 'line_price_ttc' => price2num($line->total_ttc),
898 'line_price_vat' => price2num($line->total_tva),
899 'line_price_ht_locale' => price($line->total_ht, 0, $outputlangs),
900 'line_price_ttc_locale' => price($line->total_ttc, 0, $outputlangs),
901 'line_price_vat_locale' => price($line->total_tva, 0, $outputlangs),
902
903 'line_multicurrency_code' => price2num($line->multicurrency_code),
904 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
905 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
906 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
907 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
908 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
909 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
910 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
911 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
912 );
913
914 if (property_exists($line, 'ref_fourn')) {
915 $resarray['line_product_ref_fourn'] = $line->ref_fourn; // for supplier doc lines @phan-suppress-current-line PhanUndeclaredProperty
916 } else {
917 $resarray['line_product_ref_fourn'] = '';
918 }
919 $vat_specs = array(
920 'line_localtax1_rate' => 'localtax1_tx',
921 'line_localtax2_rate' => 'localtax2_tx',
922 );
923 foreach ($vat_specs as $vat_key => $vat_spec) {
924 if (property_exists($line, $vat_spec)) {
925 // @phan-suppress-next-line PhanUndeclaredProperty
926 $resarray[$vat_key] = vatrate($line->$vat_spec);
927 }
928 }
929
930 // Dates (fields not available on all line classes)
931 $date_specs = array(
932 array('line_date_start', 'date_start', 'day', 'auto', null),
933 array('line_date_start_locale', 'date_start', 'day', 'tzserver', $outputlangs),
934 array('line_date_start_rfc', 'date_start', 'dayrfc', 'auto', null),
935 array('line_date_start_real', 'date_start_real', 'day', 'auto', null),
936 array('line_date_start_real_locale', 'date_start_real', 'day', 'tzserver', $outputlangs),
937 array('line_date_start_real_rfc', 'date_start_real', 'dayrfc', 'auto', null),
938 array('line_date_end', 'date_end', 'day', 'auto', null),
939 array('line_date_end_locale', 'date_end', 'day', 'tzserver', $outputlangs),
940 array('line_date_end_rfc', 'date_end', 'dayrfc', 'auto', null)
941 );
942 foreach ($date_specs as $date_spec) {
943 $propertyname = $date_spec[1];
944 if (property_exists($line, $propertyname)) {
945 // @phan-suppress-next-line PhanUndeclaredProperty
946 $resarray[$date_spec[0]] = dol_print_date($line->$propertyname, $date_spec[2], $date_spec[3], $date_spec[4]);
947 }
948 }
949
950 // Units
951 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
952 $resarray['line_unit'] = $line->getLabelOfUnit('long', $outputlangs);
953 $resarray['line_unit_short'] = $line->getLabelOfUnit('short', $outputlangs);
954 //$resarray['line_unit_code'] = $line->getLabelOfUnit('code', $outputlangs);
955 }
956
957 // Retrieve extrafields
958 $extrafieldkey = $line->table_element;
959 $array_key = "line";
960 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
961 $extrafields = new ExtraFields($this->db);
962 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
963 $line->fetch_optionals();
964
965 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
966
967 // Check if the current line belongs to a supplier order
968 if (get_class($line) == 'CommandeFournisseurLigne') {
969 // Add the product supplier extrafields to the substitutions
970 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
971 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
972
973 if (!empty($extralabels) && is_array($extralabels)) {
974 $columns = "";
975
976 foreach ($extralabels as $key => $label) {
977 $columns .= "$key, ";
978 }
979
980 if ($columns != "") {
981 $columns = substr($columns, 0, strlen($columns) - 2);
982 $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)."'");
983
984 if ($this->db->num_rows($resql) > 0) {
985 $resql = $this->db->fetch_object($resql);
986
987 foreach ($extralabels as $key => $label) {
988 $resarray['line_product_supplier_'.$key] = $resql->$key;
989 }
990 }
991 }
992 }
993 }
994
995 // Check if the current line belongs to a shipment
996 if (get_class($line) == 'ExpeditionLigne') {
997 $resarray['line_qty_shipped'] = $line->qty_shipped;
998 $resarray['line_qty_asked'] = $line->qty_asked;
999 $resarray['line_weight'] = empty($line->weight) ? '' : $line->weight * $line->qty_shipped.' '.measuringUnitString(0, 'weight', $line->weight_units);
1000 $resarray['line_length'] = empty($line->length) ? '' : $line->length * $line->qty_shipped.' '.measuringUnitString(0, 'size', $line->length_units);
1001 $resarray['line_surface'] = empty($line->surface) ? '' : $line->surface * $line->qty_shipped.' '.measuringUnitString(0, 'surface', $line->surface_units);
1002 $resarray['line_volume'] = empty($line->volume) ? '' : $line->volume * $line->qty_shipped.' '.measuringUnitString(0, 'volume', $line->volume_units);
1003 }
1004
1005 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
1006 if (isset($line->fk_product) && $line->fk_product > 0) {
1007 $tmpproduct = new Product($this->db);
1008 $result = $tmpproduct->fetch($line->fk_product);
1009 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
1010 foreach ($tmpproduct->array_options as $key => $label) {
1011 $resarray["line_product_".$key] = $label;
1012 }
1013 }
1014 } else {
1015 // Set unused placeholders as blank
1016 $extrafields->fetch_name_optionals_label("product");
1017 if ($extrafields->attributes["product"]['count'] > 0) {
1018 $extralabels = $extrafields->attributes["product"]['label'];
1019
1020 foreach ($extralabels as $key => $label) {
1021 $resarray['line_product_options_'.$key] = '';
1022 }
1023 }
1024 }
1025
1026 return $resarray;
1027 }
1028
1029 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1039 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
1040 {
1041 // phpcs:enable
1042 global $extrafields;
1043
1044 include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
1045
1046 $object->list_delivery_methods($object->shipping_method_id);
1047 $calculatedVolume = ((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth);
1048
1049 $array_shipment = array(
1050 $array_key.'_id' => $object->id,
1051 $array_key.'_ref' => $object->ref,
1052 $array_key.'_ref_ext' => $object->ref_ext,
1053 $array_key.'_ref_customer' => $object->ref_customer,
1054 $array_key.'_date_delivery' => dol_print_date($object->date_delivery, 'day'), // note: for shipment, delivery and reception: date_delivery, for orders: delivery_date
1055 $array_key.'_hour_delivery' => dol_print_date($object->date_delivery, 'hour'),
1056 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
1057 $array_key.'_total_ht' => price($object->total_ht),
1058 $array_key.'_total_vat' => price($object->total_tva),
1059 $array_key.'_total_ttc' => price($object->total_ttc),
1060 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
1061 $array_key.'_note_private' => $object->note_private,
1062 $array_key.'_note' => $object->note_public,
1063 $array_key.'_tracking_number' => $object->tracking_number,
1064 $array_key.'_tracking_url' => $object->tracking_url,
1065 $array_key.'_shipping_method' => $object->listmeths[0]['libelle'],
1066 $array_key.'_weight' => $object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
1067 $array_key.'_width' => $object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
1068 $array_key.'_height' => $object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
1069 $array_key.'_depth' => $object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
1070 $array_key.'_size' => $calculatedVolume.' '.measuringUnitString(0, 'volume'),
1071 );
1072
1073 // Add vat by rates
1074 foreach ($object->lines as $line) {
1075 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
1076 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
1077 }
1078 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
1079 }
1080
1081 // Retrieve extrafields
1082 if (is_array($object->array_options) && count($object->array_options)) {
1083 $object->fetch_optionals();
1084
1085 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
1086 }
1087
1088 // Add info from $object->origin_object which has been loaded by fetch() of shipment
1089 if ($object->origin_type == 'commande' && is_object($object->origin_object) && !empty($object->origin_object->ref)) {
1090 $originOrder = $object->origin_object;
1091 '@phan-var-force Commande $originOrder';
1092 $array_shipment['order_ref'] = $originOrder->ref;
1093 $array_shipment['order_ref_customer'] = $originOrder->ref_customer;
1094 }
1095
1096 // Load dim data
1097 $tmparray = $object->getTotalWeightVolume();
1098 $totalWeight = $tmparray['weight'];
1099 $totalVolume = $tmparray['volume'];
1100 $totalOrdered = $tmparray['ordered'];
1101 $totalToShip = $tmparray['toship'];
1102
1103 // Set trueVolume and volume_units not currently stored into database
1104 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
1105 $object->trueVolume = $object->trueWidth * $object->trueHeight * $object->trueDepth;
1106 $object->volume_units = $object->size_units * 3;
1107 }
1108
1109 $array_shipment[$array_key.'_total_ordered'] = (string) $totalOrdered;
1110 $array_shipment[$array_key.'_total_toship'] = (string) $totalToShip;
1111
1112 if ($object->trueWeight) {
1113 $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
1114 } elseif (!empty($totalWeight)) {
1115 $array_shipment[$array_key.'_total_weight'] = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1);
1116 } else {
1117 $array_shipment[$array_key.'_total_weight'] = "";
1118 }
1119
1120 if (!empty($object->trueVolume)) {
1121 if ($object->volume_units < 50) {
1122 $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
1123 } else {
1124 $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : price($object->trueVolume, 0, $outputlangs, 0, 0).' '.measuringUnitString(0, "volume", $object->volume_units);
1125 }
1126 } elseif (!empty($totalVolume)) {
1127 $array_shipment[$array_key.'_total_volume'] = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1);
1128 } else {
1129 $array_shipment[$array_key.'_total_volume'] = "";
1130 }
1131
1132 return $array_shipment;
1133 }
1134
1135
1136 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1147 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
1148 {
1149 // phpcs:enable
1150 $array_other = array();
1151
1152 if ((is_array($object) && count($object)) || is_object($object)) {
1153 // Loop on each entry of array or on each property of object
1154 foreach ($object as $key => $value) {
1155 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
1156 continue;
1157 }
1158 if (!empty($value)) {
1159 if (!is_array($value) && !is_object($value)) {
1160 $array_other['object_'.$key] = $value;
1161 } elseif (is_array($value) && $recursive) {
1162 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1163 if (!empty($tmparray) && is_array($tmparray)) {
1164 foreach ($tmparray as $key2 => $value2) {
1165 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1166 }
1167 }
1168 } elseif (is_object($value) && $recursive) {
1169 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1170 if (!empty($tmparray) && is_array($tmparray)) {
1171 foreach ($tmparray as $key2 => $value2) {
1172 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1173 }
1174 }
1175 }
1176 }
1177 }
1178 }
1179
1180 return $array_other;
1181 }
1182
1183
1184 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1196 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
1197 {
1198 // phpcs:enable
1199 global $conf;
1200
1201 if ($extrafields->attributes[$object->table_element]['count'] > 0) {
1202 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1203 $formatedarrayoption = $object->array_options;
1204
1205 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
1206 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
1207 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
1208 //Add value to store price with currency
1209 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
1210 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
1211 $valueofselectkey = $formatedarrayoption['options_'.$key];
1212 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
1213 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
1214 } else {
1215 $formatedarrayoption['options_'.$key] = '';
1216 }
1217 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
1218 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
1219 $output = array();
1220 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
1221 if (in_array($keyopt, $valArray)) {
1222 $output[] = $valopt;
1223 }
1224 }
1225 $formatedarrayoption['options_'.$key] = implode(', ', $output);
1226 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
1227 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
1228 $date = $formatedarrayoption['options_'.$key];
1229 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
1230 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
1231 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
1232 } else {
1233 $formatedarrayoption['options_'.$key] = '';
1234 $formatedarrayoption['options_'.$key.'_locale'] = '';
1235 $formatedarrayoption['options_'.$key.'_rfc'] = '';
1236 }
1237 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1238 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1239 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1240 $datetime = $formatedarrayoption['options_'.$key];
1241 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1242 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1243 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1244 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1245 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1246 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1247 $id = $formatedarrayoption['options_'.$key];
1248 if ($id != "") {
1249 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1250 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1251 $InfoFieldList = explode(":", $param_list[0]);
1252 $classname = $InfoFieldList[0];
1253 $classpath = $InfoFieldList[1];
1254 if (!empty($classpath)) {
1255 dol_include_once($InfoFieldList[1]);
1256 if ($classname && class_exists($classname)) {
1257 $tmpobject = new $classname($this->db);
1258 '@phan-var-force CommonObject $tmpobject';
1259 $tmpobject->fetch($id);
1260 // completely replace the id with the linked object name
1261 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1262 }
1263 }
1264 }
1265 }
1266
1267 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1268 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1269 } else {
1270 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1271 }
1272 }
1273 }
1274
1275 return $array_to_fill;
1276 }
1277
1278
1291 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1292 {
1293 if (empty($hidetop) || $hidetop == -1) {
1294 $pdf->line($x, $y, $x + $l, $y);
1295 }
1296 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1297 if (empty($hidebottom)) {
1298 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1299 }
1300 $pdf->line($x, $y + $h, $x, $y);
1301 }
1302
1317 public function printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop = 0, $hidebottom = 0, $style = 'D')
1318 {
1319 // Top line
1320 if (empty($hidetop) || $hidetop == -1) {
1321 $pdf->RoundedRect($x, $y, $w, $h, $r, '1111', $style);
1322 } else {
1323 // Draw rounded rectangle with hidden top side
1324 $pdf->RoundedRect($x, $y, $w, $h, $r, '0111', $style);
1325 }
1326 if (!empty($hidebottom)) {
1327 $pdf->RoundedRect($x, $y, $w, $h, $r, '1101', $style);
1328 }
1329 }
1330
1336 {
1337 if (empty($this->afterColsLinePositions) || !is_array($this->afterColsLinePositions)) {
1338 return false;
1339 }
1340
1341 $colId = '';
1342 $maxPage = $maxY = 0;
1343 foreach ($this->afterColsLinePositions as $colKey => $value) {
1344 if ($value['page'] > $maxPage) {
1345 $colId = $colKey;
1346 $maxPage = $value['page'];
1347 $maxY = $value['y']; // if page is higher we need to reset y to new max page y
1348 } elseif ($value['page'] == $maxPage) {
1349 $maxY = max($value['y'], $maxY);
1350 $colId = $colKey;
1351 }
1352 }
1353
1354 return [
1355 'col' => $colId,
1356 'y' => $maxY,
1357 'page' => $maxPage
1358 ];
1359 }
1360
1367 public function resetAfterColsLinePositionsData(float $y, int $pageNumb)
1368 {
1369 $this->afterColsLinePositions = [];
1370 $this->setAfterColsLinePositionsData('startLine', $y, $pageNumb);
1371 }
1372
1380 public function setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
1381 {
1382 $this->afterColsLinePositions[$colId] = [
1383 'page' => $pageNumb,
1384 'y' => $y
1385 ];
1386 }
1387
1388
1396 public function columnSort($a, $b)
1397 {
1398 if (empty($a['rank'])) {
1399 $a['rank'] = 0;
1400 }
1401 if (empty($b['rank'])) {
1402 $b['rank'] = 0;
1403 }
1404 if ($a['rank'] == $b['rank']) {
1405 return 0;
1406 }
1407 return ($a['rank'] > $b['rank']) ? -1 : 1;
1408 }
1409
1420 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1421 {
1422 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1423
1424
1425 // Sorting
1426 uasort($this->cols, array($this, 'columnSort'));
1427
1428 // Positioning
1429 $curX = $this->page_largeur - $this->marge_droite; // start from right
1430
1431 // Array width
1432 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1433
1434 // Count flexible column
1435 $totalDefinedColWidth = 0;
1436 $countFlexCol = 0;
1437 foreach ($this->cols as $colKey => & $colDef) {
1438 if (!$this->getColumnStatus($colKey)) {
1439 continue; // continue if disabled
1440 }
1441
1442 if (!empty($colDef['scale'])) {
1443 // In case of column width is defined by percentage
1444 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1445 }
1446
1447 if (empty($colDef['width'])) {
1448 $countFlexCol++;
1449 } else {
1450 $totalDefinedColWidth += $colDef['width'];
1451 }
1452 }
1453
1454 foreach ($this->cols as $colKey => & $colDef) {
1455 // setting empty conf with default
1456 if (!empty($colDef['title'])) {
1457 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1458 } else {
1459 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1460 }
1461
1462 // setting empty conf with default
1463 if (!empty($colDef['content'])) {
1464 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1465 } else {
1466 $colDef['content'] = $this->defaultContentsFieldsStyle;
1467 }
1468
1469 if ($this->getColumnStatus($colKey)) {
1470 // In case of flexible column
1471 if (empty($colDef['width'])) {
1472 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1473 }
1474
1475 // Set positions
1476 $lastX = $curX;
1477 $curX = $lastX - $colDef['width'];
1478 $colDef['xStartPos'] = $curX;
1479 $colDef['xEndPos'] = $lastX;
1480 }
1481 }
1482 }
1483
1490 public function getColumnContentWidth($colKey)
1491 {
1492 $colDef = $this->cols[$colKey];
1493 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1494 }
1495
1496
1503 public function getColumnContentXStart($colKey)
1504 {
1505 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1506 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1507 }
1508
1515 public function getColumnRank($colKey)
1516 {
1517 if (!isset($this->cols[$colKey]['rank'])) {
1518 return -1;
1519 }
1520 return $this->cols[$colKey]['rank'];
1521 }
1522
1532 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1533 {
1534 // prepare wanted rank
1535 $rank = -1;
1536
1537 // try to get rank from target column
1538 if (!empty($targetCol)) {
1539 $rank = $this->getColumnRank($targetCol);
1540 if ($rank >= 0 && $insertAfterTarget) {
1541 $rank++;
1542 }
1543 }
1544
1545 // get rank from new column definition
1546 if ($rank < 0 && !empty($defArray['rank'])) {
1547 $rank = $defArray['rank'];
1548 }
1549
1550 // error: no rank
1551 if ($rank < 0) {
1552 return -1;
1553 }
1554
1555 foreach ($this->cols as $colKey => & $colDef) {
1556 if ($rank <= $colDef['rank']) {
1557 $colDef['rank'] += 1;
1558 }
1559 }
1560
1561 $defArray['rank'] = $rank;
1562 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1563
1564 return $rank;
1565 }
1566
1567
1577 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1578 {
1579 global $hookmanager;
1580
1581 $parameters = array(
1582 'curY' => &$curY,
1583 'columnText' => $columnText,
1584 'colKey' => $colKey,
1585 'pdf' => &$pdf,
1586 );
1587 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1588 if ($reshook < 0) {
1589 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1590 }
1591 if (!$reshook) {
1592 if (empty($columnText)) {
1593 return 0;
1594 }
1595 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
1596 $colDef = $this->cols[$colKey];
1597 // save current cell padding
1598 $curentCellPaddinds = $pdf->getCellPaddings();
1599 // set cell padding with column content definition
1600 $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);
1601 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, false, true, $colDef['content']['align']);
1602 $this->setAfterColsLinePositionsData($colKey, $pdf->GetY(), $pdf->getPage());
1603
1604 // restore cell padding
1605 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1606 }
1607
1608 return 0;
1609 }
1610
1611
1626 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1627 {
1628 global $hookmanager;
1629
1630 // load desc col params
1631 $colDef = $this->cols[$colKey];
1632 // save current cell padding
1633 $curentCellPaddinds = $pdf->getCellPaddings();
1634 // set cell padding with column content definition
1635 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1636
1637 // line description
1638 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline, empty($colDef['content']['align']) ? 'J' : $colDef['content']['align']);
1639 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1640
1641 // restore cell padding
1642 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1643
1644 // Display extrafield if needed
1645 $params = array(
1646 'display' => 'list',
1647 'printableEnable' => array(3),
1648 'printableEnableNotEmpty' => array(4)
1649 );
1650 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1651 if (!empty($extrafieldDesc)) {
1652 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1653 }
1654
1655 $parameters = array(
1656 'curY' => &$curY,
1657 'colKey' => $colKey,
1658 'object' => $object,
1659 'i' => $i,
1660 'outputlangs' => $outputlangs,
1661 'pdf' => &$pdf,
1662 );
1663 $reshook = $hookmanager->executeHooks('printColDescContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1664 if ($reshook < 0) {
1665 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1666 }
1667 }
1668
1678 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1679 {
1680 global $hookmanager;
1681
1682 if (empty($object->table_element)) {
1683 return '';
1684 }
1685
1686 $extrafieldsKeyPrefix = "options_";
1687
1688 // Cleanup extrafield key to remove prefix if present
1689 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1690 if ($pos === 0) {
1691 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1692 }
1693
1694 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1695
1696
1697 // Load extra fields if they haven't been loaded already.
1698 if (is_null($this->extrafieldsCache)) {
1699 $this->extrafieldsCache = new ExtraFields($this->db);
1700 }
1701 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1702 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1703 }
1704 $extrafields = $this->extrafieldsCache;
1705
1706 $extrafieldOutputContent = '';
1707 if (isset($object->array_options[$extrafieldOptionsKey])) {
1708 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1709 }
1710
1711 // 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 ...
1712 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1713 // for lack of anything better we cleanup all html tags
1714 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1715 }
1716
1717 // Display stars extrafield as simple string
1718 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'stars') {
1719 $extrafieldOutputContent = '';
1720 for ($i = 0; $i < $object->array_options[$extrafieldOptionsKey]; $i++) {
1721 $extrafieldOutputContent .= ' *';
1722 }
1723 }
1724
1725 $parameters = array(
1726 'object' => $object,
1727 'extrafields' => $extrafields,
1728 'extrafieldKey' => $extrafieldKey,
1729 'extrafieldOutputContent' => & $extrafieldOutputContent
1730 );
1731 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1732 if ($reshook < 0) {
1733 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1734 }
1735 if ($reshook) {
1736 $extrafieldOutputContent = $hookmanager->resPrint;
1737 }
1738
1739 return $extrafieldOutputContent;
1740 }
1741
1742
1751 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1752 {
1753 global $hookmanager;
1754
1755 if (empty($object->table_element)) {
1756 return "";
1757 }
1758
1759 // Load extrafields if not already done
1760 if (is_null($this->extrafieldsCache)) {
1761 $this->extrafieldsCache = new ExtraFields($this->db);
1762 }
1763 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1764 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1765 }
1766 $extrafields = $this->extrafieldsCache;
1767
1768 $defaultParams = array(
1769 'style' => '',
1770 'display' => 'auto', // auto, table, list
1771 'printableEnable' => array(1),
1772 'printableEnableNotEmpty' => array(2),
1773
1774 'table' => array(
1775 'maxItemsInRow' => 2,
1776 'cellspacing' => 0,
1777 'cellpadding' => 0,
1778 'border' => 0,
1779 'labelcolwidth' => '25%',
1780 'arrayOfLineBreakType' => array('text', 'html')
1781 ),
1782
1783 'list' => array(
1784 'separator' => '<br>'
1785 ),
1786
1787 'auto' => array(
1788 'list' => 0, // 0 for default
1789 'table' => 4 // if there more than x extrafield to display
1790 ),
1791 );
1792
1793 $params += $defaultParams;
1794
1799 $html = '';
1800 $fields = array();
1801
1802 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1803 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1804 // Enable extrafield ?
1805 $enabled = 0;
1806 if (!empty($extrafields->attributes[$object->table_element]['enabled'][$key])) {
1807 $enabled = (int) dol_eval((string) $extrafields->attributes[$object->table_element]['enabled'][$key], 1, 1, '2');
1808 }
1809
1810 if (!$enabled) {
1811 continue;
1812 }
1813
1814 // Reset enabled: only printable attribute determines PDF visibility
1815 $enabled = 0;
1816 $disableOnEmpty = 0;
1817 $printable = 0;
1818 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1819 $printable = (int) $extrafields->attributes[$object->table_element]['printable'][$key];
1820 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1821 $enabled = 1;
1822 }
1823
1824 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1825 $disableOnEmpty = 1;
1826 }
1827 }
1828
1829 if (empty($enabled) || empty($printable)) {
1830 continue;
1831 }
1832
1833 // Load language if required
1834 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1835 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1836 }
1837
1838 $field = new stdClass();
1839 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1840 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1841 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1842 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1843 }
1844 $field->label = $outputlangs->transnoentities($label);
1845 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1846
1847 // don't display if empty
1848 if ($disableOnEmpty && empty($field->content)) {
1849 continue;
1850 }
1851
1852 $fields[] = $field;
1853 }
1854 }
1855
1856 if (!empty($fields)) {
1857 // Sort extrafields by rank
1858 uasort(
1859 $fields,
1865 static function ($a, $b) {
1866 return ($a->rank > $b->rank) ? 1 : -1;
1867 }
1868 );
1869
1870 // define some HTML content with style
1871 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1872
1873 // auto select display format
1874 if ($params['display'] == 'auto') {
1875 $lastNnumbItems = 0;
1876 foreach ($params['auto'] as $display => $numbItems) {
1877 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1878 $lastNnumbItems = $numbItems;
1879 $params['display'] = $display;
1880 }
1881 }
1882 }
1883
1884 if ($params['display'] == 'list') {
1885 // Display in list format
1886 $i = 0;
1887 foreach ($fields as $field) {
1888 $html .= !empty($i) ? $params['list']['separator'] : '';
1889 $html .= '<strong>'.$field->label.' : </strong>';
1890 $html .= $field->content;
1891 $i++;
1892 }
1893 } elseif ($params['display'] == 'table') {
1894 // Display in table format
1895 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1896
1897 $html .= "<tr>";
1898 $itemsInRow = 0;
1899 $maxItemsInRow = $params['table']['maxItemsInRow'];
1900 foreach ($fields as $field) {
1901 //$html.= !empty($html)?'<br>':'';
1902 if ($itemsInRow >= $maxItemsInRow) {
1903 // start a new line
1904 $html .= "</tr><tr>";
1905 $itemsInRow = 0;
1906 }
1907
1908 // for some type we need line break
1909 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1910 if ($itemsInRow > 0) {
1911 // close table row and empty cols
1912 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1913 $html .= "<td></td><td></td>";
1914 }
1915 $html .= "</tr>";
1916
1917 // start a new line
1918 $html .= "<tr>";
1919 }
1920
1921 $itemsInRow = $maxItemsInRow;
1922 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1923 $html .= '<strong>'.$field->label.' :</strong> ';
1924 $html .= $field->content;
1925 $html .= "</td>";
1926 } else {
1927 $itemsInRow++;
1928 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1929 $html .= '<strong>'.$field->label.' :</strong>';
1930 $html .= "</td>";
1931
1932
1933 $html .= '<td class="extrafield-content">';
1934 $html .= $field->content;
1935 $html .= "</td>";
1936 }
1937 }
1938 $html .= "</tr>";
1939
1940 $html .= '</table>';
1941 }
1942 }
1943
1944 return $html;
1945 }
1946
1947
1954 public function getColumnStatus($colKey)
1955 {
1956 if (!empty($this->cols[$colKey]['status'])) {
1957 return true;
1958 } else {
1959 return false;
1960 }
1961 }
1962
1973 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1974 {
1975 global $hookmanager, $conf;
1976
1977 foreach ($this->cols as $colKey => $colDef) {
1978 $parameters = array(
1979 'colKey' => $colKey,
1980 'pdf' => $pdf,
1981 'outputlangs' => $outputlangs,
1982 'tab_top' => $tab_top,
1983 'tab_height' => $tab_height,
1984 'hidetop' => $hidetop
1985 );
1986
1987 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1988 if ($reshook < 0) {
1989 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1990 } elseif (empty($reshook)) {
1991 if (!$this->getColumnStatus($colKey)) {
1992 continue;
1993 }
1994
1995 // get title label
1996 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1997
1998 // Add column separator
1999 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
2000 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
2001 }
2002
2003 if (empty($hidetop)) {
2004 // save current cell padding
2005 $curentCellPaddinds = $pdf->getCellPaddings();
2006
2007 // Add space for lines (more if we need to show a second alternative language)
2008 global $outputlangsbis;
2009 if (is_object($outputlangsbis)) {
2010 // set cell padding with column title definition
2011 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
2012 } else {
2013 // set cell padding with column title definition
2014 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
2015 }
2016 if (isset($colDef['title']['align'])) {
2017 $align = $colDef['title']['align'];
2018 } else {
2019 $align = '';
2020 }
2021 $pdf->SetXY($colDef['xStartPos'], $tab_top);
2022 $textWidth = $colDef['width'];
2023 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
2024
2025 // Add variant of translation if $outputlangsbis is an object
2026 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
2027 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
2028 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
2029 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
2030 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
2031 }
2032
2033 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
2034
2035 // restore cell padding
2036 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
2037 }
2038 }
2039 }
2040
2041 return $this->tabTitleHeight;
2042 }
2043
2044
2045
2054 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
2055 {
2056 if (!empty($hidedetails)) {
2057 return 0;
2058 }
2059
2060 if (empty($object->table_element)) {
2061 return 0;
2062 }
2063
2064 // Load extra fields if they haven't been loaded already.
2065 if (is_null($this->extrafieldsCache)) {
2066 $this->extrafieldsCache = new ExtraFields($this->db);
2067 }
2068 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
2069 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
2070 }
2071 $extrafields = $this->extrafieldsCache;
2072
2073
2074 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'])) {
2075 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
2076 // Don't display separator yet even is set to be displayed (not compatible yet)
2077 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
2078 continue;
2079 }
2080
2081 // Enable extrafield ?
2082 $enabled = 0;
2083 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
2084 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
2085 if ($printable === 1 || $printable === 2) {
2086 $enabled = 1;
2087 }
2088 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
2089 }
2090
2091 if (!$enabled) {
2092 continue;
2093 } // don't waste resources if we don't need them...
2094
2095 // Load language if required
2096 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
2097 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
2098 }
2099
2100 // TODO : add more extrafield customisation capacities for PDF like width, rank...
2101
2102 // set column definition
2103 $def = array(
2104 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
2105 'width' => 25, // in mm
2106 'status' => (bool) $enabled,
2107 'title' => array(
2108 'label' => $outputlangs->transnoentities($label)
2109 ),
2110 'content' => array(
2111 'align' => 'C'
2112 ),
2113 'border-left' => true, // add left line separator
2114 );
2115
2116 $alignTypeRight = array('double', 'int', 'price');
2117 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
2118 $def['content']['align'] = 'R';
2119 }
2120
2121 $alignTypeLeft = array('text', 'html');
2122 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
2123 $def['content']['align'] = 'L';
2124 }
2125
2126
2127 // for extrafields we use rank of extrafield to place it on PDF
2128 $this->insertNewColumnDef("options_".$key, $def);
2129 }
2130 }
2131
2132 return 1;
2133 }
2134
2146 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2147 {
2148 // Default field style for content
2149 $this->defaultContentsFieldsStyle = array(
2150 'align' => 'R', // R,C,L
2151 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2152 );
2153
2154 // Default field style for content
2155 $this->defaultTitlesFieldsStyle = array(
2156 'align' => 'C', // R,C,L
2157 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2158 );
2159
2160 // Example
2161 /*
2162 $rank = 0; // do not use negative rank
2163 $this->cols['desc'] = array(
2164 'rank' => $rank,
2165 'width' => false, // only for desc
2166 'status' => true,
2167 'title' => array(
2168 'textkey' => 'Designation', // use lang key is useful in some case with module
2169 'align' => 'L',
2170 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2171 // 'label' => ' ', // the final label
2172 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2173 ),
2174 'content' => array(
2175 'align' => 'L',
2176 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2177 ),
2178 );
2179 */
2180 }
2181}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
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 @phpstan-template T.
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.
getMaxAfterColsLinePositionsData()
Get position in PDF after col display.
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
setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
Used for to set afterColsLinePositions var in a pdf draw line loop.
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.
resetAfterColsLinePositionsData(float $y, int $pageNumb)
Used for reset afterColsLinePositions var in start of a new pdf draw line loop.
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.
global $mysoc
doc_getlinedesc($line, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
Return line description translated in outputlangs and encoded into UTF8.
Definition doc.lib.php:42
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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 '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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:1535
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:464