dolibarr 19.0.3
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 (empty($object->country) && !empty($object->country_code)) {
350 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
351 }
352 if (empty($object->state) && !empty($object->state_code)) {
353 $object->state = getState($object->state_code, 0);
354 }
355
356 $array_thirdparty = array(
357 'company_name'=>$object->name,
358 'company_name_alias' => $object->name_alias,
359 'company_email'=>$object->email,
360 'company_phone'=>$object->phone,
361 'company_fax'=>$object->fax,
362 'company_address'=>$object->address,
363 'company_zip'=>$object->zip,
364 'company_town'=>$object->town,
365 'company_country'=>$object->country,
366 'company_country_code'=>$object->country_code,
367 'company_state'=>$object->state,
368 'company_state_code'=>$object->state_code,
369 'company_web'=>$object->url,
370 'company_barcode'=>$object->barcode,
371 'company_vatnumber'=>$object->tva_intra,
372 'company_customercode'=>$object->code_client,
373 'company_suppliercode'=>$object->code_fournisseur,
374 'company_customeraccountancycode'=>$object->code_compta,
375 'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
376 'company_juridicalstatus'=>$object->forme_juridique,
377 'company_outstanding_limit'=>$object->outstanding_limit,
378 'company_capital'=>$object->capital,
379 'company_capital_formated'=> price($object->capital, 0, '', 1, -1),
380 'company_idprof1'=>$object->idprof1,
381 'company_idprof2'=>$object->idprof2,
382 'company_idprof3'=>$object->idprof3,
383 'company_idprof4'=>$object->idprof4,
384 'company_idprof5'=>$object->idprof5,
385 'company_idprof6'=>$object->idprof6,
386 'company_note_public'=>$object->note_public,
387 'company_note_private'=>$object->note_private,
388 'company_default_bank_iban'=>(is_object($object->bank_account) ? $object->bank_account->iban : ''),
389 'company_default_bank_bic'=>(is_object($object->bank_account) ? $object->bank_account->bic : '')
390 );
391
392 // Retrieve extrafields
393 if (is_array($object->array_options) && count($object->array_options)) {
394 $object->fetch_optionals();
395
396 $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
397 }
398 return $array_thirdparty;
399 }
400
401 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
410 public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
411 {
412 // phpcs:enable
413 global $conf, $extrafields;
414
415 if (empty($object->country) && !empty($object->country_code)) {
416 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
417 }
418 if (empty($object->state) && !empty($object->state_code)) {
419 $object->state = getState($object->state_code, 0);
420 }
421
422 $array_contact = array(
423 $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
424 $array_key.'_lastname' => $object->lastname,
425 $array_key.'_firstname' => $object->firstname,
426 $array_key.'_address' => $object->address,
427 $array_key.'_zip' => $object->zip,
428 $array_key.'_town' => $object->town,
429 $array_key.'_state_id' => $object->state_id,
430 $array_key.'_state_code' => $object->state_code,
431 $array_key.'_state' => $object->state,
432 $array_key.'_country_id' => $object->country_id,
433 $array_key.'_country_code' => $object->country_code,
434 $array_key.'_country' => $object->country,
435 $array_key.'_poste' => $object->poste,
436 $array_key.'_socid' => $object->socid,
437 $array_key.'_statut' => $object->statut,
438 $array_key.'_code' => $object->code,
439 $array_key.'_email' => $object->email,
440 $array_key.'_phone_pro' => $object->phone_pro,
441 $array_key.'_phone_perso' => $object->phone_perso,
442 $array_key.'_phone_mobile' => $object->phone_mobile,
443 $array_key.'_fax' => $object->fax,
444 $array_key.'_birthday' => $object->birthday,
445 $array_key.'_default_lang' => $object->default_lang,
446 $array_key.'_note_public' => $object->note_public,
447 $array_key.'_note_private' => $object->note_private,
448 $array_key.'_civility' => $object->civility,
449 );
450
451 // Retrieve extrafields
452 if (is_array($object->array_options) && count($object->array_options)) {
453 $object->fetch_optionals();
454
455 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
456 }
457 return $array_contact;
458 }
459
460
461 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
468 public function get_substitutionarray_other($outputlangs)
469 {
470 // phpcs:enable
471 global $conf;
472
473 $now = dol_now('gmt'); // gmt
474 $array_other = array(
475 // Date in default language
476 'current_date'=>dol_print_date($now, 'day', 'tzuser'),
477 'current_datehour'=>dol_print_date($now, 'dayhour', 'tzuser'),
478 'current_server_date'=>dol_print_date($now, 'day', 'tzserver'),
479 'current_server_datehour'=>dol_print_date($now, 'dayhour', 'tzserver'),
480 // Date in requested output language
481 'current_date_locale'=>dol_print_date($now, 'day', 'tzuser', $outputlangs),
482 'current_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
483 'current_server_date_locale'=>dol_print_date($now, 'day', 'tzserver', $outputlangs),
484 'current_server_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
485 );
486
487
488 foreach ($conf->global as $key => $val) {
489 if (isASecretKey($key)) {
490 $newval = '*****forbidden*****';
491 } else {
492 $newval = $val;
493 }
494 $array_other['__['.$key.']__'] = $newval;
495 }
496
497 return $array_other;
498 }
499
500
501 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
511 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
512 {
513 // phpcs:enable
514 global $conf, $extrafields;
515
516 $sumpayed = $sumdeposit = $sumcreditnote = '';
517 $already_payed_all = 0;
518
519 if ($object->element == 'facture') {
520 $invoice_source = new Facture($this->db);
521 if ($object->fk_facture_source > 0) {
522 $invoice_source->fetch($object->fk_facture_source);
523 }
524 $sumpayed = $object->getSommePaiement();
525 $sumdeposit = $object->getSumDepositsUsed();
526 $sumcreditnote = $object->getSumCreditNotesUsed();
527 $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
528 }
529
530 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
531
532 if (get_class($object) == 'CommandeFournisseur') {
533 /* @var $object CommandeFournisseur*/
534 $object->date_validation = $object->date_valid;
535 $object->date_commande = $object->date;
536 }
537 $resarray = array(
538 $array_key.'_id'=>$object->id,
539 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
540 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
541 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
542 $array_key.'_ref_customer'=>(!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
543 $array_key.'_ref_supplier'=>(!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
544 $array_key.'_source_invoice_ref'=>((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
545 // Dates
546 $array_key.'_hour'=>dol_print_date($date, 'hour'),
547 $array_key.'_date'=>dol_print_date($date, 'day'),
548 $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'),
549 $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
550 $array_key.'_date_limit_rfc'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
551 $array_key.'_date_end'=>(!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''),
552 $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
553 $array_key.'_date_modification'=>(!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
554 $array_key.'_date_validation'=>(!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
555 $array_key.'_date_approve'=>(!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
556 $array_key.'_date_delivery_planed'=>(!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
557 $array_key.'_date_close'=>(!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
558
559 $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
560 $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),
561 $array_key.'_payment_term_code'=>$object->cond_reglement_code,
562 $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)),
563
564 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
565
566 $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
567 $array_key.'_total_vat_locale'=>(!empty($object->total_vat) ? price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
568 $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
569 $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
570 $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
571
572 $array_key.'_total_ht'=>price2num($object->total_ht),
573 $array_key.'_total_vat'=>(!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)),
574 $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
575 $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
576 $array_key.'_total_ttc'=>price2num($object->total_ttc),
577
578 $array_key.'_multicurrency_code' => $object->multicurrency_code,
579 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
580 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
581 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
582 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
583 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
584 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
585 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
586
587 $array_key.'_note_private'=>$object->note_private,
588 $array_key.'_note_public'=>$object->note_public,
589 $array_key.'_note'=>$object->note_public, // For backward compatibility
590
591 // Payments
592 $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
593 $array_key.'_already_payed'=>price2num($sumpayed),
594 $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
595 $array_key.'_already_deposit'=>price2num($sumdeposit),
596 $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
597 $array_key.'_already_creditnote'=>price2num($sumcreditnote),
598
599 $array_key.'_already_payed_all_locale'=>price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
600 $array_key.'_already_payed_all'=> price2num($already_payed_all, 'MT'),
601
602 // Remain to pay with all known information (except open direct debit requests)
603 $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
604 $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $already_payed_all, 'MT')
605 );
606
607 if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur'))) {
608 $bank_account = null;
609
610 if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
611 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
612 $bank_account = new Account($this->db);
613 $bank_account->fetch($object->fk_account);
614 }
615
616 $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
617 $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
618 $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
619 $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
620 $resarray[$array_key.'_bank_proprio'] =(empty($bank_account) ? '' : $bank_account->proprio);
621 }
622
623 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
624 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
625 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
626 } else {
627 $resarray[$array_key.'_total_discount_ht_locale'] = '';
628 $resarray[$array_key.'_total_discount_ht'] = '';
629 }
630
631 // Fetch project information if there is a project assigned to this object
632 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
633 if (!is_object($object->project)) {
634 $object->fetch_projet();
635 }
636
637 $resarray[$array_key.'_project_ref'] = $object->project->ref;
638 $resarray[$array_key.'_project_title'] = $object->project->title;
639 $resarray[$array_key.'_project_description'] = $object->project->description;
640 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
641 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
642 } else { // empty replacement
643 $resarray[$array_key.'_project_ref'] ='';
644 $resarray[$array_key.'_project_title'] = '';
645 $resarray[$array_key.'_project_description'] = '';
646 $resarray[$array_key.'_project_date_start'] = '';
647 $resarray[$array_key.'_project_date_end'] = '';
648 }
649
650 // Add vat by rates
651 if (is_array($object->lines) && count($object->lines) > 0) {
652 $totalUp = 0;
653 // Set substitution keys for different VAT rates
654 foreach ($object->lines as $line) {
655 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
656 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
657 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
658 }
659 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
660 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
661 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
662 $vatformated = vatrate($line->tva_tx);
663 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
664 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
665 }
666 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
667 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
668
669 $totalUp += $line->subprice * $line->qty;
670 }
671
672 // Calculate total up and total discount percentage
673 // 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)
674 $resarray['object_total_up'] = $totalUp;
675 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
676 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
677 $totalDiscount = $object->getTotalDiscount();
678 } else {
679 $totalDiscount = 0;
680 }
681 if (!empty($totalUp) && !empty($totalDiscount)) {
682 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
683 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
684 } else {
685 $resarray['object_total_discount'] = '';
686 $resarray['object_total_discount_locale'] = '';
687 }
688 }
689
690 // Retrieve extrafields
691 if (is_array($object->array_options) && count($object->array_options)) {
692 $object->fetch_optionals();
693
694 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
695 }
696
697 return $resarray;
698 }
699
700 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
710 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
711 {
712 // phpcs:enable
713 $resarray = array(
714 'line_pos' => $linenumber,
715 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
716
717 'line_product_ref'=>(empty($line->product_ref) ? '' : $line->product_ref),
718 'line_product_ref_fourn'=>(empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
719 'line_product_label'=>(empty($line->product_label) ? '' : $line->product_label),
720 'line_product_type'=>(empty($line->product_type) ? '' : $line->product_type),
721 'line_product_barcode'=>(empty($line->product_barcode) ? '' : $line->product_barcode),
722 'line_product_desc'=>(empty($line->product_desc) ? '' : $line->product_desc),
723
724 'line_desc'=>$line->desc,
725 'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
726 'line_localtax1_rate'=>vatrate($line->localtax1_tx),
727 'line_localtax2_rate'=>vatrate($line->localtax1_tx),
728 'line_up'=>price2num($line->subprice),
729 'line_up_locale'=>price($line->subprice, 0, $outputlangs),
730 'line_total_up'=>price2num($line->subprice * $line->qty),
731 'line_total_up_locale'=>price($line->subprice * $line->qty, 0, $outputlangs),
732 'line_qty'=>$line->qty,
733 'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
734 'line_price_ht'=>price2num($line->total_ht),
735 'line_price_ttc'=>price2num($line->total_ttc),
736 'line_price_vat'=>price2num($line->total_tva),
737 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
738 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
739 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
740 // Dates
741 'line_date_start'=>dol_print_date($line->date_start, 'day'),
742 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
743 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc'),
744 'line_date_end'=>dol_print_date($line->date_end, 'day'),
745 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
746 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc'),
747
748 'line_multicurrency_code' => price2num($line->multicurrency_code),
749 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
750 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
751 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
752 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
753 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
754 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
755 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
756 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
757 );
758
759 // Units
760 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
761 $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
762 $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
763 }
764
765 // Retrieve extrafields
766 $extrafieldkey = $line->table_element;
767 $array_key = "line";
768 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
769 $extrafields = new ExtraFields($this->db);
770 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
771 $line->fetch_optionals();
772
773 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
774
775 // Check if the current line belongs to a supplier order
776 if (get_class($line) == 'CommandeFournisseurLigne') {
777 // Add the product supplier extrafields to the substitutions
778 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
779 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
780
781 if (!empty($extralabels) && is_array($extralabels)) {
782 $columns = "";
783
784 foreach ($extralabels as $key => $label) {
785 $columns .= "$key, ";
786 }
787
788 if ($columns != "") {
789 $columns = substr($columns, 0, strlen($columns) - 2);
790 $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)."'");
791
792 if ($this->db->num_rows($resql) > 0) {
793 $resql = $this->db->fetch_object($resql);
794
795 foreach ($extralabels as $key => $label) {
796 $resarray['line_product_supplier_'.$key] = $resql->$key;
797 }
798 }
799 }
800 }
801 }
802
803 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
804 if (isset($line->fk_product) && $line->fk_product > 0) {
805 $tmpproduct = new Product($this->db);
806 $result = $tmpproduct->fetch($line->fk_product);
807 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
808 foreach ($tmpproduct->array_options as $key => $label) {
809 $resarray["line_product_".$key] = $label;
810 }
811 }
812 } else {
813 // Set unused placeholders as blank
814 $extrafields->fetch_name_optionals_label("product");
815 $extralabels = $extrafields->attributes["product"]['label'];
816
817 if (!empty($extralabels) && is_array($extralabels)) {
818 foreach ($extralabels as $key => $label) {
819 $resarray['line_product_options_'.$key] = '';
820 }
821 }
822 }
823
824 return $resarray;
825 }
826
827 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
837 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
838 {
839 // phpcs:enable
840 global $conf, $extrafields;
841 dol_include_once('/core/lib/product.lib.php');
842 $object->list_delivery_methods($object->shipping_method_id);
843 $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
844
845 $array_shipment = array(
846 $array_key.'_id'=>$object->id,
847 $array_key.'_ref'=>$object->ref,
848 $array_key.'_ref_ext'=>$object->ref_ext,
849 $array_key.'_ref_customer'=>$object->ref_customer,
850 $array_key.'_date_delivery'=>dol_print_date($object->date_delivery, 'day'),
851 $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery, 'hour'),
852 $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
853 $array_key.'_total_ht'=>price($object->total_ht),
854 $array_key.'_total_vat'=>price($object->total_tva),
855 $array_key.'_total_ttc'=>price($object->total_ttc),
856 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
857 $array_key.'_note_private'=>$object->note_private,
858 $array_key.'_note'=>$object->note_public,
859 $array_key.'_tracking_number'=>$object->tracking_number,
860 $array_key.'_tracking_url'=>$object->tracking_url,
861 $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
862 $array_key.'_weight'=>$object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
863 $array_key.'_width'=>$object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
864 $array_key.'_height'=>$object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
865 $array_key.'_depth'=>$object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
866 $array_key.'_size'=>$calculatedVolume.' '.measuringUnitString(0, 'volume'),
867 );
868
869 // Add vat by rates
870 foreach ($object->lines as $line) {
871 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
872 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
873 }
874 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
875 }
876
877 // Retrieve extrafields
878 if (is_array($object->array_options) && count($object->array_options)) {
879 $object->fetch_optionals();
880
881 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
882 }
883
884 // Add infor from $object->xxx where xxx has been loaded by fetch_origin() of shipment
885 if (!empty($object->commande) && is_object($object->commande)) {
886 $array_shipment['order_ref'] = $object->commande->ref;
887 $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
888 }
889
890 return $array_shipment;
891 }
892
893
894 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
903 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
904 {
905 // phpcs:enable
906 $array_other = array();
907 if (!empty($object)) {
908 foreach ($object as $key => $value) {
909 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
910 continue;
911 }
912 if (!empty($value)) {
913 if (!is_array($value) && !is_object($value)) {
914 $array_other['object_'.$key] = $value;
915 } elseif (is_array($value) && $recursive) {
916 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
917 if (!empty($tmparray) && is_array($tmparray)) {
918 foreach ($tmparray as $key2 => $value2) {
919 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
920 }
921 }
922 } elseif (is_object($value) && $recursive) {
923 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
924 if (!empty($tmparray) && is_array($tmparray)) {
925 foreach ($tmparray as $key2 => $value2) {
926 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
927 }
928 }
929 }
930 }
931 }
932 }
933
934 //var_dump($array_other);
935
936 return $array_other;
937 }
938
939
940 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
952 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
953 {
954 // phpcs:enable
955 global $conf;
956
957 if (is_array($extrafields->attributes[$object->table_element]['label'])) {
958 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
959 $formatedarrayoption = $object->array_options;
960
961 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
962 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
963 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
964 //Add value to store price with currency
965 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
966 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
967 $valueofselectkey = $formatedarrayoption['options_'.$key];
968 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
969 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
970 } else {
971 $formatedarrayoption['options_'.$key] = '';
972 }
973 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
974 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
975 $output = array();
976 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
977 if (in_array($keyopt, $valArray)) {
978 $output[] = $valopt;
979 }
980 }
981 $formatedarrayoption['options_'.$key] = implode(', ', $output);
982 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
983 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
984 $date = $formatedarrayoption['options_'.$key];
985 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
986 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
987 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
988 } else {
989 $formatedarrayoption['options_'.$key] = '';
990 $formatedarrayoption['options_'.$key.'_locale'] = '';
991 $formatedarrayoption['options_'.$key.'_rfc'] = '';
992 }
993 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
994 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
995 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
996 $datetime = $formatedarrayoption['options_'.$key];
997 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
998 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
999 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1000 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1001 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1002 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1003 $id = $formatedarrayoption['options_'.$key];
1004 if ($id != "") {
1005 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1006 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1007 $InfoFieldList = explode(":", $param_list[0]);
1008 $classname = $InfoFieldList[0];
1009 $classpath = $InfoFieldList[1];
1010 if (!empty($classpath)) {
1011 dol_include_once($InfoFieldList[1]);
1012 if ($classname && class_exists($classname)) {
1013 $tmpobject = new $classname($this->db);
1014 $tmpobject->fetch($id);
1015 // completely replace the id with the linked object name
1016 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1017 }
1018 }
1019 }
1020 }
1021
1022 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1023 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1024 } else {
1025 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1026 }
1027 }
1028 }
1029
1030 return $array_to_fill;
1031 }
1032
1033
1046 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1047 {
1048 if (empty($hidetop) || $hidetop == -1) {
1049 $pdf->line($x, $y, $x + $l, $y);
1050 }
1051 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1052 if (empty($hidebottom)) {
1053 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1054 }
1055 $pdf->line($x, $y + $h, $x, $y);
1056 }
1057
1058
1066 public function columnSort($a, $b)
1067 {
1068 if (empty($a['rank'])) {
1069 $a['rank'] = 0;
1070 }
1071 if (empty($b['rank'])) {
1072 $b['rank'] = 0;
1073 }
1074 if ($a['rank'] == $b['rank']) {
1075 return 0;
1076 }
1077 return ($a['rank'] > $b['rank']) ? -1 : 1;
1078 }
1079
1090 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1091 {
1092 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1093
1094
1095 // Sorting
1096 uasort($this->cols, array($this, 'columnSort'));
1097
1098 // Positionning
1099 $curX = $this->page_largeur - $this->marge_droite; // start from right
1100
1101 // Array width
1102 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1103
1104 // Count flexible column
1105 $totalDefinedColWidth = 0;
1106 $countFlexCol = 0;
1107 foreach ($this->cols as $colKey => & $colDef) {
1108 if (!$this->getColumnStatus($colKey)) {
1109 continue; // continue if disabled
1110 }
1111
1112 if (!empty($colDef['scale'])) {
1113 // In case of column width is defined by percentage
1114 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1115 }
1116
1117 if (empty($colDef['width'])) {
1118 $countFlexCol++;
1119 } else {
1120 $totalDefinedColWidth += $colDef['width'];
1121 }
1122 }
1123
1124 foreach ($this->cols as $colKey => & $colDef) {
1125 // setting empty conf with default
1126 if (!empty($colDef['title'])) {
1127 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1128 } else {
1129 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1130 }
1131
1132 // setting empty conf with default
1133 if (!empty($colDef['content'])) {
1134 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1135 } else {
1136 $colDef['content'] = $this->defaultContentsFieldsStyle;
1137 }
1138
1139 if ($this->getColumnStatus($colKey)) {
1140 // In case of flexible column
1141 if (empty($colDef['width'])) {
1142 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1143 }
1144
1145 // Set positions
1146 $lastX = $curX;
1147 $curX = $lastX - $colDef['width'];
1148 $colDef['xStartPos'] = $curX;
1149 $colDef['xEndPos'] = $lastX;
1150 }
1151 }
1152 }
1153
1160 public function getColumnContentWidth($colKey)
1161 {
1162 $colDef = $this->cols[$colKey];
1163 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1164 }
1165
1166
1173 public function getColumnContentXStart($colKey)
1174 {
1175 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1176 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1177 }
1178
1185 public function getColumnRank($colKey)
1186 {
1187 if (!isset($this->cols[$colKey]['rank'])) {
1188 return -1;
1189 }
1190 return $this->cols[$colKey]['rank'];
1191 }
1192
1202 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1203 {
1204 // prepare wanted rank
1205 $rank = -1;
1206
1207 // try to get rank from target column
1208 if (!empty($targetCol)) {
1209 $rank = $this->getColumnRank($targetCol);
1210 if ($rank >= 0 && $insertAfterTarget) {
1211 $rank++;
1212 }
1213 }
1214
1215 // get rank from new column definition
1216 if ($rank < 0 && !empty($defArray['rank'])) {
1217 $rank = $defArray['rank'];
1218 }
1219
1220 // error: no rank
1221 if ($rank < 0) {
1222 return -1;
1223 }
1224
1225 foreach ($this->cols as $colKey => & $colDef) {
1226 if ($rank <= $colDef['rank']) {
1227 $colDef['rank'] = $colDef['rank'] + 1;
1228 }
1229 }
1230
1231 $defArray['rank'] = $rank;
1232 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1233
1234 return $rank;
1235 }
1236
1237
1247 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1248 {
1249 global $hookmanager;
1250
1251 $parameters = array(
1252 'curY' => &$curY,
1253 'columnText' => $columnText,
1254 'colKey' => $colKey,
1255 'pdf' => &$pdf,
1256 );
1257 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1258 if ($reshook < 0) {
1259 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1260 }
1261 if (!$reshook) {
1262 if (empty($columnText)) {
1263 return 0;
1264 }
1265 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set curent position
1266 $colDef = $this->cols[$colKey];
1267 // save curent cell padding
1268 $curentCellPaddinds = $pdf->getCellPaddings();
1269 // set cell padding with column content definition
1270 $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);
1271 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1272
1273 // restore cell padding
1274 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1275 }
1276
1277 return 0;
1278 }
1279
1280
1295 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1296 {
1297 // load desc col params
1298 $colDef = $this->cols[$colKey];
1299 // save curent cell padding
1300 $curentCellPaddinds = $pdf->getCellPaddings();
1301 // set cell padding with column content definition
1302 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1303
1304 // line description
1305 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline);
1306 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1307
1308 // restore cell padding
1309 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1310
1311 // Display extrafield if needed
1312 $params = array(
1313 'display' => 'list',
1314 'printableEnable' => array(3),
1315 'printableEnableNotEmpty' => array(4)
1316 );
1317 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1318 if (!empty($extrafieldDesc)) {
1319 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1320 }
1321 }
1322
1332 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1333 {
1334 global $hookmanager;
1335
1336 if (empty($object->table_element)) {
1337 return '';
1338 }
1339
1340 $extrafieldsKeyPrefix = "options_";
1341
1342 // Cleanup extrafield key to remove prefix if present
1343 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1344 if ($pos === 0) {
1345 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1346 }
1347
1348 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1349
1350
1351 // Load extra fields if they haven't been loaded already.
1352 if (empty($this->extrafieldsCache)) {
1353 $this->extrafieldsCache = new ExtraFields($this->db);
1354 }
1355 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1356 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1357 }
1358 $extrafields = $this->extrafieldsCache;
1359
1360 $extrafieldOutputContent = '';
1361 if (isset($object->array_options[$extrafieldOptionsKey])) {
1362 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1363 }
1364
1365 // 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 ...
1366 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1367 // for lack of anything better we cleanup all html tags
1368 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1369 }
1370
1371 $parameters = array(
1372 'object' => $object,
1373 'extrafields' => $extrafields,
1374 'extrafieldKey' => $extrafieldKey,
1375 'extrafieldOutputContent' =>& $extrafieldOutputContent
1376 );
1377 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1378 if ($reshook < 0) {
1379 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1380 }
1381 if ($reshook) {
1382 $extrafieldOutputContent = $hookmanager->resPrint;
1383 }
1384
1385 return $extrafieldOutputContent;
1386 }
1387
1388
1397 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1398 {
1399 global $hookmanager;
1400
1401 if (empty($object->table_element)) {
1402 return "";
1403 }
1404
1405 // Load extrafields if not allready done
1406 if (empty($this->extrafieldsCache)) {
1407 $this->extrafieldsCache = new ExtraFields($this->db);
1408 }
1409 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1410 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1411 }
1412 $extrafields = $this->extrafieldsCache;
1413
1414 $defaultParams = array(
1415 'style' => '',
1416 'display' => 'auto', // auto, table, list
1417 'printableEnable' => array(1),
1418 'printableEnableNotEmpty' => array(2),
1419
1420 'table' => array(
1421 'maxItemsInRow' => 2,
1422 'cellspacing' => 0,
1423 'cellpadding' => 0,
1424 'border' => 0,
1425 'labelcolwidth' => '25%',
1426 'arrayOfLineBreakType' => array('text', 'html')
1427 ),
1428
1429 'list' => array(
1430 'separator' => '<br>'
1431 ),
1432
1433 'auto' => array(
1434 'list' => 0, // 0 for default
1435 'table' => 4 // if there more than x extrafield to display
1436 ),
1437 );
1438
1439 $params = $params + $defaultParams;
1440
1445 $html = '';
1446 $fields = array();
1447
1448 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1449 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1450 // Enable extrafield ?
1451 $enabled = 0;
1452 $disableOnEmpty = 0;
1453 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1454 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1455 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1456 $enabled = 1;
1457 }
1458
1459 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1460 $disableOnEmpty = 1;
1461 }
1462 }
1463
1464 if (empty($enabled)) {
1465 continue;
1466 }
1467
1468 // Load language if required
1469 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1470 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1471 }
1472
1473 $field = new stdClass();
1474 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1475 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1476 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1477 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1478 }
1479 $field->label = $outputlangs->transnoentities($label);
1480 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1481
1482 // dont display if empty
1483 if ($disableOnEmpty && empty($field->content)) {
1484 continue;
1485 }
1486
1487 $fields[] = $field;
1488 }
1489 }
1490
1491 if (!empty($fields)) {
1492 // Sort extrafields by rank
1493 uasort($fields, function ($a, $b) {
1494 return ($a->rank > $b->rank) ? 1 : -1;
1495 });
1496
1497 // define some HTML content with style
1498 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1499
1500 // auto select display format
1501 if ($params['display'] == 'auto') {
1502 $lastNnumbItems = 0;
1503 foreach ($params['auto'] as $display => $numbItems) {
1504 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1505 $lastNnumbItems = $numbItems;
1506 $params['display'] = $display;
1507 }
1508 }
1509 }
1510
1511 if ($params['display'] == 'list') {
1512 // Display in list format
1513 $i = 0;
1514 foreach ($fields as $field) {
1515 $html .= !empty($i) ? $params['list']['separator'] : '';
1516 $html .= '<strong>'.$field->label.' : </strong>';
1517 $html .= $field->content;
1518 $i++;
1519 }
1520 } elseif ($params['display'] == 'table') {
1521 // Display in table format
1522 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1523
1524 $html .= "<tr>";
1525 $itemsInRow = 0;
1526 $maxItemsInRow = $params['table']['maxItemsInRow'];
1527 foreach ($fields as $field) {
1528 //$html.= !empty($html)?'<br>':'';
1529 if ($itemsInRow >= $maxItemsInRow) {
1530 // start a new line
1531 $html .= "</tr><tr>";
1532 $itemsInRow = 0;
1533 }
1534
1535 // for some type we need line break
1536 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1537 if ($itemsInRow > 0) {
1538 // close table row and empty cols
1539 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1540 $html .= "<td></td><td></td>";
1541 }
1542 $html .= "</tr>";
1543
1544 // start a new line
1545 $html .= "<tr>";
1546 }
1547
1548 $itemsInRow = $maxItemsInRow;
1549 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1550 $html .= '<strong>'.$field->label.' :</strong> ';
1551 $html .= $field->content;
1552 $html .= "</td>";
1553 } else {
1554 $itemsInRow++;
1555 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1556 $html .= '<strong>'.$field->label.' :</strong>';
1557 $html .= "</td>";
1558
1559
1560 $html .= '<td class="extrafield-content">';
1561 $html .= $field->content;
1562 $html .= "</td>";
1563 }
1564 }
1565 $html .= "</tr>";
1566
1567 $html .= '</table>';
1568 }
1569 }
1570
1571 return $html;
1572 }
1573
1574
1581 public function getColumnStatus($colKey)
1582 {
1583 if (!empty($this->cols[$colKey]['status'])) {
1584 return true;
1585 } else {
1586 return false;
1587 }
1588 }
1589
1600 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1601 {
1602 global $hookmanager, $conf;
1603
1604 foreach ($this->cols as $colKey => $colDef) {
1605 $parameters = array(
1606 'colKey' => $colKey,
1607 'pdf' => $pdf,
1608 'outputlangs' => $outputlangs,
1609 'tab_top' => $tab_top,
1610 'tab_height' => $tab_height,
1611 'hidetop' => $hidetop
1612 );
1613
1614 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1615 if ($reshook < 0) {
1616 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1617 } elseif (empty($reshook)) {
1618 if (!$this->getColumnStatus($colKey)) {
1619 continue;
1620 }
1621
1622 // get title label
1623 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1624
1625 // Add column separator
1626 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
1627 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1628 }
1629
1630 if (empty($hidetop)) {
1631 // save curent cell padding
1632 $curentCellPaddinds = $pdf->getCellPaddings();
1633
1634 // Add space for lines (more if we need to show a second alternative language)
1635 global $outputlangsbis;
1636 if (is_object($outputlangsbis)) {
1637 // set cell padding with column title definition
1638 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1639 } else {
1640 // set cell padding with column title definition
1641 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1642 }
1643 if (isset($colDef['title']['align'])) {
1644 $align = $colDef['title']['align'];
1645 } else {
1646 $align = '';
1647 }
1648 $pdf->SetXY($colDef['xStartPos'], $tab_top);
1649 $textWidth = $colDef['width'];
1650 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
1651
1652 // Add variant of translation if $outputlangsbis is an object
1653 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1654 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1655 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1656 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1657 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
1658 }
1659
1660 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1661
1662 // restore cell padding
1663 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1664 }
1665 }
1666 }
1667
1668 return $this->tabTitleHeight;
1669 }
1670
1671
1672
1681 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1682 {
1683 if (!empty($hidedetails)) {
1684 return 0;
1685 }
1686
1687 if (empty($object->table_element)) {
1688 return 0;
1689 }
1690
1691 // Load extra fields if they haven't been loaded already.
1692 if (empty($this->extrafieldsCache)) {
1693 $this->extrafieldsCache = new ExtraFields($this->db);
1694 }
1695 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1696 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1697 }
1698 $extrafields = $this->extrafieldsCache;
1699
1700
1701 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'])) {
1702 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1703 // Dont display separator yet even is set to be displayed (not compatible yet)
1704 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1705 continue;
1706 }
1707
1708 // Enable extrafield ?
1709 $enabled = 0;
1710 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1711 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1712 if ($printable === 1 || $printable === 2) {
1713 $enabled = 1;
1714 }
1715 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1716 }
1717
1718 if (!$enabled) {
1719 continue;
1720 } // don't wast resourses if we don't need them...
1721
1722 // Load language if required
1723 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1724 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1725 }
1726
1727 // TODO : add more extrafield customisation capacities for PDF like width, rank...
1728
1729 // set column definition
1730 $def = array(
1731 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1732 'width' => 25, // in mm
1733 'status' => (bool) $enabled,
1734 'title' => array(
1735 'label' => $outputlangs->transnoentities($label)
1736 ),
1737 'content' => array(
1738 'align' => 'C'
1739 ),
1740 'border-left' => true, // add left line separator
1741 );
1742
1743 $alignTypeRight = array('double', 'int', 'price');
1744 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1745 $def['content']['align'] = 'R';
1746 }
1747
1748 $alignTypeLeft = array('text', 'html');
1749 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1750 $def['content']['align'] = 'L';
1751 }
1752
1753
1754 // for extrafields we use rank of extrafield to place it on PDF
1755 $this->insertNewColumnDef("options_".$key, $def);
1756 }
1757 }
1758
1759 return 1;
1760 }
1761
1773 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1774 {
1775 // Default field style for content
1776 $this->defaultContentsFieldsStyle = array(
1777 'align' => 'R', // R,C,L
1778 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1779 );
1780
1781 // Default field style for content
1782 $this->defaultTitlesFieldsStyle = array(
1783 'align' => 'C', // R,C,L
1784 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1785 );
1786
1787 // Example
1788 /*
1789 $rank = 0; // do not use negative rank
1790 $this->cols['desc'] = array(
1791 'rank' => $rank,
1792 'width' => false, // only for desc
1793 'status' => true,
1794 'title' => array(
1795 'textkey' => 'Designation', // use lang key is usefull in somme case with module
1796 'align' => 'L',
1797 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1798 // 'label' => ' ', // the final label
1799 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1800 ),
1801 'content' => array(
1802 'align' => 'L',
1803 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1804 ),
1805 );
1806 */
1807 }
1808}
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.