dolibarr 23.0.4
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 // A title or subtotal line of the Subtotals module (special_code 3) carries the level in qty, not a quantity. The PDF hides it, see pdf_getlineqty().
894 'line_qty' => (empty($line->special_code) || $line->special_code != 3) ? $line->qty : '',
895 'line_qty_locale' => (empty($line->special_code) || $line->special_code != 3) ? price($line->qty) : '',
896 'line_discount_percent' => ($line->remise_percent ? $line->remise_percent.'%' : ''),
897 'line_price_ht' => price2num($line->total_ht),
898 'line_price_ttc' => price2num($line->total_ttc),
899 'line_price_vat' => price2num($line->total_tva),
900 'line_price_ht_locale' => price($line->total_ht, 0, $outputlangs),
901 'line_price_ttc_locale' => price($line->total_ttc, 0, $outputlangs),
902 'line_price_vat_locale' => price($line->total_tva, 0, $outputlangs),
903
904 'line_multicurrency_code' => price2num($line->multicurrency_code),
905 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
906 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
907 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
908 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
909 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
910 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
911 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
912 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
913 );
914
915 if (property_exists($line, 'ref_fourn')) {
916 $resarray['line_product_ref_fourn'] = $line->ref_fourn; // for supplier doc lines @phan-suppress-current-line PhanUndeclaredProperty
917 } else {
918 $resarray['line_product_ref_fourn'] = '';
919 }
920 $vat_specs = array(
921 'line_localtax1_rate' => 'localtax1_tx',
922 'line_localtax2_rate' => 'localtax2_tx',
923 );
924 foreach ($vat_specs as $vat_key => $vat_spec) {
925 if (property_exists($line, $vat_spec)) {
926 // @phan-suppress-next-line PhanUndeclaredProperty
927 $resarray[$vat_key] = vatrate($line->$vat_spec);
928 }
929 }
930
931 // Dates (fields not available on all line classes)
932 $date_specs = array(
933 array('line_date_start', 'date_start', 'day', 'auto', null),
934 array('line_date_start_locale', 'date_start', 'day', 'tzserver', $outputlangs),
935 array('line_date_start_rfc', 'date_start', 'dayrfc', 'auto', null),
936 array('line_date_start_real', 'date_start_real', 'day', 'auto', null),
937 array('line_date_start_real_locale', 'date_start_real', 'day', 'tzserver', $outputlangs),
938 array('line_date_start_real_rfc', 'date_start_real', 'dayrfc', 'auto', null),
939 array('line_date_end', 'date_end', 'day', 'auto', null),
940 array('line_date_end_locale', 'date_end', 'day', 'tzserver', $outputlangs),
941 array('line_date_end_rfc', 'date_end', 'dayrfc', 'auto', null)
942 );
943 foreach ($date_specs as $date_spec) {
944 $propertyname = $date_spec[1];
945 if (property_exists($line, $propertyname)) {
946 // @phan-suppress-next-line PhanUndeclaredProperty
947 $resarray[$date_spec[0]] = dol_print_date($line->$propertyname, $date_spec[2], $date_spec[3], $date_spec[4]);
948 }
949 }
950
951 // Units
952 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
953 $resarray['line_unit'] = $line->getLabelOfUnit('long', $outputlangs);
954 $resarray['line_unit_short'] = $line->getLabelOfUnit('short', $outputlangs);
955 //$resarray['line_unit_code'] = $line->getLabelOfUnit('code', $outputlangs);
956 }
957
958 // Retrieve extrafields
959 $extrafieldkey = $line->table_element;
960 $array_key = "line";
961 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
962 $extrafields = new ExtraFields($this->db);
963 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
964 $line->fetch_optionals();
965
966 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
967
968 // Check if the current line belongs to a supplier order
969 if (get_class($line) == 'CommandeFournisseurLigne') {
970 // Add the product supplier extrafields to the substitutions
971 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
972 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
973
974 if (!empty($extralabels) && is_array($extralabels)) {
975 $columns = "";
976
977 foreach ($extralabels as $key => $label) {
978 $columns .= "$key, ";
979 }
980
981 if ($columns != "") {
982 $columns = substr($columns, 0, strlen($columns) - 2);
983 $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)."'");
984
985 if ($this->db->num_rows($resql) > 0) {
986 $resql = $this->db->fetch_object($resql);
987
988 foreach ($extralabels as $key => $label) {
989 $resarray['line_product_supplier_'.$key] = $resql->$key;
990 }
991 }
992 }
993 }
994 }
995
996 // Check if the current line belongs to a shipment
997 if (get_class($line) == 'ExpeditionLigne') {
998 $resarray['line_qty_shipped'] = $line->qty_shipped;
999 $resarray['line_qty_asked'] = $line->qty_asked;
1000 $resarray['line_weight'] = empty($line->weight) ? '' : $line->weight * $line->qty_shipped.' '.measuringUnitString(0, 'weight', $line->weight_units);
1001 $resarray['line_length'] = empty($line->length) ? '' : $line->length * $line->qty_shipped.' '.measuringUnitString(0, 'size', $line->length_units);
1002 $resarray['line_surface'] = empty($line->surface) ? '' : $line->surface * $line->qty_shipped.' '.measuringUnitString(0, 'surface', $line->surface_units);
1003 $resarray['line_volume'] = empty($line->volume) ? '' : $line->volume * $line->qty_shipped.' '.measuringUnitString(0, 'volume', $line->volume_units);
1004 }
1005
1006 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
1007 if (isset($line->fk_product) && $line->fk_product > 0) {
1008 $tmpproduct = new Product($this->db);
1009 $result = $tmpproduct->fetch($line->fk_product);
1010 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
1011 foreach ($tmpproduct->array_options as $key => $label) {
1012 $resarray["line_product_".$key] = $label;
1013 }
1014 }
1015 } else {
1016 // Set unused placeholders as blank
1017 $extrafields->fetch_name_optionals_label("product");
1018 if ($extrafields->attributes["product"]['count'] > 0) {
1019 $extralabels = $extrafields->attributes["product"]['label'];
1020
1021 foreach ($extralabels as $key => $label) {
1022 $resarray['line_product_options_'.$key] = '';
1023 }
1024 }
1025 }
1026
1027 return $resarray;
1028 }
1029
1030 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1040 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
1041 {
1042 // phpcs:enable
1043 global $extrafields;
1044
1045 include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
1046
1047 $object->list_delivery_methods($object->shipping_method_id);
1048 $calculatedVolume = ((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth);
1049
1050 $array_shipment = array(
1051 $array_key.'_id' => $object->id,
1052 $array_key.'_ref' => $object->ref,
1053 $array_key.'_ref_ext' => $object->ref_ext,
1054 $array_key.'_ref_customer' => $object->ref_customer,
1055 $array_key.'_date_delivery' => dol_print_date($object->date_delivery, 'day'), // note: for shipment, delivery and reception: date_delivery, for orders: delivery_date
1056 $array_key.'_hour_delivery' => dol_print_date($object->date_delivery, 'hour'),
1057 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
1058 $array_key.'_total_ht' => price($object->total_ht),
1059 $array_key.'_total_vat' => price($object->total_tva),
1060 $array_key.'_total_ttc' => price($object->total_ttc),
1061 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
1062 $array_key.'_note_private' => $object->note_private,
1063 $array_key.'_note' => $object->note_public,
1064 $array_key.'_tracking_number' => $object->tracking_number,
1065 $array_key.'_tracking_url' => $object->tracking_url,
1066 $array_key.'_shipping_method' => $object->listmeths[0]['libelle'],
1067 $array_key.'_weight' => $object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
1068 $array_key.'_width' => $object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
1069 $array_key.'_height' => $object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
1070 $array_key.'_depth' => $object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
1071 $array_key.'_size' => $calculatedVolume.' '.measuringUnitString(0, 'volume'),
1072 );
1073
1074 // Add vat by rates
1075 foreach ($object->lines as $line) {
1076 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
1077 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
1078 }
1079 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
1080 }
1081
1082 // Retrieve extrafields
1083 if (is_array($object->array_options) && count($object->array_options)) {
1084 $object->fetch_optionals();
1085
1086 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
1087 }
1088
1089 // Add info from $object->origin_object which has been loaded by fetch() of shipment
1090 if ($object->origin_type == 'commande' && is_object($object->origin_object) && !empty($object->origin_object->ref)) {
1091 $originOrder = $object->origin_object;
1092 '@phan-var-force Commande $originOrder';
1093 $array_shipment['order_ref'] = $originOrder->ref;
1094 $array_shipment['order_ref_customer'] = $originOrder->ref_customer;
1095 }
1096
1097 // Load dim data
1098 $tmparray = $object->getTotalWeightVolume();
1099 $totalWeight = $tmparray['weight'];
1100 $totalVolume = $tmparray['volume'];
1101 $totalOrdered = $tmparray['ordered'];
1102 $totalToShip = $tmparray['toship'];
1103
1104 // Set trueVolume and volume_units not currently stored into database
1105 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
1106 $object->trueVolume = $object->trueWidth * $object->trueHeight * $object->trueDepth;
1107 $object->volume_units = $object->size_units * 3;
1108 }
1109
1110 $array_shipment[$array_key.'_total_ordered'] = (string) $totalOrdered;
1111 $array_shipment[$array_key.'_total_toship'] = (string) $totalToShip;
1112
1113 if ($object->trueWeight) {
1114 $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
1115 } elseif (!empty($totalWeight)) {
1116 $array_shipment[$array_key.'_total_weight'] = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1);
1117 } else {
1118 $array_shipment[$array_key.'_total_weight'] = "";
1119 }
1120
1121 if (!empty($object->trueVolume)) {
1122 if ($object->volume_units < 50) {
1123 $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
1124 } else {
1125 $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : price($object->trueVolume, 0, $outputlangs, 0, 0).' '.measuringUnitString(0, "volume", $object->volume_units);
1126 }
1127 } elseif (!empty($totalVolume)) {
1128 $array_shipment[$array_key.'_total_volume'] = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1);
1129 } else {
1130 $array_shipment[$array_key.'_total_volume'] = "";
1131 }
1132
1133 return $array_shipment;
1134 }
1135
1136
1137 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1148 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
1149 {
1150 // phpcs:enable
1151 $array_other = array();
1152
1153 if ((is_array($object) && count($object)) || is_object($object)) {
1154 // Loop on each entry of array or on each property of object
1155 foreach ($object as $key => $value) {
1156 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
1157 continue;
1158 }
1159 if (!empty($value)) {
1160 if (!is_array($value) && !is_object($value)) {
1161 $array_other['object_'.$key] = $value;
1162 } elseif (is_array($value) && $recursive) {
1163 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1164 if (!empty($tmparray) && is_array($tmparray)) {
1165 foreach ($tmparray as $key2 => $value2) {
1166 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1167 }
1168 }
1169 } elseif (is_object($value) && $recursive) {
1170 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1171 if (!empty($tmparray) && is_array($tmparray)) {
1172 foreach ($tmparray as $key2 => $value2) {
1173 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1174 }
1175 }
1176 }
1177 }
1178 }
1179 }
1180
1181 return $array_other;
1182 }
1183
1184
1185 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1197 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
1198 {
1199 // phpcs:enable
1200 global $conf;
1201
1202 if ($extrafields->attributes[$object->table_element]['count'] > 0) {
1203 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1204 $formatedarrayoption = $object->array_options;
1205
1206 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
1207 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
1208 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
1209 //Add value to store price with currency
1210 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
1211 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
1212 $valueofselectkey = $formatedarrayoption['options_'.$key];
1213 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
1214 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
1215 } else {
1216 $formatedarrayoption['options_'.$key] = '';
1217 }
1218 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
1219 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
1220 $output = array();
1221 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
1222 if (in_array($keyopt, $valArray)) {
1223 $output[] = $valopt;
1224 }
1225 }
1226 $formatedarrayoption['options_'.$key] = implode(', ', $output);
1227 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
1228 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
1229 $date = $formatedarrayoption['options_'.$key];
1230 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
1231 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
1232 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
1233 } else {
1234 $formatedarrayoption['options_'.$key] = '';
1235 $formatedarrayoption['options_'.$key.'_locale'] = '';
1236 $formatedarrayoption['options_'.$key.'_rfc'] = '';
1237 }
1238 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1239 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1240 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1241 $datetime = $formatedarrayoption['options_'.$key];
1242 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1243 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1244 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1245 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1246 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1247 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1248 $id = $formatedarrayoption['options_'.$key];
1249 if ($id != "") {
1250 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1251 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1252 $InfoFieldList = explode(":", $param_list[0]);
1253 $classname = $InfoFieldList[0];
1254 $classpath = $InfoFieldList[1];
1255 if (!empty($classpath)) {
1256 dol_include_once($InfoFieldList[1]);
1257 if ($classname && class_exists($classname)) {
1258 $tmpobject = new $classname($this->db);
1259 '@phan-var-force CommonObject $tmpobject';
1260 $tmpobject->fetch($id);
1261 // completely replace the id with the linked object name
1262 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1263 }
1264 }
1265 }
1266 }
1267
1268 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1269 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1270 } else {
1271 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1272 }
1273 }
1274 }
1275
1276 return $array_to_fill;
1277 }
1278
1279
1292 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1293 {
1294 if (empty($hidetop) || $hidetop == -1) {
1295 $pdf->line($x, $y, $x + $l, $y);
1296 }
1297 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1298 if (empty($hidebottom)) {
1299 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1300 }
1301 $pdf->line($x, $y + $h, $x, $y);
1302 }
1303
1318 public function printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop = 0, $hidebottom = 0, $style = 'D')
1319 {
1320 // Top line
1321 if (empty($hidetop) || $hidetop == -1) {
1322 $pdf->RoundedRect($x, $y, $w, $h, $r, '1111', $style);
1323 } else {
1324 // Draw rounded rectangle with hidden top side
1325 $pdf->RoundedRect($x, $y, $w, $h, $r, '0111', $style);
1326 }
1327 if (!empty($hidebottom)) {
1328 $pdf->RoundedRect($x, $y, $w, $h, $r, '1101', $style);
1329 }
1330 }
1331
1337 {
1338 if (empty($this->afterColsLinePositions) || !is_array($this->afterColsLinePositions)) {
1339 return false;
1340 }
1341
1342 $colId = '';
1343 $maxPage = $maxY = 0;
1344 foreach ($this->afterColsLinePositions as $colKey => $value) {
1345 if ($value['page'] > $maxPage) {
1346 $colId = $colKey;
1347 $maxPage = $value['page'];
1348 $maxY = $value['y']; // if page is higher we need to reset y to new max page y
1349 } elseif ($value['page'] == $maxPage) {
1350 $maxY = max($value['y'], $maxY);
1351 $colId = $colKey;
1352 }
1353 }
1354
1355 return [
1356 'col' => $colId,
1357 'y' => $maxY,
1358 'page' => $maxPage
1359 ];
1360 }
1361
1368 public function resetAfterColsLinePositionsData(float $y, int $pageNumb)
1369 {
1370 $this->afterColsLinePositions = [];
1371 $this->setAfterColsLinePositionsData('startLine', $y, $pageNumb);
1372 }
1373
1381 public function setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
1382 {
1383 $this->afterColsLinePositions[$colId] = [
1384 'page' => $pageNumb,
1385 'y' => $y
1386 ];
1387 }
1388
1389
1397 public function columnSort($a, $b)
1398 {
1399 if (empty($a['rank'])) {
1400 $a['rank'] = 0;
1401 }
1402 if (empty($b['rank'])) {
1403 $b['rank'] = 0;
1404 }
1405 if ($a['rank'] == $b['rank']) {
1406 return 0;
1407 }
1408 return ($a['rank'] > $b['rank']) ? -1 : 1;
1409 }
1410
1421 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1422 {
1423 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1424
1425
1426 // Sorting
1427 uasort($this->cols, array($this, 'columnSort'));
1428
1429 // Positioning
1430 $curX = $this->page_largeur - $this->marge_droite; // start from right
1431
1432 // Array width
1433 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1434
1435 // Count flexible column
1436 $totalDefinedColWidth = 0;
1437 $countFlexCol = 0;
1438 foreach ($this->cols as $colKey => & $colDef) {
1439 if (!$this->getColumnStatus($colKey)) {
1440 continue; // continue if disabled
1441 }
1442
1443 if (!empty($colDef['scale'])) {
1444 // In case of column width is defined by percentage
1445 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1446 }
1447
1448 if (empty($colDef['width'])) {
1449 $countFlexCol++;
1450 } else {
1451 $totalDefinedColWidth += $colDef['width'];
1452 }
1453 }
1454
1455 foreach ($this->cols as $colKey => & $colDef) {
1456 // setting empty conf with default
1457 if (!empty($colDef['title'])) {
1458 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1459 } else {
1460 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1461 }
1462
1463 // setting empty conf with default
1464 if (!empty($colDef['content'])) {
1465 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1466 } else {
1467 $colDef['content'] = $this->defaultContentsFieldsStyle;
1468 }
1469
1470 if ($this->getColumnStatus($colKey)) {
1471 // In case of flexible column
1472 if (empty($colDef['width'])) {
1473 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1474 }
1475
1476 // Set positions
1477 $lastX = $curX;
1478 $curX = $lastX - $colDef['width'];
1479 $colDef['xStartPos'] = $curX;
1480 $colDef['xEndPos'] = $lastX;
1481 }
1482 }
1483 }
1484
1491 public function getColumnContentWidth($colKey)
1492 {
1493 $colDef = $this->cols[$colKey];
1494 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1495 }
1496
1497
1504 public function getColumnContentXStart($colKey)
1505 {
1506 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1507 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1508 }
1509
1516 public function getColumnRank($colKey)
1517 {
1518 if (!isset($this->cols[$colKey]['rank'])) {
1519 return -1;
1520 }
1521 return $this->cols[$colKey]['rank'];
1522 }
1523
1533 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1534 {
1535 // prepare wanted rank
1536 $rank = -1;
1537
1538 // try to get rank from target column
1539 if (!empty($targetCol)) {
1540 $rank = $this->getColumnRank($targetCol);
1541 if ($rank >= 0 && $insertAfterTarget) {
1542 $rank++;
1543 }
1544 }
1545
1546 // get rank from new column definition
1547 if ($rank < 0 && !empty($defArray['rank'])) {
1548 $rank = $defArray['rank'];
1549 }
1550
1551 // error: no rank
1552 if ($rank < 0) {
1553 return -1;
1554 }
1555
1556 foreach ($this->cols as $colKey => & $colDef) {
1557 if ($rank <= $colDef['rank']) {
1558 $colDef['rank'] += 1;
1559 }
1560 }
1561
1562 $defArray['rank'] = $rank;
1563 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1564
1565 return $rank;
1566 }
1567
1568
1578 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1579 {
1580 global $hookmanager;
1581
1582 $parameters = array(
1583 'curY' => &$curY,
1584 'columnText' => $columnText,
1585 'colKey' => $colKey,
1586 'pdf' => &$pdf,
1587 );
1588 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1589 if ($reshook < 0) {
1590 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1591 }
1592 if (!$reshook) {
1593 if (empty($columnText)) {
1594 return 0;
1595 }
1596 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
1597 $colDef = $this->cols[$colKey];
1598 // save current cell padding
1599 $curentCellPaddinds = $pdf->getCellPaddings();
1600 // set cell padding with column content definition
1601 $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);
1602 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, false, true, $colDef['content']['align']);
1603 $this->setAfterColsLinePositionsData($colKey, $pdf->GetY(), $pdf->getPage());
1604
1605 // restore cell padding
1606 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1607 }
1608
1609 return 0;
1610 }
1611
1612
1627 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1628 {
1629 global $hookmanager;
1630
1631 // load desc col params
1632 $colDef = $this->cols[$colKey];
1633 // save current cell padding
1634 $curentCellPaddinds = $pdf->getCellPaddings();
1635 // set cell padding with column content definition
1636 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1637
1638 // line description
1639 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline, empty($colDef['content']['align']) ? 'J' : $colDef['content']['align']);
1640 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1641
1642 // restore cell padding
1643 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1644
1645 // Display extrafield if needed
1646 $params = array(
1647 'display' => 'list',
1648 'printableEnable' => array(3),
1649 'printableEnableNotEmpty' => array(4)
1650 );
1651 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1652 if (!empty($extrafieldDesc)) {
1653 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1654 }
1655
1656 $parameters = array(
1657 'curY' => &$curY,
1658 'colKey' => $colKey,
1659 'object' => $object,
1660 'i' => $i,
1661 'outputlangs' => $outputlangs,
1662 'pdf' => &$pdf,
1663 );
1664 $reshook = $hookmanager->executeHooks('printColDescContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1665 if ($reshook < 0) {
1666 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1667 }
1668 }
1669
1679 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1680 {
1681 global $hookmanager;
1682
1683 if (empty($object->table_element)) {
1684 return '';
1685 }
1686
1687 $extrafieldsKeyPrefix = "options_";
1688
1689 // Cleanup extrafield key to remove prefix if present
1690 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1691 if ($pos === 0) {
1692 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1693 }
1694
1695 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1696
1697
1698 // Load extra fields if they haven't been loaded already.
1699 if (is_null($this->extrafieldsCache)) {
1700 $this->extrafieldsCache = new ExtraFields($this->db);
1701 }
1702 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1703 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1704 }
1705 $extrafields = $this->extrafieldsCache;
1706
1707 $extrafieldOutputContent = '';
1708 if (isset($object->array_options[$extrafieldOptionsKey])) {
1709 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1710 }
1711
1712 // 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 ...
1713 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1714 // for lack of anything better we cleanup all html tags
1715 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1716 }
1717
1718 // Display stars extrafield as simple string
1719 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'stars') {
1720 $extrafieldOutputContent = '';
1721 for ($i = 0; $i < $object->array_options[$extrafieldOptionsKey]; $i++) {
1722 $extrafieldOutputContent .= ' *';
1723 }
1724 }
1725
1726 $parameters = array(
1727 'object' => $object,
1728 'extrafields' => $extrafields,
1729 'extrafieldKey' => $extrafieldKey,
1730 'extrafieldOutputContent' => & $extrafieldOutputContent
1731 );
1732 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1733 if ($reshook < 0) {
1734 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1735 }
1736 if ($reshook) {
1737 $extrafieldOutputContent = $hookmanager->resPrint;
1738 }
1739
1740 return $extrafieldOutputContent;
1741 }
1742
1743
1752 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1753 {
1754 global $hookmanager;
1755
1756 if (empty($object->table_element)) {
1757 return "";
1758 }
1759
1760 // Load extrafields if not already done
1761 if (is_null($this->extrafieldsCache)) {
1762 include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1763 $this->extrafieldsCache = new ExtraFields($this->db);
1764 }
1765 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1766 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1767 }
1768 $extrafields = $this->extrafieldsCache;
1769
1770 $defaultParams = array(
1771 'style' => '',
1772 'display' => 'auto', // auto, table, list
1773 'printableEnable' => array(1),
1774 'printableEnableNotEmpty' => array(2),
1775
1776 'table' => array(
1777 'maxItemsInRow' => 2,
1778 'cellspacing' => 0,
1779 'cellpadding' => 0,
1780 'border' => 0,
1781 'labelcolwidth' => '25%',
1782 'arrayOfLineBreakType' => array('text', 'html')
1783 ),
1784
1785 'list' => array(
1786 'separator' => '<br>'
1787 ),
1788
1789 'auto' => array(
1790 'list' => 0, // 0 for default
1791 'table' => 4 // if there more than x extrafield to display
1792 ),
1793 );
1794
1795 $params += $defaultParams;
1796
1801 $html = '';
1802 $fields = array();
1803
1804 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1805 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1806 // Enable extrafield ?
1807 $enabled = 0;
1808 if (!empty($extrafields->attributes[$object->table_element]['enabled'][$key])) {
1809 $enabled = (int) dol_eval((string) $extrafields->attributes[$object->table_element]['enabled'][$key], 1, 1, '2');
1810 }
1811
1812 if (!$enabled) {
1813 continue;
1814 }
1815
1816 // Reset enabled: only printable attribute determines PDF visibility
1817 $enabled = 0;
1818 $disableOnEmpty = 0;
1819 $printable = 0;
1820 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1821 $printable = (int) $extrafields->attributes[$object->table_element]['printable'][$key];
1822 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1823 $enabled = 1;
1824 }
1825
1826 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1827 $disableOnEmpty = 1;
1828 }
1829 }
1830
1831 if (empty($enabled) || empty($printable)) {
1832 continue;
1833 }
1834
1835 // Load language if required
1836 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1837 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1838 }
1839
1840 $field = new stdClass();
1841 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1842 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1843 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1844 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1845 }
1846 $field->label = $outputlangs->transnoentities($label);
1847 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1848
1849 // don't display if empty
1850 if ($disableOnEmpty && empty($field->content)) {
1851 continue;
1852 }
1853
1854 $fields[] = $field;
1855 }
1856 }
1857
1858 if (!empty($fields)) {
1859 // Sort extrafields by rank
1860 uasort(
1861 $fields,
1867 static function ($a, $b) {
1868 return ($a->rank > $b->rank) ? 1 : -1;
1869 }
1870 );
1871
1872 // define some HTML content with style
1873 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1874
1875 // auto select display format
1876 if ($params['display'] == 'auto') {
1877 $lastNnumbItems = 0;
1878 foreach ($params['auto'] as $display => $numbItems) {
1879 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1880 $lastNnumbItems = $numbItems;
1881 $params['display'] = $display;
1882 }
1883 }
1884 }
1885
1886 if ($params['display'] == 'list') {
1887 // Display in list format
1888 $i = 0;
1889 foreach ($fields as $field) {
1890 $html .= !empty($i) ? $params['list']['separator'] : '';
1891 $html .= '<strong>'.$field->label.' : </strong>';
1892 $html .= $field->content;
1893 $i++;
1894 }
1895 } elseif ($params['display'] == 'table') {
1896 // Display in table format
1897 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1898
1899 $html .= "<tr>";
1900 $itemsInRow = 0;
1901 $maxItemsInRow = $params['table']['maxItemsInRow'];
1902 foreach ($fields as $field) {
1903 //$html.= !empty($html)?'<br>':'';
1904 if ($itemsInRow >= $maxItemsInRow) {
1905 // start a new line
1906 $html .= "</tr><tr>";
1907 $itemsInRow = 0;
1908 }
1909
1910 // for some type we need line break
1911 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1912 if ($itemsInRow > 0) {
1913 // close table row and empty cols
1914 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1915 $html .= "<td></td><td></td>";
1916 }
1917 $html .= "</tr>";
1918
1919 // start a new line
1920 $html .= "<tr>";
1921 }
1922
1923 $itemsInRow = $maxItemsInRow;
1924 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1925 $html .= '<strong>'.$field->label.' :</strong> ';
1926 $html .= $field->content;
1927 $html .= "</td>";
1928 } else {
1929 $itemsInRow++;
1930 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1931 $html .= '<strong>'.$field->label.' :</strong>';
1932 $html .= "</td>";
1933
1934
1935 $html .= '<td class="extrafield-content">';
1936 $html .= $field->content;
1937 $html .= "</td>";
1938 }
1939 }
1940 $html .= "</tr>";
1941
1942 $html .= '</table>';
1943 }
1944 }
1945
1946 return $html;
1947 }
1948
1949
1956 public function getColumnStatus($colKey)
1957 {
1958 if (!empty($this->cols[$colKey]['status'])) {
1959 return true;
1960 } else {
1961 return false;
1962 }
1963 }
1964
1975 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1976 {
1977 global $hookmanager, $conf;
1978
1979 foreach ($this->cols as $colKey => $colDef) {
1980 $parameters = array(
1981 'colKey' => $colKey,
1982 'pdf' => $pdf,
1983 'outputlangs' => $outputlangs,
1984 'tab_top' => $tab_top,
1985 'tab_height' => $tab_height,
1986 'hidetop' => $hidetop
1987 );
1988
1989 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1990 if ($reshook < 0) {
1991 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1992 } elseif (empty($reshook)) {
1993 if (!$this->getColumnStatus($colKey)) {
1994 continue;
1995 }
1996
1997 // get title label
1998 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1999
2000 // Add column separator
2001 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
2002 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
2003 }
2004
2005 if (empty($hidetop)) {
2006 // save current cell padding
2007 $curentCellPaddinds = $pdf->getCellPaddings();
2008
2009 // Add space for lines (more if we need to show a second alternative language)
2010 global $outputlangsbis;
2011 if (is_object($outputlangsbis)) {
2012 // set cell padding with column title definition
2013 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
2014 } else {
2015 // set cell padding with column title definition
2016 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
2017 }
2018 if (isset($colDef['title']['align'])) {
2019 $align = $colDef['title']['align'];
2020 } else {
2021 $align = '';
2022 }
2023 $pdf->SetXY($colDef['xStartPos'], $tab_top);
2024 $textWidth = $colDef['width'];
2025 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
2026
2027 // Add variant of translation if $outputlangsbis is an object
2028 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
2029 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
2030 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
2031 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
2032 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
2033 }
2034
2035 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
2036
2037 // restore cell padding
2038 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
2039 }
2040 }
2041 }
2042
2043 return $this->tabTitleHeight;
2044 }
2045
2046
2047
2056 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
2057 {
2058 if (!empty($hidedetails)) {
2059 return 0;
2060 }
2061
2062 if (empty($object->table_element)) {
2063 return 0;
2064 }
2065
2066 // Load extra fields if they haven't been loaded already.
2067 if (is_null($this->extrafieldsCache)) {
2068 $this->extrafieldsCache = new ExtraFields($this->db);
2069 }
2070 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
2071 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
2072 }
2073 $extrafields = $this->extrafieldsCache;
2074
2075
2076 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'])) {
2077 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
2078 // Don't display separator yet even is set to be displayed (not compatible yet)
2079 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
2080 continue;
2081 }
2082
2083 // Enable extrafield ?
2084 $enabled = 0;
2085 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
2086 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
2087 if ($printable === 1 || $printable === 2) {
2088 $enabled = 1;
2089 }
2090 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
2091 }
2092
2093 if (!$enabled) {
2094 continue;
2095 } // don't waste resources if we don't need them...
2096
2097 // Load language if required
2098 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
2099 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
2100 }
2101
2102 // TODO : add more extrafield customisation capacities for PDF like width, rank...
2103
2104 // set column definition
2105 $def = array(
2106 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
2107 'width' => 25, // in mm
2108 'status' => (bool) $enabled,
2109 'title' => array(
2110 'label' => $outputlangs->transnoentities($label)
2111 ),
2112 'content' => array(
2113 'align' => 'C'
2114 ),
2115 'border-left' => true, // add left line separator
2116 );
2117
2118 $alignTypeRight = array('double', 'int', 'price');
2119 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
2120 $def['content']['align'] = 'R';
2121 }
2122
2123 $alignTypeLeft = array('text', 'html');
2124 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
2125 $def['content']['align'] = 'L';
2126 }
2127
2128
2129 // for extrafields we use rank of extrafield to place it on PDF
2130 $this->insertNewColumnDef("options_".$key, $def);
2131 }
2132 }
2133
2134 return 1;
2135 }
2136
2148 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2149 {
2150 // Default field style for content
2151 $this->defaultContentsFieldsStyle = array(
2152 'align' => 'R', // R,C,L
2153 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2154 );
2155
2156 // Default field style for content
2157 $this->defaultTitlesFieldsStyle = array(
2158 'align' => 'C', // R,C,L
2159 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2160 );
2161
2162 // Example
2163 /*
2164 $rank = 0; // do not use negative rank
2165 $this->cols['desc'] = array(
2166 'rank' => $rank,
2167 'width' => false, // only for desc
2168 'status' => true,
2169 'title' => array(
2170 'textkey' => 'Designation', // use lang key is useful in some case with module
2171 'align' => 'L',
2172 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2173 // 'label' => ' ', // the final label
2174 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2175 ),
2176 'content' => array(
2177 'align' => 'L',
2178 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2179 ),
2180 );
2181 */
2182 }
2183}
$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:469