dolibarr  20.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-2023 Charlene Benke <charlene@patas-monkey.com>
8  * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
9  * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
10  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  * or see https://www.gnu.org/
25  */
26 
37 abstract class CommonDocGenerator
38 {
42  public $name = '';
43 
47  public $version = '';
48 
52  public $error = '';
53 
57  public $errors = array();
58 
62  protected $db;
63 
67  public $extrafieldsCache;
68 
72  public $update_main_doc_field;
73 
77  public $scandir;
78 
82  public $description;
83 
87  public $format;
88 
92  public $type;
93 
94  public $page_hauteur;
95  public $page_largeur;
96  public $marge_gauche;
97  public $marge_droite;
98  public $marge_haute;
99  public $marge_basse;
100 
101  public $option_logo;
102  public $option_tva;
103  public $option_multilang;
104  public $option_freetext;
105  public $option_draft_watermark;
106  public $watermark;
107 
108  public $option_modereg;
109  public $option_condreg;
110  public $option_escompte;
111  public $option_credit_note;
112 
113  public $tva;
114  public $tva_array;
120  public $localtax1;
121 
127  public $localtax2;
128 
132  public $tabTitleHeight;
133 
137  public $defaultTitlesFieldsStyle;
138 
142  public $defaultContentsFieldsStyle;
143 
147  public $emetteur;
148 
153  public $phpmin = array(7, 1);
154 
158  public $cols;
159 
163  public $result;
164 
165  public $posxlabel;
166  public $posxup;
167  public $posxref;
168  public $posxpicture; // For picture
169  public $posxdesc; // For description
170  public $posxqty;
171  public $posxpuht;
172  public $posxtva;
173  public $posxtotalht;
174  public $postotalht;
175  public $posxunit;
176  public $posxdiscount;
177  public $posxworkload;
178  public $posxtimespent;
179  public $posxprogress;
180  public $atleastonephoto;
181  public $atleastoneratenotnull;
182  public $atleastonediscount;
183 
189  public function __construct($db)
190  {
191  $this->db = $db;
192  }
193 
194 
195  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
203  public function get_substitutionarray_user($user, $outputlangs)
204  {
205  // phpcs:enable
206  global $conf, $extrafields;
207 
208  $logotouse = $conf->user->dir_output . '/' . get_exdir(0, 0, 0, 0, $user, 'user') . 'photos/' . getImageFileNameForSize($user->photo, '_small');
209 
210  $array_user = array(
211  'myuser_lastname' => $user->lastname,
212  'myuser_firstname' => $user->firstname,
213  'myuser_fullname' => $user->getFullName($outputlangs, 1),
214  'myuser_login' => $user->login,
215  'myuser_phone' => $user->office_phone,
216  'myuser_address' => $user->address,
217  'myuser_zip' => $user->zip,
218  'myuser_town' => $user->town,
219  'myuser_country' => $user->country,
220  'myuser_country_code' => $user->country_code,
221  'myuser_state' => $user->state,
222  'myuser_state_code' => $user->state_code,
223  'myuser_fax' => $user->office_fax,
224  'myuser_mobile' => $user->user_mobile,
225  'myuser_email' => $user->email,
226  'myuser_logo' => $logotouse,
227  'myuser_job' => $user->job,
228  'myuser_web' => '', // url not exist in $user object
229  'myuser_birth' => dol_print_date($user->birth, 'day', 'gmt'),
230  'myuser_dateemployment' => dol_print_date($user->dateemployment, 'day', 'tzuser'),
231  'myuser_dateemploymentend' => dol_print_date($user->dateemploymentend, 'day', 'tzuser'),
232  'myuser_gender' => $user->gender,
233  );
234  // Retrieve extrafields
235  if (is_array($user->array_options) && count($user->array_options)) {
236  if (empty($extrafields->attributes[$user->table_element])) {
237  $extrafields->fetch_name_optionals_label($user->table_element);
238  }
239  $array_user = $this->fill_substitutionarray_with_extrafields($user, $array_user, $extrafields, 'myuser', $outputlangs);
240  }
241  return $array_user;
242  }
243 
244 
252  public function getSubstitutionarrayMember($member, $outputlangs)
253  {
254  global $conf, $extrafields;
255 
256  if ($member->photo) {
257  $logotouse = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $member, 'user').'/photos/'.$member->photo;
258  } else {
259  $logotouse = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png';
260  }
261 
262  $array_member = array(
263  'mymember_lastname' => $member->lastname,
264  'mymember_firstname' => $member->firstname,
265  'mymember_fullname' => $member->getFullName($outputlangs, 1),
266  'mymember_login' => $member->login,
267  'mymember_address' => $member->address,
268  'mymember_zip' => $member->zip,
269  'mymember_town' => $member->town,
270  'mymember_country_code' => $member->country_code,
271  'mymember_country' => $member->country,
272  'mymember_state_code' => $member->state_code,
273  'mymember_state' => $member->state,
274  'mymember_phone_perso' => $member->phone_perso,
275  'mymember_phone_pro' => $member->phone,
276  'mymember_phone_mobile' => $member->phone_mobile,
277  'mymember_email' => $member->email,
278  'mymember_logo' => $logotouse,
279  'mymember_gender' => $member->gender,
280  'mymember_birth_locale' => dol_print_date($member->birth, 'day', 'tzuser', $outputlangs),
281  'mymember_birth' => dol_print_date($member->birth, 'day', 'tzuser'),
282  );
283  // Retrieve extrafields
284  if (is_array($member->array_options) && count($member->array_options)) {
285  $array_member = $this->fill_substitutionarray_with_extrafields($member, $array_member, $extrafields, 'mymember', $outputlangs);
286  }
287  return $array_member;
288  }
289 
290 
291  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
299  public function get_substitutionarray_mysoc($mysoc, $outputlangs)
300  {
301  // phpcs:enable
302  global $conf;
303 
304  if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) {
305  $mysoc->forme_juridique = getFormeJuridiqueLabel($mysoc->forme_juridique_code);
306  }
307  if (empty($mysoc->country) && !empty($mysoc->country_code)) {
308  $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
309  }
310  if (empty($mysoc->state) && !empty($mysoc->state_code)) {
311  $mysoc->state = getState($mysoc->state_code, 0);
312  }
313 
314  $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
315 
316  return array(
317  'mycompany_logo' => $logotouse,
318  'mycompany_name' => $mysoc->name,
319  'mycompany_email' => $mysoc->email,
320  'mycompany_phone' => $mysoc->phone,
321  'mycompany_fax' => $mysoc->fax,
322  'mycompany_address' => $mysoc->address,
323  'mycompany_zip' => $mysoc->zip,
324  'mycompany_town' => $mysoc->town,
325  'mycompany_country' => $mysoc->country,
326  'mycompany_country_code' => $mysoc->country_code,
327  'mycompany_state' => $mysoc->state,
328  'mycompany_state_code' => $mysoc->state_code,
329  'mycompany_web' => $mysoc->url,
330  'mycompany_juridicalstatus' => $mysoc->forme_juridique,
331  'mycompany_managers' => $mysoc->managers,
332  'mycompany_capital' => $mysoc->capital,
333  'mycompany_barcode' => $mysoc->barcode,
334  'mycompany_idprof1' => $mysoc->idprof1,
335  'mycompany_idprof2' => $mysoc->idprof2,
336  'mycompany_idprof3' => $mysoc->idprof3,
337  'mycompany_idprof4' => $mysoc->idprof4,
338  'mycompany_idprof5' => $mysoc->idprof5,
339  'mycompany_idprof6' => $mysoc->idprof6,
340  'mycompany_vatnumber' => $mysoc->tva_intra,
341  'mycompany_socialobject' => $mysoc->socialobject,
342  'mycompany_note_private' => $mysoc->note_private,
343  //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
344  );
345  }
346 
347 
348  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
358  public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
359  {
360  // phpcs:enable
361  global $extrafields;
362 
363  if (empty($object->country) && !empty($object->country_code)) {
364  $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
365  }
366  if (empty($object->state) && !empty($object->state_code)) {
367  $object->state = getState($object->state_code, 0);
368  }
369 
370  $array_thirdparty = array(
371  'company_name' => $object->name,
372  'company_name_alias' => $object->name_alias,
373  'company_email' => $object->email,
374  'company_phone' => $object->phone,
375  'company_fax' => $object->fax,
376  'company_address' => $object->address,
377  'company_zip' => $object->zip,
378  'company_town' => $object->town,
379  'company_country' => $object->country,
380  'company_country_code' => $object->country_code,
381  'company_state' => $object->state,
382  'company_state_code' => $object->state_code,
383  'company_web' => $object->url,
384  'company_barcode' => $object->barcode,
385  'company_vatnumber' => $object->tva_intra,
386  'company_customercode' => $object->code_client,
387  'company_suppliercode' => $object->code_fournisseur,
388  'company_customeraccountancycode' => $object->code_compta,
389  'company_supplieraccountancycode' => $object->code_compta_fournisseur,
390  'company_juridicalstatus' => $object->forme_juridique,
391  'company_outstanding_limit' => $object->outstanding_limit,
392  'company_capital' => $object->capital,
393  'company_capital_formated'=> price($object->capital, 0, '', 1, -1),
394  'company_idprof1' => $object->idprof1,
395  'company_idprof2' => $object->idprof2,
396  'company_idprof3' => $object->idprof3,
397  'company_idprof4' => $object->idprof4,
398  'company_idprof5' => $object->idprof5,
399  'company_idprof6' => $object->idprof6,
400  'company_note_public' => $object->note_public,
401  'company_note_private' => $object->note_private,
402  'company_default_bank_iban' => (is_object($object->bank_account) ? $object->bank_account->iban : ''),
403  'company_default_bank_bic' => (is_object($object->bank_account) ? $object->bank_account->bic : '')
404  );
405 
406  // Retrieve extrafields
407  if (is_array($object->array_options) && count($object->array_options)) {
408  $object->fetch_optionals();
409 
410  $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
411  }
412  return $array_thirdparty;
413  }
414 
415  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
424  public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
425  {
426  // phpcs:enable
427  global $conf, $extrafields;
428 
429  if (empty($object->country) && !empty($object->country_code)) {
430  $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
431  }
432  if (empty($object->state) && !empty($object->state_code)) {
433  $object->state = getState($object->state_code, 0);
434  }
435 
436  $array_contact = array(
437  $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
438  $array_key.'_lastname' => $object->lastname,
439  $array_key.'_firstname' => $object->firstname,
440  $array_key.'_address' => $object->address,
441  $array_key.'_zip' => $object->zip,
442  $array_key.'_town' => $object->town,
443  $array_key.'_state_id' => $object->state_id,
444  $array_key.'_state_code' => $object->state_code,
445  $array_key.'_state' => $object->state,
446  $array_key.'_country_id' => $object->country_id,
447  $array_key.'_country_code' => $object->country_code,
448  $array_key.'_country' => $object->country,
449  $array_key.'_poste' => $object->poste,
450  $array_key.'_socid' => $object->socid,
451  $array_key.'_statut' => $object->statut,
452  $array_key.'_code' => $object->code,
453  $array_key.'_email' => $object->email,
454  $array_key.'_phone_pro' => $object->phone_pro,
455  $array_key.'_phone_perso' => $object->phone_perso,
456  $array_key.'_phone_mobile' => $object->phone_mobile,
457  $array_key.'_fax' => $object->fax,
458  $array_key.'_birthday' => $object->birthday,
459  $array_key.'_default_lang' => $object->default_lang,
460  $array_key.'_note_public' => $object->note_public,
461  $array_key.'_note_private' => $object->note_private,
462  $array_key.'_civility' => $object->civility,
463  );
464 
465  // Retrieve extrafields
466  if (is_array($object->array_options) && count($object->array_options)) {
467  $object->fetch_optionals();
468 
469  $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
470  }
471  return $array_contact;
472  }
473 
474 
475  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
482  public function get_substitutionarray_other($outputlangs)
483  {
484  // phpcs:enable
485  global $conf;
486 
487  $now = dol_now('gmt'); // gmt
488  $array_other = array(
489  // Date in default language
490  'current_date' => dol_print_date($now, 'day', 'tzuser'),
491  'current_datehour' => dol_print_date($now, 'dayhour', 'tzuser'),
492  'current_server_date' => dol_print_date($now, 'day', 'tzserver'),
493  'current_server_datehour' => dol_print_date($now, 'dayhour', 'tzserver'),
494  // Date in requested output language
495  'current_date_locale' => dol_print_date($now, 'day', 'tzuser', $outputlangs),
496  'current_datehour_locale' => dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
497  'current_server_date_locale' => dol_print_date($now, 'day', 'tzserver', $outputlangs),
498  'current_server_datehour_locale' => dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
499  );
500 
501 
502  foreach ($conf->global as $key => $val) {
503  if (isASecretKey($key)) {
504  $newval = '*****forbidden*****';
505  } else {
506  $newval = $val;
507  }
508  $array_other['__['.$key.']__'] = $newval;
509  }
510 
511  return $array_other;
512  }
513 
514 
515  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
525  public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
526  {
527  // phpcs:enable
528  global $extrafields;
529 
530  $sumpayed = $sumdeposit = $sumcreditnote = '';
531  $already_payed_all = 0;
532 
533  if ($object->element == 'facture') {
535  $invoice_source = new Facture($this->db);
536  if ($object->fk_facture_source > 0) {
537  $invoice_source->fetch($object->fk_facture_source);
538  }
539  $sumpayed = $object->getSommePaiement();
540  $sumdeposit = $object->getSumDepositsUsed();
541  $sumcreditnote = $object->getSumCreditNotesUsed();
542  $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
543  }
544 
545  $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
546 
547  if (get_class($object) == 'CommandeFournisseur') {
549  $object->date_validation = $object->date_valid;
550  $object->date_commande = $object->date;
551  }
552  $resarray = array(
553  $array_key.'_id' => $object->id,
554  $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
555  $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
556  $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
557  $array_key.'_ref_customer' => (!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
558  $array_key.'_ref_supplier' => (!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
559  $array_key.'_source_invoice_ref' => ((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
560  // Dates
561  $array_key.'_hour' => dol_print_date($date, 'hour'),
562  $array_key.'_date' => dol_print_date($date, 'day'),
563  $array_key.'_date_rfc' => dol_print_date($date, 'dayrfc'),
564  $array_key.'_date_limit' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
565  $array_key.'_date_limit_rfc' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
566  $array_key.'_date_end' => (!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''),
567  $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
568  $array_key.'_date_modification' => (!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
569  $array_key.'_date_validation' => (!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
570  $array_key.'_date_approve' => (!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
571  $array_key.'_date_delivery_planed' => (!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
572  $array_key.'_date_close' => (!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
573 
574  $array_key.'_payment_mode_code' => $object->mode_reglement_code,
575  $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),
576  $array_key.'_payment_term_code' => $object->cond_reglement_code,
577  $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)),
578 
579  $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
580 
581  $array_key.'_total_ht_locale' => price($object->total_ht, 0, $outputlangs),
582  $array_key.'_total_vat_locale' => (!empty($object->total_vat) ? price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
583  $array_key.'_total_localtax1_locale' => price($object->total_localtax1, 0, $outputlangs),
584  $array_key.'_total_localtax2_locale' => price($object->total_localtax2, 0, $outputlangs),
585  $array_key.'_total_ttc_locale' => price($object->total_ttc, 0, $outputlangs),
586 
587  $array_key.'_total_ht' => price2num($object->total_ht),
588  $array_key.'_total_vat' => (!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)),
589  $array_key.'_total_localtax1' => price2num($object->total_localtax1),
590  $array_key.'_total_localtax2' => price2num($object->total_localtax2),
591  $array_key.'_total_ttc' => price2num($object->total_ttc),
592 
593  $array_key.'_multicurrency_code' => $object->multicurrency_code,
594  $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
595  $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
596  $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
597  $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
598  $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
599  $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
600  $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
601 
602  $array_key.'_note_private' => $object->note_private,
603  $array_key.'_note_public' => $object->note_public,
604  $array_key.'_note' => $object->note_public, // For backward compatibility
605 
606  // Payments
607  $array_key.'_already_payed_locale' => price($sumpayed, 0, $outputlangs),
608  $array_key.'_already_payed' => price2num($sumpayed),
609  $array_key.'_already_deposit_locale' => price($sumdeposit, 0, $outputlangs),
610  $array_key.'_already_deposit' => price2num($sumdeposit),
611  $array_key.'_already_creditnote_locale' => price($sumcreditnote, 0, $outputlangs),
612  $array_key.'_already_creditnote' => price2num($sumcreditnote),
613 
614  $array_key.'_already_payed_all_locale' => price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
615  $array_key.'_already_payed_all' => price2num($already_payed_all, 'MT'),
616 
617  // Remain to pay with all known information (except open direct debit requests)
618  $array_key.'_remain_to_pay_locale' => price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
619  $array_key.'_remain_to_pay' => price2num($object->total_ttc - $already_payed_all, 'MT')
620  );
621 
622  if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur'))) {
623  $bank_account = null;
624 
625  if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
626  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
627  $bank_account = new Account($this->db);
628  $bank_account->fetch($object->fk_account);
629  }
630 
631  $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
632  $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
633  $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
634  $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
635  $resarray[$array_key.'_bank_proprio'] = (empty($bank_account) ? '' : $bank_account->proprio);
636  $resarray[$array_key.'_bank_address'] = (empty($bank_account) ? '' : $bank_account->address);
637  $resarray[$array_key.'_bank_state'] = (empty($bank_account) ? '' : $bank_account->state);
638  $resarray[$array_key.'_bank_country'] = (empty($bank_account) ? '' : $bank_account->country);
639  }
640 
641  if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
642  $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
643  $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
644  } else {
645  $resarray[$array_key.'_total_discount_ht_locale'] = '';
646  $resarray[$array_key.'_total_discount_ht'] = '';
647  }
648 
649  // Fetch project information if there is a project assigned to this object
650  if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
651  if (!is_object($object->project)) {
652  $object->fetch_projet();
653  }
654 
655  $resarray[$array_key.'_project_ref'] = $object->project->ref;
656  $resarray[$array_key.'_project_title'] = $object->project->title;
657  $resarray[$array_key.'_project_description'] = $object->project->description;
658  $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
659  $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
660  } else { // empty replacement
661  $resarray[$array_key.'_project_ref'] = '';
662  $resarray[$array_key.'_project_title'] = '';
663  $resarray[$array_key.'_project_description'] = '';
664  $resarray[$array_key.'_project_date_start'] = '';
665  $resarray[$array_key.'_project_date_end'] = '';
666  }
667 
668  // Add vat by rates
669  if (is_array($object->lines) && count($object->lines) > 0) {
670  $totalUp = 0;
671  // Set substitution keys for different VAT rates
672  foreach ($object->lines as $line) {
673  // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
674  if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
675  $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
676  }
677  $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
678  $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
679  // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
680  $vatformated = vatrate($line->tva_tx);
681  if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
682  $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
683  }
684  $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
685  $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
686 
687  $totalUp += $line->subprice * $line->qty;
688  }
689 
690  // Calculate total up and total discount percentage
691  // 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)
692  $resarray['object_total_up'] = $totalUp;
693  $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
694  if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
695  $totalDiscount = $object->getTotalDiscount();
696  } else {
697  $totalDiscount = 0;
698  }
699  if (!empty($totalUp) && !empty($totalDiscount)) {
700  $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
701  $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
702  } else {
703  $resarray['object_total_discount'] = '';
704  $resarray['object_total_discount_locale'] = '';
705  }
706  }
707 
708  // Retrieve extrafields
709  if (is_array($object->array_options) && count($object->array_options)) {
710  $object->fetch_optionals();
711 
712  $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
713  }
714 
715  return $resarray;
716  }
717 
718  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
728  public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
729  {
730  // phpcs:enable
731  $resarray = array(
732  'line_pos' => $linenumber,
733  'line_fulldesc' => doc_getlinedesc($line, $outputlangs),
734 
735  'line_product_ref' => (empty($line->product_ref) ? '' : $line->product_ref),
736  'line_product_ref_fourn' => (empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
737  'line_product_label' => (empty($line->product_label) ? '' : $line->product_label),
738  'line_product_type' => (empty($line->product_type) ? '' : $line->product_type),
739  'line_product_barcode' => (empty($line->product_barcode) ? '' : $line->product_barcode),
740  'line_product_desc' => (empty($line->product_desc) ? '' : $line->product_desc),
741 
742  'line_desc' => $line->desc,
743  'line_vatrate' => vatrate($line->tva_tx, true, $line->info_bits),
744  'line_localtax1_rate' => vatrate($line->localtax1_tx),
745  'line_localtax2_rate' => vatrate($line->localtax1_tx),
746  'line_up' => price2num($line->subprice),
747  'line_up_locale' => price($line->subprice, 0, $outputlangs),
748  'line_total_up' => price2num($line->subprice * (float) $line->qty),
749  'line_total_up_locale' => price($line->subprice * (float) $line->qty, 0, $outputlangs),
750  'line_qty' => $line->qty,
751  'line_discount_percent' => ($line->remise_percent ? $line->remise_percent.'%' : ''),
752  'line_price_ht' => price2num($line->total_ht),
753  'line_price_ttc' => price2num($line->total_ttc),
754  'line_price_vat' => price2num($line->total_tva),
755  'line_price_ht_locale' => price($line->total_ht, 0, $outputlangs),
756  'line_price_ttc_locale' => price($line->total_ttc, 0, $outputlangs),
757  'line_price_vat_locale' => price($line->total_tva, 0, $outputlangs),
758  // Dates
759  'line_date_start' => dol_print_date($line->date_start, 'day'),
760  'line_date_start_locale' => dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
761  'line_date_start_rfc' => dol_print_date($line->date_start, 'dayrfc'),
762  'line_date_end' => dol_print_date($line->date_end, 'day'),
763  'line_date_end_locale' => dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
764  'line_date_end_rfc' => dol_print_date($line->date_end, 'dayrfc'),
765 
766  'line_multicurrency_code' => price2num($line->multicurrency_code),
767  'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
768  'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
769  'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
770  'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
771  'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
772  'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
773  'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
774  'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
775  );
776 
777  // Units
778  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
779  $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
780  $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
781  }
782 
783  // Retrieve extrafields
784  $extrafieldkey = $line->table_element;
785  $array_key = "line";
786  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
787  $extrafields = new ExtraFields($this->db);
788  $extrafields->fetch_name_optionals_label($extrafieldkey, true);
789  $line->fetch_optionals();
790 
791  $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
792 
793  // Check if the current line belongs to a supplier order
794  if (get_class($line) == 'CommandeFournisseurLigne') {
795  // Add the product supplier extrafields to the substitutions
796  $extrafields->fetch_name_optionals_label("product_fournisseur_price");
797  $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
798 
799  if (!empty($extralabels) && is_array($extralabels)) {
800  $columns = "";
801 
802  foreach ($extralabels as $key => $label) {
803  $columns .= "$key, ";
804  }
805 
806  if ($columns != "") {
807  $columns = substr($columns, 0, strlen($columns) - 2);
808  $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)."'");
809 
810  if ($this->db->num_rows($resql) > 0) {
811  $resql = $this->db->fetch_object($resql);
812 
813  foreach ($extralabels as $key => $label) {
814  $resarray['line_product_supplier_'.$key] = $resql->$key;
815  }
816  }
817  }
818  }
819  }
820 
821  // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
822  if (isset($line->fk_product) && $line->fk_product > 0) {
823  $tmpproduct = new Product($this->db);
824  $result = $tmpproduct->fetch($line->fk_product);
825  if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
826  foreach ($tmpproduct->array_options as $key => $label) {
827  $resarray["line_product_".$key] = $label;
828  }
829  }
830  } else {
831  // Set unused placeholders as blank
832  $extrafields->fetch_name_optionals_label("product");
833  if ($extrafields->attributes["product"]['count'] > 0) {
834  $extralabels = $extrafields->attributes["product"]['label'];
835 
836  foreach ($extralabels as $key => $label) {
837  $resarray['line_product_options_'.$key] = '';
838  }
839  }
840  }
841 
842  return $resarray;
843  }
844 
845  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
855  public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
856  {
857  // phpcs:enable
858  global $extrafields;
859 
860  include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
861 
862  $object->list_delivery_methods($object->shipping_method_id);
863  $calculatedVolume = ((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth);
864 
865  $array_shipment = array(
866  $array_key.'_id' => $object->id,
867  $array_key.'_ref' => $object->ref,
868  $array_key.'_ref_ext' => $object->ref_ext,
869  $array_key.'_ref_customer' => $object->ref_customer,
870  $array_key.'_date_delivery' => dol_print_date($object->date_delivery, 'day'),
871  $array_key.'_hour_delivery' => dol_print_date($object->date_delivery, 'hour'),
872  $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
873  $array_key.'_total_ht' => price($object->total_ht),
874  $array_key.'_total_vat' => price($object->total_tva),
875  $array_key.'_total_ttc' => price($object->total_ttc),
876  $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
877  $array_key.'_note_private' => $object->note_private,
878  $array_key.'_note' => $object->note_public,
879  $array_key.'_tracking_number' => $object->tracking_number,
880  $array_key.'_tracking_url' => $object->tracking_url,
881  $array_key.'_shipping_method' => $object->listmeths[0]['libelle'],
882  $array_key.'_weight' => $object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
883  $array_key.'_width' => $object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
884  $array_key.'_height' => $object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
885  $array_key.'_depth' => $object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
886  $array_key.'_size' => $calculatedVolume.' '.measuringUnitString(0, 'volume'),
887  );
888 
889  // Add vat by rates
890  foreach ($object->lines as $line) {
891  if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
892  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
893  }
894  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
895  }
896 
897  // Retrieve extrafields
898  if (is_array($object->array_options) && count($object->array_options)) {
899  $object->fetch_optionals();
900 
901  $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
902  }
903 
904  // Add info from $object->xxx where xxx has been loaded by fetch_origin() of shipment
905  if (!empty($object->commande) && is_object($object->commande)) {
906  $array_shipment['order_ref'] = $object->commande->ref;
907  $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
908  }
909 
910  return $array_shipment;
911  }
912 
913 
914  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
923  public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
924  {
925  // phpcs:enable
926  $array_other = array();
927  if (!empty($object)) {
928  foreach ($object as $key => $value) {
929  if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
930  continue;
931  }
932  if (!empty($value)) {
933  if (!is_array($value) && !is_object($value)) {
934  $array_other['object_'.$key] = $value;
935  } elseif (is_array($value) && $recursive) {
936  $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
937  if (!empty($tmparray) && is_array($tmparray)) {
938  foreach ($tmparray as $key2 => $value2) {
939  $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
940  }
941  }
942  } elseif (is_object($value) && $recursive) {
943  $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
944  if (!empty($tmparray) && is_array($tmparray)) {
945  foreach ($tmparray as $key2 => $value2) {
946  $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
947  }
948  }
949  }
950  }
951  }
952  }
953 
954  return $array_other;
955  }
956 
957 
958  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
970  public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
971  {
972  // phpcs:enable
973  global $conf;
974 
975  if ($extrafields->attributes[$object->table_element]['count'] > 0) {
976  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
977  $formatedarrayoption = $object->array_options;
978 
979  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
980  $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
981  $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
982  //Add value to store price with currency
983  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
984  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
985  $valueofselectkey = $formatedarrayoption['options_'.$key];
986  if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
987  $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
988  } else {
989  $formatedarrayoption['options_'.$key] = '';
990  }
991  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
992  $valArray = explode(',', $formatedarrayoption['options_'.$key]);
993  $output = array();
994  foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
995  if (in_array($keyopt, $valArray)) {
996  $output[] = $valopt;
997  }
998  }
999  $formatedarrayoption['options_'.$key] = implode(', ', $output);
1000  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
1001  if (strlen($formatedarrayoption['options_'.$key]) > 0) {
1002  $date = $formatedarrayoption['options_'.$key];
1003  $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
1004  $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
1005  $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
1006  } else {
1007  $formatedarrayoption['options_'.$key] = '';
1008  $formatedarrayoption['options_'.$key.'_locale'] = '';
1009  $formatedarrayoption['options_'.$key.'_rfc'] = '';
1010  }
1011  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1012  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1013  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1014  $datetime = $formatedarrayoption['options_'.$key];
1015  $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1016  $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1017  $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1018  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1019  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1020  } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1021  $id = $formatedarrayoption['options_'.$key];
1022  if ($id != "") {
1023  $param = $extrafields->attributes[$object->table_element]['param'][$key];
1024  $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1025  $InfoFieldList = explode(":", $param_list[0]);
1026  $classname = $InfoFieldList[0];
1027  $classpath = $InfoFieldList[1];
1028  if (!empty($classpath)) {
1029  dol_include_once($InfoFieldList[1]);
1030  if ($classname && class_exists($classname)) {
1031  $tmpobject = new $classname($this->db);
1032  $tmpobject->fetch($id);
1033  // completely replace the id with the linked object name
1034  $formatedarrayoption['options_'.$key] = $tmpobject->name;
1035  }
1036  }
1037  }
1038  }
1039 
1040  if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1041  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1042  } else {
1043  $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1044  }
1045  }
1046  }
1047 
1048  return $array_to_fill;
1049  }
1050 
1051 
1064  public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1065  {
1066  if (empty($hidetop) || $hidetop == -1) {
1067  $pdf->line($x, $y, $x + $l, $y);
1068  }
1069  $pdf->line($x + $l, $y, $x + $l, $y + $h);
1070  if (empty($hidebottom)) {
1071  $pdf->line($x + $l, $y + $h, $x, $y + $h);
1072  }
1073  $pdf->line($x, $y + $h, $x, $y);
1074  }
1075 
1076 
1084  public function columnSort($a, $b)
1085  {
1086  if (empty($a['rank'])) {
1087  $a['rank'] = 0;
1088  }
1089  if (empty($b['rank'])) {
1090  $b['rank'] = 0;
1091  }
1092  if ($a['rank'] == $b['rank']) {
1093  return 0;
1094  }
1095  return ($a['rank'] > $b['rank']) ? -1 : 1;
1096  }
1097 
1108  public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1109  {
1110  $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1111 
1112 
1113  // Sorting
1114  uasort($this->cols, array($this, 'columnSort'));
1115 
1116  // Positioning
1117  $curX = $this->page_largeur - $this->marge_droite; // start from right
1118 
1119  // Array width
1120  $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1121 
1122  // Count flexible column
1123  $totalDefinedColWidth = 0;
1124  $countFlexCol = 0;
1125  foreach ($this->cols as $colKey => & $colDef) {
1126  if (!$this->getColumnStatus($colKey)) {
1127  continue; // continue if disabled
1128  }
1129 
1130  if (!empty($colDef['scale'])) {
1131  // In case of column width is defined by percentage
1132  $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1133  }
1134 
1135  if (empty($colDef['width'])) {
1136  $countFlexCol++;
1137  } else {
1138  $totalDefinedColWidth += $colDef['width'];
1139  }
1140  }
1141 
1142  foreach ($this->cols as $colKey => & $colDef) {
1143  // setting empty conf with default
1144  if (!empty($colDef['title'])) {
1145  $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1146  } else {
1147  $colDef['title'] = $this->defaultTitlesFieldsStyle;
1148  }
1149 
1150  // setting empty conf with default
1151  if (!empty($colDef['content'])) {
1152  $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1153  } else {
1154  $colDef['content'] = $this->defaultContentsFieldsStyle;
1155  }
1156 
1157  if ($this->getColumnStatus($colKey)) {
1158  // In case of flexible column
1159  if (empty($colDef['width'])) {
1160  $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1161  }
1162 
1163  // Set positions
1164  $lastX = $curX;
1165  $curX = $lastX - $colDef['width'];
1166  $colDef['xStartPos'] = $curX;
1167  $colDef['xEndPos'] = $lastX;
1168  }
1169  }
1170  }
1171 
1178  public function getColumnContentWidth($colKey)
1179  {
1180  $colDef = $this->cols[$colKey];
1181  return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1182  }
1183 
1184 
1191  public function getColumnContentXStart($colKey)
1192  {
1193  $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1194  return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1195  }
1196 
1203  public function getColumnRank($colKey)
1204  {
1205  if (!isset($this->cols[$colKey]['rank'])) {
1206  return -1;
1207  }
1208  return $this->cols[$colKey]['rank'];
1209  }
1210 
1220  public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1221  {
1222  // prepare wanted rank
1223  $rank = -1;
1224 
1225  // try to get rank from target column
1226  if (!empty($targetCol)) {
1227  $rank = $this->getColumnRank($targetCol);
1228  if ($rank >= 0 && $insertAfterTarget) {
1229  $rank++;
1230  }
1231  }
1232 
1233  // get rank from new column definition
1234  if ($rank < 0 && !empty($defArray['rank'])) {
1235  $rank = $defArray['rank'];
1236  }
1237 
1238  // error: no rank
1239  if ($rank < 0) {
1240  return -1;
1241  }
1242 
1243  foreach ($this->cols as $colKey => & $colDef) {
1244  if ($rank <= $colDef['rank']) {
1245  $colDef['rank'] = $colDef['rank'] + 1;
1246  }
1247  }
1248 
1249  $defArray['rank'] = $rank;
1250  $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1251 
1252  return $rank;
1253  }
1254 
1255 
1265  public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1266  {
1267  global $hookmanager;
1268 
1269  $parameters = array(
1270  'curY' => &$curY,
1271  'columnText' => $columnText,
1272  'colKey' => $colKey,
1273  'pdf' => &$pdf,
1274  );
1275  $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1276  if ($reshook < 0) {
1277  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1278  }
1279  if (!$reshook) {
1280  if (empty($columnText)) {
1281  return 0;
1282  }
1283  $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
1284  $colDef = $this->cols[$colKey];
1285  // save current cell padding
1286  $curentCellPaddinds = $pdf->getCellPaddings();
1287  // set cell padding with column content definition
1288  $pdf->setCellPaddings(isset($colDef['content']['padding'][3]) ? $colDef['content']['padding'][3] : 0, isset($colDef['content']['padding'][0]) ? $colDef['content']['padding'][0] : 0, isset($colDef['content']['padding'][1]) ? $colDef['content']['padding'][1] : 0, isset($colDef['content']['padding'][2]) ? $colDef['content']['padding'][2] : 0);
1289  $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1290 
1291  // restore cell padding
1292  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1293  }
1294 
1295  return 0;
1296  }
1297 
1298 
1313  public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1314  {
1315  // load desc col params
1316  $colDef = $this->cols[$colKey];
1317  // save current cell padding
1318  $curentCellPaddinds = $pdf->getCellPaddings();
1319  // set cell padding with column content definition
1320  $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1321 
1322  // line description
1323  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline, empty($colDef['content']['align']) ? 'J' : $colDef['content']['align']);
1324  $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1325 
1326  // restore cell padding
1327  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1328 
1329  // Display extrafield if needed
1330  $params = array(
1331  'display' => 'list',
1332  'printableEnable' => array(3),
1333  'printableEnableNotEmpty' => array(4)
1334  );
1335  $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1336  if (!empty($extrafieldDesc)) {
1337  $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1338  }
1339  }
1340 
1350  public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1351  {
1352  global $hookmanager;
1353 
1354  if (empty($object->table_element)) {
1355  return '';
1356  }
1357 
1358  $extrafieldsKeyPrefix = "options_";
1359 
1360  // Cleanup extrafield key to remove prefix if present
1361  $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1362  if ($pos === 0) {
1363  $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1364  }
1365 
1366  $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1367 
1368 
1369  // Load extra fields if they haven't been loaded already.
1370  if (empty($this->extrafieldsCache)) {
1371  $this->extrafieldsCache = new ExtraFields($this->db);
1372  }
1373  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1374  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1375  }
1376  $extrafields = $this->extrafieldsCache;
1377 
1378  $extrafieldOutputContent = '';
1379  if (isset($object->array_options[$extrafieldOptionsKey])) {
1380  $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1381  }
1382 
1383  // 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 ...
1384  if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1385  // for lack of anything better we cleanup all html tags
1386  $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1387  }
1388 
1389  $parameters = array(
1390  'object' => $object,
1391  'extrafields' => $extrafields,
1392  'extrafieldKey' => $extrafieldKey,
1393  'extrafieldOutputContent' => & $extrafieldOutputContent
1394  );
1395  $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1396  if ($reshook < 0) {
1397  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1398  }
1399  if ($reshook) {
1400  $extrafieldOutputContent = $hookmanager->resPrint;
1401  }
1402 
1403  return $extrafieldOutputContent;
1404  }
1405 
1406 
1415  public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1416  {
1417  global $hookmanager;
1418 
1419  if (empty($object->table_element)) {
1420  return "";
1421  }
1422 
1423  // Load extrafields if not already done
1424  if (empty($this->extrafieldsCache)) {
1425  $this->extrafieldsCache = new ExtraFields($this->db);
1426  }
1427  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1428  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1429  }
1430  $extrafields = $this->extrafieldsCache;
1431 
1432  $defaultParams = array(
1433  'style' => '',
1434  'display' => 'auto', // auto, table, list
1435  'printableEnable' => array(1),
1436  'printableEnableNotEmpty' => array(2),
1437 
1438  'table' => array(
1439  'maxItemsInRow' => 2,
1440  'cellspacing' => 0,
1441  'cellpadding' => 0,
1442  'border' => 0,
1443  'labelcolwidth' => '25%',
1444  'arrayOfLineBreakType' => array('text', 'html')
1445  ),
1446 
1447  'list' => array(
1448  'separator' => '<br>'
1449  ),
1450 
1451  'auto' => array(
1452  'list' => 0, // 0 for default
1453  'table' => 4 // if there more than x extrafield to display
1454  ),
1455  );
1456 
1457  $params = $params + $defaultParams;
1458 
1463  $html = '';
1464  $fields = array();
1465 
1466  if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1467  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1468  // Enable extrafield ?
1469  $enabled = 0;
1470  $disableOnEmpty = 0;
1471  if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1472  $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1473  if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1474  $enabled = 1;
1475  }
1476 
1477  if (in_array($printable, $params['printableEnableNotEmpty'])) {
1478  $disableOnEmpty = 1;
1479  }
1480  }
1481 
1482  if (empty($enabled)) {
1483  continue;
1484  }
1485 
1486  $field = new stdClass();
1487  $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1488  $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1489  $field->label = $outputlangs->transnoentities($label);
1490  $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1491 
1492  // don't display if empty
1493  if ($disableOnEmpty && empty($field->content)) {
1494  continue;
1495  }
1496 
1497  $fields[] = $field;
1498  }
1499  }
1500 
1501  if (!empty($fields)) {
1502  // Sort extrafields by rank
1503  uasort(
1504  $fields,
1510  static function ($a, $b) {
1511  return ($a->rank > $b->rank) ? 1 : -1;
1512  }
1513  );
1514 
1515  // define some HTML content with style
1516  $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1517 
1518  // auto select display format
1519  if ($params['display'] == 'auto') {
1520  $lastNnumbItems = 0;
1521  foreach ($params['auto'] as $display => $numbItems) {
1522  if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1523  $lastNnumbItems = $numbItems;
1524  $params['display'] = $display;
1525  }
1526  }
1527  }
1528 
1529  if ($params['display'] == 'list') {
1530  // Display in list format
1531  $i = 0;
1532  foreach ($fields as $field) {
1533  $html .= !empty($i) ? $params['list']['separator'] : '';
1534  $html .= '<strong>'.$field->label.' : </strong>';
1535  $html .= $field->content;
1536  $i++;
1537  }
1538  } elseif ($params['display'] == 'table') {
1539  // Display in table format
1540  $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1541 
1542  $html .= "<tr>";
1543  $itemsInRow = 0;
1544  $maxItemsInRow = $params['table']['maxItemsInRow'];
1545  foreach ($fields as $field) {
1546  //$html.= !empty($html)?'<br>':'';
1547  if ($itemsInRow >= $maxItemsInRow) {
1548  // start a new line
1549  $html .= "</tr><tr>";
1550  $itemsInRow = 0;
1551  }
1552 
1553  // for some type we need line break
1554  if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1555  if ($itemsInRow > 0) {
1556  // close table row and empty cols
1557  for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1558  $html .= "<td></td><td></td>";
1559  }
1560  $html .= "</tr>";
1561 
1562  // start a new line
1563  $html .= "<tr>";
1564  }
1565 
1566  $itemsInRow = $maxItemsInRow;
1567  $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1568  $html .= '<strong>'.$field->label.' :</strong> ';
1569  $html .= $field->content;
1570  $html .= "</td>";
1571  } else {
1572  $itemsInRow++;
1573  $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1574  $html .= '<strong>'.$field->label.' :</strong>';
1575  $html .= "</td>";
1576 
1577 
1578  $html .= '<td class="extrafield-content">';
1579  $html .= $field->content;
1580  $html .= "</td>";
1581  }
1582  }
1583  $html .= "</tr>";
1584 
1585  $html .= '</table>';
1586  }
1587  }
1588 
1589  return $html;
1590  }
1591 
1592 
1599  public function getColumnStatus($colKey)
1600  {
1601  if (!empty($this->cols[$colKey]['status'])) {
1602  return true;
1603  } else {
1604  return false;
1605  }
1606  }
1607 
1618  public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1619  {
1620  global $hookmanager, $conf;
1621 
1622  foreach ($this->cols as $colKey => $colDef) {
1623  $parameters = array(
1624  'colKey' => $colKey,
1625  'pdf' => $pdf,
1626  'outputlangs' => $outputlangs,
1627  'tab_top' => $tab_top,
1628  'tab_height' => $tab_height,
1629  'hidetop' => $hidetop
1630  );
1631 
1632  $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1633  if ($reshook < 0) {
1634  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1635  } elseif (empty($reshook)) {
1636  if (!$this->getColumnStatus($colKey)) {
1637  continue;
1638  }
1639 
1640  // get title label
1641  $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1642 
1643  // Add column separator
1644  if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
1645  $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1646  }
1647 
1648  if (empty($hidetop)) {
1649  // save current cell padding
1650  $curentCellPaddinds = $pdf->getCellPaddings();
1651 
1652  // Add space for lines (more if we need to show a second alternative language)
1653  global $outputlangsbis;
1654  if (is_object($outputlangsbis)) {
1655  // set cell padding with column title definition
1656  $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1657  } else {
1658  // set cell padding with column title definition
1659  $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1660  }
1661  if (isset($colDef['title']['align'])) {
1662  $align = $colDef['title']['align'];
1663  } else {
1664  $align = '';
1665  }
1666  $pdf->SetXY($colDef['xStartPos'], $tab_top);
1667  $textWidth = $colDef['width'];
1668  $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
1669 
1670  // Add variant of translation if $outputlangsbis is an object
1671  if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1672  $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1673  $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1674  $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1675  $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
1676  }
1677 
1678  $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1679 
1680  // restore cell padding
1681  $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1682  }
1683  }
1684  }
1685 
1686  return $this->tabTitleHeight;
1687  }
1688 
1689 
1690 
1699  public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1700  {
1701  if (!empty($hidedetails)) {
1702  return 0;
1703  }
1704 
1705  if (empty($object->table_element)) {
1706  return 0;
1707  }
1708 
1709  // Load extra fields if they haven't been loaded already.
1710  if (empty($this->extrafieldsCache)) {
1711  $this->extrafieldsCache = new ExtraFields($this->db);
1712  }
1713  if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1714  $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1715  }
1716  $extrafields = $this->extrafieldsCache;
1717 
1718 
1719  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'])) {
1720  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1721  // Don't display separator yet even is set to be displayed (not compatible yet)
1722  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1723  continue;
1724  }
1725 
1726  // Enable extrafield ?
1727  $enabled = 0;
1728  if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1729  $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1730  if ($printable === 1 || $printable === 2) {
1731  $enabled = 1;
1732  }
1733  // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1734  }
1735 
1736  if (!$enabled) {
1737  continue;
1738  } // don't waste resources if we don't need them...
1739 
1740  // Load language if required
1741  if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1742  $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1743  }
1744 
1745  // TODO : add more extrafield customisation capacities for PDF like width, rank...
1746 
1747  // set column definition
1748  $def = array(
1749  'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1750  'width' => 25, // in mm
1751  'status' => (bool) $enabled,
1752  'title' => array(
1753  'label' => $outputlangs->transnoentities($label)
1754  ),
1755  'content' => array(
1756  'align' => 'C'
1757  ),
1758  'border-left' => true, // add left line separator
1759  );
1760 
1761  $alignTypeRight = array('double', 'int', 'price');
1762  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1763  $def['content']['align'] = 'R';
1764  }
1765 
1766  $alignTypeLeft = array('text', 'html');
1767  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1768  $def['content']['align'] = 'L';
1769  }
1770 
1771 
1772  // for extrafields we use rank of extrafield to place it on PDF
1773  $this->insertNewColumnDef("options_".$key, $def);
1774  }
1775  }
1776 
1777  return 1;
1778  }
1779 
1791  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1792  {
1793  // Default field style for content
1794  $this->defaultContentsFieldsStyle = array(
1795  'align' => 'R', // R,C,L
1796  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1797  );
1798 
1799  // Default field style for content
1800  $this->defaultTitlesFieldsStyle = array(
1801  'align' => 'C', // R,C,L
1802  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1803  );
1804 
1805  // Example
1806  /*
1807  $rank = 0; // do not use negative rank
1808  $this->cols['desc'] = array(
1809  'rank' => $rank,
1810  'width' => false, // only for desc
1811  'status' => true,
1812  'title' => array(
1813  'textkey' => 'Designation', // use lang key is useful in somme case with module
1814  'align' => 'L',
1815  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1816  // 'label' => ' ', // the final label
1817  'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1818  ),
1819  'content' => array(
1820  'align' => 'L',
1821  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1822  ),
1823  );
1824  */
1825  }
1826 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class to manage bank accounts.
Parent class for documents (PDF, ODT, ...) generators.
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
insertNewColumnDef($newColKey, $defArray, $targetCol='', $insertAfterTarget=false)
get column position rank from column key
getSubstitutionarrayMember($member, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive=1)
Define array with couple substitution key => substitution value.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple substitution key => substitution value.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
get_substitutionarray_contact($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
get_substitutionarray_other($outputlangs)
Define array with couple substitution key => substitution value.
columnSort($a, $b)
uasort callback function to Sort columns fields
fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
Fill array with couple extrafield key => extrafield value Note that vars into substitutions array are...
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getColumnContentWidth($colKey)
get column content width from column key
getColumnRank($colKey)
get column position rank from column key
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
get_substitutionarray_lines($line, $outputlangs, $linenumber=0)
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field into $this->cols This method must be implemented by the module that generat...
get_substitutionarray_thirdparty($object, $outputlangs, $array_key='company')
Define array with couple substitution key => substitution value For example {company_name},...
get_substitutionarray_user($user, $outputlangs)
Define array with couple substitution key => substitution value.
Class to manage standard extra fields.
Class to manage invoices.
Class to manage products or services.
getState($id, $withcode='', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
doc_getlinedesc($line, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
Return line description translated in outputlangs and encoded into UTF8.
Definition: doc.lib.php:41
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
div float
Buy price without taxes.
Definition: style.css.php:959
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition: pdf.lib.php:1425
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.