dolibarr 24.0.0-beta
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-2026 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' => (string) $user->lastname,
342 'myuser_firstname' => (string) $user->firstname,
343 'myuser_fullname' => $user->getFullName($outputlangs, 1),
344 'myuser_login' => (string) $user->login,
345 'myuser_phone' => (string) $user->office_phone,
346 'myuser_address' => (string) $user->address,
347 'myuser_zip' => (string) $user->zip,
348 'myuser_town' => (string) $user->town,
349 'myuser_country' => (string) $user->country,
350 'myuser_country_code' => (string) $user->country_code,
351 'myuser_state' => (string) $user->state,
352 'myuser_state_code' => (string) $user->state_code,
353 'myuser_fax' => (string) $user->office_fax,
354 'myuser_mobile' => (string) $user->user_mobile,
355 'myuser_email' => (string) $user->email,
356 'myuser_logo' => (string) $logotouse,
357 'myuser_job' => (string) $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' => (string) $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' => (string) $member->lastname,
394 'mymember_firstname' => (string) $member->firstname,
395 'mymember_fullname' => $member->getFullName($outputlangs, 1),
396 'mymember_login' => (string) $member->login,
397 'mymember_address' => (string) $member->address,
398 'mymember_zip' => (string) $member->zip,
399 'mymember_town' => (string) $member->town,
400 'mymember_country_code' => (string) $member->country_code,
401 'mymember_country' => (string) $member->country,
402 'mymember_state_code' => (string) $member->state_code,
403 'mymember_state' => (string) $member->state,
404 'mymember_phone_perso' => (string) $member->phone_perso,
405 'mymember_phone_pro' => (string) $member->phone,
406 'mymember_phone_mobile' => (string) $member->phone_mobile,
407 'mymember_email' => (string) $member->email,
408 'mymember_logo' => $logotouse,
409 'mymember_gender' => (string) $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' => (string) $object->name,
508 'company_name_alias' => (string) $object->name_alias,
509 'company_email' => (string) $object->email,
510 'company_phone' => (string) $object->phone,
511 'company_fax' => (string) $object->fax,
512 'company_address' => (string) $object->address,
513 'company_zip' => (string) $object->zip,
514 'company_town' => (string) $object->town,
515 'company_country' => (string) $object->country,
516 'company_country_code' => (string) $object->country_code,
517 'company_state' => (string) $object->state,
518 'company_state_code' => (string) $object->state_code,
519 'company_web' => (string) $object->url,
520 'company_barcode' => (string) $object->barcode,
521 'company_vatnumber' => (string) $object->tva_intra,
522 'company_customercode' => (string) $object->code_client,
523 'company_suppliercode' => (string) $object->code_fournisseur,
524 'company_customeraccountancycode' => (string) $object->code_compta_client,
525 'company_supplieraccountancycode' => (string) $object->code_compta_fournisseur,
526 'company_juridicalstatus' => (string) $object->forme_juridique,
527 'company_outstanding_limit' => (string) $object->outstanding_limit,
528 'company_capital' => (string) $object->capital,
529 'company_capital_formated' => price($object->capital, 0, '', 1, -1),
530 'company_idprof1' => (string) $object->idprof1,
531 'company_idprof2' => (string) $object->idprof2,
532 'company_idprof3' => (string) $object->idprof3,
533 'company_idprof4' => (string) $object->idprof4,
534 'company_idprof5' => (string) $object->idprof5,
535 'company_idprof6' => (string) $object->idprof6,
536 'company_note_public' => (string) $object->note_public,
537 'company_note_private' => (string) $object->note_private,
538 'company_default_bank_iban' => (is_object($object->bank_account) ? (string) $object->bank_account->iban : ''),
539 'company_default_bank_bic' => (is_object($object->bank_account) ? (string) $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 $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 ? $object->statut : $object->status,
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_locale' => (!empty($object->birthday) ? dol_print_date($object->birthday, 'day', false, $outputlangs) : ''),
596 $array_key.'_birthday' => $object->birthday,
597 $array_key.'_default_lang' => $object->default_lang,
598 $array_key.'_note_public' => $object->note_public,
599 $array_key.'_note_private' => $object->note_private,
600 $array_key.'_civility' => $object->civility,
601 );
602
603 // Retrieve extrafields
604 if (is_array($object->array_options) && count($object->array_options)) {
605 $object->fetch_optionals();
606
607 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
608 }
609 return $array_contact;
610 }
611
612
613 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
620 public function get_substitutionarray_other($outputlangs)
621 {
622 // phpcs:enable
623 global $conf;
624
625 $now = dol_now('gmt'); // gmt
626 $array_other = array(
627 // Date in default language
628 'current_date' => dol_print_date($now, 'day', 'tzuser'),
629 'current_datehour' => dol_print_date($now, 'dayhour', 'tzuser'),
630 'current_server_date' => dol_print_date($now, 'day', 'tzserver'),
631 'current_server_datehour' => dol_print_date($now, 'dayhour', 'tzserver'),
632 // Date in requested output language
633 'current_date_locale' => dol_print_date($now, 'day', 'tzuser', $outputlangs),
634 'current_datehour_locale' => dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
635 'current_server_date_locale' => dol_print_date($now, 'day', 'tzserver', $outputlangs),
636 'current_server_datehour_locale' => dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
637 );
638
639
640 foreach ($conf->global as $key => $val) {
641 if (isASecretKey($key)) {
642 $newval = '*****forbidden*****';
643 } else {
644 $newval = $val;
645 }
646 $array_other['__['.$key.']__'] = $newval;
647 }
648
649 return $array_other;
650 }
651
652
653 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
663 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
664 {
665 // phpcs:enable
666 global $extrafields;
667
668 $totalpaid = $totaldeposits = $totalcreditnotes = '';
669 $already_payed_all = 0;
670
671 if ($object->element == 'facture') {
673 '@phan-var-force Facture $object';
674 $invoice_source = new Facture($this->db);
675 if ($object->fk_facture_source > 0) {
676 $invoice_source->fetch($object->fk_facture_source);
677 }
678 $totalpaid = $object->getSommePaiement();
679 $totaldeposits = $object->getSumDepositsUsed();
680 $totalcreditnotes = $object->getSumCreditNotesUsed();
681 $already_payed_all = $totalpaid + $totaldeposits + $totalcreditnotes;
682 }
683
684 // Ignore notice for deprecated date - @phan-suppress-next-line PhanUndeclaredProperty
685 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
686
687 if ($object instanceof CommandeFournisseur) {
688 $object->date_validation = $object->date_valid;
689 $object->date_commande = $object->date;
690 }
691 $resarray = array(
692 $array_key.'_id' => $object->id,
693 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
694 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''), // @phan-suppress-current-line PhanUndeclaredProperty
695 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
696 $array_key.'_ref_customer' => (!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
697 $array_key.'_ref_supplier' => (!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), // @phan-suppress-current-line PhanUndeclaredProperty
698 $array_key.'_source_invoice_ref' => ((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
699 // Dates
700 $array_key.'_hour' => dol_print_date($date, 'hour'),
701 $array_key.'_date' => dol_print_date($date, 'day'),
702 $array_key.'_date_rfc' => dol_print_date($date, 'dayrfc'),
703 $array_key.'_date_limit' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
704 $array_key.'_date_limit_rfc' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
705 $array_key.'_date_end' => (!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''), // @phan-suppress-current-line PhanUndeclaredProperty
706 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
707 $array_key.'_date_modification' => (!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
708 $array_key.'_date_validation' => (!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
709 $array_key.'_date_approve' => (!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
710 $array_key.'_date_delivery_planed' => (!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
711 $array_key.'_date_close' => (!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
712
713 $array_key.'_payment_mode_code' => $object->mode_reglement_code,
714 $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),
715 $array_key.'_payment_term_code' => $object->cond_reglement_code,
716 $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),
717
718 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
719
720 $array_key.'_total_ht_locale' => price($object->total_ht, 0, $outputlangs),
721 $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
722 $array_key.'_total_localtax1_locale' => price($object->total_localtax1, 0, $outputlangs),
723 $array_key.'_total_localtax2_locale' => price($object->total_localtax2, 0, $outputlangs),
724 $array_key.'_total_ttc_locale' => price($object->total_ttc, 0, $outputlangs),
725
726 $array_key.'_total_ht' => price2num($object->total_ht),
727 $array_key.'_total_vat' => (!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)), // @phan-suppress-current-line PhanUndeclaredProperty
728 $array_key.'_total_localtax1' => price2num($object->total_localtax1),
729 $array_key.'_total_localtax2' => price2num($object->total_localtax2),
730 $array_key.'_total_ttc' => price2num($object->total_ttc),
731
732 $array_key.'_multicurrency_code' => $object->multicurrency_code,
733 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
734 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
735 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
736 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
737 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
738 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
739 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
740
741 $array_key.'_note_private' => $object->note_private,
742 $array_key.'_note_public' => $object->note_public,
743 $array_key.'_note' => $object->note_public, // For backward compatibility
744
745 // Payments
746 $array_key.'_already_payed_locale' => price($totalpaid, 0, $outputlangs),
747 $array_key.'_already_payed' => price2num($totalpaid),
748 $array_key.'_already_deposit_locale' => price($totaldeposits, 0, $outputlangs),
749 $array_key.'_already_deposit' => price2num($totaldeposits),
750 $array_key.'_already_creditnote_locale' => price($totalcreditnotes, 0, $outputlangs),
751 $array_key.'_already_creditnote' => price2num($totalcreditnotes),
752
753 $array_key.'_already_payed_all_locale' => price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
754 $array_key.'_already_payed_all' => price2num($already_payed_all, 'MT'),
755
756 // Remain to pay with all known information (except open direct debit requests)
757 $array_key.'_remain_to_pay_locale' => price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
758 $array_key.'_remain_to_pay' => price2num($object->total_ttc - $already_payed_all, 'MT')
759 );
760
761 if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur', 'commande'))) {
762 $bank_account = null;
763
764 if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
765 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
766 $bank_account = new Account($this->db);
767 $bank_account->fetch((int) $object->fk_account);
768 }
769
770 $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
771 $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
772 $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
773 $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
774 $resarray[$array_key.'_bank_proprio'] = (empty($bank_account) ? '' : $bank_account->owner_name);
775 $resarray[$array_key.'_bank_address'] = (empty($bank_account) ? '' : $bank_account->address);
776 $resarray[$array_key.'_bank_state'] = (empty($bank_account) ? '' : $bank_account->state);
777 $resarray[$array_key.'_bank_country'] = (empty($bank_account) ? '' : $bank_account->country);
778 }
779
780 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
781 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
782 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
783 } else {
784 $resarray[$array_key.'_total_discount_ht_locale'] = '';
785 $resarray[$array_key.'_total_discount_ht'] = '';
786 }
787
788 if ($object->element == 'facture' || $object->element == 'invoice_supplier') {
789 if ($object->type == 0) {
790 $resarray[$array_key.'_type_label'] = $outputlangs->transnoentities("PdfInvoiceTitle");
791 } else {
792 $resarray[$array_key.'_type_label'] = (empty($object)) ? '' : $object->getLibType(0);
793 }
794 }
795
796 // Fetch project information if there is a project assigned to this object
797 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
798 if (!is_object($object->project)) {
799 $object->fetchProject();
800 }
801
802 $resarray[$array_key.'_project_ref'] = $object->project->ref;
803 $resarray[$array_key.'_project_title'] = $object->project->title;
804 $resarray[$array_key.'_project_description'] = $object->project->description;
805 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
806 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
807 } else { // empty replacement
808 $resarray[$array_key.'_project_ref'] = '';
809 $resarray[$array_key.'_project_title'] = '';
810 $resarray[$array_key.'_project_description'] = '';
811 $resarray[$array_key.'_project_date_start'] = '';
812 $resarray[$array_key.'_project_date_end'] = '';
813 }
814
815 // Add vat by rates
816 if (is_array($object->lines) && count($object->lines) > 0) {
817 $totalUp = 0;
818 // Set substitution keys for different VAT rates
819 foreach ($object->lines as $line) {
820 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
821 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
822 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
823 }
824 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
825 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
826 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
827 $vatformated = vatrate($line->tva_tx);
828 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
829 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
830 }
831 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
832 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
833
834 $totalUp += $line->subprice * $line->qty;
835 }
836
837 // Calculate total up and total discount percentage
838 // 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)
839 $resarray['object_total_up'] = $totalUp;
840 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
841 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
842 $totalDiscount = $object->getTotalDiscount();
843 } else {
844 $totalDiscount = 0;
845 }
846 if (!empty($totalUp) && !empty($totalDiscount)) {
847 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
848 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
849 } else {
850 $resarray['object_total_discount'] = '';
851 $resarray['object_total_discount_locale'] = '';
852 }
853 }
854
855 // Retrieve extrafields
856 if (is_array($object->array_options) && count($object->array_options)) {
857 $object->fetch_optionals();
858
859 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
860 }
861
862 return $resarray;
863 }
864
865 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
875 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
876 {
877 // phpcs:enable
878 $resarray = array(
879 'line_pos' => $linenumber,
880 'line_fulldesc' => doc_getlinedesc($line, $outputlangs),
881
882 'line_product_ref' => (empty($line->product_ref) ? '' : $line->product_ref),
883 'line_product_label' => (empty($line->product_label) ? '' : $line->product_label),
884 'line_product_type' => (empty($line->product_type) ? '' : $line->product_type),
885 'line_product_barcode' => (empty($line->product_barcode) ? '' : $line->product_barcode),
886 'line_product_desc' => (empty($line->product_desc) ? '' : $line->product_desc),
887
888 'line_desc' => $line->desc,
889 'line_vatrate' => vatrate($line->tva_tx, true, (int) $line->info_bits),
890 'line_up' => price2num($line->subprice),
891 'line_up_locale' => price($line->subprice, 0, $outputlangs),
892 'line_total_up' => price2num($line->subprice * (float) $line->qty),
893 'line_total_up_locale' => price($line->subprice * (float) $line->qty, 0, $outputlangs),
894 'line_qty' => $line->qty,
895 'line_qty_locale' => 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((int) $object->shipping_method_id);
1048
1049 $calculatedVolume = ((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth);
1050
1051 $array_shipment = array(
1052 $array_key.'_id' => $object->id,
1053 $array_key.'_ref' => $object->ref,
1054 $array_key.'_ref_ext' => $object->ref_ext,
1055 $array_key.'_ref_customer' => $object->ref_customer,
1056 $array_key.'_date_delivery' => dol_print_date($object->date_delivery, 'day'), // note: for shipment, delivery and reception: date_delivery, for orders: delivery_date
1057 $array_key.'_hour_delivery' => dol_print_date($object->date_delivery, 'hour'),
1058 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
1059 $array_key.'_total_ht' => price($object->total_ht),
1060 $array_key.'_total_vat' => price($object->total_tva),
1061 $array_key.'_total_ttc' => price($object->total_ttc),
1062 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
1063 $array_key.'_note_private' => $object->note_private,
1064 $array_key.'_note' => $object->note_public,
1065 $array_key.'_tracking_number' => $object->tracking_number,
1066 $array_key.'_tracking_url' => $object->tracking_url,
1067 $array_key.'_shipping_method' => $object->listmeths[0]['libelle'],
1068 $array_key.'_weight' => $object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
1069 $array_key.'_width' => $object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
1070 $array_key.'_height' => $object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
1071 $array_key.'_depth' => $object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
1072 $array_key.'_size' => $calculatedVolume.' '.measuringUnitString(0, 'volume'),
1073 );
1074
1075 // Add vat by rates
1076 foreach ($object->lines as $line) {
1077 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
1078 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
1079 }
1080 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
1081 }
1082
1083 // Retrieve extrafields
1084 if (is_array($object->array_options) && count($object->array_options)) {
1085 $object->fetch_optionals();
1086
1087 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
1088 }
1089
1090 // Add info from $object->origin_object which has been loaded by fetch() of shipment
1091 if ($object->origin_type == 'commande' && is_object($object->origin_object) && !empty($object->origin_object->ref)) {
1092 $originOrder = $object->origin_object;
1093 '@phan-var-force Commande $originOrder';
1094 $array_shipment['order_ref'] = $originOrder->ref;
1095 $array_shipment['order_ref_customer'] = $originOrder->ref_customer;
1096 }
1097
1098 // Load dim data
1099 $tmparray = $object->getTotalWeightVolume();
1100 $totalWeight = $tmparray['weight'];
1101 $totalVolume = $tmparray['volume'];
1102 $totalOrdered = $tmparray['ordered'];
1103 $totalToShip = $tmparray['toship'];
1104
1105 // Set trueVolume and volume_units not currently stored into database
1106 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
1107 $object->trueVolume = $object->trueWidth * $object->trueHeight * $object->trueDepth;
1108 $object->volume_units = $object->size_units * 3;
1109 }
1110
1111 $array_shipment[$array_key.'_total_ordered'] = (string) $totalOrdered;
1112 $array_shipment[$array_key.'_total_toship'] = (string) $totalToShip;
1113
1114 if ($object->trueWeight) {
1115 $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($object->trueWeight, (int) $object->weight_units, "weight", $outputlangs);
1116 } elseif (!empty($totalWeight)) {
1117 $array_shipment[$array_key.'_total_weight'] = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1);
1118 } else {
1119 $array_shipment[$array_key.'_total_weight'] = "";
1120 }
1121
1122 if (!empty($object->trueVolume)) {
1123 if ($object->volume_units < 50) {
1124 $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
1125 } else {
1126 $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : price($object->trueVolume, 0, $outputlangs, 0, 0).' '.measuringUnitString(0, "volume", $object->volume_units);
1127 }
1128 } elseif (!empty($totalVolume)) {
1129 $array_shipment[$array_key.'_total_volume'] = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1);
1130 } else {
1131 $array_shipment[$array_key.'_total_volume'] = "";
1132 }
1133
1134 return $array_shipment;
1135 }
1136
1137
1138 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1149 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
1150 {
1151 // phpcs:enable
1152 $array_other = array();
1153
1154 if ((is_array($object) && count($object)) || is_object($object)) {
1155 // Loop on each entry of array or on each property of object
1156 foreach ($object as $key => $value) {
1157 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
1158 continue;
1159 }
1160 if (!empty($value)) {
1161 if (!is_array($value) && !is_object($value)) {
1162 $array_other['object_'.$key] = $value;
1163 } elseif (is_array($value) && $recursive) {
1164 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1165 if (!empty($tmparray) && is_array($tmparray)) {
1166 foreach ($tmparray as $key2 => $value2) {
1167 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1168 }
1169 }
1170 } elseif (is_object($value) && $recursive) {
1171 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
1172 if (!empty($tmparray) && is_array($tmparray)) {
1173 foreach ($tmparray as $key2 => $value2) {
1174 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
1175 }
1176 }
1177 }
1178 }
1179 }
1180 }
1181
1182 return $array_other;
1183 }
1184
1185
1186 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1198 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
1199 {
1200 // phpcs:enable
1201 global $conf;
1202
1203 if ($extrafields->attributes[$object->table_element]['count'] > 0) {
1204 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1205 $formatedarrayoption = $object->array_options;
1206
1207 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
1208 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
1209 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
1210 //Add value to store price with currency
1211 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
1212 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
1213 $valueofselectkey = $formatedarrayoption['options_'.$key];
1214 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
1215 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
1216 } else {
1217 $formatedarrayoption['options_'.$key] = '';
1218 }
1219 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
1220 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
1221 $output = array();
1222 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
1223 if (in_array($keyopt, $valArray)) {
1224 $output[] = $valopt;
1225 }
1226 }
1227 $formatedarrayoption['options_'.$key] = implode(', ', $output);
1228 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
1229 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
1230 $date = $formatedarrayoption['options_'.$key];
1231 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
1232 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
1233 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
1234 } else {
1235 $formatedarrayoption['options_'.$key] = '';
1236 $formatedarrayoption['options_'.$key.'_locale'] = '';
1237 $formatedarrayoption['options_'.$key.'_rfc'] = '';
1238 }
1239 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1240 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1241 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1242 $datetime = $formatedarrayoption['options_'.$key];
1243 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1244 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1245 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1246 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1247 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1248 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1249 $id = $formatedarrayoption['options_'.$key];
1250 if ($id != "") {
1251 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1252 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1253 $InfoFieldList = explode(":", $param_list[0]);
1254 $classname = $InfoFieldList[0];
1255 $classpath = $InfoFieldList[1];
1256 if (!empty($classpath)) {
1257 dol_include_once($InfoFieldList[1]);
1258 if ($classname && class_exists($classname)) {
1259 $tmpobject = new $classname($this->db);
1260 '@phan-var-force CommonObject $tmpobject';
1261 $tmpobject->fetch($id);
1262 // completely replace the id with the linked object name
1263 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1264 }
1265 }
1266 }
1267 }
1268
1269 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1270 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1271 } else {
1272 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1273 }
1274 }
1275 }
1276
1277 return $array_to_fill;
1278 }
1279
1280
1293 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1294 {
1295 if (empty($hidetop) || $hidetop == -1) {
1296 $pdf->line($x, $y, $x + $l, $y);
1297 }
1298 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1299 if (empty($hidebottom)) {
1300 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1301 }
1302 $pdf->line($x, $y + $h, $x, $y);
1303 }
1304
1319 public function printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop = 0, $hidebottom = 0, $style = 'D')
1320 {
1321 // Top line
1322 if (empty($hidetop) || $hidetop == -1) {
1323 $pdf->RoundedRect($x, $y, $w, $h, $r, '1111', $style);
1324 } else {
1325 // Draw rounded rectangle with hidden top side
1326 $pdf->RoundedRect($x, $y, $w, $h, $r, '0111', $style);
1327 }
1328 if (!empty($hidebottom)) {
1329 $pdf->RoundedRect($x, $y, $w, $h, $r, '1101', $style);
1330 }
1331 }
1332
1338 {
1339 if (empty($this->afterColsLinePositions) || !is_array($this->afterColsLinePositions)) {
1340 return false;
1341 }
1342
1343 $colId = '';
1344 $maxPage = $maxY = 0;
1345 foreach ($this->afterColsLinePositions as $colKey => $value) {
1346 if ($value['page'] > $maxPage) {
1347 $colId = $colKey;
1348 $maxPage = $value['page'];
1349 $maxY = $value['y']; // if page is higher we need to reset y to new max page y
1350 } elseif ($value['page'] == $maxPage) {
1351 $maxY = max($value['y'], $maxY);
1352 $colId = $colKey;
1353 }
1354 }
1355
1356 return [
1357 'col' => $colId,
1358 'y' => $maxY,
1359 'page' => $maxPage
1360 ];
1361 }
1362
1369 public function resetAfterColsLinePositionsData(float $y, int $pageNumb)
1370 {
1371 $this->afterColsLinePositions = [];
1372 $this->setAfterColsLinePositionsData('startLine', $y, $pageNumb);
1373 }
1374
1382 public function setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
1383 {
1384 $this->afterColsLinePositions[$colId] = [
1385 'page' => $pageNumb,
1386 'y' => $y
1387 ];
1388 }
1389
1390
1398 public function columnSort($a, $b)
1399 {
1400 if (empty($a['rank'])) {
1401 $a['rank'] = 0;
1402 }
1403 if (empty($b['rank'])) {
1404 $b['rank'] = 0;
1405 }
1406 if ($a['rank'] == $b['rank']) {
1407 return 0;
1408 }
1409 return ($a['rank'] > $b['rank']) ? -1 : 1;
1410 }
1411
1422 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1423 {
1424 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1425
1426
1427 // Sorting
1428 uasort($this->cols, array($this, 'columnSort'));
1429
1430 // Positioning
1431 $curX = $this->page_largeur - $this->marge_droite; // start from right
1432
1433 // Array width
1434 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1435
1436 // Count flexible column
1437 $totalDefinedColWidth = 0;
1438 $countFlexCol = 0;
1439 foreach ($this->cols as $colKey => & $colDef) {
1440 if (!$this->getColumnStatus($colKey)) {
1441 continue; // continue if disabled
1442 }
1443
1444 if (!empty($colDef['scale'])) {
1445 // In case of column width is defined by percentage
1446 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1447 }
1448
1449 if (empty($colDef['width'])) {
1450 $countFlexCol++;
1451 } else {
1452 $totalDefinedColWidth += $colDef['width'];
1453 }
1454 }
1455
1456 foreach ($this->cols as $colKey => & $colDef) {
1457 // setting empty conf with default
1458 if (!empty($colDef['title'])) {
1459 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1460 } else {
1461 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1462 }
1463
1464 // setting empty conf with default
1465 if (!empty($colDef['content'])) {
1466 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1467 } else {
1468 $colDef['content'] = $this->defaultContentsFieldsStyle;
1469 }
1470
1471 if ($this->getColumnStatus($colKey)) {
1472 // In case of flexible column
1473 if (empty($colDef['width'])) {
1474 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1475 }
1476
1477 // Set positions
1478 $lastX = $curX;
1479 $curX = $lastX - $colDef['width'];
1480 $colDef['xStartPos'] = $curX;
1481 $colDef['xEndPos'] = $lastX;
1482 }
1483 }
1484 }
1485
1492 public function getColumnContentWidth($colKey)
1493 {
1494 $colDef = $this->cols[$colKey];
1495 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1496 }
1497
1498
1505 public function getColumnContentXStart($colKey)
1506 {
1507 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1508 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1509 }
1510
1517 public function getColumnRank($colKey)
1518 {
1519 if (!isset($this->cols[$colKey]['rank'])) {
1520 return -1;
1521 }
1522 return $this->cols[$colKey]['rank'];
1523 }
1524
1534 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1535 {
1536 // prepare wanted rank
1537 $rank = -1;
1538
1539 // try to get rank from target column
1540 if (!empty($targetCol)) {
1541 $rank = $this->getColumnRank($targetCol);
1542 if ($rank >= 0 && $insertAfterTarget) {
1543 $rank++;
1544 }
1545 }
1546
1547 // get rank from new column definition
1548 if ($rank < 0 && !empty($defArray['rank'])) {
1549 $rank = $defArray['rank'];
1550 }
1551
1552 // error: no rank
1553 if ($rank < 0) {
1554 return -1;
1555 }
1556
1557 foreach ($this->cols as $colKey => & $colDef) {
1558 if ($rank <= $colDef['rank']) {
1559 $colDef['rank'] += 1;
1560 }
1561 }
1562
1563 $defArray['rank'] = $rank;
1564 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1565
1566 return $rank;
1567 }
1568
1569
1579 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1580 {
1581 global $hookmanager;
1582
1583 $parameters = array(
1584 'curY' => &$curY,
1585 'columnText' => &$columnText,
1586 'colKey' => $colKey,
1587 'pdf' => &$pdf,
1588 );
1589 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1590 if ($reshook > 0 && isset($hookmanager->resArray['columnText'])) {
1591 $columnText = $hookmanager->resArray['columnText'];
1592 }
1593 if ($reshook < 0) {
1594 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1595 }
1596 if (!$reshook || $reshook > 0) {
1597 if (empty($columnText)) {
1598 return 0;
1599 }
1600 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
1601 $colDef = $this->cols[$colKey];
1602 // save current cell padding
1603 $curentCellPaddinds = $pdf->getCellPaddings();
1604 // set cell padding with column content definition
1605 $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);
1606 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, false, true, $colDef['content']['align']);
1607 $this->setAfterColsLinePositionsData($colKey, $pdf->GetY(), $pdf->getPage());
1608
1609 // restore cell padding
1610 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1611 }
1612
1613 return 0;
1614 }
1615
1616
1631 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1632 {
1633 global $hookmanager;
1634
1635 // load desc col params
1636 $colDef = $this->cols[$colKey];
1637 // save current cell padding
1638 $curentCellPaddinds = $pdf->getCellPaddings();
1639 // set cell padding with column content definition
1640 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1641
1642 // line description
1643 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline, empty($colDef['content']['align']) ? 'J' : $colDef['content']['align']);
1644 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1645
1646 // restore cell padding
1647 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1648
1649 // Display extrafield if needed
1650 $params = array(
1651 'display' => 'list',
1652 'printableEnable' => array(3),
1653 'printableEnableNotEmpty' => array(4)
1654 );
1655 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1656 if (!empty($extrafieldDesc)) {
1657 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1658 }
1659
1660 $parameters = array(
1661 'curY' => &$curY,
1662 'colKey' => $colKey,
1663 'object' => $object,
1664 'i' => $i,
1665 'outputlangs' => $outputlangs,
1666 'pdf' => &$pdf,
1667 );
1668 $reshook = $hookmanager->executeHooks('printColDescContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1669 if ($reshook < 0) {
1670 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1671 }
1672 }
1673
1683 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1684 {
1685 global $hookmanager;
1686
1687 if (empty($object->table_element)) {
1688 return '';
1689 }
1690
1691 $extrafieldsKeyPrefix = "options_";
1692
1693 // Cleanup extrafield key to remove prefix if present
1694 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1695 if ($pos === 0) {
1696 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1697 }
1698
1699 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1700
1701
1702 // Load extra fields if they haven't been loaded already.
1703 if (is_null($this->extrafieldsCache)) {
1704 $this->extrafieldsCache = new ExtraFields($this->db);
1705 }
1706 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1707 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1708 }
1709 $extrafields = $this->extrafieldsCache;
1710
1711 $extrafieldOutputContent = '';
1712 if (isset($object->array_options[$extrafieldOptionsKey])) {
1713 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1714 }
1715
1716 // 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 ...
1717 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1718 // for lack of anything better we cleanup all html tags
1719 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1720 }
1721
1722 // Display stars extrafield as simple string
1723 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'stars') {
1724 $extrafieldOutputContent = '';
1725 for ($i = 0; $i < $object->array_options[$extrafieldOptionsKey]; $i++) {
1726 $extrafieldOutputContent .= ' *';
1727 }
1728 }
1729
1730 $parameters = array(
1731 'object' => $object,
1732 'extrafields' => $extrafields,
1733 'extrafieldKey' => $extrafieldKey,
1734 'extrafieldOutputContent' => & $extrafieldOutputContent
1735 );
1736 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1737 if ($reshook < 0) {
1738 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1739 }
1740 if ($reshook) {
1741 $extrafieldOutputContent = $hookmanager->resPrint;
1742 }
1743
1744 return $extrafieldOutputContent;
1745 }
1746
1747
1756 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1757 {
1758 global $hookmanager;
1759
1760 if (empty($object->table_element)) {
1761 return "";
1762 }
1763
1764 // Load extrafields if not already done
1765 if (is_null($this->extrafieldsCache)) {
1766 $this->extrafieldsCache = new ExtraFields($this->db);
1767 }
1768 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1769 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1770 }
1771 $extrafields = $this->extrafieldsCache;
1772
1773 $defaultParams = array(
1774 'style' => '',
1775 'display' => 'auto', // auto, table, list
1776 'printableEnable' => array(1),
1777 'printableEnableNotEmpty' => array(2),
1778
1779 'table' => array(
1780 'maxItemsInRow' => 2,
1781 'cellspacing' => 0,
1782 'cellpadding' => 0,
1783 'border' => 0,
1784 'labelcolwidth' => '25%',
1785 'arrayOfLineBreakType' => array('text', 'html')
1786 ),
1787
1788 'list' => array(
1789 'separator' => '<br>'
1790 ),
1791
1792 'auto' => array(
1793 'list' => 0, // 0 for default
1794 'table' => 4 // if there more than x extrafield to display
1795 ),
1796 );
1797
1798 $params += $defaultParams;
1799
1804 $html = '';
1805 $fields = array();
1806
1807 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1808 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1809 // Enable extrafield ?
1810 $enabled = 0;
1811 if (!empty($extrafields->attributes[$object->table_element]['enabled'][$key])) {
1812 $enabled = (int) dol_eval((string) $extrafields->attributes[$object->table_element]['enabled'][$key], 1, 1, '2');
1813 }
1814
1815 if (!$enabled) {
1816 continue;
1817 }
1818
1819 // Reset enabled: only printable attribute determines PDF visibility
1820 $enabled = 0;
1821 $disableOnEmpty = 0;
1822 $printable = 0;
1823 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1824 $printable = (int) $extrafields->attributes[$object->table_element]['printable'][$key];
1825 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1826 $enabled = 1;
1827 }
1828
1829 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1830 $disableOnEmpty = 1;
1831 }
1832 }
1833
1834 if (empty($enabled) || empty($printable)) {
1835 continue;
1836 }
1837
1838 // Load language if required
1839 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1840 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1841 }
1842
1843 $field = new stdClass();
1844 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1845 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1846 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1847 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1848 }
1849 $field->label = $outputlangs->transnoentities($label);
1850 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1851
1852 // don't display if empty
1853 if ($disableOnEmpty && empty($field->content)) {
1854 continue;
1855 }
1856
1857 $fields[] = $field;
1858 }
1859 }
1860
1861 if (!empty($fields)) {
1862 // Sort extrafields by rank
1863 uasort(
1864 $fields,
1870 static function ($a, $b) {
1871 return ($a->rank > $b->rank) ? 1 : -1;
1872 }
1873 );
1874
1875 // define some HTML content with style
1876 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1877
1878 // auto select display format
1879 if ($params['display'] == 'auto') {
1880 $lastNnumbItems = 0;
1881 foreach ($params['auto'] as $display => $numbItems) {
1882 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1883 $lastNnumbItems = $numbItems;
1884 $params['display'] = $display;
1885 }
1886 }
1887 }
1888
1889 if ($params['display'] == 'list') {
1890 // Display in list format
1891 $i = 0;
1892 foreach ($fields as $field) {
1893 $html .= !empty($i) ? $params['list']['separator'] : '';
1894 $html .= '<strong>'.$field->label.' : </strong>';
1895 $html .= $field->content;
1896 $i++;
1897 }
1898 } elseif ($params['display'] == 'table') {
1899 // Display in table format
1900 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1901
1902 $html .= "<tr>";
1903 $itemsInRow = 0;
1904 $maxItemsInRow = $params['table']['maxItemsInRow'];
1905 foreach ($fields as $field) {
1906 //$html.= !empty($html)?'<br>':'';
1907 if ($itemsInRow >= $maxItemsInRow) {
1908 // start a new line
1909 $html .= "</tr><tr>";
1910 $itemsInRow = 0;
1911 }
1912
1913 // for some type we need line break
1914 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1915 if ($itemsInRow > 0) {
1916 // close table row and empty cols
1917 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1918 $html .= "<td></td><td></td>";
1919 }
1920 $html .= "</tr>";
1921
1922 // start a new line
1923 $html .= "<tr>";
1924 }
1925
1926 $itemsInRow = $maxItemsInRow;
1927 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1928 $html .= '<strong>'.$field->label.' :</strong> ';
1929 $html .= $field->content;
1930 $html .= "</td>";
1931 } else {
1932 $itemsInRow++;
1933 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1934 $html .= '<strong>'.$field->label.' :</strong>';
1935 $html .= "</td>";
1936
1937
1938 $html .= '<td class="extrafield-content">';
1939 $html .= $field->content;
1940 $html .= "</td>";
1941 }
1942 }
1943 $html .= "</tr>";
1944
1945 $html .= '</table>';
1946 }
1947 }
1948
1949 return $html;
1950 }
1951
1952
1959 public function getColumnStatus($colKey)
1960 {
1961 if (!empty($this->cols[$colKey]['status'])) {
1962 return true;
1963 } else {
1964 return false;
1965 }
1966 }
1967
1978 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1979 {
1980 global $hookmanager, $conf;
1981
1982 foreach ($this->cols as $colKey => $colDef) {
1983 $parameters = array(
1984 'colKey' => $colKey,
1985 'pdf' => $pdf,
1986 'outputlangs' => $outputlangs,
1987 'tab_top' => $tab_top,
1988 'tab_height' => $tab_height,
1989 'hidetop' => $hidetop
1990 );
1991
1992 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1993 if ($reshook < 0) {
1994 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1995 } elseif (empty($reshook)) {
1996 if (!$this->getColumnStatus($colKey)) {
1997 continue;
1998 }
1999
2000 // get title label
2001 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
2002
2003 // Add column separator
2004 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
2005 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
2006 }
2007
2008 if (empty($hidetop)) {
2009 // save current cell padding
2010 $curentCellPaddinds = $pdf->getCellPaddings();
2011
2012 // Add space for lines (more if we need to show a second alternative language)
2013 global $outputlangsbis;
2014 if (is_object($outputlangsbis)) {
2015 // set cell padding with column title definition
2016 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
2017 } else {
2018 // set cell padding with column title definition
2019 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
2020 }
2021 if (isset($colDef['title']['align'])) {
2022 $align = $colDef['title']['align'];
2023 } else {
2024 $align = '';
2025 }
2026 $pdf->SetXY($colDef['xStartPos'], $tab_top);
2027 $textWidth = $colDef['width'];
2028 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
2029
2030 // Add variant of translation if $outputlangsbis is an object
2031 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
2032 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
2033 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
2034 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
2035 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
2036 }
2037
2038 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
2039
2040 // restore cell padding
2041 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
2042 }
2043 }
2044 }
2045
2046 return $this->tabTitleHeight;
2047 }
2048
2049
2050
2059 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
2060 {
2061 if (!empty($hidedetails)) {
2062 return 0;
2063 }
2064
2065 if (empty($object->table_element)) {
2066 return 0;
2067 }
2068
2069 // Load extra fields if they haven't been loaded already.
2070 if (is_null($this->extrafieldsCache)) {
2071 $this->extrafieldsCache = new ExtraFields($this->db);
2072 }
2073 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
2074 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
2075 }
2076 $extrafields = $this->extrafieldsCache;
2077
2078
2079 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'])) {
2080 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
2081 // Don't display separator yet even is set to be displayed (not compatible yet)
2082 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
2083 continue;
2084 }
2085
2086 // Enable extrafield ?
2087 $enabled = 0;
2088 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
2089 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
2090 if ($printable === 1 || $printable === 2) {
2091 $enabled = 1;
2092 }
2093 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
2094 }
2095
2096 if (!$enabled) {
2097 continue;
2098 } // don't waste resources if we don't need them...
2099
2100 // Load language if required
2101 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
2102 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
2103 }
2104
2105 // TODO : add more extrafield customisation capacities for PDF like width, rank...
2106
2107 // set column definition
2108 $def = array(
2109 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
2110 'width' => 25, // in mm
2111 'status' => (bool) $enabled,
2112 'title' => array(
2113 'label' => $outputlangs->transnoentities($label)
2114 ),
2115 'content' => array(
2116 'align' => 'C'
2117 ),
2118 'border-left' => true, // add left line separator
2119 );
2120
2121 $alignTypeRight = array('double', 'int', 'price');
2122 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
2123 $def['content']['align'] = 'R';
2124 }
2125
2126 $alignTypeLeft = array('text', 'html');
2127 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
2128 $def['content']['align'] = 'L';
2129 }
2130
2131
2132 // for extrafields we use rank of extrafield to place it on PDF
2133 $this->insertNewColumnDef("options_".$key, $def);
2134 }
2135 }
2136
2137 return 1;
2138 }
2139
2151 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2152 {
2153 // Default field style for content
2154 $this->defaultContentsFieldsStyle = array(
2155 'align' => 'R', // R,C,L
2156 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2157 );
2158
2159 // Default field style for content
2160 $this->defaultTitlesFieldsStyle = array(
2161 'align' => 'C', // R,C,L
2162 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2163 );
2164
2165 // Example
2166 /*
2167 $rank = 0; // do not use negative rank
2168 $this->cols['desc'] = array(
2169 'rank' => $rank,
2170 'width' => false, // only for desc
2171 'status' => true,
2172 'title' => array(
2173 'textkey' => 'Designation', // use lang key is useful in some case with module
2174 'align' => 'L',
2175 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2176 // 'label' => ' ', // the final label
2177 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2178 ),
2179 'content' => array(
2180 'align' => 'L',
2181 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2182 ),
2183 );
2184 */
2185 }
2186}
$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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:1846
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
print $langs trans('Date')." left Ref 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 Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:487