dolibarr 20.0.0
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 (!is_object($object)) {
365 return array();
366 }
367
368 if (empty($object->country) && !empty($object->country_code)) {
369 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
370 }
371 if (empty($object->state) && !empty($object->state_code)) {
372 $object->state = getState($object->state_code, 0);
373 }
374
375 $array_thirdparty = array(
376 'company_name' => $object->name,
377 'company_name_alias' => $object->name_alias,
378 'company_email' => $object->email,
379 'company_phone' => $object->phone,
380 'company_fax' => $object->fax,
381 'company_address' => $object->address,
382 'company_zip' => $object->zip,
383 'company_town' => $object->town,
384 'company_country' => $object->country,
385 'company_country_code' => $object->country_code,
386 'company_state' => $object->state,
387 'company_state_code' => $object->state_code,
388 'company_web' => $object->url,
389 'company_barcode' => $object->barcode,
390 'company_vatnumber' => $object->tva_intra,
391 'company_customercode' => $object->code_client,
392 'company_suppliercode' => $object->code_fournisseur,
393 'company_customeraccountancycode' => $object->code_compta_client,
394 'company_supplieraccountancycode' => $object->code_compta_fournisseur,
395 'company_juridicalstatus' => $object->forme_juridique,
396 'company_outstanding_limit' => $object->outstanding_limit,
397 'company_capital' => $object->capital,
398 'company_capital_formated'=> price($object->capital, 0, '', 1, -1),
399 'company_idprof1' => $object->idprof1,
400 'company_idprof2' => $object->idprof2,
401 'company_idprof3' => $object->idprof3,
402 'company_idprof4' => $object->idprof4,
403 'company_idprof5' => $object->idprof5,
404 'company_idprof6' => $object->idprof6,
405 'company_note_public' => $object->note_public,
406 'company_note_private' => $object->note_private,
407 'company_default_bank_iban' => (is_object($object->bank_account) ? $object->bank_account->iban : ''),
408 'company_default_bank_bic' => (is_object($object->bank_account) ? $object->bank_account->bic : '')
409 );
410
411 // Retrieve extrafields
412 if (is_array($object->array_options) && count($object->array_options)) {
413 $object->fetch_optionals();
414
415 $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
416 }
417 return $array_thirdparty;
418 }
419
420 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
429 public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
430 {
431 // phpcs:enable
432 global $conf, $extrafields;
433
434 if (empty($object->country) && !empty($object->country_code)) {
435 $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code);
436 }
437 if (empty($object->state) && !empty($object->state_code)) {
438 $object->state = getState($object->state_code, 0);
439 }
440
441 $array_contact = array(
442 $array_key.'_fullname' => $object->getFullName($outputlangs, 1),
443 $array_key.'_lastname' => $object->lastname,
444 $array_key.'_firstname' => $object->firstname,
445 $array_key.'_address' => $object->address,
446 $array_key.'_zip' => $object->zip,
447 $array_key.'_town' => $object->town,
448 $array_key.'_state_id' => $object->state_id,
449 $array_key.'_state_code' => $object->state_code,
450 $array_key.'_state' => $object->state,
451 $array_key.'_country_id' => $object->country_id,
452 $array_key.'_country_code' => $object->country_code,
453 $array_key.'_country' => $object->country,
454 $array_key.'_poste' => $object->poste,
455 $array_key.'_socid' => $object->socid,
456 $array_key.'_statut' => $object->statut,
457 $array_key.'_code' => $object->code,
458 $array_key.'_email' => $object->email,
459 $array_key.'_phone_pro' => $object->phone_pro,
460 $array_key.'_phone_perso' => $object->phone_perso,
461 $array_key.'_phone_mobile' => $object->phone_mobile,
462 $array_key.'_fax' => $object->fax,
463 $array_key.'_birthday' => $object->birthday,
464 $array_key.'_default_lang' => $object->default_lang,
465 $array_key.'_note_public' => $object->note_public,
466 $array_key.'_note_private' => $object->note_private,
467 $array_key.'_civility' => $object->civility,
468 );
469
470 // Retrieve extrafields
471 if (is_array($object->array_options) && count($object->array_options)) {
472 $object->fetch_optionals();
473
474 $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
475 }
476 return $array_contact;
477 }
478
479
480 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
487 public function get_substitutionarray_other($outputlangs)
488 {
489 // phpcs:enable
490 global $conf;
491
492 $now = dol_now('gmt'); // gmt
493 $array_other = array(
494 // Date in default language
495 'current_date' => dol_print_date($now, 'day', 'tzuser'),
496 'current_datehour' => dol_print_date($now, 'dayhour', 'tzuser'),
497 'current_server_date' => dol_print_date($now, 'day', 'tzserver'),
498 'current_server_datehour' => dol_print_date($now, 'dayhour', 'tzserver'),
499 // Date in requested output language
500 'current_date_locale' => dol_print_date($now, 'day', 'tzuser', $outputlangs),
501 'current_datehour_locale' => dol_print_date($now, 'dayhour', 'tzuser', $outputlangs),
502 'current_server_date_locale' => dol_print_date($now, 'day', 'tzserver', $outputlangs),
503 'current_server_datehour_locale' => dol_print_date($now, 'dayhour', 'tzserver', $outputlangs),
504 );
505
506
507 foreach ($conf->global as $key => $val) {
508 if (isASecretKey($key)) {
509 $newval = '*****forbidden*****';
510 } else {
511 $newval = $val;
512 }
513 $array_other['__['.$key.']__'] = $newval;
514 }
515
516 return $array_other;
517 }
518
519
520 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
530 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
531 {
532 // phpcs:enable
533 global $extrafields;
534
535 $sumpayed = $sumdeposit = $sumcreditnote = '';
536 $already_payed_all = 0;
537
538 if ($object->element == 'facture') {
540 $invoice_source = new Facture($this->db);
541 if ($object->fk_facture_source > 0) {
542 $invoice_source->fetch($object->fk_facture_source);
543 }
544 $sumpayed = $object->getSommePaiement();
545 $sumdeposit = $object->getSumDepositsUsed();
546 $sumcreditnote = $object->getSumCreditNotesUsed();
547 $already_payed_all = $sumpayed + $sumdeposit + $sumcreditnote;
548 }
549
550 $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
551
552 if (get_class($object) == 'CommandeFournisseur') {
554 $object->date_validation = $object->date_valid;
555 $object->date_commande = $object->date;
556 }
557 $resarray = array(
558 $array_key.'_id' => $object->id,
559 $array_key.'_ref' => (property_exists($object, 'ref') ? $object->ref : ''),
560 $array_key.'_label' => (property_exists($object, 'label') ? $object->label : ''),
561 $array_key.'_ref_ext' => (property_exists($object, 'ref_ext') ? $object->ref_ext : ''),
562 $array_key.'_ref_customer' => (!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
563 $array_key.'_ref_supplier' => (!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
564 $array_key.'_source_invoice_ref' => ((empty($invoice_source) || empty($invoice_source->ref)) ? '' : $invoice_source->ref),
565 // Dates
566 $array_key.'_hour' => dol_print_date($date, 'hour'),
567 $array_key.'_date' => dol_print_date($date, 'day'),
568 $array_key.'_date_rfc' => dol_print_date($date, 'dayrfc'),
569 $array_key.'_date_limit' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''),
570 $array_key.'_date_limit_rfc' => (!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''),
571 $array_key.'_date_end' => (!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''),
572 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
573 $array_key.'_date_modification' => (!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''),
574 $array_key.'_date_validation' => (!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''),
575 $array_key.'_date_approve' => (!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''),
576 $array_key.'_date_delivery_planed' => (!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''),
577 $array_key.'_date_close' => (!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''),
578
579 $array_key.'_payment_mode_code' => $object->mode_reglement_code,
580 $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),
581 $array_key.'_payment_term_code' => $object->cond_reglement_code,
582 $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)),
583
584 $array_key.'_incoterms' => (method_exists($object, 'display_incoterms') ? $object->display_incoterms() : ''),
585
586 $array_key.'_total_ht_locale' => price($object->total_ht, 0, $outputlangs),
587 $array_key.'_total_vat_locale' => (!empty($object->total_vat) ? price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)),
588 $array_key.'_total_localtax1_locale' => price($object->total_localtax1, 0, $outputlangs),
589 $array_key.'_total_localtax2_locale' => price($object->total_localtax2, 0, $outputlangs),
590 $array_key.'_total_ttc_locale' => price($object->total_ttc, 0, $outputlangs),
591
592 $array_key.'_total_ht' => price2num($object->total_ht),
593 $array_key.'_total_vat' => (!empty($object->total_vat) ? price2num($object->total_vat) : price2num($object->total_tva)),
594 $array_key.'_total_localtax1' => price2num($object->total_localtax1),
595 $array_key.'_total_localtax2' => price2num($object->total_localtax2),
596 $array_key.'_total_ttc' => price2num($object->total_ttc),
597
598 $array_key.'_multicurrency_code' => $object->multicurrency_code,
599 $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
600 $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
601 $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
602 $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
603 $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
604 $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
605 $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
606
607 $array_key.'_note_private' => $object->note_private,
608 $array_key.'_note_public' => $object->note_public,
609 $array_key.'_note' => $object->note_public, // For backward compatibility
610
611 // Payments
612 $array_key.'_already_payed_locale' => price($sumpayed, 0, $outputlangs),
613 $array_key.'_already_payed' => price2num($sumpayed),
614 $array_key.'_already_deposit_locale' => price($sumdeposit, 0, $outputlangs),
615 $array_key.'_already_deposit' => price2num($sumdeposit),
616 $array_key.'_already_creditnote_locale' => price($sumcreditnote, 0, $outputlangs),
617 $array_key.'_already_creditnote' => price2num($sumcreditnote),
618
619 $array_key.'_already_payed_all_locale' => price(price2num($already_payed_all, 'MT'), 0, $outputlangs),
620 $array_key.'_already_payed_all' => price2num($already_payed_all, 'MT'),
621
622 // Remain to pay with all known information (except open direct debit requests)
623 $array_key.'_remain_to_pay_locale' => price(price2num($object->total_ttc - $already_payed_all, 'MT'), 0, $outputlangs),
624 $array_key.'_remain_to_pay' => price2num($object->total_ttc - $already_payed_all, 'MT')
625 );
626
627 if (in_array($object->element, array('facture', 'invoice', 'supplier_invoice', 'facture_fournisseur'))) {
628 $bank_account = null;
629
630 if (property_exists($object, 'fk_account') && $object->fk_account > 0) {
631 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
632 $bank_account = new Account($this->db);
633 $bank_account->fetch($object->fk_account);
634 }
635
636 $resarray[$array_key.'_bank_iban'] = (empty($bank_account) ? '' : $bank_account->iban);
637 $resarray[$array_key.'_bank_bic'] = (empty($bank_account) ? '' : $bank_account->bic);
638 $resarray[$array_key.'_bank_label'] = (empty($bank_account) ? '' : $bank_account->label);
639 $resarray[$array_key.'_bank_number'] = (empty($bank_account) ? '' : $bank_account->number);
640 $resarray[$array_key.'_bank_proprio'] = (empty($bank_account) ? '' : $bank_account->proprio);
641 $resarray[$array_key.'_bank_address'] = (empty($bank_account) ? '' : $bank_account->address);
642 $resarray[$array_key.'_bank_state'] = (empty($bank_account) ? '' : $bank_account->state);
643 $resarray[$array_key.'_bank_country'] = (empty($bank_account) ? '' : $bank_account->country);
644 }
645
646 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
647 $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
648 $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
649 } else {
650 $resarray[$array_key.'_total_discount_ht_locale'] = '';
651 $resarray[$array_key.'_total_discount_ht'] = '';
652 }
653
654 // Fetch project information if there is a project assigned to this object
655 if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) {
656 if (!is_object($object->project)) {
657 $object->fetch_projet();
658 }
659
660 $resarray[$array_key.'_project_ref'] = $object->project->ref;
661 $resarray[$array_key.'_project_title'] = $object->project->title;
662 $resarray[$array_key.'_project_description'] = $object->project->description;
663 $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
664 $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
665 } else { // empty replacement
666 $resarray[$array_key.'_project_ref'] = '';
667 $resarray[$array_key.'_project_title'] = '';
668 $resarray[$array_key.'_project_description'] = '';
669 $resarray[$array_key.'_project_date_start'] = '';
670 $resarray[$array_key.'_project_date_end'] = '';
671 }
672
673 // Add vat by rates
674 if (is_array($object->lines) && count($object->lines) > 0) {
675 $totalUp = 0;
676 // Set substitution keys for different VAT rates
677 foreach ($object->lines as $line) {
678 // $line->tva_tx format depends on database field accuracy, no reliable. This is kept for backward compatibility
679 if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) {
680 $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0;
681 }
682 $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
683 $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
684 // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
685 $vatformated = vatrate($line->tva_tx);
686 if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) {
687 $resarray[$array_key.'_total_vat_'.$vatformated] = 0;
688 }
689 $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva;
690 $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]);
691
692 $totalUp += $line->subprice * $line->qty;
693 }
694
695 // Calculate total up and total discount percentage
696 // 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)
697 $resarray['object_total_up'] = $totalUp;
698 $resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
699 if (method_exists($object, 'getTotalDiscount') && in_array(get_class($object), array('Propal', 'Proposal', 'Commande', 'Facture', 'SupplierProposal', 'CommandeFournisseur', 'FactureFournisseur'))) {
700 $totalDiscount = $object->getTotalDiscount();
701 } else {
702 $totalDiscount = 0;
703 }
704 if (!empty($totalUp) && !empty($totalDiscount)) {
705 $resarray['object_total_discount'] = round(100 / $totalUp * $totalDiscount, 2);
706 $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
707 } else {
708 $resarray['object_total_discount'] = '';
709 $resarray['object_total_discount_locale'] = '';
710 }
711 }
712
713 // Retrieve extrafields
714 if (is_array($object->array_options) && count($object->array_options)) {
715 $object->fetch_optionals();
716
717 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
718 }
719
720 return $resarray;
721 }
722
723 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
733 public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0)
734 {
735 // phpcs:enable
736 $resarray = array(
737 'line_pos' => $linenumber,
738 'line_fulldesc' => doc_getlinedesc($line, $outputlangs),
739
740 'line_product_ref' => (empty($line->product_ref) ? '' : $line->product_ref),
741 'line_product_ref_fourn' => (empty($line->ref_fourn) ? '' : $line->ref_fourn), // for supplier doc lines
742 'line_product_label' => (empty($line->product_label) ? '' : $line->product_label),
743 'line_product_type' => (empty($line->product_type) ? '' : $line->product_type),
744 'line_product_barcode' => (empty($line->product_barcode) ? '' : $line->product_barcode),
745 'line_product_desc' => (empty($line->product_desc) ? '' : $line->product_desc),
746
747 'line_desc' => $line->desc,
748 'line_vatrate' => vatrate($line->tva_tx, true, $line->info_bits),
749 'line_localtax1_rate' => vatrate($line->localtax1_tx),
750 'line_localtax2_rate' => vatrate($line->localtax1_tx),
751 'line_up' => price2num($line->subprice),
752 'line_up_locale' => price($line->subprice, 0, $outputlangs),
753 'line_total_up' => price2num($line->subprice * (float) $line->qty),
754 'line_total_up_locale' => price($line->subprice * (float) $line->qty, 0, $outputlangs),
755 'line_qty' => $line->qty,
756 'line_discount_percent' => ($line->remise_percent ? $line->remise_percent.'%' : ''),
757 'line_price_ht' => price2num($line->total_ht),
758 'line_price_ttc' => price2num($line->total_ttc),
759 'line_price_vat' => price2num($line->total_tva),
760 'line_price_ht_locale' => price($line->total_ht, 0, $outputlangs),
761 'line_price_ttc_locale' => price($line->total_ttc, 0, $outputlangs),
762 'line_price_vat_locale' => price($line->total_tva, 0, $outputlangs),
763 // Dates
764 'line_date_start' => dol_print_date($line->date_start, 'day'),
765 'line_date_start_locale' => dol_print_date($line->date_start, 'day', 'tzserver', $outputlangs),
766 'line_date_start_rfc' => dol_print_date($line->date_start, 'dayrfc'),
767 'line_date_end' => dol_print_date($line->date_end, 'day'),
768 'line_date_end_locale' => dol_print_date($line->date_end, 'day', 'tzserver', $outputlangs),
769 'line_date_end_rfc' => dol_print_date($line->date_end, 'dayrfc'),
770
771 'line_multicurrency_code' => price2num($line->multicurrency_code),
772 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
773 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
774 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
775 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
776 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
777 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
778 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
779 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
780 );
781
782 // Units
783 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
784 $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long'));
785 $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short'));
786 }
787
788 // Retrieve extrafields
789 $extrafieldkey = $line->table_element;
790 $array_key = "line";
791 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
792 $extrafields = new ExtraFields($this->db);
793 $extrafields->fetch_name_optionals_label($extrafieldkey, true);
794 $line->fetch_optionals();
795
796 $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
797
798 // Check if the current line belongs to a supplier order
799 if (get_class($line) == 'CommandeFournisseurLigne') {
800 // Add the product supplier extrafields to the substitutions
801 $extrafields->fetch_name_optionals_label("product_fournisseur_price");
802 $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
803
804 if (!empty($extralabels) && is_array($extralabels)) {
805 $columns = "";
806
807 foreach ($extralabels as $key => $label) {
808 $columns .= "$key, ";
809 }
810
811 if ($columns != "") {
812 $columns = substr($columns, 0, strlen($columns) - 2);
813 $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)."'");
814
815 if ($this->db->num_rows($resql) > 0) {
816 $resql = $this->db->fetch_object($resql);
817
818 foreach ($extralabels as $key => $label) {
819 $resarray['line_product_supplier_'.$key] = $resql->$key;
820 }
821 }
822 }
823 }
824 }
825
826 // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
827 if (isset($line->fk_product) && $line->fk_product > 0) {
828 $tmpproduct = new Product($this->db);
829 $result = $tmpproduct->fetch($line->fk_product);
830 if (!empty($tmpproduct->array_options) && is_array($tmpproduct->array_options)) {
831 foreach ($tmpproduct->array_options as $key => $label) {
832 $resarray["line_product_".$key] = $label;
833 }
834 }
835 } else {
836 // Set unused placeholders as blank
837 $extrafields->fetch_name_optionals_label("product");
838 if ($extrafields->attributes["product"]['count'] > 0) {
839 $extralabels = $extrafields->attributes["product"]['label'];
840
841 foreach ($extralabels as $key => $label) {
842 $resarray['line_product_options_'.$key] = '';
843 }
844 }
845 }
846
847 return $resarray;
848 }
849
850 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
860 public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
861 {
862 // phpcs:enable
863 global $extrafields;
864
865 include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
866
867 $object->list_delivery_methods($object->shipping_method_id);
868 $calculatedVolume = ((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth);
869
870 $array_shipment = array(
871 $array_key.'_id' => $object->id,
872 $array_key.'_ref' => $object->ref,
873 $array_key.'_ref_ext' => $object->ref_ext,
874 $array_key.'_ref_customer' => $object->ref_customer,
875 $array_key.'_date_delivery' => dol_print_date($object->date_delivery, 'day'),
876 $array_key.'_hour_delivery' => dol_print_date($object->date_delivery, 'hour'),
877 $array_key.'_date_creation' => dol_print_date($object->date_creation, 'day'),
878 $array_key.'_total_ht' => price($object->total_ht),
879 $array_key.'_total_vat' => price($object->total_tva),
880 $array_key.'_total_ttc' => price($object->total_ttc),
881 $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
882 $array_key.'_note_private' => $object->note_private,
883 $array_key.'_note' => $object->note_public,
884 $array_key.'_tracking_number' => $object->tracking_number,
885 $array_key.'_tracking_url' => $object->tracking_url,
886 $array_key.'_shipping_method' => $object->listmeths[0]['libelle'],
887 $array_key.'_weight' => $object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
888 $array_key.'_width' => $object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
889 $array_key.'_height' => $object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
890 $array_key.'_depth' => $object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
891 $array_key.'_size' => $calculatedVolume.' '.measuringUnitString(0, 'volume'),
892 );
893
894 // Add vat by rates
895 foreach ($object->lines as $line) {
896 if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) {
897 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0;
898 }
899 $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
900 }
901
902 // Retrieve extrafields
903 if (is_array($object->array_options) && count($object->array_options)) {
904 $object->fetch_optionals();
905
906 $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
907 }
908
909 // Add info from $object->xxx where xxx has been loaded by fetch_origin() of shipment
910 if (is_object($object->commande) && !empty($object->commande->ref)) {
911 $array_shipment['order_ref'] = $object->commande->ref;
912 $array_shipment['order_ref_customer'] = $object->commande->ref_customer;
913 }
914
915 return $array_shipment;
916 }
917
918
919 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
928 public function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = 1)
929 {
930 // phpcs:enable
931 $array_other = array();
932 if (!empty($object)) {
933 foreach ($object as $key => $value) {
934 if (in_array($key, array('db', 'fields', 'lines', 'modelpdf', 'model_pdf'))) { // discard some properties
935 continue;
936 }
937 if (!empty($value)) {
938 if (!is_array($value) && !is_object($value)) {
939 $array_other['object_'.$key] = $value;
940 } elseif (is_array($value) && $recursive) {
941 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
942 if (!empty($tmparray) && is_array($tmparray)) {
943 foreach ($tmparray as $key2 => $value2) {
944 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
945 }
946 }
947 } elseif (is_object($value) && $recursive) {
948 $tmparray = $this->get_substitutionarray_each_var_object($value, $outputlangs, 0);
949 if (!empty($tmparray) && is_array($tmparray)) {
950 foreach ($tmparray as $key2 => $value2) {
951 $array_other['object_'.$key.'_'.preg_replace('/^object_/', '', $key2)] = $value2;
952 }
953 }
954 }
955 }
956 }
957 }
958
959 return $array_other;
960 }
961
962
963 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
975 public function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
976 {
977 // phpcs:enable
978 global $conf;
979
980 if ($extrafields->attributes[$object->table_element]['count'] > 0) {
981 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
982 $formatedarrayoption = $object->array_options;
983
984 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') {
985 $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]);
986 $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
987 //Add value to store price with currency
988 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency']));
989 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') {
990 $valueofselectkey = $formatedarrayoption['options_'.$key];
991 if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) {
992 $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey];
993 } else {
994 $formatedarrayoption['options_'.$key] = '';
995 }
996 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') {
997 $valArray = explode(',', $formatedarrayoption['options_'.$key]);
998 $output = array();
999 foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) {
1000 if (in_array($keyopt, $valArray)) {
1001 $output[] = $valopt;
1002 }
1003 }
1004 $formatedarrayoption['options_'.$key] = implode(', ', $output);
1005 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') {
1006 if (strlen($formatedarrayoption['options_'.$key]) > 0) {
1007 $date = $formatedarrayoption['options_'.$key];
1008 $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language
1009 $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format
1010 $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format
1011 } else {
1012 $formatedarrayoption['options_'.$key] = '';
1013 $formatedarrayoption['options_'.$key.'_locale'] = '';
1014 $formatedarrayoption['options_'.$key.'_rfc'] = '';
1015 }
1016 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1017 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1018 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') {
1019 $datetime = $formatedarrayoption['options_'.$key];
1020 $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language
1021 $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format
1022 $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format
1023 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale']));
1024 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc']));
1025 } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') {
1026 $id = $formatedarrayoption['options_'.$key];
1027 if ($id != "") {
1028 $param = $extrafields->attributes[$object->table_element]['param'][$key];
1029 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath'
1030 $InfoFieldList = explode(":", $param_list[0]);
1031 $classname = $InfoFieldList[0];
1032 $classpath = $InfoFieldList[1];
1033 if (!empty($classpath)) {
1034 dol_include_once($InfoFieldList[1]);
1035 if ($classname && class_exists($classname)) {
1036 $tmpobject = new $classname($this->db);
1037 $tmpobject->fetch($id);
1038 // completely replace the id with the linked object name
1039 $formatedarrayoption['options_'.$key] = $tmpobject->name;
1040 }
1041 }
1042 }
1043 }
1044
1045 if (array_key_exists('options_'.$key, $formatedarrayoption)) {
1046 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key]));
1047 } else {
1048 $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => ''));
1049 }
1050 }
1051 }
1052
1053 return $array_to_fill;
1054 }
1055
1056
1069 public function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
1070 {
1071 if (empty($hidetop) || $hidetop == -1) {
1072 $pdf->line($x, $y, $x + $l, $y);
1073 }
1074 $pdf->line($x + $l, $y, $x + $l, $y + $h);
1075 if (empty($hidebottom)) {
1076 $pdf->line($x + $l, $y + $h, $x, $y + $h);
1077 }
1078 $pdf->line($x, $y + $h, $x, $y);
1079 }
1080
1081
1089 public function columnSort($a, $b)
1090 {
1091 if (empty($a['rank'])) {
1092 $a['rank'] = 0;
1093 }
1094 if (empty($b['rank'])) {
1095 $b['rank'] = 0;
1096 }
1097 if ($a['rank'] == $b['rank']) {
1098 return 0;
1099 }
1100 return ($a['rank'] > $b['rank']) ? -1 : 1;
1101 }
1102
1113 public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1114 {
1115 $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
1116
1117
1118 // Sorting
1119 uasort($this->cols, array($this, 'columnSort'));
1120
1121 // Positioning
1122 $curX = $this->page_largeur - $this->marge_droite; // start from right
1123
1124 // Array width
1125 $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
1126
1127 // Count flexible column
1128 $totalDefinedColWidth = 0;
1129 $countFlexCol = 0;
1130 foreach ($this->cols as $colKey => & $colDef) {
1131 if (!$this->getColumnStatus($colKey)) {
1132 continue; // continue if disabled
1133 }
1134
1135 if (!empty($colDef['scale'])) {
1136 // In case of column width is defined by percentage
1137 $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
1138 }
1139
1140 if (empty($colDef['width'])) {
1141 $countFlexCol++;
1142 } else {
1143 $totalDefinedColWidth += $colDef['width'];
1144 }
1145 }
1146
1147 foreach ($this->cols as $colKey => & $colDef) {
1148 // setting empty conf with default
1149 if (!empty($colDef['title'])) {
1150 $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
1151 } else {
1152 $colDef['title'] = $this->defaultTitlesFieldsStyle;
1153 }
1154
1155 // setting empty conf with default
1156 if (!empty($colDef['content'])) {
1157 $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
1158 } else {
1159 $colDef['content'] = $this->defaultContentsFieldsStyle;
1160 }
1161
1162 if ($this->getColumnStatus($colKey)) {
1163 // In case of flexible column
1164 if (empty($colDef['width'])) {
1165 $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
1166 }
1167
1168 // Set positions
1169 $lastX = $curX;
1170 $curX = $lastX - $colDef['width'];
1171 $colDef['xStartPos'] = $curX;
1172 $colDef['xEndPos'] = $lastX;
1173 }
1174 }
1175 }
1176
1183 public function getColumnContentWidth($colKey)
1184 {
1185 $colDef = $this->cols[$colKey];
1186 return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
1187 }
1188
1189
1196 public function getColumnContentXStart($colKey)
1197 {
1198 $colDef = (isset($this->cols[$colKey]) ? $this->cols[$colKey] : null);
1199 return (is_array($colDef) ? ((isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0) + $colDef['content']['padding'][3]) : 0);
1200 }
1201
1208 public function getColumnRank($colKey)
1209 {
1210 if (!isset($this->cols[$colKey]['rank'])) {
1211 return -1;
1212 }
1213 return $this->cols[$colKey]['rank'];
1214 }
1215
1225 public function insertNewColumnDef($newColKey, $defArray, $targetCol = '', $insertAfterTarget = false)
1226 {
1227 // prepare wanted rank
1228 $rank = -1;
1229
1230 // try to get rank from target column
1231 if (!empty($targetCol)) {
1232 $rank = $this->getColumnRank($targetCol);
1233 if ($rank >= 0 && $insertAfterTarget) {
1234 $rank++;
1235 }
1236 }
1237
1238 // get rank from new column definition
1239 if ($rank < 0 && !empty($defArray['rank'])) {
1240 $rank = $defArray['rank'];
1241 }
1242
1243 // error: no rank
1244 if ($rank < 0) {
1245 return -1;
1246 }
1247
1248 foreach ($this->cols as $colKey => & $colDef) {
1249 if ($rank <= $colDef['rank']) {
1250 $colDef['rank'] = $colDef['rank'] + 1;
1251 }
1252 }
1253
1254 $defArray['rank'] = $rank;
1255 $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
1256
1257 return $rank;
1258 }
1259
1260
1270 public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
1271 {
1272 global $hookmanager;
1273
1274 $parameters = array(
1275 'curY' => &$curY,
1276 'columnText' => $columnText,
1277 'colKey' => $colKey,
1278 'pdf' => &$pdf,
1279 );
1280 $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1281 if ($reshook < 0) {
1282 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1283 }
1284 if (!$reshook) {
1285 if (empty($columnText)) {
1286 return 0;
1287 }
1288 $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set current position
1289 $colDef = $this->cols[$colKey];
1290 // save current cell padding
1291 $curentCellPaddinds = $pdf->getCellPaddings();
1292 // set cell padding with column content definition
1293 $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);
1294 $pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
1295
1296 // restore cell padding
1297 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1298 }
1299
1300 return 0;
1301 }
1302
1303
1318 public function printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1319 {
1320 // load desc col params
1321 $colDef = $this->cols[$colKey];
1322 // save current cell padding
1323 $curentCellPaddinds = $pdf->getCellPaddings();
1324 // set cell padding with column content definition
1325 $pdf->setCellPaddings($colDef['content']['padding'][3], $colDef['content']['padding'][0], $colDef['content']['padding'][1], $colDef['content']['padding'][2]);
1326
1327 // line description
1328 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $colDef['width'], 3, $colDef['xStartPos'], $curY, $hideref, $hidedesc, $issupplierline, empty($colDef['content']['align']) ? 'J' : $colDef['content']['align']);
1329 $posYAfterDescription = $pdf->GetY() - $colDef['content']['padding'][0];
1330
1331 // restore cell padding
1332 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1333
1334 // Display extrafield if needed
1335 $params = array(
1336 'display' => 'list',
1337 'printableEnable' => array(3),
1338 'printableEnableNotEmpty' => array(4)
1339 );
1340 $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params);
1341 if (!empty($extrafieldDesc)) {
1342 $this->printStdColumnContent($pdf, $posYAfterDescription, $colKey, $extrafieldDesc);
1343 }
1344 }
1345
1355 public function getExtrafieldContent($object, $extrafieldKey, $outputlangs = null)
1356 {
1357 global $hookmanager;
1358
1359 if (empty($object->table_element)) {
1360 return '';
1361 }
1362
1363 $extrafieldsKeyPrefix = "options_";
1364
1365 // Cleanup extrafield key to remove prefix if present
1366 $pos = strpos($extrafieldKey, $extrafieldsKeyPrefix);
1367 if ($pos === 0) {
1368 $extrafieldKey = substr($extrafieldKey, strlen($extrafieldsKeyPrefix));
1369 }
1370
1371 $extrafieldOptionsKey = $extrafieldsKeyPrefix.$extrafieldKey;
1372
1373
1374 // Load extra fields if they haven't been loaded already.
1375 if (empty($this->extrafieldsCache)) {
1376 $this->extrafieldsCache = new ExtraFields($this->db);
1377 }
1378 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1379 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1380 }
1381 $extrafields = $this->extrafieldsCache;
1382
1383 $extrafieldOutputContent = '';
1384 if (isset($object->array_options[$extrafieldOptionsKey])) {
1385 $extrafieldOutputContent = $extrafields->showOutputField($extrafieldKey, $object->array_options[$extrafieldOptionsKey], '', $object->table_element, $outputlangs);
1386 }
1387
1388 // 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 ...
1389 if ($extrafields->attributes[$object->table_element]['type'][$extrafieldKey] == 'link') {
1390 // for lack of anything better we cleanup all html tags
1391 $extrafieldOutputContent = dol_string_nohtmltag($extrafieldOutputContent);
1392 }
1393
1394 $parameters = array(
1395 'object' => $object,
1396 'extrafields' => $extrafields,
1397 'extrafieldKey' => $extrafieldKey,
1398 'extrafieldOutputContent' => & $extrafieldOutputContent
1399 );
1400 $reshook = $hookmanager->executeHooks('getPDFExtrafieldContent', $parameters, $this); // Note that $action and $object may have been modified by hook
1401 if ($reshook < 0) {
1402 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1403 }
1404 if ($reshook) {
1405 $extrafieldOutputContent = $hookmanager->resPrint;
1406 }
1407
1408 return $extrafieldOutputContent;
1409 }
1410
1411
1420 public function getExtrafieldsInHtml($object, $outputlangs, $params = array())
1421 {
1422 global $hookmanager;
1423
1424 if (empty($object->table_element)) {
1425 return "";
1426 }
1427
1428 // Load extrafields if not already done
1429 if (empty($this->extrafieldsCache)) {
1430 $this->extrafieldsCache = new ExtraFields($this->db);
1431 }
1432 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1433 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1434 }
1435 $extrafields = $this->extrafieldsCache;
1436
1437 $defaultParams = array(
1438 'style' => '',
1439 'display' => 'auto', // auto, table, list
1440 'printableEnable' => array(1),
1441 'printableEnableNotEmpty' => array(2),
1442
1443 'table' => array(
1444 'maxItemsInRow' => 2,
1445 'cellspacing' => 0,
1446 'cellpadding' => 0,
1447 'border' => 0,
1448 'labelcolwidth' => '25%',
1449 'arrayOfLineBreakType' => array('text', 'html')
1450 ),
1451
1452 'list' => array(
1453 'separator' => '<br>'
1454 ),
1455
1456 'auto' => array(
1457 'list' => 0, // 0 for default
1458 'table' => 4 // if there more than x extrafield to display
1459 ),
1460 );
1461
1462 $params = $params + $defaultParams;
1463
1468 $html = '';
1469 $fields = array();
1470
1471 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label'])) {
1472 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1473 // Enable extrafield ?
1474 $enabled = 0;
1475 $disableOnEmpty = 0;
1476 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1477 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1478 if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) {
1479 $enabled = 1;
1480 }
1481
1482 if (in_array($printable, $params['printableEnableNotEmpty'])) {
1483 $disableOnEmpty = 1;
1484 }
1485 }
1486
1487 if (empty($enabled)) {
1488 continue;
1489 }
1490
1491 // Load language if required
1492 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1493 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1494 }
1495
1496 $field = new stdClass();
1497 $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]);
1498 $field->content = $this->getExtrafieldContent($object, $key, $outputlangs);
1499 if (isset($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1500 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1501 }
1502 $field->label = $outputlangs->transnoentities($label);
1503 $field->type = $extrafields->attributes[$object->table_element]['type'][$key];
1504
1505 // don't display if empty
1506 if ($disableOnEmpty && empty($field->content)) {
1507 continue;
1508 }
1509
1510 $fields[] = $field;
1511 }
1512 }
1513
1514 if (!empty($fields)) {
1515 // Sort extrafields by rank
1516 uasort(
1517 $fields,
1523 static function ($a, $b) {
1524 return ($a->rank > $b->rank) ? 1 : -1;
1525 }
1526 );
1527
1528 // define some HTML content with style
1529 $html .= !empty($params['style']) ? '<style>'.$params['style'].'</style>' : '';
1530
1531 // auto select display format
1532 if ($params['display'] == 'auto') {
1533 $lastNnumbItems = 0;
1534 foreach ($params['auto'] as $display => $numbItems) {
1535 if ($lastNnumbItems <= $numbItems && count($fields) > $numbItems) {
1536 $lastNnumbItems = $numbItems;
1537 $params['display'] = $display;
1538 }
1539 }
1540 }
1541
1542 if ($params['display'] == 'list') {
1543 // Display in list format
1544 $i = 0;
1545 foreach ($fields as $field) {
1546 $html .= !empty($i) ? $params['list']['separator'] : '';
1547 $html .= '<strong>'.$field->label.' : </strong>';
1548 $html .= $field->content;
1549 $i++;
1550 }
1551 } elseif ($params['display'] == 'table') {
1552 // Display in table format
1553 $html .= '<table class="extrafield-table" cellspacing="'.$params['table']['cellspacing'].'" cellpadding="'.$params['table']['cellpadding'].'" border="'.$params['table']['border'].'">';
1554
1555 $html .= "<tr>";
1556 $itemsInRow = 0;
1557 $maxItemsInRow = $params['table']['maxItemsInRow'];
1558 foreach ($fields as $field) {
1559 //$html.= !empty($html)?'<br>':'';
1560 if ($itemsInRow >= $maxItemsInRow) {
1561 // start a new line
1562 $html .= "</tr><tr>";
1563 $itemsInRow = 0;
1564 }
1565
1566 // for some type we need line break
1567 if (in_array($field->type, $params['table']['arrayOfLineBreakType'])) {
1568 if ($itemsInRow > 0) {
1569 // close table row and empty cols
1570 for ($i = $itemsInRow; $i <= $maxItemsInRow; $i++) {
1571 $html .= "<td></td><td></td>";
1572 }
1573 $html .= "</tr>";
1574
1575 // start a new line
1576 $html .= "<tr>";
1577 }
1578
1579 $itemsInRow = $maxItemsInRow;
1580 $html .= '<td colspan="'.($maxItemsInRow * 2 - 1).'">';
1581 $html .= '<strong>'.$field->label.' :</strong> ';
1582 $html .= $field->content;
1583 $html .= "</td>";
1584 } else {
1585 $itemsInRow++;
1586 $html .= '<td width="'.$params['table']['labelcolwidth'].'" class="extrafield-label">';
1587 $html .= '<strong>'.$field->label.' :</strong>';
1588 $html .= "</td>";
1589
1590
1591 $html .= '<td class="extrafield-content">';
1592 $html .= $field->content;
1593 $html .= "</td>";
1594 }
1595 }
1596 $html .= "</tr>";
1597
1598 $html .= '</table>';
1599 }
1600 }
1601
1602 return $html;
1603 }
1604
1605
1612 public function getColumnStatus($colKey)
1613 {
1614 if (!empty($this->cols[$colKey]['status'])) {
1615 return true;
1616 } else {
1617 return false;
1618 }
1619 }
1620
1631 public function pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop = 0)
1632 {
1633 global $hookmanager, $conf;
1634
1635 foreach ($this->cols as $colKey => $colDef) {
1636 $parameters = array(
1637 'colKey' => $colKey,
1638 'pdf' => $pdf,
1639 'outputlangs' => $outputlangs,
1640 'tab_top' => $tab_top,
1641 'tab_height' => $tab_height,
1642 'hidetop' => $hidetop
1643 );
1644
1645 $reshook = $hookmanager->executeHooks('pdfTabTitles', $parameters, $this); // Note that $object may have been modified by hook
1646 if ($reshook < 0) {
1647 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1648 } elseif (empty($reshook)) {
1649 if (!$this->getColumnStatus($colKey)) {
1650 continue;
1651 }
1652
1653 // get title label
1654 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1655
1656 // Add column separator
1657 if (!empty($colDef['border-left']) && isset($colDef['xStartPos'])) {
1658 $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1659 }
1660
1661 if (empty($hidetop)) {
1662 // save current cell padding
1663 $curentCellPaddinds = $pdf->getCellPaddings();
1664
1665 // Add space for lines (more if we need to show a second alternative language)
1666 global $outputlangsbis;
1667 if (is_object($outputlangsbis)) {
1668 // set cell padding with column title definition
1669 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], 0.5);
1670 } else {
1671 // set cell padding with column title definition
1672 $pdf->setCellPaddings($colDef['title']['padding'][3], $colDef['title']['padding'][0], $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1673 }
1674 if (isset($colDef['title']['align'])) {
1675 $align = $colDef['title']['align'];
1676 } else {
1677 $align = '';
1678 }
1679 $pdf->SetXY($colDef['xStartPos'], $tab_top);
1680 $textWidth = $colDef['width'];
1681 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $align);
1682
1683 // Add variant of translation if $outputlangsbis is an object
1684 if (is_object($outputlangsbis) && trim($colDef['title']['label'])) {
1685 $pdf->setCellPaddings($colDef['title']['padding'][3], 0, $colDef['title']['padding'][1], $colDef['title']['padding'][2]);
1686 $pdf->SetXY($colDef['xStartPos'], $pdf->GetY());
1687 $textbis = $outputlangsbis->transnoentities($colDef['title']['textkey']);
1688 $pdf->MultiCell($textWidth, 2, $textbis, '', $align);
1689 }
1690
1691 $this->tabTitleHeight = max($pdf->GetY() - $tab_top, $this->tabTitleHeight);
1692
1693 // restore cell padding
1694 $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);
1695 }
1696 }
1697 }
1698
1699 return $this->tabTitleHeight;
1700 }
1701
1702
1703
1712 public function defineColumnExtrafield($object, $outputlangs, $hidedetails = 0)
1713 {
1714 if (!empty($hidedetails)) {
1715 return 0;
1716 }
1717
1718 if (empty($object->table_element)) {
1719 return 0;
1720 }
1721
1722 // Load extra fields if they haven't been loaded already.
1723 if (empty($this->extrafieldsCache)) {
1724 $this->extrafieldsCache = new ExtraFields($this->db);
1725 }
1726 if (empty($this->extrafieldsCache->attributes[$object->table_element])) {
1727 $this->extrafieldsCache->fetch_name_optionals_label($object->table_element);
1728 }
1729 $extrafields = $this->extrafieldsCache;
1730
1731
1732 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'])) {
1733 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
1734 // Don't display separator yet even is set to be displayed (not compatible yet)
1735 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
1736 continue;
1737 }
1738
1739 // Enable extrafield ?
1740 $enabled = 0;
1741 if (!empty($extrafields->attributes[$object->table_element]['printable'][$key])) {
1742 $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]);
1743 if ($printable === 1 || $printable === 2) {
1744 $enabled = 1;
1745 }
1746 // Note : if $printable === 3 or 4 so, it's displayed after line description not in cols
1747 }
1748
1749 if (!$enabled) {
1750 continue;
1751 } // don't waste resources if we don't need them...
1752
1753 // Load language if required
1754 if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) {
1755 $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
1756 }
1757
1758 // TODO : add more extrafield customisation capacities for PDF like width, rank...
1759
1760 // set column definition
1761 $def = array(
1762 'rank' => intval($extrafields->attributes[$object->table_element]['pos'][$key]),
1763 'width' => 25, // in mm
1764 'status' => (bool) $enabled,
1765 'title' => array(
1766 'label' => $outputlangs->transnoentities($label)
1767 ),
1768 'content' => array(
1769 'align' => 'C'
1770 ),
1771 'border-left' => true, // add left line separator
1772 );
1773
1774 $alignTypeRight = array('double', 'int', 'price');
1775 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeRight)) {
1776 $def['content']['align'] = 'R';
1777 }
1778
1779 $alignTypeLeft = array('text', 'html');
1780 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], $alignTypeLeft)) {
1781 $def['content']['align'] = 'L';
1782 }
1783
1784
1785 // for extrafields we use rank of extrafield to place it on PDF
1786 $this->insertNewColumnDef("options_".$key, $def);
1787 }
1788 }
1789
1790 return 1;
1791 }
1792
1804 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1805 {
1806 // Default field style for content
1807 $this->defaultContentsFieldsStyle = array(
1808 'align' => 'R', // R,C,L
1809 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1810 );
1811
1812 // Default field style for content
1813 $this->defaultTitlesFieldsStyle = array(
1814 'align' => 'C', // R,C,L
1815 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1816 );
1817
1818 // Example
1819 /*
1820 $rank = 0; // do not use negative rank
1821 $this->cols['desc'] = array(
1822 'rank' => $rank,
1823 'width' => false, // only for desc
1824 'status' => true,
1825 'title' => array(
1826 'textkey' => 'Designation', // use lang key is useful in somme case with module
1827 'align' => 'L',
1828 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1829 // 'label' => ' ', // the final label
1830 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1831 ),
1832 'content' => array(
1833 'align' => 'L',
1834 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1835 ),
1836 );
1837 */
1838 }
1839}
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.