dolibarr 18.0.6
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 Charlie Benke <charlie@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 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
36abstract class CommonDocGenerator
37{
41 public $name = '';
42
46 public $error = '';
47
51 public $errors = array();
52
56 protected $db;
57
61 public $extrafieldsCache;
62
66 public $update_main_doc_field;
67
71 public $scandir;
72
76 public $description;
77
81 public $format;
82
86 public $type;
87
88 public $page_hauteur;
89 public $page_largeur;
90 public $marge_gauche;
91 public $marge_droite;
92 public $marge_haute;
93 public $marge_basse;
94
95 public $option_logo;
96 public $option_tva;
97 public $option_multilang;
98 public $option_freetext;
99 public $option_draft_watermark;
100 public $watermark;
101
102 public $option_modereg;
103 public $option_condreg;
104 public $option_escompte;
105 public $option_credit_note;
106
107 public $emetteur;
108
113 public $phpmin = array(7, 1);
114
118 public $cols;
119
120
126 public function __construct($db)
127 {
128 $this->db = $db;
129 }
130
131
132 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
140 public function get_substitutionarray_user($user, $outputlangs)
141 {
142 // phpcs:enable
143 global $conf, $extrafields;
144
145 $logotouse = $conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo;
146
147 $array_user = array(
148 'myuser_lastname'=>$user->lastname,
149 'myuser_firstname'=>$user->firstname,
150 'myuser_fullname'=>$user->getFullName($outputlangs, 1),
151 'myuser_login'=>$user->login,
152 'myuser_phone'=>$user->office_phone,
153 'myuser_address'=>$user->address,
154 'myuser_zip'=>$user->zip,
155 'myuser_town'=>$user->town,
156 'myuser_country'=>$user->country,
157 'myuser_country_code'=>$user->country_code,
158 'myuser_state'=>$user->state,
159 'myuser_state_code'=>$user->state_code,
160 'myuser_fax'=>$user->office_fax,
161 'myuser_mobile'=>$user->user_mobile,
162 'myuser_email'=>$user->email,
163 'myuser_logo'=>$logotouse,
164 'myuser_job'=>$user->job,
165 'myuser_web'=>'', // url not exist in $user object
166 'myuser_birth'=>dol_print_date($user->birth, 'day', 'gmt'),
167 'myuser_dateemployment'=>dol_print_date($user->dateemployment, 'day', 'tzuser'),
168 'myuser_dateemploymentend'=>dol_print_date($user->dateemploymentend, 'day', 'tzuser'),
169 'myuser_gender'=>$user->gender,
170 );
171 // Retrieve extrafields
172 if (is_array($user->array_options) && count($user->array_options)) {
173 $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
174 }
175 return $array_user;
176 }
177
178
186 public function getSubstitutionarrayMember($member, $outputlangs)
187 {
188 global $conf, $extrafields;
189
190 if ($member->photo) {
191 $logotouse = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
192 } else {
193 $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
194 }
195
196 $array_member = array(
197 'mymember_lastname' => $member->lastname,
198 'mymember_firstname' => $member->firstname,
199 'mymember_fullname' => $member->getFullName($outputlangs, 1),
200 'mymember_login' => $member->login,
201 'mymember_address' => $member->address,
202 'mymember_zip' => $member->zip,
203 'mymember_town' => $member->town,
204 'mymember_country_code' => $member->country_code,
205 'mymember_country' => $member->country,
206 'mymember_state_code' => $member->state_code,
207 'mymember_state' => $member->state,
208 'mymember_phone_perso' => $member->phone_perso,
209 'mymember_phone_pro' => $member->phone,
210 'mymember_phone_mobile' => $member->phone_mobile,
211 'mymember_email' => $member->email,
212 'mymember_logo' => $logotouse,
213 'mymember_gender' => $member->gender,
214 'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
215 'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
216 );
217 // Retrieve extrafields
218 if (is_array($member->array_options) && count($member->array_options)) {
219 $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
220 }
221 return $array_member;
222 }
223
224
225 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
233 public function get_substitutionarray_mysoc($mysoc, $outputlangs)
234 {
235 // phpcs:enable
236 global $conf;
237
238 if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
239 $mysoc->forme_juridique = getFormeJuridiqueLabel($mysoc->forme_juridique_code);
240 }
241 if (empty($mysoc->country) && !empty($mysoc->country_code)) {
242 $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
243 }
244 if (empty($mysoc->state) && !empty($mysoc->state_code)) {
245 $mysoc->state = getState($mysoc->state_code, 0);
246 }
247
248 $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
249
250 return array(
251 'mycompany_logo'=>$logotouse,
252 'mycompany_name'=>$mysoc->name,
253 'mycompany_email'=>$mysoc->email,
254 'mycompany_phone'=>$mysoc->phone,
255 'mycompany_fax'=>$mysoc->fax,
256 'mycompany_address'=>$mysoc->address,
257 'mycompany_zip'=>$mysoc->zip,
258 'mycompany_town'=>$mysoc->town,
259 'mycompany_country'=>$mysoc->country,
260 'mycompany_country_code'=>$mysoc->country_code,
261 'mycompany_state'=>$mysoc->state,
262 'mycompany_state_code'=>$mysoc->state_code,
263 'mycompany_web'=>$mysoc->url,
264 'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
265 'mycompany_managers'=>$mysoc->managers,
266 'mycompany_capital'=>$mysoc->capital,
267 'mycompany_barcode'=>$mysoc->barcode,
268 'mycompany_idprof1'=>$mysoc->idprof1,
269 'mycompany_idprof2'=>$mysoc->idprof2,
270 'mycompany_idprof3'=>$mysoc->idprof3,
271 'mycompany_idprof4'=>$mysoc->idprof4,
272 'mycompany_idprof5'=>$mysoc->idprof5,
273 'mycompany_idprof6'=>$mysoc->idprof6,
274 'mycompany_vatnumber'=>$mysoc->tva_intra,
275 'mycompany_socialobject'=>$mysoc->socialobject,
276 'mycompany_note_private'=>$mysoc->note_private,
277 //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
278 );
279 }
280
281
282 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
292 public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
293 {
294 // phpcs:enable
295 global $conf, $extrafields;
296
297 if (empty($object->country) && !empty($object->country_code)) {
298 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
299 }
300 if (empty($object->state) && !empty($object->state_code)) {
301 $object->state = getState($object->state_code, 0);
302 }
303
304 $array_thirdparty = array(
305 'company_name'=>$object->name,
306 'company_name_alias' => $object->name_alias,
307 'company_email'=>$object->email,
308 'company_phone'=>$object->phone,
309 'company_fax'=>$object->fax,
310 'company_address'=>$object->address,
311 'company_zip'=>$object->zip,
312 'company_town'=>$object->town,
313 'company_country'=>$object->country,
314 'company_country_code'=>$object->country_code,
315 'company_state'=>$object->state,
316 'company_state_code'=>$object->state_code,
317 'company_web'=>$object->url,
318 'company_barcode'=>$object->barcode,
319 'company_vatnumber'=>$object->tva_intra,
320 'company_customercode'=>$object->code_client,
321 'company_suppliercode'=>$object->code_fournisseur,
322 'company_customeraccountancycode'=>$object->code_compta,
323 'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
324 'company_juridicalstatus'=>$object->forme_juridique,
325 'company_outstanding_limit'=>$object->outstanding_limit,
326 'company_capital'=>$object->capital,
327 'company_capital_formated'=> price($object->capital, 0, '', 1, -1),
328 'company_idprof1'=>$object->idprof1,
329 'company_idprof2'=>$object->idprof2,
330 'company_idprof3'=>$object->idprof3,
331 'company_idprof4'=>$object->idprof4,
332 'company_idprof5'=>$object->idprof5,
333 'company_idprof6'=>$object->idprof6,
334 'company_note_public'=>$object->note_public,
335 'company_note_private'=>$object->note_private,
336 'company_default_bank_iban'=>(is_object($object->bank_account) ? $object->bank_account->iban : ''),
337 'company_default_bank_bic'=>(is_object($object->bank_account) ? $object->bank_account->bic : '')
338 );
339
340 // Retrieve extrafields
341 if (is_array($object->array_options) && count($object->array_options)) {
342 $object->fetch_optionals();
343
344 $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
345 }
346 return $array_thirdparty;
347 }
348
349 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
358 public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
359 {
360 // phpcs:enable
361 global $conf, $extrafields;
362
363 if (empty($object->country) && !empty($object->country_code)) {
364 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
365 }
366 if (empty($object->state) && !empty($object->state_code)) {
367 $object->state = getState($object->state_code, 0);
368 }
369
370 $array_contact = array(
371 $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
372 $array_key.'_lastname' => $object->lastname,
373 $array_key.'_firstname' => $object->firstname,
374 $array_key.'_address' => $object->address,
375 $array_key.'_zip' => $object->zip,
376 $array_key.'_town' => $object->town,
377 $array_key.'_state_id' => $object->state_id,
378 $array_key.'_state_code' => $object->state_code,
379 $array_key.'_state' => $object->state,
380 $array_key.'_country_id' => $object->country_id,
381 $array_key.'_country_code' => $object->country_code,
382 $array_key.'_country' => $object->country,
383 $array_key.'_poste' => $object->poste,
384 $array_key.'_socid' => $object->socid,
385 $array_key.'_statut' => $object->statut,
386 $array_key.'_code' => $object->code,
387 $array_key.'_email' => $object->email,
388 $array_key.'_phone_pro' => $object->phone_pro,
389 $array_key.'_phone_perso' => $object->phone_perso,
390 $array_key.'_phone_mobile' => $object->phone_mobile,
391 $array_key.'_fax' => $object->fax,
392 $array_key.'_birthday' => $object->birthday,
393 $array_key.'_default_lang' => $object->default_lang,
394 $array_key.'_note_public' => $object->note_public,
395 $array_key.'_note_private' => $object->note_private,
396 $array_key.'_civility' => $object->civility,
397 );
398
399 // Retrieve extrafields
400 if (is_array($object->array_options) && count($object->array_options)) {
401 $object->fetch_optionals();
402
403 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
404 }
405 return $array_contact;
406 }
407
408
409 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
416 public function get_substitutionarray_other($outputlangs)
417 {
418 // phpcs:enable
419 global $conf;
420
421 $now = dol_now('gmt'); // gmt
422 $array_other = array(
423 // Date in default language
424 'current_date'=>dol_print_date($now, 'day', 'tzuser'),
425 'current_datehour'=>dol_print_date($now, 'dayhour', 'tzuser'),
426 'current_server_date'=>dol_print_date($now, 'day', 'tzserver'),
427 'current_server_datehour'=>dol_print_date($now, 'dayhour', 'tzserver'),
428 // Date in requested output language
429 'current_date_locale'=>dol_print_date($now, 'day', 'tzuser', $outputlangs),
430 'current_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
431 'current_server_date_locale'=>dol_print_date($now, 'day', 'tzserver', $outputlangs),
432 'current_server_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
433 );
434
435
436 foreach ($conf->global as $key => $val) {
437 if (isASecretKey($key)) {
438 $newval = '*****forbidden*****';
439 } else {
440 $newval = $val;
441 }
442 $array_other['__['.$key.']__'] = $newval;
443 }
444
445 return $array_other;
446 }
447
448
449 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
459 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
460 {
461 // phpcs:enable
462 global $conf, $extrafields;
463
464 $sumpayed = $sumdeposit = $sumcreditnote = '';
465 $already_payed_all = 0;
466
467 if ($object->element == 'facture') {
468 $invoice_source = new Facture($this->db);
469 if ($object->fk_facture_source > 0) {
470 $invoice_source->fetch($object->fk_facture_source);
471 }
472 $sumpayed = $object->getSommePaiement();
473 $sumdeposit = $object->getSumDepositsUsed();
474 $sumcreditnote = $object->getSumCreditNotesUsed();
475 $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
476
477 if ($object->fk_account > 0) {
478 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
479 $bank_account = new Account($this->db);
480 $bank_account->fetch($object->fk_account);
481 }
482 }
483
484 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
485
486 if (get_class($object) == 'CommandeFournisseur') {
487 /* @var $object CommandeFournisseur*/
488 $object->date_validation = $object->date_valid;
489 $object->date_commande = $object->date;
490 }
491 $resarray = array(
492 $array_key.'_id'=>$object->id,
493 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
494 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
495 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
496 $array_key.'_ref_customer'=>(!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
497 $array_key.'_ref_supplier'=>(!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
498 $array_key.'_source_invoice_ref'=>((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
499 // Dates
500 $array_key.'_hour'=>dol_print_date($date, 'hour'),
501 $array_key.'_date'=>dol_print_date($date, 'day'),
502 $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'),
503 $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
504 $array_key.'_date_limit_rfc'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
505 $array_key.'_date_end'=>(!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''),
506 $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
507 $array_key.'_date_modification'=>(!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
508 $array_key.'_date_validation'=>(!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
509 $array_key.'_date_approve'=>(!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
510 $array_key.'_date_delivery_planed'=>(!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
511 $array_key.'_date_close'=>(!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
512
513 $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
514 $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),
515 $array_key.'_payment_term_code'=>$object->cond_reglement_code,
516 $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)),
517
518 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
519
520 $array_key.'_bank_iban' => (!empty($bank_account) ? $bank_account->iban : ''),
521 $array_key.'_bank_bic' => (!empty($bank_account) ? $bank_account->bic : ''),
522 $array_key.'_bank_label' => (!empty($bank_account) ? $bank_account->label : ''),
523 $array_key.'_bank_number' => (!empty($bank_account) ? $bank_account->number : ''),
524 $array_key.'_bank_proprio' => (!empty($bank_account) ? $bank_account->proprio : ''),
525
526 $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
527 $array_key.'_total_vat_locale'=>(!empty($object->total_vat) ?price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
528 $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
529 $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
530 $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
531
532 $array_key.'_total_ht'=>price2num($object->total_ht),
533 $array_key.'_total_vat'=>(!empty($object->total_vat) ?price2num($object->total_vat) : price2num($object->total_tva)),
534 $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
535 $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
536 $array_key.'_total_ttc'=>price2num($object->total_ttc),
537
538 $array_key.'_multicurrency_code' => $object->multicurrency_code,
539 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
540 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
541 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
542 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
543 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
544 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
545 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
546
547 $array_key.'_note_private'=>$object->note,
548 $array_key.'_note_public'=>$object->note_public,
549 $array_key.'_note'=>$object->note_public, // For backward compatibility
550
551 // Payments
552 $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
553 $array_key.'_already_payed'=>price2num($sumpayed),
554 $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
555 $array_key.'_already_deposit'=>price2num($sumdeposit),
556 $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
557 $array_key.'_already_creditnote'=>price2num($sumcreditnote),
558
559 $array_key.'_already_payed_all_locale'=>price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
560 $array_key.'_already_payed_all'=> price2num($already_payed_all, 'MT'),
561
562 // Remain to pay with all known information (except open direct debit requests)
563 $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
564 $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $already_payed_all, 'MT')
565 );
566
567 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
568 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
569 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
570 } else {
571 $resarray[$array_key.'_total_discount_ht_locale'] = '';
572 $resarray[$array_key.'_total_discount_ht'] = '';
573 }
574
575 // Fetch project information if there is a project assigned to this object
576 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
577 if (!is_object($object->project)) {
578 $object->fetch_projet();
579 }
580
581 $resarray[$array_key.'_project_ref'] = $object->project->ref;
582 $resarray[$array_key.'_project_title'] = $object->project->title;
583 $resarray[$array_key.'_project_description'] = $object->project->description;
584 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
585 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
586 } else { // empty replacement
587 $resarray[$array_key.'_project_ref'] ='';
588 $resarray[$array_key.'_project_title'] = '';
589 $resarray[$array_key.'_project_description'] = '';
590 $resarray[$array_key.'_project_date_start'] = '';
591 $resarray[$array_key.'_project_date_end'] = '';
592 }
593
594 // Add vat by rates
595 if (is_array($object->lines) && count($object->lines) > 0) {
596 $totalUp = 0;
597 // Set substitution keys for different VAT rates
598 foreach ($object->lines as $line) {
599 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
600 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
601 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
602 }
603 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
604 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
605 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
606 $vatformated = vatrate($line->tva_tx);
607 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
608 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
609 }
610 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
611 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
612
613 $totalUp += $line->subprice * $line->qty;
614 }
615
616 // Calculate total up and total discount percentage
617 // 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)
618 $resarray['object_total_up'] = $totalUp;
619 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
620 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
621 $totalDiscount = $object->getTotalDiscount();
622 } else {
623 $totalDiscount = 0;
624 }
625 if (!empty($totalUp) && !empty($totalDiscount)) {
626 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
627 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
628 } else {
629 $resarray['object_total_discount'] = '';
630 $resarray['object_total_discount_locale'] = '';
631 }
632 }
633
634 // Retrieve extrafields
635 if (is_array($object->array_options) && count($object->array_options)) {
636 $object->fetch_optionals();
637
638 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
639 }
640
641 return $resarray;
642 }
643
644 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
654 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
655 {
656 // phpcs:enable
657 $resarray = array(
658 'line_pos' => $linenumber,
659 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
660
661 'line_product_ref'=>(empty($line->product_ref) ? '' : $line->product_ref),
662 'line_product_ref_fourn'=>(empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
663 'line_product_label'=>(empty($line->product_label) ? '' : $line->product_label),
664 'line_product_type'=>(empty($line->product_type) ? '' : $line->product_type),
665 'line_product_barcode'=>(empty($line->product_barcode) ? '' : $line->product_barcode),
666 'line_product_desc'=>(empty($line->product_desc) ? '' : $line->product_desc),
667
668 'line_desc'=>$line->desc,
669 'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
670 'line_localtax1_rate'=>vatrate($line->localtax1_tx),
671 'line_localtax2_rate'=>vatrate($line->localtax1_tx),
672 'line_up'=>price2num($line->subprice),
673 'line_up_locale'=>price($line->subprice, 0, $outputlangs),
674 'line_total_up'=>price2num($line->subprice * $line->qty),
675 'line_total_up_locale'=>price($line->subprice * $line->qty, 0, $outputlangs),
676 'line_qty'=>$line->qty,
677 'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
678 'line_price_ht'=>price2num($line->total_ht),
679 'line_price_ttc'=>price2num($line->total_ttc),
680 'line_price_vat'=>price2num($line->total_tva),
681 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
682 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
683 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
684 // Dates
685 'line_date_start'=>dol_print_date($line->date_start, 'day'),
686 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
687 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc'),
688 'line_date_end'=>dol_print_date($line->date_end, 'day'),
689 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
690 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc'),
691
692 'line_multicurrency_code' => price2num($line->multicurrency_code),
693 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
694 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
695 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
696 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
697 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
698 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
699 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
700 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
701 );
702
703 // Units
704 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
705 $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
706 $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
707 }
708
709 // Retrieve extrafields
710 $extrafieldkey = $line->table_element;
711 $array_key = "line";
712 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
713 $extrafields = new ExtraFields($this->db);
714 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
715 $line->fetch_optionals();
716
717 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
718
719 // Check if the current line belongs to a supplier order
720 if (get_class($line) == 'CommandeFournisseurLigne') {
721 // Add the product supplier extrafields to the substitutions
722 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
723 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
724
725 if (!empty($extralabels) && is_array($extralabels)) {
726 $columns = "";
727
728 foreach ($extralabels as $key => $label) {
729 $columns .= "$key, ";
730 }
731
732 if ($columns != "") {
733 $columns = substr($columns, 0, strlen($columns) - 2);
734 $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)."'");
735
736 if ($this->db->num_rows($resql) > 0) {
737 $resql = $this->db->fetch_object($resql);
738
739 foreach ($extralabels as $key => $label) {
740 $resarray['line_product_supplier_'.$key] = $resql->$key;
741 }
742 }
743 }
744 }
745 }
746
747 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
748 if (isset($line->fk_product) && $line->fk_product > 0) {
749 $tmpproduct = new Product($this->db);
750 $result = $tmpproduct->fetch($line->fk_product);
751 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
752 foreach ($tmpproduct->array_options as $key => $label) {
753 $resarray["line_product_".$key] = $label;
754 }
755 }
756 } else {
757 // Set unused placeholders as blank
758 $extrafields->fetch_name_optionals_label("product");
759 $extralabels = $extrafields->attributes["product"]['label'];
760
761 if (!empty($extralabels) && is_array($extralabels)) {
762 foreach ($extralabels as $key => $label) {
763 $resarray['line_product_options_'.$key] = '';
764 }
765 }
766 }
767
768 return $resarray;
769 }
770
771 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
781 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
782 {
783 // phpcs:enable
784 global $conf, $extrafields;
785 dol_include_once('/core/lib/product.lib.php');
786 $object->list_delivery_methods($object->shipping_method_id);
787 $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
788
789 $array_shipment = array(
790 $array_key.'_id'=>$object->id,
791 $array_key.'_ref'=>$object->ref,
792 $array_key.'_ref_ext'=>$object->ref_ext,
793 $array_key.'_ref_customer'=>$object->ref_customer,
794 $array_key.'_date_delivery'=>dol_print_date($object->date_delivery, 'day'),
795 $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery, 'hour'),
796 $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
797 $array_key.'_total_ht'=>price($object->total_ht),
798 $array_key.'_total_vat'=>price($object->total_tva),
799 $array_key.'_total_ttc'=>price($object->total_ttc),
800 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
801 $array_key.'_note_private'=>$object->note_private,
802 $array_key.'_note'=>$object->note_public,
803 $array_key.'_tracking_number'=>$object->tracking_number,
804 $array_key.'_tracking_url'=>$object->tracking_url,
805 $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
806 $array_key.'_weight'=>$object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
807 $array_key.'_width'=>$object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
808 $array_key.'_height'=>$object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
809 $array_key.'_depth'=>$object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
810 $array_key.'_size'=>$calculatedVolume.' '.measuringUnitString(0, 'volume'),
811 );
812
813 // Add vat by rates
814 foreach ($object->lines as $line) {
815 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
816 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
817 }
818 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
819 }
820
821 // Retrieve extrafields
822 if (is_array($object->array_options) && count($object->array_options)) {
823 $object->fetch_optionals();
824
825 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
826 }
827
828 // Add infor from $object->xxx where xxx has been loaded by fetch_origin() of shipment
829 if (!empty($object->commande) && is_object($object->commande)) {
830 $array_shipment['order_ref'] = $object->commande->ref;
831 $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
832 }
833
834 return $array_shipment;
835 }
836
837
838 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
847 public function get_substitutionarray_shipment_lines($line, $outputlangs)
848 {
849 // phpcs:enable
850 dol_include_once('/core/lib/product.lib.php');
851
852 $resarray = array(
853 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
854 'line_product_ref'=>$line->product_ref,
855 'line_product_label'=>$line->product_label,
856 'line_desc'=>$line->desc,
857 'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
858 'line_up'=>price($line->subprice),
859 'line_total_up'=>price($line->subprice * $line->qty),
860 'line_qty'=>$line->qty,
861 'line_qty_shipped'=>$line->qty_shipped,
862 'line_qty_asked'=>$line->qty_asked,
863 'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
864 'line_price_ht'=>price($line->total_ht),
865 'line_price_ttc'=>price($line->total_ttc),
866 'line_price_vat'=>price($line->total_tva),
867 'line_weight'=>empty($line->weight) ? '' : $line->weight * $line->qty_shipped.' '.measuringUnitString(0, 'weight', $line->weight_units),
868 'line_length'=>empty($line->length) ? '' : $line->length * $line->qty_shipped.' '.measuringUnitString(0, 'size', $line->length_units),
869 'line_surface'=>empty($line->surface) ? '' : $line->surface * $line->qty_shipped.' '.measuringUnitString(0, 'surface', $line->surface_units),
870 'line_volume'=>empty($line->volume) ? '' : $line->volume * $line->qty_shipped.' '.measuringUnitString(0, 'volume', $line->volume_units),
871 );
872
873 // Retrieve extrafields
874 $extrafieldkey = $line->element;
875 $array_key = "line";
876 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
877 $extrafields = new ExtraFields($this->db);
878 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
879 $line->fetch_optionals();
880
881 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
882
883 // Load product data optional fields to the line -> enables to use "line_product_options_{extrafield}"
884 if (isset($line->fk_product) && $line->fk_product > 0) {
885 $tmpproduct = new Product($this->db);
886 $tmpproduct->fetch($line->fk_product);
887 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
888 foreach ($tmpproduct->array_options as $key=>$label) {
889 $resarray["line_product_".$key] = $label;
890 }
891 }
892 }
893
894 return $resarray;
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 (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 = false, $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 $field = new stdClass();
1473 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1474 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1475 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1476 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1477 }
1478 $field->label = $outputlangs->transnoentities($label);
1479 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1480
1481 // dont display if empty
1482 if ($disableOnEmpty && empty($field->content)) {
1483 continue;
1484 }
1485
1486 $fields[] = $field;
1487 }
1488 }
1489
1490 if (!empty($fields)) {
1491 // Sort extrafields by rank
1492 uasort($fields, function ($a, $b) {
1493 return ($a->rank > $b->rank) ? 1 : -1;
1494 });
1495
1496 // define some HTML content with style
1497 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1498
1499 // auto select display format
1500 if ($params['display'] == 'auto') {
1501 $lastNnumbItems = 0;
1502 foreach ($params['auto'] as $display => $numbItems) {
1503 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1504 $lastNnumbItems = $numbItems;
1505 $params['display'] = $display;
1506 }
1507 }
1508 }
1509
1510 if ($params['display'] == 'list') {
1511 // Display in list format
1512 $i = 0;
1513 foreach ($fields as $field) {
1514 $html .= !empty($i) ? $params['list']['separator'] : '';
1515 $html .= '<strong>'.$field->label.' : </strong>';
1516 $html .= $field->content;
1517 $i++;
1518 }
1519 } elseif ($params['display'] == 'table') {
1520 // Display in table format
1521 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1522
1523 $html .= "<tr>";
1524 $itemsInRow = 0;
1525 $maxItemsInRow = $params['table']['maxItemsInRow'];
1526 foreach ($fields as $field) {
1527 //$html.= !empty($html)?'<br>':'';
1528 if ($itemsInRow >= $maxItemsInRow) {
1529 // start a new line
1530 $html .= "</tr><tr>";
1531 $itemsInRow = 0;
1532 }
1533
1534 // for some type we need line break
1535 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1536 if ($itemsInRow > 0) {
1537 // close table row and empty cols
1538 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1539 $html .= "<td></td><td></td>";
1540 }
1541 $html .= "</tr>";
1542
1543 // start a new line
1544 $html .= "<tr>";
1545 }
1546
1547 $itemsInRow = $maxItemsInRow;
1548 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1549 $html .= '<strong>'.$field->label.' :</strong> ';
1550 $html .= $field->content;
1551 $html .= "</td>";
1552 } else {
1553 $itemsInRow++;
1554 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1555 $html .= '<strong>'.$field->label.' :</strong>';
1556 $html .= "</td>";
1557
1558
1559 $html .= '<td class="extrafield-content">';
1560 $html .= $field->content;
1561 $html .= "</td>";
1562 }
1563 }
1564 $html .= "</tr>";
1565
1566 $html .= '</table>';
1567 }
1568 }
1569
1570 return $html;
1571 }
1572
1573
1580 public function getColumnStatus($colKey)
1581 {
1582 if (!empty($this->cols[$colKey]['status'])) {
1583 return true;
1584 } else {
1585 return false;
1586 }
1587 }
1588
1599 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1600 {
1601 global $hookmanager, $conf;
1602
1603 foreach ($this->cols as $colKey => $colDef) {
1604 $parameters = array(
1605 'colKey' => $colKey,
1606 'pdf' => $pdf,
1607 'outputlangs' => $outputlangs,
1608 'tab_top' => $tab_top,
1609 'tab_height' => $tab_height,
1610 'hidetop' => $hidetop
1611 );
1612
1613 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1614 if ($reshook < 0) {
1615 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1616 } elseif (empty($reshook)) {
1617 if (!$this->getColumnStatus($colKey)) {
1618 continue;
1619 }
1620
1621 // get title label
1622 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1623
1624 // Add column separator
1625 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
1626 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1627 }
1628
1629 if (empty($hidetop)) {
1630 // save curent cell padding
1631 $curentCellPaddinds = $pdf->getCellPaddings();
1632
1633 // Add space for lines (more if we need to show a second alternative language)
1634 global $outputlangsbis;
1635 if (is_object($outputlangsbis)) {
1636 // set cell padding with column title definition
1637 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1638 } else {
1639 // set cell padding with column title definition
1640 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1641 }
1642 if (isset($colDef['title']['align'])) {
1643 $align = $colDef['title']['align'];
1644 } else {
1645 $align = '';
1646 }
1647 $pdf->SetXY($colDef['xStartPos'], $tab_top);
1648 $textWidth = $colDef['width'];
1649 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
1650
1651 // Add variant of translation if $outputlangsbis is an object
1652 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1653 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1654 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1655 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1656 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
1657 }
1658
1659 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1660
1661 // restore cell padding
1662 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1663 }
1664 }
1665 }
1666
1667 return $this->tabTitleHeight;
1668 }
1669
1670
1671
1680 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1681 {
1682 if (!empty($hidedetails)) {
1683 return 0;
1684 }
1685
1686 if (empty($object->table_element)) {
1687 return 0;
1688 }
1689
1690 // Load extra fields if they haven't been loaded already.
1691 if (empty($this->extrafieldsCache)) {
1692 $this->extrafieldsCache = new ExtraFields($this->db);
1693 }
1694 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1695 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1696 }
1697 $extrafields = $this->extrafieldsCache;
1698
1699
1700 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'])) {
1701 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1702 // Dont display separator yet even is set to be displayed (not compatible yet)
1703 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1704 continue;
1705 }
1706
1707 // Enable extrafield ?
1708 $enabled = 0;
1709 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1710 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1711 if ($printable === 1 || $printable === 2) {
1712 $enabled = 1;
1713 }
1714 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1715 }
1716
1717 if (!$enabled) {
1718 continue;
1719 } // don't wast resourses if we don't need them...
1720
1721 // Load language if required
1722 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1723 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1724 }
1725
1726 // TODO : add more extrafield customisation capacities for PDF like width, rank...
1727
1728 // set column definition
1729 $def = array(
1730 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1731 'width' => 25, // in mm
1732 'status' => boolval($enabled),
1733 'title' => array(
1734 'label' => $outputlangs->transnoentities($label)
1735 ),
1736 'content' => array(
1737 'align' => 'C'
1738 ),
1739 'border-left' => true, // add left line separator
1740 );
1741
1742 $alignTypeRight = array('double', 'int', 'price');
1743 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1744 $def['content']['align'] = 'R';
1745 }
1746
1747 $alignTypeLeft = array('text', 'html');
1748 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1749 $def['content']['align'] = 'L';
1750 }
1751
1752
1753 // for extrafields we use rank of extrafield to place it on PDF
1754 $this->insertNewColumnDef("options_".$key, $def);
1755 }
1756 }
1757
1758 return 1;
1759 }
1760}
Class to manage bank accounts.
Parent class for documents generators.
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
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.
insertNewColumnDef($newColKey, $defArray, $targetCol=false, $insertAfterTarget=false)
get column position rank from column key
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.
get_substitutionarray_shipment_lines($line, $outputlangs)
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
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 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:1374
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.