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