dolibarr  18.0.0-alpha
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 
83  public $page_hauteur;
84  public $page_largeur;
85  public $marge_gauche;
86  public $marge_droite;
87  public $marge_haute;
88  public $marge_basse;
89 
90  public $option_logo;
91  public $option_tva;
92  public $option_multilang;
93  public $option_freetext;
94  public $option_draft_watermark;
95 
96  public $option_modereg;
97  public $option_condreg;
98  public $option_escompte;
99  public $option_credit_note;
100 
101  public $emetteur;
102 
103 
109  public function __construct($db)
110  {
111  $this->db = $db;
112  }
113 
114 
115  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
123  public function get_substitutionarray_user($user, $outputlangs)
124  {
125  // phpcs:enable
126  global $conf, $extrafields;
127 
128  $logotouse = $conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo;
129 
130  $array_user = array(
131  'myuser_lastname'=>$user->lastname,
132  'myuser_firstname'=>$user->firstname,
133  'myuser_fullname'=>$user->getFullName($outputlangs, 1),
134  'myuser_login'=>$user->login,
135  'myuser_phone'=>$user->office_phone,
136  'myuser_address'=>$user->address,
137  'myuser_zip'=>$user->zip,
138  'myuser_town'=>$user->town,
139  'myuser_country'=>$user->country,
140  'myuser_country_code'=>$user->country_code,
141  'myuser_state'=>$user->state,
142  'myuser_state_code'=>$user->state_code,
143  'myuser_fax'=>$user->office_fax,
144  'myuser_mobile'=>$user->user_mobile,
145  'myuser_email'=>$user->email,
146  'myuser_logo'=>$logotouse,
147  'myuser_job'=>$user->job,
148  'myuser_web'=>'', // url not exist in $user object
149  'myuser_birth'=>dol_print_date($user->birth, 'day', 'gmt'),
150  'myuser_dateemployment'=>dol_print_date($user->dateemployment, 'day', 'tzuser'),
151  'myuser_dateemploymentend'=>dol_print_date($user->dateemploymentend, 'day', 'tzuser'),
152  'myuser_gender'=>$user->gender,
153  );
154  // Retrieve extrafields
155  if (is_array($user->array_options) && count($user->array_options)) {
156  $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
157  }
158  return $array_user;
159  }
160 
161 
169  public function getSubstitutionarrayMember($member, $outputlangs)
170  {
171  global $conf, $extrafields;
172 
173  if ($member->photo) {
174  $logotouse = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
175  } else {
176  $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
177  }
178 
179  $array_member = array(
180  'mymember_lastname' => $member->lastname,
181  'mymember_firstname' => $member->firstname,
182  'mymember_fullname' => $member->getFullName($outputlangs, 1),
183  'mymember_login' => $member->login,
184  'mymember_address' => $member->address,
185  'mymember_zip' => $member->zip,
186  'mymember_town' => $member->town,
187  'mymember_country_code' => $member->country_code,
188  'mymember_country' => $member->country,
189  'mymember_state_code' => $member->state_code,
190  'mymember_state' => $member->state,
191  'mymember_phone_perso' => $member->phone_perso,
192  'mymember_phone_pro' => $member->phone,
193  'mymember_phone_mobile' => $member->phone_mobile,
194  'mymember_email' => $member->email,
195  'mymember_logo' => $logotouse,
196  'mymember_gender' => $member->gender,
197  'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
198  'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
199  );
200  // Retrieve extrafields
201  if (is_array($member->array_options) && count($member->array_options)) {
202  $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
203  }
204  return $array_member;
205  }
206 
207 
208  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
216  public function get_substitutionarray_mysoc($mysoc, $outputlangs)
217  {
218  // phpcs:enable
219  global $conf;
220 
221  if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
222  $mysoc->forme_juridique = getFormeJuridiqueLabel($mysoc->forme_juridique_code);
223  }
224  if (empty($mysoc->country) && !empty($mysoc->country_code)) {
225  $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
226  }
227  if (empty($mysoc->state) && !empty($mysoc->state_code)) {
228  $mysoc->state = getState($mysoc->state_code, 0);
229  }
230 
231  $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
232 
233  return array(
234  'mycompany_logo'=>$logotouse,
235  'mycompany_name'=>$mysoc->name,
236  'mycompany_email'=>$mysoc->email,
237  'mycompany_phone'=>$mysoc->phone,
238  'mycompany_fax'=>$mysoc->fax,
239  'mycompany_address'=>$mysoc->address,
240  'mycompany_zip'=>$mysoc->zip,
241  'mycompany_town'=>$mysoc->town,
242  'mycompany_country'=>$mysoc->country,
243  'mycompany_country_code'=>$mysoc->country_code,
244  'mycompany_state'=>$mysoc->state,
245  'mycompany_state_code'=>$mysoc->state_code,
246  'mycompany_web'=>$mysoc->url,
247  'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
248  'mycompany_managers'=>$mysoc->managers,
249  'mycompany_capital'=>$mysoc->capital,
250  'mycompany_barcode'=>$mysoc->barcode,
251  'mycompany_idprof1'=>$mysoc->idprof1,
252  'mycompany_idprof2'=>$mysoc->idprof2,
253  'mycompany_idprof3'=>$mysoc->idprof3,
254  'mycompany_idprof4'=>$mysoc->idprof4,
255  'mycompany_idprof5'=>$mysoc->idprof5,
256  'mycompany_idprof6'=>$mysoc->idprof6,
257  'mycompany_vatnumber'=>$mysoc->tva_intra,
258  'mycompany_object'=>$mysoc->object,
259  'mycompany_note_private'=>$mysoc->note_private,
260  //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
261  );
262  }
263 
264 
265  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
275  public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
276  {
277  // phpcs:enable
278  global $conf, $extrafields;
279 
280  if (empty($object->country) && !empty($object->country_code)) {
281  $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
282  }
283  if (empty($object->state) && !empty($object->state_code)) {
284  $object->state = getState($object->state_code, 0);
285  }
286 
287  $array_thirdparty = array(
288  'company_name'=>$object->name,
289  'company_name_alias' => $object->name_alias,
290  'company_email'=>$object->email,
291  'company_phone'=>$object->phone,
292  'company_fax'=>$object->fax,
293  'company_address'=>$object->address,
294  'company_zip'=>$object->zip,
295  'company_town'=>$object->town,
296  'company_country'=>$object->country,
297  'company_country_code'=>$object->country_code,
298  'company_state'=>$object->state,
299  'company_state_code'=>$object->state_code,
300  'company_web'=>$object->url,
301  'company_barcode'=>$object->barcode,
302  'company_vatnumber'=>$object->tva_intra,
303  'company_customercode'=>$object->code_client,
304  'company_suppliercode'=>$object->code_fournisseur,
305  'company_customeraccountancycode'=>$object->code_compta,
306  'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
307  'company_juridicalstatus'=>$object->forme_juridique,
308  'company_outstanding_limit'=>$object->outstanding_limit,
309  'company_capital'=>$object->capital,
310  'company_idprof1'=>$object->idprof1,
311  'company_idprof2'=>$object->idprof2,
312  'company_idprof3'=>$object->idprof3,
313  'company_idprof4'=>$object->idprof4,
314  'company_idprof5'=>$object->idprof5,
315  'company_idprof6'=>$object->idprof6,
316  'company_note_public'=>$object->note_public,
317  'company_note_private'=>$object->note_private,
318  'company_default_bank_iban'=>(is_object($object->bank_account) ? $object->bank_account->iban : ''),
319  'company_default_bank_bic'=>(is_object($object->bank_account) ? $object->bank_account->bic : '')
320  );
321 
322  // Retrieve extrafields
323  if (is_array($object->array_options) && count($object->array_options)) {
324  $object->fetch_optionals();
325 
326  $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
327  }
328  return $array_thirdparty;
329  }
330 
331  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
340  public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
341  {
342  // phpcs:enable
343  global $conf, $extrafields;
344 
345  if (empty($object->country) && !empty($object->country_code)) {
346  $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
347  }
348  if (empty($object->state) && !empty($object->state_code)) {
349  $object->state = getState($object->state_code, 0);
350  }
351 
352  $array_contact = array(
353  $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
354  $array_key.'_lastname' => $object->lastname,
355  $array_key.'_firstname' => $object->firstname,
356  $array_key.'_address' => $object->address,
357  $array_key.'_zip' => $object->zip,
358  $array_key.'_town' => $object->town,
359  $array_key.'_state_id' => $object->state_id,
360  $array_key.'_state_code' => $object->state_code,
361  $array_key.'_state' => $object->state,
362  $array_key.'_country_id' => $object->country_id,
363  $array_key.'_country_code' => $object->country_code,
364  $array_key.'_country' => $object->country,
365  $array_key.'_poste' => $object->poste,
366  $array_key.'_socid' => $object->socid,
367  $array_key.'_statut' => $object->statut,
368  $array_key.'_code' => $object->code,
369  $array_key.'_email' => $object->email,
370  $array_key.'_phone_pro' => $object->phone_pro,
371  $array_key.'_phone_perso' => $object->phone_perso,
372  $array_key.'_phone_mobile' => $object->phone_mobile,
373  $array_key.'_fax' => $object->fax,
374  $array_key.'_birthday' => $object->birthday,
375  $array_key.'_default_lang' => $object->default_lang,
376  $array_key.'_note_public' => $object->note_public,
377  $array_key.'_note_private' => $object->note_private,
378  $array_key.'_civility' => $object->civility,
379  );
380 
381  // Retrieve extrafields
382  if (is_array($object->array_options) && count($object->array_options)) {
383  $object->fetch_optionals();
384 
385  $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
386  }
387  return $array_contact;
388  }
389 
390 
391  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
398  public function get_substitutionarray_other($outputlangs)
399  {
400  // phpcs:enable
401  global $conf;
402 
403  $now = dol_now('gmt'); // gmt
404  $array_other = array(
405  // Date in default language
406  'current_date'=>dol_print_date($now, 'day', 'tzuser'),
407  'current_datehour'=>dol_print_date($now, 'dayhour', 'tzuser'),
408  'current_server_date'=>dol_print_date($now, 'day', 'tzserver'),
409  'current_server_datehour'=>dol_print_date($now, 'dayhour', 'tzserver'),
410  // Date in requested output language
411  'current_date_locale'=>dol_print_date($now, 'day', 'tzuser', $outputlangs),
412  'current_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
413  'current_server_date_locale'=>dol_print_date($now, 'day', 'tzserver', $outputlangs),
414  'current_server_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
415  );
416 
417 
418  foreach ($conf->global as $key => $val) {
419  if (isASecretKey($key)) {
420  $newval = '*****forbidden*****';
421  } else {
422  $newval = $val;
423  }
424  $array_other['__['.$key.']__'] = $newval;
425  }
426 
427  return $array_other;
428  }
429 
430 
431  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
440  public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
441  {
442  // phpcs:enable
443  global $conf, $extrafields;
444 
445  $sumpayed = $sumdeposit = $sumcreditnote = '';
446  $already_payed_all = 0;
447 
448  if ($object->element == 'facture') {
449  $invoice_source = new Facture($this->db);
450  if ($object->fk_facture_source > 0) {
451  $invoice_source->fetch($object->fk_facture_source);
452  }
453  $sumpayed = $object->getSommePaiement();
454  $sumdeposit = $object->getSumDepositsUsed();
455  $sumcreditnote = $object->getSumCreditNotesUsed();
456  $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
457 
458  if ($object->fk_account > 0) {
459  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
460  $bank_account = new Account($this->db);
461  $bank_account->fetch($object->fk_account);
462  }
463  }
464 
465  $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
466 
467  $resarray = array(
468  $array_key.'_id'=>$object->id,
469  $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
470  $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
471  $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
472  $array_key.'_ref_customer'=>(!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
473  $array_key.'_ref_supplier'=>(!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
474  $array_key.'_source_invoice_ref'=>((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
475  // Dates
476  $array_key.'_hour'=>dol_print_date($date, 'hour'),
477  $array_key.'_date'=>dol_print_date($date, 'day'),
478  $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'),
479  $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ?dol_print_date($object->date_lim_reglement, 'day') : ''),
480  $array_key.'_date_end'=>(!empty($object->fin_validite) ?dol_print_date($object->fin_validite, 'day') : ''),
481  $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
482  $array_key.'_date_modification'=>(!empty($object->date_modification) ?dol_print_date($object->date_modification, 'day') : ''),
483  $array_key.'_date_validation'=>(!empty($object->date_validation) ?dol_print_date($object->date_validation, 'dayhour') : ''),
484  $array_key.'_date_delivery_planed'=>(!empty($object->date_livraison) ?dol_print_date($object->date_livraison, 'day') : ''),
485  $array_key.'_date_close'=>(!empty($object->date_cloture) ?dol_print_date($object->date_cloture, 'dayhour') : ''),
486 
487  $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
488  $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),
489  $array_key.'_payment_term_code'=>$object->cond_reglement_code,
490  $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)),
491 
492  $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
493 
494  $array_key.'_bank_iban'=>$bank_account->iban,
495  $array_key.'_bank_bic'=>$bank_account->bic,
496  $array_key.'_bank_label'=>$bank_account->label,
497  $array_key.'_bank_number'=>$bank_account->number,
498  $array_key.'_bank_proprio'=>$bank_account->proprio,
499 
500  $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
501  $array_key.'_total_vat_locale'=>(!empty($object->total_vat) ?price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
502  $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
503  $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
504  $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
505 
506  $array_key.'_total_ht'=>price2num($object->total_ht),
507  $array_key.'_total_vat'=>(!empty($object->total_vat) ?price2num($object->total_vat) : price2num($object->total_tva)),
508  $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
509  $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
510  $array_key.'_total_ttc'=>price2num($object->total_ttc),
511 
512  $array_key.'_multicurrency_code' => $object->multicurrency_code,
513  $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
514  $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
515  $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
516  $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
517  $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
518  $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
519  $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
520 
521  $array_key.'_note_private'=>$object->note,
522  $array_key.'_note_public'=>$object->note_public,
523  $array_key.'_note'=>$object->note_public, // For backward compatibility
524 
525  // Payments
526  $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
527  $array_key.'_already_payed'=>price2num($sumpayed),
528  $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
529  $array_key.'_already_deposit'=>price2num($sumdeposit),
530  $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
531  $array_key.'_already_creditnote'=>price2num($sumcreditnote),
532 
533  $array_key.'_already_payed_all_locale'=>price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
534  $array_key.'_already_payed_all'=> price2num($already_payed_all, 'MT'),
535 
536  // Remain to pay with all known information (except open direct debit requests)
537  $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
538  $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $already_payed_all, 'MT')
539  );
540 
541  if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
542  $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
543  $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
544  } else {
545  $resarray[$array_key.'_total_discount_ht_locale'] = '';
546  $resarray[$array_key.'_total_discount_ht'] = '';
547  }
548 
549  // Fetch project information if there is a project assigned to this object
550  if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
551  if (!is_object($object->project)) {
552  $object->fetch_projet();
553  }
554 
555  $resarray[$array_key.'_project_ref'] = $object->project->ref;
556  $resarray[$array_key.'_project_title'] = $object->project->title;
557  $resarray[$array_key.'_project_description'] = $object->project->description;
558  $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
559  $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
560  } else { // empty replacement
561  $resarray[$array_key.'_project_ref'] ='';
562  $resarray[$array_key.'_project_title'] = '';
563  $resarray[$array_key.'_project_description'] = '';
564  $resarray[$array_key.'_project_date_start'] = '';
565  $resarray[$array_key.'_project_date_end'] = '';
566  }
567 
568  // Add vat by rates
569  if (is_array($object->lines) && count($object->lines) > 0) {
570  $totalUp = 0;
571  // Set substitution keys for different VAT rates
572  foreach ($object->lines as $line) {
573  // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
574  if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
575  $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
576  }
577  $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
578  $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
579  // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
580  $vatformated = vatrate($line->tva_tx);
581  if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
582  $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
583  }
584  $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
585  $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
586 
587  $totalUp += $line->subprice * $line->qty;
588  }
589 
590  // Calculate total up and total discount percentage
591  // 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)
592  $resarray['object_total_up'] = $totalUp;
593  $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
594  if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
595  $totalDiscount = $object->getTotalDiscount();
596  } else {
597  $totalDiscount = 0;
598  }
599  if (!empty($totalUp) && !empty($totalDiscount)) {
600  $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
601  $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
602  } else {
603  $resarray['object_total_discount'] = '';
604  $resarray['object_total_discount_locale'] = '';
605  }
606  }
607 
608  // Retrieve extrafields
609  if (is_array($object->array_options) && count($object->array_options)) {
610  $object->fetch_optionals();
611 
612  $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
613  }
614 
615  return $resarray;
616  }
617 
618  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
627  public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
628  {
629  // phpcs:enable
630  global $conf;
631 
632  $resarray = array(
633  'line_pos' => $linenumber,
634  'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
635 
636  'line_product_ref'=>(empty($line->product_ref) ? '' : $line->product_ref),
637  'line_product_ref_fourn'=>(empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
638  'line_product_label'=>(empty($line->product_label) ? '' : $line->product_label),
639  'line_product_type'=>(empty($line->product_type) ? '' : $line->product_type),
640  'line_product_barcode'=>(empty($line->product_barcode) ? '' : $line->product_barcode),
641  'line_product_desc'=>(empty($line->product_desc) ? '' : $line->product_desc),
642 
643  'line_desc'=>$line->desc,
644  'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
645  'line_localtax1_rate'=>vatrate($line->localtax1_tx),
646  'line_localtax2_rate'=>vatrate($line->localtax1_tx),
647  'line_up'=>price2num($line->subprice),
648  'line_up_locale'=>price($line->subprice, 0, $outputlangs),
649  'line_total_up'=>price2num($line->subprice * $line->qty),
650  'line_total_up_locale'=>price($line->subprice * $line->qty, 0, $outputlangs),
651  'line_qty'=>$line->qty,
652  'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
653  'line_price_ht'=>price2num($line->total_ht),
654  'line_price_ttc'=>price2num($line->total_ttc),
655  'line_price_vat'=>price2num($line->total_tva),
656  'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
657  'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
658  'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
659  // Dates
660  'line_date_start'=>dol_print_date($line->date_start, 'day'),
661  'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
662  'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc'),
663  'line_date_end'=>dol_print_date($line->date_end, 'day'),
664  'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
665  'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc'),
666 
667  'line_multicurrency_code' => price2num($line->multicurrency_code),
668  'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
669  'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
670  'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
671  'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
672  'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
673  'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
674  'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
675  'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
676  );
677 
678  // Units
679  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
680  $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
681  $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
682  }
683 
684  // Retrieve extrafields
685  $extrafieldkey = $line->table_element;
686  $array_key = "line";
687  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
688  $extrafields = new ExtraFields($this->db);
689  $extrafields->fetch_name_optionals_label($extrafieldkey, true);
690  $line->fetch_optionals();
691 
692  $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
693 
694  // Check if the current line belongs to a supplier order
695  if (get_class($line) == 'CommandeFournisseurLigne') {
696  // Add the product supplier extrafields to the substitutions
697  $extrafields->fetch_name_optionals_label("product_fournisseur_price");
698  $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
699 
700  if (!empty($extralabels) && is_array($extralabels)) {
701  $columns = "";
702 
703  foreach ($extralabels as $key => $label) {
704  $columns .= "$key, ";
705  }
706 
707  if ($columns != "") {
708  $columns = substr($columns, 0, strlen($columns) - 2);
709  $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)."'");
710 
711  if ($this->db->num_rows($resql) > 0) {
712  $resql = $this->db->fetch_object($resql);
713 
714  foreach ($extralabels as $key => $label) {
715  $resarray['line_product_supplier_'.$key] = $resql->$key;
716  }
717  }
718  }
719  }
720  }
721 
722  // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
723  if (isset($line->fk_product) && $line->fk_product > 0) {
724  $tmpproduct = new Product($this->db);
725  $result = $tmpproduct->fetch($line->fk_product);
726  foreach ($tmpproduct->array_options as $key => $label) {
727  $resarray["line_product_".$key] = $label;
728  }
729  } else {
730  // Set unused placeholders as blank
731  $extrafields->fetch_name_optionals_label("product");
732  $extralabels = $extrafields->attributes["product"]['label'];
733 
734  foreach ($extralabels as $key => $label) {
735  $resarray['line_product_options_'.$key] = '';
736  }
737  }
738 
739  return $resarray;
740  }
741 
742  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
751  public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
752  {
753  // phpcs:enable
754  global $conf, $extrafields;
755  dol_include_once('/core/lib/product.lib.php');
756  $object->list_delivery_methods($object->shipping_method_id);
757  $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
758 
759  $array_shipment = array(
760  $array_key.'_id'=>$object->id,
761  $array_key.'_ref'=>$object->ref,
762  $array_key.'_ref_ext'=>$object->ref_ext,
763  $array_key.'_ref_customer'=>$object->ref_customer,
764  $array_key.'_date_delivery'=>dol_print_date($object->date_delivery, 'day'),
765  $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery, 'hour'),
766  $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
767  $array_key.'_total_ht'=>price($object->total_ht),
768  $array_key.'_total_vat'=>price($object->total_tva),
769  $array_key.'_total_ttc'=>price($object->total_ttc),
770  $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
771  $array_key.'_note_private'=>$object->note_private,
772  $array_key.'_note'=>$object->note_public,
773  $array_key.'_tracking_number'=>$object->tracking_number,
774  $array_key.'_tracking_url'=>$object->tracking_url,
775  $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
776  $array_key.'_weight'=>$object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
777  $array_key.'_width'=>$object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
778  $array_key.'_height'=>$object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
779  $array_key.'_depth'=>$object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
780  $array_key.'_size'=>$calculatedVolume.' '.measuringUnitString(0, 'volume'),
781  );
782 
783  // Add vat by rates
784  foreach ($object->lines as $line) {
785  if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
786  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
787  }
788  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
789  }
790 
791  // Retrieve extrafields
792  if (is_array($object->array_options) && count($object->array_options)) {
793  $object->fetch_optionals();
794 
795  $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
796  }
797 
798  // Add infor from $object->xxx where xxx has been loaded by fetch_origin() of shipment
799  if (!empty($object->commande) && is_object($object->commande)) {
800  $array_shipment['order_ref'] = $object->commande->ref;
801  $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
802  }
803 
804  return $array_shipment;
805  }
806 
807 
808  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
816  public function get_substitutionarray_shipment_lines($line, $outputlangs)
817  {
818  // phpcs:enable
819  global $conf;
820  dol_include_once('/core/lib/product.lib.php');
821 
822  $resarray = array(
823  'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
824  'line_product_ref'=>$line->product_ref,
825  'line_product_label'=>$line->product_label,
826  'line_desc'=>$line->desc,
827  'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
828  'line_up'=>price($line->subprice),
829  'line_total_up'=>price($line->subprice * $line->qty),
830  'line_qty'=>$line->qty,
831  'line_qty_shipped'=>$line->qty_shipped,
832  'line_qty_asked'=>$line->qty_asked,
833  'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
834  'line_price_ht'=>price($line->total_ht),
835  'line_price_ttc'=>price($line->total_ttc),
836  'line_price_vat'=>price($line->total_tva),
837  'line_weight'=>empty($line->weight) ? '' : $line->weight * $line->qty_shipped.' '.measuringUnitString(0, 'weight', $line->weight_units),
838  'line_length'=>empty($line->length) ? '' : $line->length * $line->qty_shipped.' '.measuringUnitString(0, 'size', $line->length_units),
839  'line_surface'=>empty($line->surface) ? '' : $line->surface * $line->qty_shipped.' '.measuringUnitString(0, 'surface', $line->surface_units),
840  'line_volume'=>empty($line->volume) ? '' : $line->volume * $line->qty_shipped.' '.measuringUnitString(0, 'volume', $line->volume_units),
841  );
842 
843  // Retrieve extrafields
844  $extrafieldkey = $line->element;
845  $array_key = "line";
846  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
847  $extrafields = new ExtraFields($this->db);
848  $extrafields->fetch_name_optionals_label($extrafieldkey, true);
849  $line->fetch_optionals();
850 
851  $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
852 
853  // Load product data optional fields to the line -> enables to use "line_product_options_{extrafield}"
854  if (isset($line->fk_product) && $line->fk_product > 0) {
855  $tmpproduct = new Product($this->db);
856  $tmpproduct->fetch($line->fk_product);
857  foreach ($tmpproduct->array_options as $key=>$label)
858  $resarray["line_product_".$key] = $label;
859  }
860 
861  return $resarray;
862  }
863 
864 
865  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
874  public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
875  {
876  // phpcs:enable
877  $array_other = array();
878  if (!empty($object)) {
879  foreach ($object as $key => $value) {
880  if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
881  continue;
882  }
883  if (!empty($value)) {
884  if (!is_array($value) && !is_object($value)) {
885  $array_other['object_'.$key] = $value;
886  } elseif (is_array($value) && $recursive) {
887  $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
888  foreach ($tmparray as $key2 => $value2) {
889  $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
890  }
891  } elseif (is_object($value) && $recursive) {
892  $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
893  foreach ($tmparray as $key2 => $value2) {
894  $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
895  }
896  }
897  }
898  }
899  }
900 
901  //var_dump($array_other);
902 
903  return $array_other;
904  }
905 
906 
907  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
918  public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
919  {
920  // phpcs:enable
921  global $conf;
922 
923  if (is_array($extrafields->attributes[$object->table_element]['label'])) {
924  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
925  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
926  $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]);
927  $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
928  //Add value to store price with currency
929  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency']));
930  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
931  $valueofselectkey = $object->array_options['options_'.$key];
932  if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
933  $object->array_options['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
934  } else {
935  $object->array_options['options_'.$key] = '';
936  }
937  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
938  $valArray = explode(',', $object->array_options['options_'.$key]);
939  $output = array();
940  foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
941  if (in_array($keyopt, $valArray)) {
942  $output[] = $valopt;
943  }
944  }
945  $object->array_options['options_'.$key] = implode(', ', $output);
946  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
947  if (strlen($object->array_options['options_'.$key]) > 0) {
948  $date = $object->array_options['options_'.$key];
949  $object->array_options['options_'.$key] = dol_print_date($date, 'day'); // using company output language
950  $object->array_options['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
951  $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
952  } else {
953  $object->array_options['options_'.$key] = '';
954  $object->array_options['options_'.$key.'_locale'] = '';
955  $object->array_options['options_'.$key.'_rfc'] = '';
956  }
957  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
958  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
959  } elseif ($extrafields->attributes[$object->table_element]['label'][$key] == 'datetime') {
960  $datetime = $object->array_options['options_'.$key];
961  $object->array_options['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhour') : ''); // using company output language
962  $object->array_options['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
963  $object->array_options['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhourrfc') : ''); // international format
964  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
965  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
966  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
967  $id = $object->array_options['options_'.$key];
968  if ($id != "") {
969  $param = $extrafields->attributes[$object->table_element]['param'][$key];
970  $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
971  $InfoFieldList = explode(":", $param_list[0]);
972  $classname = $InfoFieldList[0];
973  $classpath = $InfoFieldList[1];
974  if (!empty($classpath)) {
975  dol_include_once($InfoFieldList[1]);
976  if ($classname && class_exists($classname)) {
977  $tmpobject = new $classname($this->db);
978  $tmpobject->fetch($id);
979  // completely replace the id with the linked object name
980  $object->array_options['options_'.$key] = $tmpobject->name;
981  }
982  }
983  }
984  }
985 
986  if (array_key_exists('options_'.$key, $object->array_options)) {
987  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $object->array_options['options_'.$key]));
988  } else {
989  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
990  }
991  }
992  }
993 
994  return $array_to_fill;
995  }
996 
997 
1010  public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1011  {
1012  if (empty($hidetop) || $hidetop == -1) {
1013  $pdf->line($x, $y, $x + $l, $y);
1014  }
1015  $pdf->line($x + $l, $y, $x + $l, $y + $h);
1016  if (empty($hidebottom)) {
1017  $pdf->line($x + $l, $y + $h, $x, $y + $h);
1018  }
1019  $pdf->line($x, $y + $h, $x, $y);
1020  }
1021 
1022 
1030  public function columnSort($a, $b)
1031  {
1032  if (empty($a['rank'])) {
1033  $a['rank'] = 0;
1034  }
1035  if (empty($b['rank'])) {
1036  $b['rank'] = 0;
1037  }
1038  if ($a['rank'] == $b['rank']) {
1039  return 0;
1040  }
1041  return ($a['rank'] > $b['rank']) ? -1 : 1;
1042  }
1043 
1054  public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1055  {
1056  $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1057 
1058 
1059  // Sorting
1060  uasort($this->cols, array($this, 'columnSort'));
1061 
1062  // Positionning
1063  $curX = $this->page_largeur - $this->marge_droite; // start from right
1064 
1065  // Array width
1066  $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1067 
1068  // Count flexible column
1069  $totalDefinedColWidth = 0;
1070  $countFlexCol = 0;
1071  foreach ($this->cols as $colKey => & $colDef) {
1072  if (!$this->getColumnStatus($colKey)) {
1073  continue; // continue if disabled
1074  }
1075 
1076  if (!empty($colDef['scale'])) {
1077  // In case of column width is defined by percentage
1078  $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1079  }
1080 
1081  if (empty($colDef['width'])) {
1082  $countFlexCol++;
1083  } else {
1084  $totalDefinedColWidth += $colDef['width'];
1085  }
1086  }
1087 
1088  foreach ($this->cols as $colKey => & $colDef) {
1089  // setting empty conf with default
1090  if (!empty($colDef['title'])) {
1091  $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1092  } else {
1093  $colDef['title'] = $this->defaultTitlesFieldsStyle;
1094  }
1095 
1096  // setting empty conf with default
1097  if (!empty($colDef['content'])) {
1098  $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1099  } else {
1100  $colDef['content'] = $this->defaultContentsFieldsStyle;
1101  }
1102 
1103  if ($this->getColumnStatus($colKey)) {
1104  // In case of flexible column
1105  if (empty($colDef['width'])) {
1106  $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1107  }
1108 
1109  // Set positions
1110  $lastX = $curX;
1111  $curX = $lastX - $colDef['width'];
1112  $colDef['xStartPos'] = $curX;
1113  $colDef['xEndPos'] = $lastX;
1114  }
1115  }
1116  }
1117 
1124  public function getColumnContentWidth($colKey)
1125  {
1126  $colDef = $this->cols[$colKey];
1127  return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1128  }
1129 
1130 
1137  public function getColumnContentXStart($colKey)
1138  {
1139  $colDef = $this->cols[$colKey];
1140  return (isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3];
1141  }
1142 
1149  public function getColumnRank($colKey)
1150  {
1151  if (!isset($this->cols[$colKey]['rank'])) {
1152  return -1;
1153  }
1154  return $this->cols[$colKey]['rank'];
1155  }
1156 
1166  public function insertNewColumnDef($newColKey, $defArray, $targetCol = false, $insertAfterTarget = false)
1167  {
1168  // prepare wanted rank
1169  $rank = -1;
1170 
1171  // try to get rank from target column
1172  if (!empty($targetCol)) {
1173  $rank = $this->getColumnRank($targetCol);
1174  if ($rank >= 0 && $insertAfterTarget) {
1175  $rank++;
1176  }
1177  }
1178 
1179  // get rank from new column definition
1180  if ($rank < 0 && !empty($defArray['rank'])) {
1181  $rank = $defArray['rank'];
1182  }
1183 
1184  // error: no rank
1185  if ($rank < 0) {
1186  return -1;
1187  }
1188 
1189  foreach ($this->cols as $colKey => & $colDef) {
1190  if ($rank <= $colDef['rank']) {
1191  $colDef['rank'] = $colDef['rank'] + 1;
1192  }
1193  }
1194 
1195  $defArray['rank'] = $rank;
1196  $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1197 
1198  return $rank;
1199  }
1200 
1201 
1211  public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1212  {
1213  global $hookmanager;
1214 
1215  $parameters = array(
1216  'curY' => &$curY,
1217  'columnText' => $columnText,
1218  'colKey' => $colKey,
1219  'pdf' => &$pdf,
1220  );
1221  $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1222  if ($reshook < 0) {
1223  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1224  }
1225  if (!$reshook) {
1226  if (empty($columnText)) {
1227  return 0;
1228  }
1229  $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set curent position
1230  $colDef = $this->cols[$colKey];
1231  // save curent cell padding
1232  $curentCellPaddinds = $pdf->getCellPaddings();
1233  // set cell padding with column content definition
1234  $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1235  $pdf->writeHTMLCell($colDef['width'], 2, $colDef['xStartPos'], $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1236 
1237  // restore cell padding
1238  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1239  }
1240 
1241  return 0;
1242  }
1243 
1244 
1259  public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1260  {
1261  // load desc col params
1262  $colDef = $this->cols[$colKey];
1263  // save curent cell padding
1264  $curentCellPaddinds = $pdf->getCellPaddings();
1265  // set cell padding with column content definition
1266  $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1267 
1268  // line description
1269  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline);
1270  $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1271 
1272  // restore cell padding
1273  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1274 
1275  // Display extrafield if needed
1276  $params = array(
1277  'display' => 'list',
1278  'printableEnable' => array(3),
1279  'printableEnableNotEmpty' => array(4)
1280  );
1281  $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1282  if (!empty($extrafieldDesc)) {
1283  $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1284  }
1285  }
1286 
1296  public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1297  {
1298  global $hookmanager;
1299 
1300  if (empty($object->table_element)) {
1301  return '';
1302  }
1303 
1304  $extrafieldsKeyPrefix = "options_";
1305 
1306  // Cleanup extrafield key to remove prefix if present
1307  $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1308  if ($pos === 0) {
1309  $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1310  }
1311 
1312  $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1313 
1314 
1315  // Load extra fields if they haven't been loaded already.
1316  if (empty($this->extrafieldsCache)) {
1317  $this->extrafieldsCache = new ExtraFields($this->db);
1318  }
1319  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1320  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1321  }
1322  $extrafields = $this->extrafieldsCache;
1323 
1324  $extrafieldOutputContent = '';
1325  if (isset($object->array_options[$extrafieldOptionsKey])) $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element);
1326 
1327  // 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 ...
1328  if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1329  // for lack of anything better we cleanup all html tags
1330  $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1331  }
1332 
1333  $parameters = array(
1334  'object' => $object,
1335  'extrafields' => $extrafields,
1336  'extrafieldKey' => $extrafieldKey,
1337  'extrafieldOutputContent' =>& $extrafieldOutputContent
1338  );
1339  $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1340  if ($reshook < 0) {
1341  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1342  }
1343  if ($reshook) {
1344  $extrafieldOutputContent = $hookmanager->resPrint;
1345  }
1346 
1347  return $extrafieldOutputContent;
1348  }
1349 
1350 
1359  public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1360  {
1361  global $hookmanager;
1362 
1363  if (empty($object->table_element)) {
1364  return;
1365  }
1366 
1367  // Load extrafields if not allready done
1368  if (empty($this->extrafieldsCache)) {
1369  $this->extrafieldsCache = new ExtraFields($this->db);
1370  }
1371  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1372  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1373  }
1374  $extrafields = $this->extrafieldsCache;
1375 
1376  $defaultParams = array(
1377  'style' => '',
1378  'display' => 'auto', // auto, table, list
1379  'printableEnable' => array(1),
1380  'printableEnableNotEmpty' => array(2),
1381 
1382  'table' => array(
1383  'maxItemsInRow' => 2,
1384  'cellspacing' => 0,
1385  'cellpadding' => 0,
1386  'border' => 0,
1387  'labelcolwidth' => '25%',
1388  'arrayOfLineBreakType' => array('text', 'html')
1389  ),
1390 
1391  'list' => array(
1392  'separator' => '<br>'
1393  ),
1394 
1395  'auto' => array(
1396  'list' => 0, // 0 for default
1397  'table' => 4 // if there more than x extrafield to display
1398  ),
1399  );
1400 
1401  $params = $params + $defaultParams;
1402 
1407  $html = '';
1408  $fields = array();
1409 
1410  if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1411  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1412  // Enable extrafield ?
1413  $enabled = 0;
1414  $disableOnEmpty = 0;
1415  if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1416  $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1417  if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1418  $enabled = 1;
1419  }
1420 
1421  if (in_array($printable, $params['printableEnableNotEmpty'])) {
1422  $disableOnEmpty = 1;
1423  }
1424  }
1425 
1426  if (empty($enabled)) {
1427  continue;
1428  }
1429 
1430  $field = new stdClass();
1431  $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1432  $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1433  $field->label = $outputlangs->transnoentities($label);
1434  $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1435 
1436  // dont display if empty
1437  if ($disableOnEmpty && empty($field->content)) {
1438  continue;
1439  }
1440 
1441  $fields[] = $field;
1442  }
1443  }
1444 
1445  if (!empty($fields)) {
1446  // Sort extrafields by rank
1447  uasort($fields, function ($a, $b) {
1448  return ($a->rank > $b->rank) ? 1 : -1;
1449  });
1450 
1451  // define some HTML content with style
1452  $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1453 
1454  // auto select display format
1455  if ($params['display'] == 'auto') {
1456  $lastNnumbItems = 0;
1457  foreach ($params['auto'] as $display => $numbItems) {
1458  if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1459  $lastNnumbItems = $numbItems;
1460  $params['display'] = $display;
1461  }
1462  }
1463  }
1464 
1465  if ($params['display'] == 'list') {
1466  // Display in list format
1467  $i = 0;
1468  foreach ($fields as $field) {
1469  $html .= !empty($i) ? $params['list']['separator'] : '';
1470  $html .= '<strong>'.$field->label.' : </strong>';
1471  $html .= $field->content;
1472  $i++;
1473  }
1474  } elseif ($params['display'] == 'table') {
1475  // Display in table format
1476  $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1477 
1478  $html .= "<tr>";
1479  $itemsInRow = 0;
1480  $maxItemsInRow = $params['table']['maxItemsInRow'];
1481  foreach ($fields as $field) {
1482  //$html.= !empty($html)?'<br>':'';
1483  if ($itemsInRow >= $maxItemsInRow) {
1484  // start a new line
1485  $html .= "</tr><tr>";
1486  $itemsInRow = 0;
1487  }
1488 
1489  // for some type we need line break
1490  if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1491  if ($itemsInRow > 0) {
1492  // close table row and empty cols
1493  for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1494  $html .= "<td></td><td></td>";
1495  }
1496  $html .= "</tr>";
1497 
1498  // start a new line
1499  $html .= "<tr>";
1500  }
1501 
1502  $itemsInRow = $maxItemsInRow;
1503  $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1504  $html .= '<strong>'.$field->label.' :</strong> ';
1505  $html .= $field->content;
1506  $html .= "</td>";
1507  } else {
1508  $itemsInRow++;
1509  $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1510  $html .= '<strong>'.$field->label.' :</strong>';
1511  $html .= "</td>";
1512 
1513 
1514  $html .= '<td class="extrafield-content">';
1515  $html .= $field->content;
1516  $html .= "</td>";
1517  }
1518  }
1519  $html .= "</tr>";
1520 
1521  $html .= '</table>';
1522  }
1523  }
1524 
1525  return $html;
1526  }
1527 
1528 
1535  public function getColumnStatus($colKey)
1536  {
1537  if (!empty($this->cols[$colKey]['status'])) {
1538  return true;
1539  } else {
1540  return false;
1541  }
1542  }
1543 
1554  public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1555  {
1556  global $hookmanager, $conf;
1557 
1558  foreach ($this->cols as $colKey => $colDef) {
1559  $parameters = array(
1560  'colKey' => $colKey,
1561  'pdf' => $pdf,
1562  'outputlangs' => $outputlangs,
1563  'tab_top' => $tab_top,
1564  'tab_height' => $tab_height,
1565  'hidetop' => $hidetop
1566  );
1567 
1568  $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1569  if ($reshook < 0) {
1570  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1571  } elseif (empty($reshook)) {
1572  if (!$this->getColumnStatus($colKey)) {
1573  continue;
1574  }
1575 
1576  // get title label
1577  $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1578 
1579  // Add column separator
1580  if (!empty($colDef['border-left'])) {
1581  $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1582  }
1583 
1584  if (empty($hidetop)) {
1585  // save curent cell padding
1586  $curentCellPaddinds = $pdf->getCellPaddings();
1587 
1588  // Add space for lines (more if we need to show a second alternative language)
1589  global $outputlangsbis;
1590  if (is_object($outputlangsbis)) {
1591  // set cell padding with column title definition
1592  $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1593  } else {
1594  // set cell padding with column title definition
1595  $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1596  }
1597 
1598  $pdf->SetXY($colDef['xStartPos'], $tab_top);
1599  $textWidth = $colDef['width'];
1600  $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1601 
1602  // Add variant of translation if $outputlangsbis is an object
1603  if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1604  $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1605  $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1606  $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1607  $pdf->MultiCell($textWidth, 2, $textbis, '', $colDef['title']['align']);
1608  }
1609 
1610  $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1611 
1612  // restore cell padding
1613  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1614  }
1615  }
1616  }
1617 
1618  return $this->tabTitleHeight;
1619  }
1620 
1621 
1622 
1631  public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1632  {
1633  if (!empty($hidedetails)) {
1634  return 0;
1635  }
1636 
1637  if (empty($object->table_element)) {
1638  return 0;
1639  }
1640 
1641  // Load extra fields if they haven't been loaded already.
1642  if (empty($this->extrafieldsCache)) {
1643  $this->extrafieldsCache = new ExtraFields($this->db);
1644  }
1645  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1646  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1647  }
1648  $extrafields = $this->extrafieldsCache;
1649 
1650 
1651  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'])) {
1652  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1653  // Dont display separator yet even is set to be displayed (not compatible yet)
1654  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1655  continue;
1656  }
1657 
1658  // Enable extrafield ?
1659  $enabled = 0;
1660  if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1661  $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1662  if ($printable === 1 || $printable === 2) {
1663  $enabled = 1;
1664  }
1665  // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1666  }
1667 
1668  if (!$enabled) {
1669  continue;
1670  } // don't wast resourses if we don't need them...
1671 
1672  // Load language if required
1673  if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1674  $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1675  }
1676 
1677  // TODO : add more extrafield customisation capacities for PDF like width, rank...
1678 
1679  // set column definition
1680  $def = array(
1681  'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1682  'width' => 25, // in mm
1683  'status' => boolval($enabled),
1684  'title' => array(
1685  'label' => $outputlangs->transnoentities($label)
1686  ),
1687  'content' => array(
1688  'align' => 'C'
1689  ),
1690  'border-left' => true, // add left line separator
1691  );
1692 
1693  $alignTypeRight = array('double', 'int', 'price');
1694  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1695  $def['content']['align'] = 'R';
1696  }
1697 
1698  $alignTypeLeft = array('text', 'html');
1699  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1700  $def['content']['align'] = 'L';
1701  }
1702 
1703 
1704  // for extrafields we use rank of extrafield to place it on PDF
1705  $this->insertNewColumnDef("options_".$key, $def);
1706  }
1707  }
1708 
1709  return 1;
1710  }
1711 }
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_writelinedesc
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:1354
CommonDocGenerator\__construct
__construct($db)
Constructor.
Definition: commondocgenerator.class.php:109
CommonDocGenerator\getColumnContentXStart
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
Definition: commondocgenerator.class.php:1137
CommonDocGenerator\printStdColumnContent
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
Definition: commondocgenerator.class.php:1211
CommonDocGenerator\getSubstitutionarrayMember
getSubstitutionarrayMember($member, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:169
CommonDocGenerator\get_substitutionarray_user
get_substitutionarray_user($user, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:123
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1043
CommonDocGenerator\pdfTabTitles
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
Definition: commondocgenerator.class.php:1554
doc_getlinedesc
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
CommonDocGenerator\getExtrafieldContent
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
Definition: commondocgenerator.class.php:1296
Facture
Class to manage invoices.
Definition: facture.class.php:60
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
measuringUnitString
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:805
CommonDocGenerator\prepareArrayColumnField
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
Definition: commondocgenerator.class.php:1054
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
isASecretKey
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
Definition: functions.lib.php:266
CommonDocGenerator\get_substitutionarray_contact
get_substitutionarray_contact($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:340
getState
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
Definition: company.lib.php:595
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6757
CommonDocGenerator\get_substitutionarray_shipment_lines
get_substitutionarray_shipment_lines($line, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:816
CommonDocGenerator\getColumnRank
getColumnRank($colKey)
get column position rank from column key
Definition: commondocgenerator.class.php:1149
CommonDocGenerator\fill_substitutionarray_with_extrafields
fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
Fill array with couple extrafield key => extrafield value.
Definition: commondocgenerator.class.php:918
CommonDocGenerator\get_substitutionarray_thirdparty
get_substitutionarray_thirdparty($object, $outputlangs, $array_key='company')
Define array with couple substitution key => substitution value For example {company_name},...
Definition: commondocgenerator.class.php:275
CommonDocGenerator\get_substitutionarray_object
get_substitutionarray_object($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:440
CommonDocGenerator\printRect
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Definition: commondocgenerator.class.php:1010
CommonDocGenerator\get_substitutionarray_each_var_object
get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive=1)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:874
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6921
CommonDocGenerator\insertNewColumnDef
insertNewColumnDef($newColKey, $defArray, $targetCol=false, $insertAfterTarget=false)
get column position rank from column key
Definition: commondocgenerator.class.php:1166
CommonDocGenerator\get_substitutionarray_mysoc
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:216
CommonDocGenerator\get_substitutionarray_shipment
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:751
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Definition: company.lib.php:711
CommonDocGenerator\columnSort
columnSort($a, $b)
uasort callback function to Sort columns fields
Definition: commondocgenerator.class.php:1030
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Product
Class to manage products or services.
Definition: product.class.php:46
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2947
CommonDocGenerator\get_substitutionarray_lines
get_substitutionarray_lines($line, $outputlangs, $linenumber=0)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:627
CommonDocGenerator\printColDescContent
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
Definition: commondocgenerator.class.php:1259
CommonDocGenerator\getColumnContentWidth
getColumnContentWidth($colKey)
get column content width from column key
Definition: commondocgenerator.class.php:1124
price
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.
Definition: functions.lib.php:5708
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8509
CommonDocGenerator
Parent class for documents generators.
Definition: commondocgenerator.class.php:36
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
CommonDocGenerator\defineColumnExtrafield
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Definition: commondocgenerator.class.php:1631
CommonDocGenerator\getColumnStatus
getColumnStatus($colKey)
get column status from column key
Definition: commondocgenerator.class.php:1535
Account
Class to manage bank accounts.
Definition: account.class.php:39
CommonDocGenerator\get_substitutionarray_other
get_substitutionarray_other($outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:398
vatrate
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.
Definition: functions.lib.php:5659