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