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