dolibarr 19.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-2023 Frédéric France <frederic.france@netlogic.fr>
9 * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
10 * Copyright (C) 2024 Mélina Joum <melina.joum@altairis.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
37abstract class CommonDocGenerator
38{
42 public $name = '';
43
47 public $version = '';
48
52 public $error = '';
53
57 public $errors = array();
58
62 protected $db;
63
67 public $extrafieldsCache;
68
72 public $update_main_doc_field;
73
77 public $scandir;
78
82 public $description;
83
87 public $format;
88
92 public $type;
93
94 public $page_hauteur;
95 public $page_largeur;
96 public $marge_gauche;
97 public $marge_droite;
98 public $marge_haute;
99 public $marge_basse;
100
101 public $option_logo;
102 public $option_tva;
103 public $option_multilang;
104 public $option_freetext;
105 public $option_draft_watermark;
106 public $watermark;
107
108 public $option_modereg;
109 public $option_condreg;
110 public $option_escompte;
111 public $option_credit_note;
112
113 public $tva;
114 public $tva_array;
115 public $localtax1;
116 public $localtax2;
117
121 public $tabTitleHeight;
122
126 public $defaultTitlesFieldsStyle;
127
131 public $defaultContentsFieldsStyle;
132
136 public $emetteur;
137
142 public $phpmin = array(7, 1);
143
147 public $cols;
148
152 public $result;
153
154 public $posxlabel;
155 public $posxup;
156 public $posxref;
157 public $posxpicture; // For picture
158 public $posxdesc; // For description
159 public $posxqty;
160 public $posxpuht;
161 public $posxtva;
162 public $posxtotalht;
163 public $postotalht;
164 public $posxunit;
165 public $posxdiscount;
166 public $posxworkload;
167 public $posxtimespent;
168 public $posxprogress;
169 public $atleastonephoto;
170 public $atleastoneratenotnull;
171 public $atleastonediscount;
172
178 public function __construct($db)
179 {
180 $this->db = $db;
181 }
182
183
184 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
192 public function get_substitutionarray_user($user, $outputlangs)
193 {
194 // phpcs:enable
195 global $conf, $extrafields;
196
197 $logotouse = $conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo;
198
199 $array_user = array(
200 'myuser_lastname'=>$user->lastname,
201 'myuser_firstname'=>$user->firstname,
202 'myuser_fullname'=>$user->getFullName($outputlangs, 1),
203 'myuser_login'=>$user->login,
204 'myuser_phone'=>$user->office_phone,
205 'myuser_address'=>$user->address,
206 'myuser_zip'=>$user->zip,
207 'myuser_town'=>$user->town,
208 'myuser_country'=>$user->country,
209 'myuser_country_code'=>$user->country_code,
210 'myuser_state'=>$user->state,
211 'myuser_state_code'=>$user->state_code,
212 'myuser_fax'=>$user->office_fax,
213 'myuser_mobile'=>$user->user_mobile,
214 'myuser_email'=>$user->email,
215 'myuser_logo'=>$logotouse,
216 'myuser_job'=>$user->job,
217 'myuser_web'=>'', // url not exist in $user object
218 'myuser_birth'=>dol_print_date($user->birth, 'day', 'gmt'),
219 'myuser_dateemployment'=>dol_print_date($user->dateemployment, 'day', 'tzuser'),
220 'myuser_dateemploymentend'=>dol_print_date($user->dateemploymentend, 'day', 'tzuser'),
221 'myuser_gender'=>$user->gender,
222 );
223 // Retrieve extrafields
224 if (is_array($user->array_options) && count($user->array_options)) {
225 $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
226 }
227 return $array_user;
228 }
229
230
238 public function getSubstitutionarrayMember($member, $outputlangs)
239 {
240 global $conf, $extrafields;
241
242 if ($member->photo) {
243 $logotouse = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
244 } else {
245 $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
246 }
247
248 $array_member = array(
249 'mymember_lastname' => $member->lastname,
250 'mymember_firstname' => $member->firstname,
251 'mymember_fullname' => $member->getFullName($outputlangs, 1),
252 'mymember_login' => $member->login,
253 'mymember_address' => $member->address,
254 'mymember_zip' => $member->zip,
255 'mymember_town' => $member->town,
256 'mymember_country_code' => $member->country_code,
257 'mymember_country' => $member->country,
258 'mymember_state_code' => $member->state_code,
259 'mymember_state' => $member->state,
260 'mymember_phone_perso' => $member->phone_perso,
261 'mymember_phone_pro' => $member->phone,
262 'mymember_phone_mobile' => $member->phone_mobile,
263 'mymember_email' => $member->email,
264 'mymember_logo' => $logotouse,
265 'mymember_gender' => $member->gender,
266 'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
267 'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
268 );
269 // Retrieve extrafields
270 if (is_array($member->array_options) && count($member->array_options)) {
271 $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
272 }
273 return $array_member;
274 }
275
276
277 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
285 public function get_substitutionarray_mysoc($mysoc, $outputlangs)
286 {
287 // phpcs:enable
288 global $conf;
289
290 if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
291 $mysoc->forme_juridique = getFormeJuridiqueLabel($mysoc->forme_juridique_code);
292 }
293 if (empty($mysoc->country) && !empty($mysoc->country_code)) {
294 $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
295 }
296 if (empty($mysoc->state) && !empty($mysoc->state_code)) {
297 $mysoc->state = getState($mysoc->state_code, 0);
298 }
299
300 $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
301
302 return array(
303 'mycompany_logo'=>$logotouse,
304 'mycompany_name'=>$mysoc->name,
305 'mycompany_email'=>$mysoc->email,
306 'mycompany_phone'=>$mysoc->phone,
307 'mycompany_fax'=>$mysoc->fax,
308 'mycompany_address'=>$mysoc->address,
309 'mycompany_zip'=>$mysoc->zip,
310 'mycompany_town'=>$mysoc->town,
311 'mycompany_country'=>$mysoc->country,
312 'mycompany_country_code'=>$mysoc->country_code,
313 'mycompany_state'=>$mysoc->state,
314 'mycompany_state_code'=>$mysoc->state_code,
315 'mycompany_web'=>$mysoc->url,
316 'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
317 'mycompany_managers'=>$mysoc->managers,
318 'mycompany_capital'=>$mysoc->capital,
319 'mycompany_barcode'=>$mysoc->barcode,
320 'mycompany_idprof1'=>$mysoc->idprof1,
321 'mycompany_idprof2'=>$mysoc->idprof2,
322 'mycompany_idprof3'=>$mysoc->idprof3,
323 'mycompany_idprof4'=>$mysoc->idprof4,
324 'mycompany_idprof5'=>$mysoc->idprof5,
325 'mycompany_idprof6'=>$mysoc->idprof6,
326 'mycompany_vatnumber'=>$mysoc->tva_intra,
327 'mycompany_socialobject'=>$mysoc->socialobject,
328 'mycompany_note_private'=>$mysoc->note_private,
329 //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
330 );
331 }
332
333
334 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
344 public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
345 {
346 // phpcs:enable
347 global $extrafields;
348
349 if (!is_object($object)) {
350 return array();
351 }
352
353 if (empty($object->country) && !empty($object->country_code)) {
354 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
355 }
356 if (empty($object->state) && !empty($object->state_code)) {
357 $object->state = getState($object->state_code, 0);
358 }
359
360 $array_thirdparty = array(
361 'company_name'=>$object->name,
362 'company_name_alias' => $object->name_alias,
363 'company_email'=>$object->email,
364 'company_phone'=>$object->phone,
365 'company_fax'=>$object->fax,
366 'company_address'=>$object->address,
367 'company_zip'=>$object->zip,
368 'company_town'=>$object->town,
369 'company_country'=>$object->country,
370 'company_country_code'=>$object->country_code,
371 'company_state'=>$object->state,
372 'company_state_code'=>$object->state_code,
373 'company_web'=>$object->url,
374 'company_barcode'=>$object->barcode,
375 'company_vatnumber'=>$object->tva_intra,
376 'company_customercode'=>$object->code_client,
377 'company_suppliercode'=>$object->code_fournisseur,
378 'company_customeraccountancycode'=>$object->code_compta,
379 'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
380 'company_juridicalstatus'=>$object->forme_juridique,
381 'company_outstanding_limit'=>$object->outstanding_limit,
382 'company_capital'=>$object->capital,
383 'company_capital_formated'=> price($object->capital, 0, '', 1, -1),
384 'company_idprof1'=>$object->idprof1,
385 'company_idprof2'=>$object->idprof2,
386 'company_idprof3'=>$object->idprof3,
387 'company_idprof4'=>$object->idprof4,
388 'company_idprof5'=>$object->idprof5,
389 'company_idprof6'=>$object->idprof6,
390 'company_note_public'=>$object->note_public,
391 'company_note_private'=>$object->note_private,
392 'company_default_bank_iban'=>(is_object($object->bank_account) ? $object->bank_account->iban : ''),
393 'company_default_bank_bic'=>(is_object($object->bank_account) ? $object->bank_account->bic : '')
394 );
395
396 // Retrieve extrafields
397 if (is_array($object->array_options) && count($object->array_options)) {
398 $object->fetch_optionals();
399
400 $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
401 }
402 return $array_thirdparty;
403 }
404
405 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
414 public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
415 {
416 // phpcs:enable
417 global $conf, $extrafields;
418
419 if (empty($object->country) && !empty($object->country_code)) {
420 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
421 }
422 if (empty($object->state) && !empty($object->state_code)) {
423 $object->state = getState($object->state_code, 0);
424 }
425
426 $array_contact = array(
427 $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
428 $array_key.'_lastname' => $object->lastname,
429 $array_key.'_firstname' => $object->firstname,
430 $array_key.'_address' => $object->address,
431 $array_key.'_zip' => $object->zip,
432 $array_key.'_town' => $object->town,
433 $array_key.'_state_id' => $object->state_id,
434 $array_key.'_state_code' => $object->state_code,
435 $array_key.'_state' => $object->state,
436 $array_key.'_country_id' => $object->country_id,
437 $array_key.'_country_code' => $object->country_code,
438 $array_key.'_country' => $object->country,
439 $array_key.'_poste' => $object->poste,
440 $array_key.'_socid' => $object->socid,
441 $array_key.'_statut' => $object->statut,
442 $array_key.'_code' => $object->code,
443 $array_key.'_email' => $object->email,
444 $array_key.'_phone_pro' => $object->phone_pro,
445 $array_key.'_phone_perso' => $object->phone_perso,
446 $array_key.'_phone_mobile' => $object->phone_mobile,
447 $array_key.'_fax' => $object->fax,
448 $array_key.'_birthday' => $object->birthday,
449 $array_key.'_default_lang' => $object->default_lang,
450 $array_key.'_note_public' => $object->note_public,
451 $array_key.'_note_private' => $object->note_private,
452 $array_key.'_civility' => $object->civility,
453 );
454
455 // Retrieve extrafields
456 if (is_array($object->array_options) && count($object->array_options)) {
457 $object->fetch_optionals();
458
459 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
460 }
461 return $array_contact;
462 }
463
464
465 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
472 public function get_substitutionarray_other($outputlangs)
473 {
474 // phpcs:enable
475 global $conf;
476
477 $now = dol_now('gmt'); // gmt
478 $array_other = array(
479 // Date in default language
480 'current_date'=>dol_print_date($now, 'day', 'tzuser'),
481 'current_datehour'=>dol_print_date($now, 'dayhour', 'tzuser'),
482 'current_server_date'=>dol_print_date($now, 'day', 'tzserver'),
483 'current_server_datehour'=>dol_print_date($now, 'dayhour', 'tzserver'),
484 // Date in requested output language
485 'current_date_locale'=>dol_print_date($now, 'day', 'tzuser', $outputlangs),
486 'current_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
487 'current_server_date_locale'=>dol_print_date($now, 'day', 'tzserver', $outputlangs),
488 'current_server_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
489 );
490
491
492 foreach ($conf->global as $key => $val) {
493 if (isASecretKey($key)) {
494 $newval = '*****forbidden*****';
495 } else {
496 $newval = $val;
497 }
498 $array_other['__['.$key.']__'] = $newval;
499 }
500
501 return $array_other;
502 }
503
504
505 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
515 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
516 {
517 // phpcs:enable
518 global $conf, $extrafields;
519
520 $sumpayed = $sumdeposit = $sumcreditnote = '';
521 $already_payed_all = 0;
522
523 if ($object->element == 'facture') {
524 $invoice_source = new Facture($this->db);
525 if ($object->fk_facture_source > 0) {
526 $invoice_source->fetch($object->fk_facture_source);
527 }
528 $sumpayed = $object->getSommePaiement();
529 $sumdeposit = $object->getSumDepositsUsed();
530 $sumcreditnote = $object->getSumCreditNotesUsed();
531 $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
532 }
533
534 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
535
536 if (get_class($object) == 'CommandeFournisseur') {
537 /* @var $object CommandeFournisseur*/
538 $object->date_validation = $object->date_valid;
539 $object->date_commande = $object->date;
540 }
541 $resarray = array(
542 $array_key.'_id'=>$object->id,
543 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
544 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
545 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
546 $array_key.'_ref_customer'=>(!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
547 $array_key.'_ref_supplier'=>(!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
548 $array_key.'_source_invoice_ref'=>((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
549 // Dates
550 $array_key.'_hour'=>dol_print_date($date, 'hour'),
551 $array_key.'_date'=>dol_print_date($date, 'day'),
552 $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'),
553 $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
554 $array_key.'_date_limit_rfc'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
555 $array_key.'_date_end'=>(!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''),
556 $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
557 $array_key.'_date_modification'=>(!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
558 $array_key.'_date_validation'=>(!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
559 $array_key.'_date_approve'=>(!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
560 $array_key.'_date_delivery_planed'=>(!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
561 $array_key.'_date_close'=>(!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
562
563 $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
564 $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),
565 $array_key.'_payment_term_code'=>$object->cond_reglement_code,
566 $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)),
567
568 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
569
570 $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
571 $array_key.'_total_vat_locale'=>(!empty($object->total_vat) ? price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
572 $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
573 $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
574 $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
575
576 $array_key.'_total_ht'=>price2num($object->total_ht),
577 $array_key.'_total_vat'=>(!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)),
578 $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
579 $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
580 $array_key.'_total_ttc'=>price2num($object->total_ttc),
581
582 $array_key.'_multicurrency_code' => $object->multicurrency_code,
583 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
584 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
585 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
586 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
587 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
588 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
589 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
590
591 $array_key.'_note_private'=>$object->note_private,
592 $array_key.'_note_public'=>$object->note_public,
593 $array_key.'_note'=>$object->note_public, // For backward compatibility
594
595 // Payments
596 $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
597 $array_key.'_already_payed'=>price2num($sumpayed),
598 $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
599 $array_key.'_already_deposit'=>price2num($sumdeposit),
600 $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
601 $array_key.'_already_creditnote'=>price2num($sumcreditnote),
602
603 $array_key.'_already_payed_all_locale'=>price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
604 $array_key.'_already_payed_all'=> price2num($already_payed_all, 'MT'),
605
606 // Remain to pay with all known information (except open direct debit requests)
607 $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
608 $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $already_payed_all, 'MT')
609 );
610
611 if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur'))) {
612 $bank_account = null;
613
614 if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
615 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
616 $bank_account = new Account($this->db);
617 $bank_account->fetch($object->fk_account);
618 }
619
620 $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
621 $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
622 $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
623 $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
624 $resarray[$array_key.'_bank_proprio'] =(empty($bank_account) ? '' : $bank_account->proprio);
625 }
626
627 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
628 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
629 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
630 } else {
631 $resarray[$array_key.'_total_discount_ht_locale'] = '';
632 $resarray[$array_key.'_total_discount_ht'] = '';
633 }
634
635 // Fetch project information if there is a project assigned to this object
636 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
637 if (!is_object($object->project)) {
638 $object->fetch_projet();
639 }
640
641 $resarray[$array_key.'_project_ref'] = $object->project->ref;
642 $resarray[$array_key.'_project_title'] = $object->project->title;
643 $resarray[$array_key.'_project_description'] = $object->project->description;
644 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
645 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
646 } else { // empty replacement
647 $resarray[$array_key.'_project_ref'] ='';
648 $resarray[$array_key.'_project_title'] = '';
649 $resarray[$array_key.'_project_description'] = '';
650 $resarray[$array_key.'_project_date_start'] = '';
651 $resarray[$array_key.'_project_date_end'] = '';
652 }
653
654 // Add vat by rates
655 if (is_array($object->lines) && count($object->lines) > 0) {
656 $totalUp = 0;
657 // Set substitution keys for different VAT rates
658 foreach ($object->lines as $line) {
659 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
660 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
661 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
662 }
663 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
664 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
665 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
666 $vatformated = vatrate($line->tva_tx);
667 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
668 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
669 }
670 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
671 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
672
673 $totalUp += $line->subprice * $line->qty;
674 }
675
676 // Calculate total up and total discount percentage
677 // 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)
678 $resarray['object_total_up'] = $totalUp;
679 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
680 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
681 $totalDiscount = $object->getTotalDiscount();
682 } else {
683 $totalDiscount = 0;
684 }
685 if (!empty($totalUp) && !empty($totalDiscount)) {
686 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
687 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
688 } else {
689 $resarray['object_total_discount'] = '';
690 $resarray['object_total_discount_locale'] = '';
691 }
692 }
693
694 // Retrieve extrafields
695 if (is_array($object->array_options) && count($object->array_options)) {
696 $object->fetch_optionals();
697
698 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
699 }
700
701 return $resarray;
702 }
703
704 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
714 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
715 {
716 // phpcs:enable
717 $resarray = array(
718 'line_pos' => $linenumber,
719 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
720
721 'line_product_ref'=>(empty($line->product_ref) ? '' : $line->product_ref),
722 'line_product_ref_fourn'=>(empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
723 'line_product_label'=>(empty($line->product_label) ? '' : $line->product_label),
724 'line_product_type'=>(empty($line->product_type) ? '' : $line->product_type),
725 'line_product_barcode'=>(empty($line->product_barcode) ? '' : $line->product_barcode),
726 'line_product_desc'=>(empty($line->product_desc) ? '' : $line->product_desc),
727
728 'line_desc'=>$line->desc,
729 'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
730 'line_localtax1_rate'=>vatrate($line->localtax1_tx),
731 'line_localtax2_rate'=>vatrate($line->localtax1_tx),
732 'line_up'=>price2num($line->subprice),
733 'line_up_locale'=>price($line->subprice, 0, $outputlangs),
734 'line_total_up'=>price2num($line->subprice * $line->qty),
735 'line_total_up_locale'=>price($line->subprice * $line->qty, 0, $outputlangs),
736 'line_qty'=>$line->qty,
737 'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
738 'line_price_ht'=>price2num($line->total_ht),
739 'line_price_ttc'=>price2num($line->total_ttc),
740 'line_price_vat'=>price2num($line->total_tva),
741 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
742 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
743 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
744 // Dates
745 'line_date_start'=>dol_print_date($line->date_start, 'day'),
746 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
747 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc'),
748 'line_date_end'=>dol_print_date($line->date_end, 'day'),
749 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
750 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc'),
751
752 'line_multicurrency_code' => price2num($line->multicurrency_code),
753 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
754 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
755 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
756 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
757 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
758 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
759 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
760 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
761 );
762
763 // Units
764 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
765 $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
766 $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
767 }
768
769 // Retrieve extrafields
770 $extrafieldkey = $line->table_element;
771 $array_key = "line";
772 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
773 $extrafields = new ExtraFields($this->db);
774 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
775 $line->fetch_optionals();
776
777 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
778
779 // Check if the current line belongs to a supplier order
780 if (get_class($line) == 'CommandeFournisseurLigne') {
781 // Add the product supplier extrafields to the substitutions
782 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
783 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
784
785 if (!empty($extralabels) && is_array($extralabels)) {
786 $columns = "";
787
788 foreach ($extralabels as $key => $label) {
789 $columns .= "$key, ";
790 }
791
792 if ($columns != "") {
793 $columns = substr($columns, 0, strlen($columns) - 2);
794 $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)."'");
795
796 if ($this->db->num_rows($resql) > 0) {
797 $resql = $this->db->fetch_object($resql);
798
799 foreach ($extralabels as $key => $label) {
800 $resarray['line_product_supplier_'.$key] = $resql->$key;
801 }
802 }
803 }
804 }
805 }
806
807 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
808 if (isset($line->fk_product) && $line->fk_product > 0) {
809 $tmpproduct = new Product($this->db);
810 $result = $tmpproduct->fetch($line->fk_product);
811 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
812 foreach ($tmpproduct->array_options as $key => $label) {
813 $resarray["line_product_".$key] = $label;
814 }
815 }
816 } else {
817 // Set unused placeholders as blank
818 $extrafields->fetch_name_optionals_label("product");
819 $extralabels = $extrafields->attributes["product"]['label'];
820
821 if (!empty($extralabels) && is_array($extralabels)) {
822 foreach ($extralabels as $key => $label) {
823 $resarray['line_product_options_'.$key] = '';
824 }
825 }
826 }
827
828 return $resarray;
829 }
830
831 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
841 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
842 {
843 // phpcs:enable
844 global $conf, $extrafields;
845 dol_include_once('/core/lib/product.lib.php');
846 $object->list_delivery_methods($object->shipping_method_id);
847 $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
848
849 $array_shipment = array(
850 $array_key.'_id'=>$object->id,
851 $array_key.'_ref'=>$object->ref,
852 $array_key.'_ref_ext'=>$object->ref_ext,
853 $array_key.'_ref_customer'=>$object->ref_customer,
854 $array_key.'_date_delivery'=>dol_print_date($object->date_delivery, 'day'),
855 $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery, 'hour'),
856 $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
857 $array_key.'_total_ht'=>price($object->total_ht),
858 $array_key.'_total_vat'=>price($object->total_tva),
859 $array_key.'_total_ttc'=>price($object->total_ttc),
860 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
861 $array_key.'_note_private'=>$object->note_private,
862 $array_key.'_note'=>$object->note_public,
863 $array_key.'_tracking_number'=>$object->tracking_number,
864 $array_key.'_tracking_url'=>$object->tracking_url,
865 $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
866 $array_key.'_weight'=>$object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
867 $array_key.'_width'=>$object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
868 $array_key.'_height'=>$object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
869 $array_key.'_depth'=>$object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
870 $array_key.'_size'=>$calculatedVolume.' '.measuringUnitString(0, 'volume'),
871 );
872
873 // Add vat by rates
874 foreach ($object->lines as $line) {
875 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
876 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
877 }
878 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
879 }
880
881 // Retrieve extrafields
882 if (is_array($object->array_options) && count($object->array_options)) {
883 $object->fetch_optionals();
884
885 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
886 }
887
888 // Add infor from $object->xxx where xxx has been loaded by fetch_origin() of shipment
889 if (!empty($object->commande) && is_object($object->commande)) {
890 $array_shipment['order_ref'] = $object->commande->ref;
891 $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
892 }
893
894 return $array_shipment;
895 }
896
897
898 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
907 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
908 {
909 // phpcs:enable
910 $array_other = array();
911 if (!empty($object)) {
912 foreach ($object as $key => $value) {
913 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
914 continue;
915 }
916 if (!empty($value)) {
917 if (!is_array($value) && !is_object($value)) {
918 $array_other['object_'.$key] = $value;
919 } elseif (is_array($value) && $recursive) {
920 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
921 if (!empty($tmparray) && is_array($tmparray)) {
922 foreach ($tmparray as $key2 => $value2) {
923 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
924 }
925 }
926 } elseif (is_object($value) && $recursive) {
927 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
928 if (!empty($tmparray) && is_array($tmparray)) {
929 foreach ($tmparray as $key2 => $value2) {
930 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
931 }
932 }
933 }
934 }
935 }
936 }
937
938 //var_dump($array_other);
939
940 return $array_other;
941 }
942
943
944 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
956 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
957 {
958 // phpcs:enable
959 global $conf;
960
961 if (isset($extrafields->attributes[$object->table_element]) && is_array($extrafields->attributes[$object->table_element]) && is_array($extrafields->attributes[$object->table_element]['label'])) {
962 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
963 $formatedarrayoption = $object->array_options;
964
965 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
966 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
967 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
968 //Add value to store price with currency
969 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
970 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
971 $valueofselectkey = $formatedarrayoption['options_'.$key];
972 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
973 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
974 } else {
975 $formatedarrayoption['options_'.$key] = '';
976 }
977 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
978 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
979 $output = array();
980 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
981 if (in_array($keyopt, $valArray)) {
982 $output[] = $valopt;
983 }
984 }
985 $formatedarrayoption['options_'.$key] = implode(', ', $output);
986 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
987 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
988 $date = $formatedarrayoption['options_'.$key];
989 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
990 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
991 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
992 } else {
993 $formatedarrayoption['options_'.$key] = '';
994 $formatedarrayoption['options_'.$key.'_locale'] = '';
995 $formatedarrayoption['options_'.$key.'_rfc'] = '';
996 }
997 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
998 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
999 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1000 $datetime = $formatedarrayoption['options_'.$key];
1001 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1002 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1003 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1004 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1005 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1006 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1007 $id = $formatedarrayoption['options_'.$key];
1008 if ($id != "") {
1009 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1010 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1011 $InfoFieldList = explode(":", $param_list[0]);
1012 $classname = $InfoFieldList[0];
1013 $classpath = $InfoFieldList[1];
1014 if (!empty($classpath)) {
1015 dol_include_once($InfoFieldList[1]);
1016 if ($classname && class_exists($classname)) {
1017 $tmpobject = new $classname($this->db);
1018 $tmpobject->fetch($id);
1019 // completely replace the id with the linked object name
1020 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1021 }
1022 }
1023 }
1024 }
1025
1026 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1027 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1028 } else {
1029 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1030 }
1031 }
1032 }
1033
1034 return $array_to_fill;
1035 }
1036
1037
1050 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1051 {
1052 if (empty($hidetop) || $hidetop == -1) {
1053 $pdf->line($x, $y, $x + $l, $y);
1054 }
1055 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1056 if (empty($hidebottom)) {
1057 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1058 }
1059 $pdf->line($x, $y + $h, $x, $y);
1060 }
1061
1062
1070 public function columnSort($a, $b)
1071 {
1072 if (empty($a['rank'])) {
1073 $a['rank'] = 0;
1074 }
1075 if (empty($b['rank'])) {
1076 $b['rank'] = 0;
1077 }
1078 if ($a['rank'] == $b['rank']) {
1079 return 0;
1080 }
1081 return ($a['rank'] > $b['rank']) ? -1 : 1;
1082 }
1083
1094 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1095 {
1096 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1097
1098
1099 // Sorting
1100 uasort($this->cols, array($this, 'columnSort'));
1101
1102 // Positionning
1103 $curX = $this->page_largeur - $this->marge_droite; // start from right
1104
1105 // Array width
1106 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1107
1108 // Count flexible column
1109 $totalDefinedColWidth = 0;
1110 $countFlexCol = 0;
1111 foreach ($this->cols as $colKey => & $colDef) {
1112 if (!$this->getColumnStatus($colKey)) {
1113 continue; // continue if disabled
1114 }
1115
1116 if (!empty($colDef['scale'])) {
1117 // In case of column width is defined by percentage
1118 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1119 }
1120
1121 if (empty($colDef['width'])) {
1122 $countFlexCol++;
1123 } else {
1124 $totalDefinedColWidth += $colDef['width'];
1125 }
1126 }
1127
1128 foreach ($this->cols as $colKey => & $colDef) {
1129 // setting empty conf with default
1130 if (!empty($colDef['title'])) {
1131 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1132 } else {
1133 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1134 }
1135
1136 // setting empty conf with default
1137 if (!empty($colDef['content'])) {
1138 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1139 } else {
1140 $colDef['content'] = $this->defaultContentsFieldsStyle;
1141 }
1142
1143 if ($this->getColumnStatus($colKey)) {
1144 // In case of flexible column
1145 if (empty($colDef['width'])) {
1146 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1147 }
1148
1149 // Set positions
1150 $lastX = $curX;
1151 $curX = $lastX - $colDef['width'];
1152 $colDef['xStartPos'] = $curX;
1153 $colDef['xEndPos'] = $lastX;
1154 }
1155 }
1156 }
1157
1164 public function getColumnContentWidth($colKey)
1165 {
1166 $colDef = $this->cols[$colKey];
1167 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1168 }
1169
1170
1177 public function getColumnContentXStart($colKey)
1178 {
1179 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1180 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1181 }
1182
1189 public function getColumnRank($colKey)
1190 {
1191 if (!isset($this->cols[$colKey]['rank'])) {
1192 return -1;
1193 }
1194 return $this->cols[$colKey]['rank'];
1195 }
1196
1206 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1207 {
1208 // prepare wanted rank
1209 $rank = -1;
1210
1211 // try to get rank from target column
1212 if (!empty($targetCol)) {
1213 $rank = $this->getColumnRank($targetCol);
1214 if ($rank >= 0 && $insertAfterTarget) {
1215 $rank++;
1216 }
1217 }
1218
1219 // get rank from new column definition
1220 if ($rank < 0 && !empty($defArray['rank'])) {
1221 $rank = $defArray['rank'];
1222 }
1223
1224 // error: no rank
1225 if ($rank < 0) {
1226 return -1;
1227 }
1228
1229 foreach ($this->cols as $colKey => & $colDef) {
1230 if ($rank <= $colDef['rank']) {
1231 $colDef['rank'] = $colDef['rank'] + 1;
1232 }
1233 }
1234
1235 $defArray['rank'] = $rank;
1236 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1237
1238 return $rank;
1239 }
1240
1241
1251 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1252 {
1253 global $hookmanager;
1254
1255 $parameters = array(
1256 'curY' => &$curY,
1257 'columnText' => $columnText,
1258 'colKey' => $colKey,
1259 'pdf' => &$pdf,
1260 );
1261 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1262 if ($reshook < 0) {
1263 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1264 }
1265 if (!$reshook) {
1266 if (empty($columnText)) {
1267 return 0;
1268 }
1269 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set curent position
1270 $colDef = $this->cols[$colKey];
1271 // save curent cell padding
1272 $curentCellPaddinds = $pdf->getCellPaddings();
1273 // set cell padding with column content definition
1274 $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);
1275 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1276
1277 // restore cell padding
1278 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1279 }
1280
1281 return 0;
1282 }
1283
1284
1299 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1300 {
1301 // load desc col params
1302 $colDef = $this->cols[$colKey];
1303 // save curent cell padding
1304 $curentCellPaddinds = $pdf->getCellPaddings();
1305 // set cell padding with column content definition
1306 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1307
1308 // line description
1309 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline);
1310 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1311
1312 // restore cell padding
1313 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1314
1315 // Display extrafield if needed
1316 $params = array(
1317 'display' => 'list',
1318 'printableEnable' => array(3),
1319 'printableEnableNotEmpty' => array(4)
1320 );
1321 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1322 if (!empty($extrafieldDesc)) {
1323 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1324 }
1325 }
1326
1336 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1337 {
1338 global $hookmanager;
1339
1340 if (empty($object->table_element)) {
1341 return '';
1342 }
1343
1344 $extrafieldsKeyPrefix = "options_";
1345
1346 // Cleanup extrafield key to remove prefix if present
1347 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1348 if ($pos === 0) {
1349 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1350 }
1351
1352 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1353
1354
1355 // Load extra fields if they haven't been loaded already.
1356 if (empty($this->extrafieldsCache)) {
1357 $this->extrafieldsCache = new ExtraFields($this->db);
1358 }
1359 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1360 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1361 }
1362 $extrafields = $this->extrafieldsCache;
1363
1364 $extrafieldOutputContent = '';
1365 if (isset($object->array_options[$extrafieldOptionsKey])) {
1366 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1367 }
1368
1369 // 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 ...
1370 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1371 // for lack of anything better we cleanup all html tags
1372 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1373 }
1374
1375 $parameters = array(
1376 'object' => $object,
1377 'extrafields' => $extrafields,
1378 'extrafieldKey' => $extrafieldKey,
1379 'extrafieldOutputContent' =>& $extrafieldOutputContent
1380 );
1381 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1382 if ($reshook < 0) {
1383 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1384 }
1385 if ($reshook) {
1386 $extrafieldOutputContent = $hookmanager->resPrint;
1387 }
1388
1389 return $extrafieldOutputContent;
1390 }
1391
1392
1401 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1402 {
1403 global $hookmanager;
1404
1405 if (empty($object->table_element)) {
1406 return "";
1407 }
1408
1409 // Load extrafields if not allready done
1410 if (empty($this->extrafieldsCache)) {
1411 $this->extrafieldsCache = new ExtraFields($this->db);
1412 }
1413 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1414 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1415 }
1416 $extrafields = $this->extrafieldsCache;
1417
1418 $defaultParams = array(
1419 'style' => '',
1420 'display' => 'auto', // auto, table, list
1421 'printableEnable' => array(1),
1422 'printableEnableNotEmpty' => array(2),
1423
1424 'table' => array(
1425 'maxItemsInRow' => 2,
1426 'cellspacing' => 0,
1427 'cellpadding' => 0,
1428 'border' => 0,
1429 'labelcolwidth' => '25%',
1430 'arrayOfLineBreakType' => array('text', 'html')
1431 ),
1432
1433 'list' => array(
1434 'separator' => '<br>'
1435 ),
1436
1437 'auto' => array(
1438 'list' => 0, // 0 for default
1439 'table' => 4 // if there more than x extrafield to display
1440 ),
1441 );
1442
1443 $params = $params + $defaultParams;
1444
1449 $html = '';
1450 $fields = array();
1451
1452 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1453 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1454 // Enable extrafield ?
1455 $enabled = 0;
1456 $disableOnEmpty = 0;
1457 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1458 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1459 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1460 $enabled = 1;
1461 }
1462
1463 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1464 $disableOnEmpty = 1;
1465 }
1466 }
1467
1468 if (empty($enabled)) {
1469 continue;
1470 }
1471
1472 // Load language if required
1473 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1474 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1475 }
1476
1477 $field = new stdClass();
1478 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1479 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1480 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1481 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1482 }
1483 $field->label = $outputlangs->transnoentities($label);
1484 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1485
1486 // dont display if empty
1487 if ($disableOnEmpty && empty($field->content)) {
1488 continue;
1489 }
1490
1491 $fields[] = $field;
1492 }
1493 }
1494
1495 if (!empty($fields)) {
1496 // Sort extrafields by rank
1497 uasort($fields, function ($a, $b) {
1498 return ($a->rank > $b->rank) ? 1 : -1;
1499 });
1500
1501 // define some HTML content with style
1502 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1503
1504 // auto select display format
1505 if ($params['display'] == 'auto') {
1506 $lastNnumbItems = 0;
1507 foreach ($params['auto'] as $display => $numbItems) {
1508 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1509 $lastNnumbItems = $numbItems;
1510 $params['display'] = $display;
1511 }
1512 }
1513 }
1514
1515 if ($params['display'] == 'list') {
1516 // Display in list format
1517 $i = 0;
1518 foreach ($fields as $field) {
1519 $html .= !empty($i) ? $params['list']['separator'] : '';
1520 $html .= '<strong>'.$field->label.' : </strong>';
1521 $html .= $field->content;
1522 $i++;
1523 }
1524 } elseif ($params['display'] == 'table') {
1525 // Display in table format
1526 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1527
1528 $html .= "<tr>";
1529 $itemsInRow = 0;
1530 $maxItemsInRow = $params['table']['maxItemsInRow'];
1531 foreach ($fields as $field) {
1532 //$html.= !empty($html)?'<br>':'';
1533 if ($itemsInRow >= $maxItemsInRow) {
1534 // start a new line
1535 $html .= "</tr><tr>";
1536 $itemsInRow = 0;
1537 }
1538
1539 // for some type we need line break
1540 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1541 if ($itemsInRow > 0) {
1542 // close table row and empty cols
1543 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1544 $html .= "<td></td><td></td>";
1545 }
1546 $html .= "</tr>";
1547
1548 // start a new line
1549 $html .= "<tr>";
1550 }
1551
1552 $itemsInRow = $maxItemsInRow;
1553 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1554 $html .= '<strong>'.$field->label.' :</strong> ';
1555 $html .= $field->content;
1556 $html .= "</td>";
1557 } else {
1558 $itemsInRow++;
1559 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1560 $html .= '<strong>'.$field->label.' :</strong>';
1561 $html .= "</td>";
1562
1563
1564 $html .= '<td class="extrafield-content">';
1565 $html .= $field->content;
1566 $html .= "</td>";
1567 }
1568 }
1569 $html .= "</tr>";
1570
1571 $html .= '</table>';
1572 }
1573 }
1574
1575 return $html;
1576 }
1577
1578
1585 public function getColumnStatus($colKey)
1586 {
1587 if (!empty($this->cols[$colKey]['status'])) {
1588 return true;
1589 } else {
1590 return false;
1591 }
1592 }
1593
1604 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1605 {
1606 global $hookmanager, $conf;
1607
1608 foreach ($this->cols as $colKey => $colDef) {
1609 $parameters = array(
1610 'colKey' => $colKey,
1611 'pdf' => $pdf,
1612 'outputlangs' => $outputlangs,
1613 'tab_top' => $tab_top,
1614 'tab_height' => $tab_height,
1615 'hidetop' => $hidetop
1616 );
1617
1618 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1619 if ($reshook < 0) {
1620 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1621 } elseif (empty($reshook)) {
1622 if (!$this->getColumnStatus($colKey)) {
1623 continue;
1624 }
1625
1626 // get title label
1627 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1628
1629 // Add column separator
1630 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
1631 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1632 }
1633
1634 if (empty($hidetop)) {
1635 // save curent cell padding
1636 $curentCellPaddinds = $pdf->getCellPaddings();
1637
1638 // Add space for lines (more if we need to show a second alternative language)
1639 global $outputlangsbis;
1640 if (is_object($outputlangsbis)) {
1641 // set cell padding with column title definition
1642 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1643 } else {
1644 // set cell padding with column title definition
1645 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1646 }
1647 if (isset($colDef['title']['align'])) {
1648 $align = $colDef['title']['align'];
1649 } else {
1650 $align = '';
1651 }
1652 $pdf->SetXY($colDef['xStartPos'], $tab_top);
1653 $textWidth = $colDef['width'];
1654 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
1655
1656 // Add variant of translation if $outputlangsbis is an object
1657 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1658 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1659 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1660 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1661 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
1662 }
1663
1664 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1665
1666 // restore cell padding
1667 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1668 }
1669 }
1670 }
1671
1672 return $this->tabTitleHeight;
1673 }
1674
1675
1676
1685 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1686 {
1687 if (!empty($hidedetails)) {
1688 return 0;
1689 }
1690
1691 if (empty($object->table_element)) {
1692 return 0;
1693 }
1694
1695 // Load extra fields if they haven't been loaded already.
1696 if (empty($this->extrafieldsCache)) {
1697 $this->extrafieldsCache = new ExtraFields($this->db);
1698 }
1699 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1700 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1701 }
1702 $extrafields = $this->extrafieldsCache;
1703
1704
1705 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'])) {
1706 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1707 // Dont display separator yet even is set to be displayed (not compatible yet)
1708 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1709 continue;
1710 }
1711
1712 // Enable extrafield ?
1713 $enabled = 0;
1714 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1715 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1716 if ($printable === 1 || $printable === 2) {
1717 $enabled = 1;
1718 }
1719 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1720 }
1721
1722 if (!$enabled) {
1723 continue;
1724 } // don't wast resourses if we don't need them...
1725
1726 // Load language if required
1727 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1728 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1729 }
1730
1731 // TODO : add more extrafield customisation capacities for PDF like width, rank...
1732
1733 // set column definition
1734 $def = array(
1735 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1736 'width' => 25, // in mm
1737 'status' => (bool) $enabled,
1738 'title' => array(
1739 'label' => $outputlangs->transnoentities($label)
1740 ),
1741 'content' => array(
1742 'align' => 'C'
1743 ),
1744 'border-left' => true, // add left line separator
1745 );
1746
1747 $alignTypeRight = array('double', 'int', 'price');
1748 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1749 $def['content']['align'] = 'R';
1750 }
1751
1752 $alignTypeLeft = array('text', 'html');
1753 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1754 $def['content']['align'] = 'L';
1755 }
1756
1757
1758 // for extrafields we use rank of extrafield to place it on PDF
1759 $this->insertNewColumnDef("options_".$key, $def);
1760 }
1761 }
1762
1763 return 1;
1764 }
1765
1777 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1778 {
1779 // Default field style for content
1780 $this->defaultContentsFieldsStyle = array(
1781 'align' => 'R', // R,C,L
1782 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1783 );
1784
1785 // Default field style for content
1786 $this->defaultTitlesFieldsStyle = array(
1787 'align' => 'C', // R,C,L
1788 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1789 );
1790
1791 // Example
1792 /*
1793 $rank = 0; // do not use negative rank
1794 $this->cols['desc'] = array(
1795 'rank' => $rank,
1796 'width' => false, // only for desc
1797 'status' => true,
1798 'title' => array(
1799 'textkey' => 'Designation', // use lang key is usefull in somme case with module
1800 'align' => 'L',
1801 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1802 // 'label' => ' ', // the final label
1803 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1804 ),
1805 'content' => array(
1806 'align' => 'L',
1807 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1808 ),
1809 );
1810 */
1811 }
1812}
Class to manage bank accounts.
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.
get_substitutionarray_object($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
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...
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.
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $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:41
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated 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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition pdf.lib.php:1422
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.