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