dolibarr  16.0.5
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-2020 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 $error = '';
42 
46  public $errors = array();
47 
51  protected $db;
52 
56  public $extrafieldsCache;
57 
61  public $update_main_doc_field;
62 
66  public $scandir;
67 
68  public $page_hauteur;
69  public $page_largeur;
70  public $marge_gauche;
71  public $marge_droite;
72  public $marge_haute;
73  public $marge_basse;
74 
75  public $option_logo;
76  public $option_tva;
77  public $option_multilang;
78  public $option_freetext;
79  public $option_draft_watermark;
80 
81  public $option_modereg;
82  public $option_condreg;
83  public $option_escompte;
84  public $option_credit_note;
85 
86  public $emetteur;
87 
88 
94  public function __construct($db)
95  {
96  $this->db = $db;
97  }
98 
99 
100  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
108  public function get_substitutionarray_user($user, $outputlangs)
109  {
110  // phpcs:enable
111  global $conf, $extrafields;
112 
113  $logotouse = $conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo;
114 
115  $array_user = array(
116  'myuser_lastname'=>$user->lastname,
117  'myuser_firstname'=>$user->firstname,
118  'myuser_fullname'=>$user->getFullName($outputlangs, 1),
119  'myuser_login'=>$user->login,
120  'myuser_phone'=>$user->office_phone,
121  'myuser_address'=>$user->address,
122  'myuser_zip'=>$user->zip,
123  'myuser_town'=>$user->town,
124  'myuser_country'=>$user->country,
125  'myuser_country_code'=>$user->country_code,
126  'myuser_state'=>$user->state,
127  'myuser_state_code'=>$user->state_code,
128  'myuser_fax'=>$user->office_fax,
129  'myuser_mobile'=>$user->user_mobile,
130  'myuser_email'=>$user->email,
131  'myuser_logo'=>$logotouse,
132  'myuser_job'=>$user->job,
133  'myuser_web'=>'' // url not exist in $user object
134  );
135  // Retrieve extrafields
136  if (is_array($user->array_options) && count($user->array_options)) {
137  $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
138  }
139  return $array_user;
140  }
141 
142 
150  public function getSubstitutionarrayMember($member, $outputlangs)
151  {
152  global $conf, $extrafields;
153 
154  if ($member->photo) {
155  $logotouse = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
156  } else {
157  $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
158  }
159 
160  $array_member = array(
161  'mymember_lastname' => $member->lastname,
162  'mymember_firstname' => $member->firstname,
163  'mymember_fullname' => $member->getFullName($outputlangs, 1),
164  'mymember_login' => $member->login,
165  'mymember_address' => $member->address,
166  'mymember_zip' => $member->zip,
167  'mymember_town' => $member->town,
168  'mymember_country_code' => $member->country_code,
169  'mymember_country' => $member->country,
170  'mymember_state_code' => $member->state_code,
171  'mymember_state' => $member->state,
172  'mymember_phone_perso' => $member->phone_perso,
173  'mymember_phone_pro' => $member->phone,
174  'mymember_phone_mobile' => $member->phone_mobile,
175  'mymember_email' => $member->email,
176  'mymember_logo' => $logotouse,
177  'mymember_gender' => $member->gender,
178  'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
179  'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
180  );
181  // Retrieve extrafields
182  if (is_array($member->array_options) && count($member->array_options)) {
183  $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
184  }
185  return $array_member;
186  }
187 
188 
189  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
197  public function get_substitutionarray_mysoc($mysoc, $outputlangs)
198  {
199  // phpcs:enable
200  global $conf;
201 
202  if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
203  $mysoc->forme_juridique = getFormeJuridiqueLabel($mysoc->forme_juridique_code);
204  }
205  if (empty($mysoc->country) && !empty($mysoc->country_code)) {
206  $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
207  }
208  if (empty($mysoc->state) && !empty($mysoc->state_code)) {
209  $mysoc->state = getState($mysoc->state_code, 0);
210  }
211 
212  $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
213 
214  return array(
215  'mycompany_logo'=>$logotouse,
216  'mycompany_name'=>$mysoc->name,
217  'mycompany_email'=>$mysoc->email,
218  'mycompany_phone'=>$mysoc->phone,
219  'mycompany_fax'=>$mysoc->fax,
220  'mycompany_address'=>$mysoc->address,
221  'mycompany_zip'=>$mysoc->zip,
222  'mycompany_town'=>$mysoc->town,
223  'mycompany_country'=>$mysoc->country,
224  'mycompany_country_code'=>$mysoc->country_code,
225  'mycompany_state'=>$mysoc->state,
226  'mycompany_state_code'=>$mysoc->state_code,
227  'mycompany_web'=>$mysoc->url,
228  'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
229  'mycompany_managers'=>$mysoc->managers,
230  'mycompany_capital'=>$mysoc->capital,
231  'mycompany_barcode'=>$mysoc->barcode,
232  'mycompany_idprof1'=>$mysoc->idprof1,
233  'mycompany_idprof2'=>$mysoc->idprof2,
234  'mycompany_idprof3'=>$mysoc->idprof3,
235  'mycompany_idprof4'=>$mysoc->idprof4,
236  'mycompany_idprof5'=>$mysoc->idprof5,
237  'mycompany_idprof6'=>$mysoc->idprof6,
238  'mycompany_vatnumber'=>$mysoc->tva_intra,
239  'mycompany_object'=>$mysoc->object,
240  'mycompany_note_private'=>$mysoc->note_private,
241  //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
242  );
243  }
244 
245 
246  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
256  public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
257  {
258  // phpcs:enable
259  global $conf, $extrafields;
260 
261  if (empty($object->country) && !empty($object->country_code)) {
262  $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
263  }
264  if (empty($object->state) && !empty($object->state_code)) {
265  $object->state = getState($object->state_code, 0);
266  }
267 
268  $array_thirdparty = array(
269  'company_name'=>$object->name,
270  'company_name_alias' => $object->name_alias,
271  'company_email'=>$object->email,
272  'company_phone'=>$object->phone,
273  'company_fax'=>$object->fax,
274  'company_address'=>$object->address,
275  'company_zip'=>$object->zip,
276  'company_town'=>$object->town,
277  'company_country'=>$object->country,
278  'company_country_code'=>$object->country_code,
279  'company_state'=>$object->state,
280  'company_state_code'=>$object->state_code,
281  'company_web'=>$object->url,
282  'company_barcode'=>$object->barcode,
283  'company_vatnumber'=>$object->tva_intra,
284  'company_customercode'=>$object->code_client,
285  'company_suppliercode'=>$object->code_fournisseur,
286  'company_customeraccountancycode'=>$object->code_compta,
287  'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
288  'company_juridicalstatus'=>$object->forme_juridique,
289  'company_outstanding_limit'=>$object->outstanding_limit,
290  'company_capital'=>$object->capital,
291  'company_idprof1'=>$object->idprof1,
292  'company_idprof2'=>$object->idprof2,
293  'company_idprof3'=>$object->idprof3,
294  'company_idprof4'=>$object->idprof4,
295  'company_idprof5'=>$object->idprof5,
296  'company_idprof6'=>$object->idprof6,
297  'company_note_public'=>$object->note_public,
298  'company_note_private'=>$object->note_private,
299  'company_default_bank_iban'=>(is_object($object->bank_account) ? $object->bank_account->iban : ''),
300  'company_default_bank_bic'=>(is_object($object->bank_account) ? $object->bank_account->bic : '')
301  );
302 
303  // Retrieve extrafields
304  if (is_array($object->array_options) && count($object->array_options)) {
305  $object->fetch_optionals();
306 
307  $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
308  }
309  return $array_thirdparty;
310  }
311 
312  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
321  public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
322  {
323  // phpcs:enable
324  global $conf, $extrafields;
325 
326  if (empty($object->country) && !empty($object->country_code)) {
327  $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
328  }
329  if (empty($object->state) && !empty($object->state_code)) {
330  $object->state = getState($object->state_code, 0);
331  }
332 
333  $array_contact = array(
334  $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
335  $array_key.'_lastname' => $object->lastname,
336  $array_key.'_firstname' => $object->firstname,
337  $array_key.'_address' => $object->address,
338  $array_key.'_zip' => $object->zip,
339  $array_key.'_town' => $object->town,
340  $array_key.'_state_id' => $object->state_id,
341  $array_key.'_state_code' => $object->state_code,
342  $array_key.'_state' => $object->state,
343  $array_key.'_country_id' => $object->country_id,
344  $array_key.'_country_code' => $object->country_code,
345  $array_key.'_country' => $object->country,
346  $array_key.'_poste' => $object->poste,
347  $array_key.'_socid' => $object->socid,
348  $array_key.'_statut' => $object->statut,
349  $array_key.'_code' => $object->code,
350  $array_key.'_email' => $object->email,
351  $array_key.'_phone_pro' => $object->phone_pro,
352  $array_key.'_phone_perso' => $object->phone_perso,
353  $array_key.'_phone_mobile' => $object->phone_mobile,
354  $array_key.'_fax' => $object->fax,
355  $array_key.'_birthday' => $object->birthday,
356  $array_key.'_default_lang' => $object->default_lang,
357  $array_key.'_note_public' => $object->note_public,
358  $array_key.'_note_private' => $object->note_private,
359  $array_key.'_civility' => $object->civility,
360  );
361 
362  // Retrieve extrafields
363  if (is_array($object->array_options) && count($object->array_options)) {
364  $object->fetch_optionals();
365 
366  $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
367  }
368  return $array_contact;
369  }
370 
371 
372  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
379  public function get_substitutionarray_other($outputlangs)
380  {
381  // phpcs:enable
382  global $conf;
383 
384  $now = dol_now('gmt'); // gmt
385  $array_other = array(
386  // Date in default language
387  'current_date'=>dol_print_date($now, 'day', 'tzuser'),
388  'current_datehour'=>dol_print_date($now, 'dayhour', 'tzuser'),
389  'current_server_date'=>dol_print_date($now, 'day', 'tzserver'),
390  'current_server_datehour'=>dol_print_date($now, 'dayhour', 'tzserver'),
391  // Date in requested output language
392  'current_date_locale'=>dol_print_date($now, 'day', 'tzuser', $outputlangs),
393  'current_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
394  'current_server_date_locale'=>dol_print_date($now, 'day', 'tzserver', $outputlangs),
395  'current_server_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
396  );
397 
398 
399  foreach ($conf->global as $key => $val) {
400  if (isASecretKey($key)) {
401  $newval = '*****forbidden*****';
402  } else {
403  $newval = $val;
404  }
405  $array_other['__['.$key.']__'] = $newval;
406  }
407 
408  return $array_other;
409  }
410 
411 
412  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
421  public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
422  {
423  // phpcs:enable
424  global $conf, $extrafields;
425 
426  $sumpayed = $sumdeposit = $sumcreditnote = '';
427  $already_payed_all = 0;
428 
429  if ($object->element == 'facture') {
430  $invoice_source = new Facture($this->db);
431  if ($object->fk_facture_source > 0) {
432  $invoice_source->fetch($object->fk_facture_source);
433  }
434  $sumpayed = $object->getSommePaiement();
435  $sumdeposit = $object->getSumDepositsUsed();
436  $sumcreditnote = $object->getSumCreditNotesUsed();
437  $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
438 
439  if ($object->fk_account > 0) {
440  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
441  $bank_account = new Account($this->db);
442  $bank_account->fetch($object->fk_account);
443  }
444  }
445 
446  $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date);
447 
448  $resarray = array(
449  $array_key.'_id'=>$object->id,
450  $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
451  $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
452  $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
453  $array_key.'_ref_customer'=>(!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
454  $array_key.'_ref_supplier'=>(!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
455  $array_key.'_source_invoice_ref'=>$invoice_source->ref,
456  // Dates
457  $array_key.'_hour'=>dol_print_date($date, 'hour'),
458  $array_key.'_date'=>dol_print_date($date, 'day'),
459  $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'),
460  $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ?dol_print_date($object->date_lim_reglement, 'day') : ''),
461  $array_key.'_date_end'=>(!empty($object->fin_validite) ?dol_print_date($object->fin_validite, 'day') : ''),
462  $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
463  $array_key.'_date_modification'=>(!empty($object->date_modification) ?dol_print_date($object->date_modification, 'day') : ''),
464  $array_key.'_date_validation'=>(!empty($object->date_validation) ?dol_print_date($object->date_validation, 'dayhour') : ''),
465  $array_key.'_date_delivery_planed'=>(!empty($object->date_livraison) ?dol_print_date($object->date_livraison, 'day') : ''),
466  $array_key.'_date_close'=>(!empty($object->date_cloture) ?dol_print_date($object->date_cloture, 'dayhour') : ''),
467 
468  $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
469  $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),
470  $array_key.'_payment_term_code'=>$object->cond_reglement_code,
471  $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)),
472 
473  $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
474 
475  $array_key.'_bank_iban'=>$bank_account->iban,
476  $array_key.'_bank_bic'=>$bank_account->bic,
477  $array_key.'_bank_label'=>$bank_account->label,
478  $array_key.'_bank_number'=>$bank_account->number,
479  $array_key.'_bank_proprio'=>$bank_account->proprio,
480 
481  $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
482  $array_key.'_total_vat_locale'=>(!empty($object->total_vat) ?price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
483  $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
484  $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
485  $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
486 
487  $array_key.'_total_ht'=>price2num($object->total_ht),
488  $array_key.'_total_vat'=>(!empty($object->total_vat) ?price2num($object->total_vat) : price2num($object->total_tva)),
489  $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
490  $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
491  $array_key.'_total_ttc'=>price2num($object->total_ttc),
492 
493  $array_key.'_multicurrency_code' => $object->multicurrency_code,
494  $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
495  $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
496  $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
497  $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
498  $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
499  $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
500  $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
501 
502  $array_key.'_note_private'=>$object->note,
503  $array_key.'_note_public'=>$object->note_public,
504  $array_key.'_note'=>$object->note_public, // For backward compatibility
505 
506  // Payments
507  $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
508  $array_key.'_already_payed'=>price2num($sumpayed),
509  $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
510  $array_key.'_already_deposit'=>price2num($sumdeposit),
511  $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
512  $array_key.'_already_creditnote'=>price2num($sumcreditnote),
513 
514  $array_key.'_already_payed_all_locale'=>price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
515  $array_key.'_already_payed_all'=> price2num($already_payed_all, 'MT'),
516 
517  // Remain to pay with all known information (except open direct debit requests)
518  $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
519  $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $already_payed_all, 'MT')
520  );
521 
522  if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
523  $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
524  $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
525  } else {
526  $resarray[$array_key.'_total_discount_ht_locale'] = '';
527  $resarray[$array_key.'_total_discount_ht'] = '';
528  }
529 
530  // Fetch project information if there is a project assigned to this object
531  if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
532  if (!is_object($object->project)) {
533  $object->fetch_projet();
534  }
535 
536  $resarray[$array_key.'_project_ref'] = $object->project->ref;
537  $resarray[$array_key.'_project_title'] = $object->project->title;
538  $resarray[$array_key.'_project_description'] = $object->project->description;
539  $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
540  $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
541  }
542 
543  // Add vat by rates
544  if (is_array($object->lines) && count($object->lines) > 0) {
545  $totalUp = 0;
546  // Set substitution keys for different VAT rates
547  foreach ($object->lines as $line) {
548  // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
549  if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
550  $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
551  }
552  $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
553  $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
554  // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
555  $vatformated = vatrate($line->tva_tx);
556  if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
557  $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
558  }
559  $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
560  $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
561 
562  $totalUp += $line->subprice * $line->qty;
563  }
564 
565  // Calculate total up and total discount percentage
566  // 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)
567  $resarray['object_total_up'] = $totalUp;
568  $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
569  if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
570  $totalDiscount = $object->getTotalDiscount();
571  } else {
572  $totalDiscount = 0;
573  }
574  if (!empty($totalUp) && !empty($totalDiscount)) {
575  $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
576  $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
577  } else {
578  $resarray['object_total_discount'] = '';
579  $resarray['object_total_discount_locale'] = '';
580  }
581  }
582 
583  // Retrieve extrafields
584  if (is_array($object->array_options) && count($object->array_options)) {
585  $object->fetch_optionals();
586 
587  $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
588  }
589 
590  return $resarray;
591  }
592 
593  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
602  public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
603  {
604  // phpcs:enable
605  global $conf;
606 
607  $resarray = array(
608  'line_pos' => $linenumber,
609  'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
610 
611  'line_product_ref'=>(empty($line->product_ref) ? '' : $line->product_ref),
612  'line_product_ref_fourn'=>(empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
613  'line_product_label'=>(empty($line->product_label) ? '' : $line->product_label),
614  'line_product_type'=>(empty($line->product_type) ? '' : $line->product_type),
615  'line_product_barcode'=>(empty($line->product_barcode) ? '' : $line->product_barcode),
616  'line_product_desc'=>(empty($line->product_desc) ? '' : $line->product_desc),
617 
618  'line_desc'=>$line->desc,
619  'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
620  'line_localtax1_rate'=>vatrate($line->localtax1_tx),
621  'line_localtax2_rate'=>vatrate($line->localtax1_tx),
622  'line_up'=>price2num($line->subprice),
623  'line_up_locale'=>price($line->subprice, 0, $outputlangs),
624  'line_total_up'=>price2num($line->subprice * $line->qty),
625  'line_total_up_locale'=>price($line->subprice * $line->qty, 0, $outputlangs),
626  'line_qty'=>$line->qty,
627  'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
628  'line_price_ht'=>price2num($line->total_ht),
629  'line_price_ttc'=>price2num($line->total_ttc),
630  'line_price_vat'=>price2num($line->total_tva),
631  'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
632  'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
633  'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
634  // Dates
635  'line_date_start'=>dol_print_date($line->date_start, 'day'),
636  'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
637  'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc'),
638  'line_date_end'=>dol_print_date($line->date_end, 'day'),
639  'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
640  'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc'),
641 
642  'line_multicurrency_code' => price2num($line->multicurrency_code),
643  'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
644  'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
645  'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
646  'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
647  'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
648  'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
649  'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
650  'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
651  );
652 
653  // Units
654  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
655  $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
656  $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
657  }
658 
659  // Retrieve extrafields
660  $extrafieldkey = $line->table_element;
661  $array_key = "line";
662  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
663  $extrafields = new ExtraFields($this->db);
664  $extrafields->fetch_name_optionals_label($extrafieldkey, true);
665  $line->fetch_optionals();
666 
667  $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
668 
669  // Check if the current line belongs to a supplier order
670  if (get_class($line) == 'CommandeFournisseurLigne') {
671  // Add the product supplier extrafields to the substitutions
672  $extrafields->fetch_name_optionals_label("product_fournisseur_price");
673  $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
674 
675  if (!empty($extralabels) && is_array($extralabels)) {
676  $columns = "";
677 
678  foreach ($extralabels as $key => $label) {
679  $columns .= "$key, ";
680  }
681 
682  if ($columns != "") {
683  $columns = substr($columns, 0, strlen($columns) - 2);
684  $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)."'");
685 
686  if ($this->db->num_rows($resql) > 0) {
687  $resql = $this->db->fetch_object($resql);
688 
689  foreach ($extralabels as $key => $label) {
690  $resarray['line_product_supplier_'.$key] = $resql->{$key};
691  }
692  }
693  }
694  }
695  }
696 
697  // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
698  if (isset($line->fk_product) && $line->fk_product > 0) {
699  $tmpproduct = new Product($this->db);
700  $result = $tmpproduct->fetch($line->fk_product);
701  foreach ($tmpproduct->array_options as $key => $label) {
702  $resarray["line_product_".$key] = $label;
703  }
704  }
705 
706  return $resarray;
707  }
708 
709  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
718  public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
719  {
720  // phpcs:enable
721  global $conf, $extrafields;
722  dol_include_once('/core/lib/product.lib.php');
723  $object->list_delivery_methods($object->shipping_method_id);
724  $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
725 
726  $array_shipment = array(
727  $array_key.'_id'=>$object->id,
728  $array_key.'_ref'=>$object->ref,
729  $array_key.'_ref_ext'=>$object->ref_ext,
730  $array_key.'_ref_customer'=>$object->ref_customer,
731  $array_key.'_date_delivery'=>dol_print_date($object->date_delivery, 'day'),
732  $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery, 'hour'),
733  $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'),
734  $array_key.'_total_ht'=>price($object->total_ht),
735  $array_key.'_total_vat'=>price($object->total_tva),
736  $array_key.'_total_ttc'=>price($object->total_ttc),
737  $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
738  $array_key.'_note_private'=>$object->note_private,
739  $array_key.'_note'=>$object->note_public,
740  $array_key.'_tracking_number'=>$object->tracking_number,
741  $array_key.'_tracking_url'=>$object->tracking_url,
742  $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
743  $array_key.'_weight'=>$object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
744  $array_key.'_width'=>$object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
745  $array_key.'_height'=>$object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
746  $array_key.'_depth'=>$object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
747  $array_key.'_size'=>$calculatedVolume.' '.measuringUnitString(0, 'volume'),
748  );
749 
750  // Add vat by rates
751  foreach ($object->lines as $line) {
752  if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
753  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
754  }
755  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
756  }
757 
758  // Retrieve extrafields
759  if (is_array($object->array_options) && count($object->array_options)) {
760  $object->fetch_optionals();
761 
762  $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
763  }
764 
765  // Add infor from $object->xxx where xxx has been loaded by fetch_origin() of shipment
766  if (!empty($object->commande) && is_object($object->commande)) {
767  $array_shipment['order_ref'] = $object->commande->ref;
768  $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
769  }
770 
771  return $array_shipment;
772  }
773 
774 
775  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
783  public function get_substitutionarray_shipment_lines($line, $outputlangs)
784  {
785  // phpcs:enable
786  global $conf;
787  dol_include_once('/core/lib/product.lib.php');
788 
789  $resarray = array(
790  'line_fulldesc'=>doc_getlinedesc($line, $outputlangs),
791  'line_product_ref'=>$line->product_ref,
792  'line_product_label'=>$line->product_label,
793  'line_desc'=>$line->desc,
794  'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits),
795  'line_up'=>price($line->subprice),
796  'line_total_up'=>price($line->subprice * $line->qty),
797  'line_qty'=>$line->qty,
798  'line_qty_shipped'=>$line->qty_shipped,
799  'line_qty_asked'=>$line->qty_asked,
800  'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''),
801  'line_price_ht'=>price($line->total_ht),
802  'line_price_ttc'=>price($line->total_ttc),
803  'line_price_vat'=>price($line->total_tva),
804  'line_weight'=>empty($line->weight) ? '' : $line->weight * $line->qty_shipped.' '.measuringUnitString(0, 'weight', $line->weight_units),
805  'line_length'=>empty($line->length) ? '' : $line->length * $line->qty_shipped.' '.measuringUnitString(0, 'size', $line->length_units),
806  'line_surface'=>empty($line->surface) ? '' : $line->surface * $line->qty_shipped.' '.measuringUnitString(0, 'surface', $line->surface_units),
807  'line_volume'=>empty($line->volume) ? '' : $line->volume * $line->qty_shipped.' '.measuringUnitString(0, 'volume', $line->volume_units),
808  );
809 
810  // Retrieve extrafields
811  $extrafieldkey = $line->element;
812  $array_key = "line";
813  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
814  $extrafields = new ExtraFields($this->db);
815  $extrafields->fetch_name_optionals_label($extrafieldkey, true);
816  $line->fetch_optionals();
817 
818  $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
819 
820  // Load product data optional fields to the line -> enables to use "line_product_options_{extrafield}"
821  if (isset($line->fk_product) && $line->fk_product > 0) {
822  $tmpproduct = new Product($this->db);
823  $tmpproduct->fetch($line->fk_product);
824  foreach ($tmpproduct->array_options as $key=>$label)
825  $resarray["line_product_".$key] = $label;
826  }
827 
828  return $resarray;
829  }
830 
831 
832  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
841  public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
842  {
843  // phpcs:enable
844  $array_other = array();
845  if (!empty($object)) {
846  foreach ($object as $key => $value) {
847  if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
848  continue;
849  }
850  if (!empty($value)) {
851  if (!is_array($value) && !is_object($value)) {
852  $array_other['object_'.$key] = $value;
853  } elseif (is_array($value) && $recursive) {
854  $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
855  foreach ($tmparray as $key2 => $value2) {
856  $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
857  }
858  } elseif (is_object($value) && $recursive) {
859  $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
860  foreach ($tmparray as $key2 => $value2) {
861  $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
862  }
863  }
864  }
865  }
866  }
867 
868  //var_dump($array_other);
869 
870  return $array_other;
871  }
872 
873 
874  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
885  public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
886  {
887  // phpcs:enable
888  global $conf;
889 
890  if (is_array($extrafields->attributes[$object->table_element]['label'])) {
891  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
892  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
893  $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]);
894  $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
895  //Add value to store price with currency
896  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency']));
897  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
898  $valueofselectkey = $object->array_options['options_'.$key];
899  if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
900  $object->array_options['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
901  } else {
902  $object->array_options['options_'.$key] = '';
903  }
904  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
905  $valArray = explode(',', $object->array_options['options_'.$key]);
906  $output = array();
907  foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
908  if (in_array($keyopt, $valArray)) {
909  $output[] = $valopt;
910  }
911  }
912  $object->array_options['options_'.$key] = implode(', ', $output);
913  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
914  if (strlen($object->array_options['options_'.$key]) > 0) {
915  $date = $object->array_options['options_'.$key];
916  $object->array_options['options_'.$key] = dol_print_date($date, 'day'); // using company output language
917  $object->array_options['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
918  $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
919  } else {
920  $object->array_options['options_'.$key] = '';
921  $object->array_options['options_'.$key.'_locale'] = '';
922  $object->array_options['options_'.$key.'_rfc'] = '';
923  }
924  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
925  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
926  } elseif ($extrafields->attributes[$object->table_element]['label'][$key] == 'datetime') {
927  $datetime = $object->array_options['options_'.$key];
928  $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
929  $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
930  $object->array_options['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhourrfc') : ''); // international format
931  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
932  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
933  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
934  $id = $object->array_options['options_'.$key];
935  if ($id != "") {
936  $param = $extrafields->attributes[$object->table_element]['param'][$key];
937  $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
938  $InfoFieldList = explode(":", $param_list[0]);
939  $classname = $InfoFieldList[0];
940  $classpath = $InfoFieldList[1];
941  if (!empty($classpath)) {
942  dol_include_once($InfoFieldList[1]);
943  if ($classname && class_exists($classname)) {
944  $tmpobject = new $classname($this->db);
945  $tmpobject->fetch($id);
946  // completely replace the id with the linked object name
947  $object->array_options['options_'.$key] = $tmpobject->name;
948  }
949  }
950  }
951  }
952 
953  if (array_key_exists('options_'.$key, $object->array_options)) {
954  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $object->array_options['options_'.$key]));
955  } else {
956  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
957  }
958  }
959  }
960 
961  return $array_to_fill;
962  }
963 
964 
977  public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
978  {
979  if (empty($hidetop) || $hidetop == -1) {
980  $pdf->line($x, $y, $x + $l, $y);
981  }
982  $pdf->line($x + $l, $y, $x + $l, $y + $h);
983  if (empty($hidebottom)) {
984  $pdf->line($x + $l, $y + $h, $x, $y + $h);
985  }
986  $pdf->line($x, $y + $h, $x, $y);
987  }
988 
989 
997  public function columnSort($a, $b)
998  {
999  if (empty($a['rank'])) {
1000  $a['rank'] = 0;
1001  }
1002  if (empty($b['rank'])) {
1003  $b['rank'] = 0;
1004  }
1005  if ($a['rank'] == $b['rank']) {
1006  return 0;
1007  }
1008  return ($a['rank'] > $b['rank']) ? -1 : 1;
1009  }
1010 
1021  public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1022  {
1023  global $conf;
1024 
1025  $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1026 
1027 
1028  // Sorting
1029  uasort($this->cols, array($this, 'columnSort'));
1030 
1031  // Positionning
1032  $curX = $this->page_largeur - $this->marge_droite; // start from right
1033 
1034  // Array width
1035  $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1036 
1037  // Count flexible column
1038  $totalDefinedColWidth = 0;
1039  $countFlexCol = 0;
1040  foreach ($this->cols as $colKey => & $colDef) {
1041  if (!$this->getColumnStatus($colKey)) {
1042  continue; // continue if disabled
1043  }
1044 
1045  if (!empty($colDef['scale'])) {
1046  // In case of column width is defined by percentage
1047  $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1048  }
1049 
1050  if (empty($colDef['width'])) {
1051  $countFlexCol++;
1052  } else {
1053  $totalDefinedColWidth += $colDef['width'];
1054  }
1055  }
1056 
1057  foreach ($this->cols as $colKey => & $colDef) {
1058  // setting empty conf with default
1059  if (!empty($colDef['title'])) {
1060  $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1061  } else {
1062  $colDef['title'] = $this->defaultTitlesFieldsStyle;
1063  }
1064 
1065  // setting empty conf with default
1066  if (!empty($colDef['content'])) {
1067  $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1068  } else {
1069  $colDef['content'] = $this->defaultContentsFieldsStyle;
1070  }
1071 
1072  if ($this->getColumnStatus($colKey)) {
1073  // In case of flexible column
1074  if (empty($colDef['width'])) {
1075  $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1076  }
1077 
1078  // Set positions
1079  $lastX = $curX;
1080  $curX = $lastX - $colDef['width'];
1081  $colDef['xStartPos'] = $curX;
1082  $colDef['xEndPos'] = $lastX;
1083  }
1084  }
1085  }
1086 
1093  public function getColumnContentWidth($colKey)
1094  {
1095  $colDef = $this->cols[$colKey];
1096  return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1097  }
1098 
1099 
1106  public function getColumnContentXStart($colKey)
1107  {
1108  $colDef = $this->cols[$colKey];
1109  return $colDef['xStartPos'] + $colDef['content']['padding'][3];
1110  }
1111 
1118  public function getColumnRank($colKey)
1119  {
1120  if (!isset($this->cols[$colKey]['rank'])) {
1121  return -1;
1122  }
1123  return $this->cols[$colKey]['rank'];
1124  }
1125 
1135  public function insertNewColumnDef($newColKey, $defArray, $targetCol = false, $insertAfterTarget = false)
1136  {
1137  // prepare wanted rank
1138  $rank = -1;
1139 
1140  // try to get rank from target column
1141  if (!empty($targetCol)) {
1142  $rank = $this->getColumnRank($targetCol);
1143  if ($rank >= 0 && $insertAfterTarget) {
1144  $rank++;
1145  }
1146  }
1147 
1148  // get rank from new column definition
1149  if ($rank < 0 && !empty($defArray['rank'])) {
1150  $rank = $defArray['rank'];
1151  }
1152 
1153  // error: no rank
1154  if ($rank < 0) {
1155  return -1;
1156  }
1157 
1158  foreach ($this->cols as $colKey => & $colDef) {
1159  if ($rank <= $colDef['rank']) {
1160  $colDef['rank'] = $colDef['rank'] + 1;
1161  }
1162  }
1163 
1164  $defArray['rank'] = $rank;
1165  $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1166 
1167  return $rank;
1168  }
1169 
1170 
1180  public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1181  {
1182  global $hookmanager;
1183 
1184  $parameters = array(
1185  'curY' => &$curY,
1186  'columnText' => $columnText,
1187  'colKey' => $colKey,
1188  'pdf' => &$pdf,
1189  );
1190  $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1191  if ($reshook < 0) {
1192  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1193  }
1194  if (!$reshook) {
1195  if (empty($columnText)) {
1196  return;
1197  }
1198  $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set curent position
1199  $colDef = $this->cols[$colKey];
1200  // save curent cell padding
1201  $curentCellPaddinds = $pdf->getCellPaddings();
1202  // set cell padding with column content definition
1203  $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1204  $pdf->writeHTMLCell($colDef['width'], 2, $colDef['xStartPos'], $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1205 
1206  // restore cell padding
1207  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1208  }
1209  }
1210 
1211 
1226  public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1227  {
1228  // load desc col params
1229  $colDef = $this->cols[$colKey];
1230  // save curent cell padding
1231  $curentCellPaddinds = $pdf->getCellPaddings();
1232  // set cell padding with column content definition
1233  $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1234 
1235  // line description
1236  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline);
1237  $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1238 
1239  // restore cell padding
1240  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1241 
1242  // Display extrafield if needed
1243  $params = array(
1244  'display' => 'list',
1245  'printableEnable' => array(3),
1246  'printableEnableNotEmpty' => array(4)
1247  );
1248  $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1249  if (!empty($extrafieldDesc)) {
1250  $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1251  }
1252  }
1253 
1263  public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1264  {
1265  global $hookmanager;
1266 
1267  if (empty($object->table_element)) {
1268  return;
1269  }
1270 
1271  $extrafieldsKeyPrefix = "options_";
1272 
1273  // Cleanup extrafield key to remove prefix if present
1274  $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1275  if ($pos === 0) {
1276  $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1277  }
1278 
1279  $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1280 
1281 
1282  // Load extrafiels if not allready does
1283  if (empty($this->extrafieldsCache)) {
1284  $this->extrafieldsCache = new ExtraFields($this->db);
1285  }
1286  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1287  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1288  }
1289  $extrafields = $this->extrafieldsCache;
1290 
1291  $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element);
1292 
1293  // 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 ...
1294  if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1295  // for lack of anything better we cleanup all html tags
1296  $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1297  }
1298 
1299  $parameters = array(
1300  'object' => $object,
1301  'extrafields' => $extrafields,
1302  'extrafieldKey' => $extrafieldKey,
1303  'extrafieldOutputContent' =>& $extrafieldOutputContent
1304  );
1305  $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1306  if ($reshook < 0) {
1307  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1308  }
1309  if ($reshook) {
1310  $extrafieldOutputContent = $hookmanager->resPrint;
1311  }
1312 
1313  return $extrafieldOutputContent;
1314  }
1315 
1316 
1325  public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1326  {
1327  global $hookmanager;
1328 
1329  if (empty($object->table_element)) {
1330  return;
1331  }
1332 
1333  // Load extrafiels if not allready does
1334  if (empty($this->extrafieldsCache)) {
1335  $this->extrafieldsCache = new ExtraFields($this->db);
1336  }
1337  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1338  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1339  }
1340  $extrafields = $this->extrafieldsCache;
1341 
1342  $defaultParams = array(
1343  'style' => '',
1344  'display' => 'auto', // auto, table, list
1345  'printableEnable' => array(1),
1346  'printableEnableNotEmpty' => array(2),
1347 
1348  'table' => array(
1349  'maxItemsInRow' => 2,
1350  'cellspacing' => 0,
1351  'cellpadding' => 0,
1352  'border' => 0,
1353  'labelcolwidth' => '25%',
1354  'arrayOfLineBreakType' => array('text', 'html')
1355  ),
1356 
1357  'list' => array(
1358  'separator' => '<br>'
1359  ),
1360 
1361  'auto' => array(
1362  'list' => 0, // 0 for default
1363  'table' => 4 // if there more than x extrafield to display
1364  ),
1365  );
1366 
1367  $params = $params + $defaultParams;
1368 
1369 
1374  $html = '';
1375  $fields = array();
1376 
1377  if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1378  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1379  // Enable extrafield ?
1380  $enabled = 0;
1381  $disableOnEmpty = 0;
1382  if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1383  $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1384  if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1385  $enabled = 1;
1386  }
1387 
1388  if (in_array($printable, $params['printableEnableNotEmpty'])) {
1389  $disableOnEmpty = 1;
1390  }
1391  }
1392 
1393  if (empty($enabled)) {
1394  continue;
1395  }
1396 
1397  $field = new stdClass();
1398  $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1399  $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1400  $field->label = $outputlangs->transnoentities($label);
1401  $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1402 
1403  // dont display if empty
1404  if ($disableOnEmpty && empty($field->content)) {
1405  continue;
1406  }
1407 
1408  $fields[] = $field;
1409  }
1410  }
1411 
1412  if (!empty($fields)) {
1413  // Sort extrafields by rank
1414  uasort($fields, function ($a, $b) {
1415  return ($a->rank > $b->rank) ? 1 : -1;
1416  });
1417 
1418  // define some HTML content with style
1419  $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1420 
1421  // auto select display format
1422  if ($params['display'] == 'auto') {
1423  $lastNnumbItems = 0;
1424  foreach ($params['auto'] as $display => $numbItems) {
1425  if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1426  $lastNnumbItems = $numbItems;
1427  $params['display'] = $display;
1428  }
1429  }
1430  }
1431 
1432  if ($params['display'] == 'list') {
1433  // Display in list format
1434  $i = 0;
1435  foreach ($fields as $field) {
1436  $html .= !empty($i) ? $params['list']['separator'] : '';
1437  $html .= '<strong>'.$field->label.' : </strong>';
1438  $html .= $field->content;
1439  $i++;
1440  }
1441  } elseif ($params['display'] == 'table') {
1442  // Display in table format
1443  $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1444 
1445  $html .= "<tr>";
1446  $itemsInRow = 0;
1447  $maxItemsInRow = $params['table']['maxItemsInRow'];
1448  foreach ($fields as $field) {
1449  //$html.= !empty($html)?'<br>':'';
1450  if ($itemsInRow >= $maxItemsInRow) {
1451  // start a new line
1452  $html .= "</tr><tr>";
1453  $itemsInRow = 0;
1454  }
1455 
1456  // for some type we need line break
1457  if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1458  if ($itemsInRow > 0) {
1459  // close table row and empty cols
1460  for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1461  $html .= "<td></td><td></td>";
1462  }
1463  $html .= "</tr>";
1464 
1465  // start a new line
1466  $html .= "<tr>";
1467  }
1468 
1469  $itemsInRow = $maxItemsInRow;
1470  $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1471  $html .= '<strong>'.$field->label.' :</strong> ';
1472  $html .= $field->content;
1473  $html .= "</td>";
1474  } else {
1475  $itemsInRow++;
1476  $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1477  $html .= '<strong>'.$field->label.' :</strong>';
1478  $html .= "</td>";
1479 
1480 
1481  $html .= '<td class="extrafield-content">';
1482  $html .= $field->content;
1483  $html .= "</td>";
1484  }
1485  }
1486  $html .= "</tr>";
1487 
1488  $html .= '</table>';
1489  }
1490  }
1491 
1492  return $html;
1493  }
1494 
1495 
1502  public function getColumnStatus($colKey)
1503  {
1504  if (!empty($this->cols[$colKey]['status'])) {
1505  return true;
1506  } else {
1507  return false;
1508  }
1509  }
1510 
1521  public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1522  {
1523  global $hookmanager, $conf;
1524 
1525  foreach ($this->cols as $colKey => $colDef) {
1526  $parameters = array(
1527  'colKey' => $colKey,
1528  'pdf' => $pdf,
1529  'outputlangs' => $outputlangs,
1530  'tab_top' => $tab_top,
1531  'tab_height' => $tab_height,
1532  'hidetop' => $hidetop
1533  );
1534 
1535  $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1536  if ($reshook < 0) {
1537  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1538  } elseif (empty($reshook)) {
1539  if (!$this->getColumnStatus($colKey)) {
1540  continue;
1541  }
1542 
1543  // get title label
1544  $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1545 
1546  // Add column separator
1547  if (!empty($colDef['border-left'])) {
1548  $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1549  }
1550 
1551  if (empty($hidetop)) {
1552  // save curent cell padding
1553  $curentCellPaddinds = $pdf->getCellPaddings();
1554 
1555  // Add space for lines (more if we need to show a second alternative language)
1556  global $outputlangsbis;
1557  if (is_object($outputlangsbis)) {
1558  // set cell padding with column title definition
1559  $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1560  } else {
1561  // set cell padding with column title definition
1562  $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1563  }
1564 
1565  $pdf->SetXY($colDef['xStartPos'], $tab_top);
1566  $textWidth = $colDef['width'];
1567  $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1568 
1569  // Add variant of translation if $outputlangsbis is an object
1570  if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1571  $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1572  $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1573  $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1574  $pdf->MultiCell($textWidth, 2, $textbis, '', $colDef['title']['align']);
1575  }
1576 
1577  $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1578 
1579  // restore cell padding
1580  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1581  }
1582  }
1583  }
1584 
1585  return $this->tabTitleHeight;
1586  }
1587 
1588 
1589 
1598  public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1599  {
1600  global $conf;
1601 
1602  if (!empty($hidedetails)) {
1603  return;
1604  }
1605 
1606  if (empty($object->table_element)) {
1607  return;
1608  }
1609 
1610  // Load extrafiels if not allready does
1611  if (empty($this->extrafieldsCache)) {
1612  $this->extrafieldsCache = new ExtraFields($this->db);
1613  }
1614  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1615  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1616  }
1617  $extrafields = $this->extrafieldsCache;
1618 
1619 
1620  if (!empty($extrafields->attributes[$object->table_element]) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1621  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1622  // Dont display separator yet even is set to be displayed (not compatible yet)
1623  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1624  continue;
1625  }
1626 
1627  // Enable extrafield ?
1628  $enabled = 0;
1629  if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1630  $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1631  if ($printable === 1 || $printable === 2) {
1632  $enabled = 1;
1633  }
1634  // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1635  }
1636 
1637  if (!$enabled) {
1638  continue;
1639  } // don't wast resourses if we don't need them...
1640 
1641  // Load language if required
1642  if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1643  $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1644  }
1645 
1646  // TODO : add more extrafield customisation capacities for PDF like width, rank...
1647 
1648  // set column definition
1649  $def = array(
1650  'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1651  'width' => 25, // in mm
1652  'status' => boolval($enabled),
1653  'title' => array(
1654  'label' => $outputlangs->transnoentities($label)
1655  ),
1656  'content' => array(
1657  'align' => 'C'
1658  ),
1659  'border-left' => true, // add left line separator
1660  );
1661 
1662  $alignTypeRight = array('double', 'int', 'price');
1663  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1664  $def['content']['align'] = 'R';
1665  }
1666 
1667  $alignTypeLeft = array('text', 'html');
1668  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1669  $def['content']['align'] = 'L';
1670  }
1671 
1672 
1673  // for extrafields we use rank of extrafield to place it on PDF
1674  $this->insertNewColumnDef("options_".$key, $def);
1675  }
1676  }
1677  }
1678 }
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:1345
CommonDocGenerator\__construct
__construct($db)
Constructor.
Definition: commondocgenerator.class.php:94
CommonDocGenerator\getColumnContentXStart
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
Definition: commondocgenerator.class.php:1106
CommonDocGenerator\printStdColumnContent
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
Definition: commondocgenerator.class.php:1180
CommonDocGenerator\getSubstitutionarrayMember
getSubstitutionarrayMember($member, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:150
CommonDocGenerator\get_substitutionarray_user
get_substitutionarray_user($user, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:108
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:1033
CommonDocGenerator\pdfTabTitles
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
Definition: commondocgenerator.class.php:1521
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:1263
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:5661
measuringUnitString
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:619
CommonDocGenerator\prepareArrayColumnField
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
Definition: commondocgenerator.class.php:1021
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:2514
isASecretKey
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
Definition: functions.lib.php:224
CommonDocGenerator\get_substitutionarray_contact
get_substitutionarray_contact($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:321
getState
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
Definition: company.lib.php:569
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:6549
CommonDocGenerator\get_substitutionarray_shipment_lines
get_substitutionarray_shipment_lines($line, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:783
CommonDocGenerator\getColumnRank
getColumnRank($colKey)
get column position rank from column key
Definition: commondocgenerator.class.php:1118
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:885
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:256
CommonDocGenerator\get_substitutionarray_object
get_substitutionarray_object($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:421
CommonDocGenerator\printRect
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Definition: commondocgenerator.class.php:977
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:841
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:6694
CommonDocGenerator\insertNewColumnDef
insertNewColumnDef($newColKey, $defArray, $targetCol=false, $insertAfterTarget=false)
get column position rank from column key
Definition: commondocgenerator.class.php:1135
CommonDocGenerator\get_substitutionarray_mysoc
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:197
CommonDocGenerator\get_substitutionarray_shipment
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:718
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Definition: company.lib.php:683
CommonDocGenerator\columnSort
columnSort($a, $b)
uasort callback function to Sort columns fields
Definition: commondocgenerator.class.php:997
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:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonDocGenerator\get_substitutionarray_lines
get_substitutionarray_lines($line, $outputlangs, $linenumber=0)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:602
CommonDocGenerator\printColDescContent
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
Definition: commondocgenerator.class.php:1226
CommonDocGenerator\getColumnContentWidth
getColumnContentWidth($colKey)
get column content width from column key
Definition: commondocgenerator.class.php:1093
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:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
CommonDocGenerator
Parent class for documents generators.
Definition: commondocgenerator.class.php:36
CommonDocGenerator\defineColumnExtrafield
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Definition: commondocgenerator.class.php:1598
CommonDocGenerator\getColumnStatus
getColumnStatus($colKey)
get column status from column key
Definition: commondocgenerator.class.php:1502
Account
Class to manage bank accounts.
Definition: account.class.php:38
CommonDocGenerator\get_substitutionarray_other
get_substitutionarray_other($outputlangs)
Define array with couple substitution key => substitution value.
Definition: commondocgenerator.class.php:379
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:5492