dolibarr 23.0.4
pdf_cyan.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5 * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2021-2024 Anthony Berton <anthony.berton@bb2a.fr>
11 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
13 * Copyright (C) 2024 Nick Fragoulis
14 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 * or see https://www.gnu.org/
29 */
30
36require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
37require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
41
46{
50 public $db;
51
55 public $name;
56
60 public $description;
61
65 public $update_main_doc_field;
66
70 public $type;
71
76 public $version = 'dolibarr';
77
81 public $cols;
82
88 public function __construct($db)
89 {
90 global $langs, $mysoc;
91
92 // Translations
93 $langs->loadLangs(array("main", "bills"));
94
95 $this->db = $db;
96 $this->name = "cyan";
97 $this->description = $langs->trans('DocModelCyanDescription');
98 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
99
100 // Dimension page
101 $this->type = 'pdf';
102 $formatarray = pdf_getFormat();
103 $this->page_largeur = $formatarray['width'];
104 $this->page_hauteur = $formatarray['height'];
105 $this->format = array($this->page_largeur, $this->page_hauteur);
106 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
107 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
108 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
109 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
110 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
111 $this->option_logo = 1; // Display logo
112 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
113 $this->option_modereg = 1; // Display payment mode
114 $this->option_condreg = 1; // Display payment terms
115 $this->option_multilang = 1; // Available in several languages
116 $this->option_escompte = 0; // Displays if there has been a discount
117 $this->option_credit_note = 0; // Support credit notes
118 $this->option_freetext = 1; // Support add of a personalised text
119 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
120 $this->watermark = '';
121
122 // Define position of columns
123 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
124
125
126 $this->tabTitleHeight = 5; // default height
127
128 // Use new system for position of columns, view $this->defineColumnField()
129
130 $this->tva = array();
131 $this->tva_array = array();
132 $this->localtax1 = array();
133 $this->localtax2 = array();
134 $this->atleastoneratenotnull = 0;
135 $this->atleastonediscount = 0;
136
137 if ($mysoc === null) {
138 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
139 return;
140 }
141
142 // Get source company
143 $this->emetteur = $mysoc;
144 if (empty($this->emetteur->country_code)) {
145 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
146 }
147 }
148
149 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
161 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
162 {
163 // phpcs:enable
164 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
165
166 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
167
168 if (!is_object($outputlangs)) {
169 $outputlangs = $langs;
170 }
171 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
172 if (getDolGlobalString('MAIN_USE_FPDF')) {
173 $outputlangs->charset_output = 'ISO-8859-1';
174 }
175
176 // Load translation files required by page
177 $langfiles = array("main", "dict", "companies", "bills", "products", "propal", "compta");
178 $outputlangs->loadLangs($langfiles);
179
180 // Show Draft Watermark
181 if ($object->status == $object::STATUS_DRAFT && getDolGlobalString('PROPALE_DRAFT_WATERMARK')) {
182 $this->watermark = getDolGlobalString('PROPALE_DRAFT_WATERMARK');
183 }
184
185 global $outputlangsbis;
186 $outputlangsbis = null;
187 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
188 $outputlangsbis = new Translate('', $conf);
189 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
190 $outputlangsbis->loadLangs($langfiles);
191 }
192
193 $nblines = count($object->lines);
194
195 $hidetop = getDolGlobalInt('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
196
197 // Loop on each lines to detect if there is at least one image to show
198 $realpatharray = array();
199 $this->atleastonephoto = false;
200 if (getDolGlobalString('MAIN_GENERATE_PROPOSALS_WITH_PICTURE')) {
201 $objphoto = new Product($this->db);
202
203 for ($i = 0; $i < $nblines; $i++) {
204 if (empty($object->lines[$i]->fk_product)) {
205 continue;
206 }
207
208 $objphoto->fetch($object->lines[$i]->fk_product);
209 //var_dump($objphoto->ref);exit;
210 $pdir = array();
211 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
212 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
213 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
214 } else {
215 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
216 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
217 }
218
219 $realpath = '';
220 $arephoto = false;
221 foreach ($pdir as $midir) {
222 if (!$arephoto) {
223 $entity = $objphoto->entity;
224 if ($entity !== null && $conf->entity != $entity) {
225 $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
226 } else {
227 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
228 }
229
230 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
231 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
232 if ($obj['photo_vignette']) {
233 $filename = $obj['photo_vignette'];
234 } else {
235 $filename = $obj['photo'];
236 }
237 } else {
238 $filename = $obj['photo'];
239 }
240
241 $realpath = $dir.$filename;
242 $arephoto = true;
243 $this->atleastonephoto = true;
244 }
245 }
246 }
247
248 if ($realpath && $arephoto) {
249 $realpatharray[$i] = $realpath;
250 }
251 }
252 }
253
254 if (count($realpatharray) == 0) {
255 $this->posxpicture = $this->posxtva;
256 }
257
258 if ($conf->propal->multidir_output[$conf->entity]) {
259 $object->fetch_thirdparty();
260
261 $deja_regle = 0;
262
263 // Definition of $dir and $file
264 if ($object->specimen) {
265 $dir = $conf->propal->multidir_output[$conf->entity];
266 $file = $dir."/SPECIMEN.pdf";
267 } else {
268 $objectref = dol_sanitizeFileName($object->ref);
269 $dir = $conf->propal->multidir_output[$object->entity ?? $conf->entity]."/".$objectref;
270 $file = $dir."/".$objectref.".pdf";
271 }
272
273 if (!file_exists($dir)) {
274 if (dol_mkdir($dir) < 0) {
275 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
276 return 0;
277 }
278 }
279
280 if (file_exists($dir)) {
281 // Add pdfgeneration hook
282 if (!is_object($hookmanager)) {
283 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
284 $hookmanager = new HookManager($this->db);
285 }
286 $hookmanager->initHooks(array('pdfgeneration'));
287 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
288 global $action;
289 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
290
291 // Set nblines with the new content of lines after hook
292 $nblines = count($object->lines);
293 //$nbpayments = count($object->getListOfPayments());
294
295 // Create pdf instance
296 $pdf = pdf_getInstance($this->format);
297 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
298 $pdf->setAutoPageBreak(true, 0);
299
300 if (class_exists('TCPDF')) {
301 $pdf->setPrintHeader(false);
302 $pdf->setPrintFooter(false);
303 }
304 $pdf->SetFont(pdf_getPDFFont($outputlangs));
305 // Set path to the background PDF File
306 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
307 $logodir = $conf->mycompany->dir_output;
308 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
309 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
310 }
311 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
312 $tplidx = $pdf->importPage(1);
313 }
314
315 $pdf->Open();
316 $pagenb = 0;
317 $pdf->SetDrawColor(128, 128, 128);
318
319 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
320 $pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
321 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
322 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
323 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
324 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
325 $pdf->SetCompression(false);
326 }
327
328 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
329 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
330
331 // Set $this->atleastonediscount if you have at least one discount
332 for ($i = 0; $i < $nblines; $i++) {
333 if ($object->lines[$i]->remise_percent) {
334 $this->atleastonediscount++;
335 }
336 }
337
338
339 // New page
340 $pdf->AddPage();
341 if (!empty($tplidx)) {
342 $pdf->useTemplate($tplidx);
343 }
344 $pagenb++;
345
346 $heightforinfotot = 40; // Height reserved to output the info and total part
347 $heightforsignature = !getDolGlobalString('PROPAL_DISABLE_SIGNATURE') ? (pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature")) + 10) : 0;
348 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
349 $heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
350 //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
351
352 $save_note_public = $object->note_public; // Because $object->note_public may be modified by _pagehead() that calls pdf_writeLinkedObjects() that calls ... that modify $object->note_private
353
354 $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
355 $top_shift = $pagehead['top_shift'];
356 $shipp_shift = $pagehead['shipp_shift'];
357 $pdf->SetFont('', '', $default_font_size - 1);
358 $pdf->MultiCell(0, 3, ''); // Set interline to 3
359 $pdf->SetTextColor(0, 0, 0);
360
361
362 $tab_top = 90 + $top_shift + $shipp_shift;
363 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
364 if (!$hidetop && getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
365 // TODO : make this hidden conf the default behavior for each PDF when each PDF managed this new Display
366 $tab_top_newpage += $this->tabTitleHeight;
367 }
368
369 $nexY = $tab_top;
370
371 // Incoterm
372 $height_incoterms = 0;
373 if (isModEnabled('incoterm')) {
374 $desc_incoterms = $object->getIncotermsForPDF();
375 if ($desc_incoterms) {
376 $tab_top -= 2;
377
378 $pdf->SetFont('', '', $default_font_size - 1);
379 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
380 $nexY = max($pdf->GetY(), $nexY);
381 $height_incoterms = $nexY - $tab_top;
382
383 // Rect takes a length in 3rd parameter
384 $pdf->SetDrawColor(192, 192, 192);
385 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
386
387 $tab_top = $nexY + 6;
388 $height_incoterms += 4;
389 }
390 }
391
392 // Displays notes
393 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
394 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
395 // Get first sale rep
396 if (is_object($object->thirdparty)) {
397 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
398 $salerepobj = new User($this->db);
399 $salerepobj->fetch($salereparray[0]['id']);
400 if (!empty($salerepobj->signature)) {
401 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
402 }
403 }
404 }
405
406 $object->note_public = $save_note_public; // Now that we have output the note_public, we can restore it to initial value.
407
408 // Extrafields in note
409 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
410 if (!empty($extranote)) {
411 $notetoshow = dol_concatdesc((string) $notetoshow, $extranote);
412 }
413
414 if (getDolGlobalString('MAIN_ADD_CREATOR_IN_NOTE') && $object->user_author_id > 0) {
415 $tmpuser = new User($this->db);
416 $tmpuser->fetch($object->user_author_id);
417
418 $creator_info = $langs->trans("CaseFollowedBy").' '.$tmpuser->getFullName($langs);
419 if ($tmpuser->email) {
420 $creator_info .= ', '.$langs->trans("EMail").': '.$tmpuser->email;
421 }
422 if ($tmpuser->office_phone) {
423 $creator_info .= ', '.$langs->trans("Phone").': '.$tmpuser->office_phone;
424 }
425
426 $notetoshow = dol_concatdesc((string) $notetoshow, $creator_info);
427 }
428
429 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
430
431 $pagenb = $pdf->getPage();
432 if ($notetoshow) {
433 $tab_top -= 2;
434
435 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
436 $pageposbeforenote = $pagenb;
437
438 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
439 complete_substitutions_array($substitutionarray, $outputlangs, $object);
440 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
441 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
442
443 $pdf->startTransaction();
444
445 $pdf->SetFont('', '', $default_font_size - 1);
446 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
447 // Description
448 $pageposafternote = $pdf->getPage();
449 $posyafter = $pdf->GetY();
450
451 if ($pageposafternote > $pageposbeforenote) {
452 $pdf->rollbackTransaction(true);
453
454 // prepare pages to receive notes
455 while ($pagenb < $pageposafternote) {
456 $pdf->AddPage();
457 $pagenb++;
458 if (!empty($tplidx)) {
459 $pdf->useTemplate($tplidx);
460 }
461 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
462 $this->_pagehead($pdf, $object, 0, $outputlangs);
463 }
464 // $this->_pagefoot($pdf,$object,$outputlangs,1);
465 $pdf->setTopMargin($tab_top_newpage);
466 // The only function to edit the bottom margin of current page to set it.
467 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
468 }
469
470 // back to start
471 $pdf->setPage($pageposbeforenote);
472 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
473 $pdf->SetFont('', '', $default_font_size - 1);
474 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
475 $pageposafternote = $pdf->getPage();
476
477 $posyafter = $pdf->GetY();
478
479 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
480 $pdf->AddPage('', '', true);
481 $pagenb++;
482 $pageposafternote++;
483 $pdf->setPage($pageposafternote);
484 $pdf->setTopMargin($tab_top_newpage);
485 // The only function to edit the bottom margin of current page to set it.
486 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
487 //$posyafter = $tab_top_newpage;
488 }
489
490
491 // apply note frame to previous pages
492 $i = $pageposbeforenote;
493 while ($i < $pageposafternote) {
494 $pdf->setPage($i);
495
496
497 $pdf->SetDrawColor(128, 128, 128);
498 // Draw note frame
499 if ($i > $pageposbeforenote) {
500 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
501 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
502 } else {
503 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
504 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
505 }
506
507 // Add footer
508 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
509 $this->_pagefoot($pdf, $object, $outputlangs, 1);
510
511 $i++;
512 }
513
514 // apply note frame to last page
515 $pdf->setPage($pageposafternote);
516 if (!empty($tplidx)) {
517 $pdf->useTemplate($tplidx);
518 }
519 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
520 $this->_pagehead($pdf, $object, 0, $outputlangs);
521 }
522 $height_note = $posyafter - $tab_top_newpage;
523 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
524 } else {
525 // No pagebreak
526 $pdf->commitTransaction();
527 $posyafter = $pdf->GetY();
528 $height_note = $posyafter - $tab_top;
529 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
530
531
532 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
533 // not enough space, need to add page
534 $pdf->AddPage('', '', true);
535 $pagenb++;
536 $pageposafternote++;
537 $pdf->setPage($pageposafternote);
538 if (!empty($tplidx)) {
539 $pdf->useTemplate($tplidx);
540 }
541 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
542 $this->_pagehead($pdf, $object, 0, $outputlangs);
543 }
544
545 $posyafter = $tab_top_newpage;
546 }
547 }
548 $tab_height -= $height_note;
549 $tab_top = $posyafter + 6;
550 } else {
551 $height_note = 0;
552 }
553
554 // Use new auto column system
555 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
556
557 // Table simulation to know the height of the title line
558 $pdf->startTransaction();
559 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
560 $pdf->rollbackTransaction(true);
561
562 $nexY = $tab_top + $this->tabTitleHeight;
563
564 // Loop on each lines
565 $pageposbeforeprintlines = $pdf->getPage();
566 $pagenb = $pageposbeforeprintlines;
567
568 $pdf_sub_options = array();
569 $pdf_sub_options['titleshowuponpdf'] = 1;
570 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = 1;
571 $pdf_sub_options_before_title = array(); // Options in use before each title line, by level
572
573 $hidenextline = 0;
574
575 for ($i = 0; $i < $nblines; $i++) {
576 $linePosition = $i + 1;
577 $curY = $nexY;
578
579 $sub_options = $object->lines[$i]->extraparams["subtotal"] ?? array();
580
581 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
582 $level = $object->lines[$i]->qty;
583 // Keep the options in use before a title line, to restore them after the subtotal line that closes its block
584 if ($level > 0 && !isset($pdf_sub_options_before_title[(int) $level])) {
585 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
586 }
587 if ($sub_options) {
588 $hidenextline = 0;
589 if (isset($sub_options['titleshowuponpdf'])) {
590 $pdf_sub_options['titleshowuponpdf'] = isset($pdf_sub_options['titleshowuponpdf']) && $pdf_sub_options['titleshowuponpdf'] < $level ? $pdf_sub_options['titleshowuponpdf'] : $level;
591 } elseif (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
592 unset($pdf_sub_options['titleshowuponpdf']);
593 }
594 if (isset($sub_options['titleshowtotalexludingvatonpdf'])) {
595 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && $pdf_sub_options['titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options['titleshowtotalexludingvatonpdf'] : $level;
596 } elseif (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
597 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
598 }
599 } else {
600 if (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
601 unset($pdf_sub_options['titleshowuponpdf']);
602 }
603 if (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
604 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
605 }
606 }
607 // A subtotal line closes the block of the title line of same level: the next lines get back the options in use before this title line
608 if ($level < 0 && isset($pdf_sub_options_before_title[(int) abs($level)])) {
609 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
610 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
611 if ($tmplevel >= abs($level)) {
612 unset($pdf_sub_options_before_title[$tmplevel]);
613 }
614 }
615 }
616 }
617
618 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options['subtotalshowtotalexludingvatonpdf']) && getDolGlobalString('SUBTOTAL_HIDE_LINES_UNDER_TITLE')) { // TODO Use $sub_options['titlehidelinesundertitle'] instead of SUBTOTAL_HIDE_LINES_UNDER_TITLE
619 $hidenextline = 0;
620 $pdf_sub_options = array();
621 $pdf_sub_options['titleshowuponpdf'] = 1;
622 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = 1;
623 }
624
625 if ($hidenextline) {
626 $linePosition--;
627 } else {
628 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options['titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
629 $object->lines[$i]->pagebreak = true;
630 }
631
632 // in First Check line page break and add page if needed
633 if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
634 // New page
635 $pdf->AddPage();
636 if (!empty($tplidx)) {
637 $pdf->useTemplate($tplidx);
638 }
639
640 $pdf->setPage($pdf->getNumPages());
641 $nexY = $curY = $tab_top_newpage;
642 }
643
644 $this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
645
646 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
647 $pdf->SetTextColor(0, 0, 0);
648
649 // Define size of image if we need it
650 $imglinesize = array();
651 if (!empty($realpatharray[$i])) {
652 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
653 }
654
655 $pdf->setTopMargin($tab_top_newpage);
656 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
657 $pageposbefore = $pdf->getPage();
658 $curYBefore = $curY;
659
660 // Allows data in the first page if description is long enough to break in multiples pages
661 $showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
662
663 $posYAfterImage = 0;
664
665 if ($this->getColumnStatus('photo')) {
666 // We start with Photo of product line
667 $imageTopMargin = 1;
668 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imageTopMargin + $imglinesize['height']) > ($this->page_hauteur - $heightforfooter)) { // If photo too high, we moved completely on new page
669 $pdf->AddPage('', '', true);
670 if (!empty($tplidx)) {
671 $pdf->useTemplate($tplidx);
672 }
673 $pdf->setPage($pageposbefore + 1);
674 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
675 $curY = $tab_top_newpage;
676 $showpricebeforepagebreak = 0;
677 }
678
679 $pdf->setPageOrientation('', false, $heightforfooter + $heightforfreetext); // The only function to edit the bottom margin of current page to set it.
680 // @phan-suppress-next-line PhanTypeMismatchProperty
681 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
682 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
683 // $pdf->Image does not increase value return by getY, so we save it manually
684 $posYAfterImage = $curY + $imglinesize['height'];
685
686 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
687 }
688 }
689
690 // restore Page orientation for text
691 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
692
693 if ($this->getColumnStatus('desc')) {
694 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
695 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
696 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
697 } else {
698 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty), 'ffffff'));
699 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
700 }
701 }
702
703 $afterPosData = $this->getMaxAfterColsLinePositionsData();
704 $pdf->setPage($pageposbefore);
705 $pdf->setTopMargin($this->marge_haute);
706 $curY = $curYBefore;
707 $pdf->setPageOrientation('', false, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
708
709
710 // We suppose that a too long description or photo were moved completely on next page
711 if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
712 $pdf->setPage($afterPosData['page']);
713 $curY = $tab_top_newpage;
714 }
715
716 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
717
718
719 // # of line
720 if ($this->getColumnStatus('position')) {
721 $this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
722 }
723
724 // VAT Rate
725 if ($this->getColumnStatus('vat') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
726 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
727 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
728 }
729
730 // Unit price before discount
731 if ($this->getColumnStatus('subprice') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowuponpdf'])) {
732 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
733 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
734 }
735
736 // Quantity
737 // Enough for 6 chars
738 if ($this->getColumnStatus('qty') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
739 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
740 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
741 }
742
743
744 // Unit
745 if ($this->getColumnStatus('unit') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
746 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
747 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
748 }
749
750 // Discount on line
751 if ($this->getColumnStatus('discount') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && $object->lines[$i]->remise_percent) {
752 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
753 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
754 }
755
756 // Total excl tax line (HT)
757 if ($this->getColumnStatus('totalexcltax')) {
758 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowtotalexludingvatonpdf'])) {
759 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
760 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
761 } elseif ($object->lines[$i]->qty < 0 && isset($sub_options['subtotalshowtotalexludingvatonpdf'])) {
762 if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency) {
763 $total_excl_tax = $object->getSubtotalLineMulticurrencyAmount($object->lines[$i]);
764 } else {
765 $total_excl_tax = $object->getSubtotalLineAmount($object->lines[$i]);
766 }
767 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
768 }
769 }
770
771 // Total with tax line (TTC)
772 if ($this->getColumnStatus('totalincltax') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
773 $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
774 $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
775 }
776
777 // Extrafields
778 if (!empty($object->lines[$i]->array_options)) {
779 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
780 if ($this->getColumnStatus($extrafieldColKey)) {
781 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
782 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
783
784 $this->setAfterColsLinePositionsData('options_'.$extrafieldColKey, $pdf->GetY(), $pdf->getPage());
785 }
786 }
787 }
788
789 $afterPosData = $this->getMaxAfterColsLinePositionsData();
790 $parameters = array(
791 'object' => $object,
792 'i' => $i,
793 'pdf' => & $pdf,
794 'curY' => & $curY,
795 'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
796 'outputlangs' => $outputlangs,
797 'hidedetails' => $hidedetails
798 );
799 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
800 }
801
802 // Collection of totals by value of vat in $this->tva["rate"] = total_tva
803 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
804 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
805 } else {
806 $tvaligne = $object->lines[$i]->total_tva;
807 }
808
809 $localtax1ligne = $object->lines[$i]->total_localtax1;
810 $localtax2ligne = $object->lines[$i]->total_localtax2;
811 $localtax1_rate = $object->lines[$i]->localtax1_tx;
812 $localtax2_rate = $object->lines[$i]->localtax2_tx;
813 $localtax1_type = $object->lines[$i]->localtax1_type;
814 $localtax2_type = $object->lines[$i]->localtax2_type;
815
816 // TODO remise_percent is an obsolete field for object parent
817 /*if ($object->remise_percent) {
818 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
819 }
820 if ($object->remise_percent) {
821 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
822 }
823 if ($object->remise_percent) {
824 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
825 }*/
826
827 $vatrate = (string) $object->lines[$i]->tva_tx;
828
829 // Retrieve type from database for backward compatibility with old records
830 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
831 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
832 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
833 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
834 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
835 }
836
837 // retrieve global local tax
838 if ($localtax1_type && $localtax1ligne != 0) {
839 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
840 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
841 } else {
842 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
843 }
844 }
845 if ($localtax2_type && $localtax2ligne != 0) {
846 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
847 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
848 } else {
849 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
850 }
851 }
852
853 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
854 $vatrate .= '*';
855 }
856
857 // Fill $this->tva and $this->tva_array
858 if (!isset($this->tva[$vatrate])) {
859 $this->tva[$vatrate] = 0;
860 }
861 $this->tva[$vatrate] += $tvaligne;
862 $vatcode = $object->lines[$i]->vat_src_code;
863 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
864 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
865 }
866 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
867
868
869 if (!$hidenextline) {
870 $afterPosData = $this->getMaxAfterColsLinePositionsData();
871 $pdf->setPage($afterPosData['page']);
872 $nexY = $afterPosData['y'];
873
874 // Add line
875 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $heightforfooter - 5) {
876 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
877 //$pdf->SetDrawColor(190,190,200);
878 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
879 $pdf->SetLineStyle(array('dash' => 0));
880 }
881 }
882
883 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options['titleshowuponpdf']) || isset($sub_options['titleshowtotalexludingvatonpdf'])) && getDolGlobalString('SUBTOTAL_HIDE_LINES_UNDER_TITLE')) { // TODO Use $sub_options['titlehidelinesundertitle'] instead of SUBTOTAL_HIDE_LINES_UNDER_TITLE
884 $hidenextline = 1;
885 }
886
887 $nexY += 0; // Add space between lines
888 }
889
890
891 // Add last page for document footer if there are not enough size left
892 $afterPosData = $this->getMaxAfterColsLinePositionsData();
893 if (isset($afterPosData['y']) && $afterPosData['y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
894 $pdf->AddPage();
895 if (!empty($tplidx)) {
896 $pdf->useTemplate($tplidx);
897 }
898 $pagenb++;
899 $pdf->setPage($pagenb);
900 }
901
902 // Draw table frames and columns borders
903 $drawTabNumbPage = $pdf->getNumPages();
904 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
905 $pdf->setPage($i);
906 // reset page orientation each loop to override it if it was changed
907 $pdf->setPageOrientation('', false, 0); // The only function to edit the bottom margin of current page to set it.
908
909 $drawTabHideTop = $hidetop;
910 $drawTabTop = $tab_top_newpage;
911 $drawTabBottom = $this->page_hauteur - $heightforfooter;
912 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
913
914 if ($i == $pageposbeforeprintlines) {
915 // first page need to start after notes
916 $drawTabTop = $tab_top;
917 } elseif (!$drawTabHideTop) {
918 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
919 $drawTabTop -= $this->tabTitleHeight;
920 } else {
921 $drawTabHideTop = 1;
922 }
923 }
924
925 // last page need to include document footer
926 if ($i == $pdf->getNumPages()) {
927 // remove document footer height to tab bottom position
928 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
929 }
930
931 $drawTabHeight = $drawTabBottom - $drawTabTop;
932 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object->multicurrency_code, $outputlangsbis);
933
934 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
935 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText);
936
937 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
938
939 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
940 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
941
942 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
943 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
944 $this->_pagehead($pdf, $object, 0, $outputlangs);
945 }
946 if (!empty($tplidx)) {
947 $pdf->useTemplate($tplidx);
948 }
949 }
950
951 // reset text color before print footers
952 $pdf->SetTextColor(0, 0, 0);
953
954 $pdf->setPage($pdf->getNumPages());
955
956 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
957
958 // Display infos area
959 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
960
961 // Display total zone
962 $posy = $this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
963
964 // Customer signature area
965 if (!getDolGlobalString('PROPAL_DISABLE_SIGNATURE')) {
966 $posy = $this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
967
968 // Rewrite keywords to add a tag with the numero of page that contains the signature section
969 $keywords = $outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name);
970 $pdf->SetKeyWords($keywords." PAGESIGN=".$pdf->getPage());
971 }
972
973 // Add number of pages in footer
974 if (method_exists($pdf, 'AliasNbPages')) {
975 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
976 }
977
978 // Add terms to sale
979 $termsofsalefilename = getDolGlobalString('MAIN_INFO_PROPAL_TERMSOFSALE');
980 if (getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_PROPAL') && $termsofsalefilename) {
981 $termsofsale = $conf->propal->dir_output.'/'.$termsofsalefilename;
982 if (!empty($conf->propal->multidir_output[$object->entity ?? $conf->entity])) {
983 $termsofsale = $conf->propal->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
984 }
985 if (file_exists($termsofsale) && is_readable($termsofsale)) {
986 $pagecount = $pdf->setSourceFile($termsofsale);
987 for ($i = 1; $i <= $pagecount; $i++) {
988 $tplIdx = $pdf->importPage($i);
989 if ($tplIdx !== false) {
990 $s = $pdf->getTemplatesize($tplIdx);
991 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
992 $pdf->useTemplate($tplIdx);
993 } else {
994 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
995 }
996 }
997 }
998 }
999
1000 //If propal merge product PDF is active
1001 if (getDolGlobalString('PRODUIT_PDF_MERGE_PROPAL')) {
1002 require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
1003
1004 $already_merged = array();
1005 foreach ($object->lines as $line) {
1006 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
1007 // Find the desired PDF
1008 $filetomerge = new Propalmergepdfproduct($this->db);
1009
1010 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1011 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
1012 } else {
1013 $filetomerge->fetch_by_product($line->fk_product);
1014 }
1015
1016 $already_merged[] = $line->fk_product;
1017
1018 $product = new Product($this->db);
1019 $product->fetch($line->fk_product);
1020
1021 if ($product->entity != $conf->entity) {
1022 $entity_product_file = $product->entity;
1023 } else {
1024 $entity_product_file = $conf->entity;
1025 }
1026
1027 // If PDF is selected and file is not empty
1028 if (count($filetomerge->lines) > 0) {
1029 foreach ($filetomerge->lines as $linefile) {
1030 if (!empty($linefile->id) && !empty($linefile->file_name)) {
1031 $filetomerge_dir = null;
1032 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
1033 if (isModEnabled("product")) {
1034 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file ?? $conf->entity].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
1035 } elseif (isModEnabled("service")) {
1036 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file ?? $conf->entity].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
1037 }
1038 } else {
1039 if (isModEnabled("product")) {
1040 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file ?? $conf->entity].'/'.get_exdir(0, 0, 0, 0, $product, 'product');
1041 } elseif (isModEnabled("service")) {
1042 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file ?? $conf->entity].'/'.get_exdir(0, 0, 0, 0, $product, 'product');
1043 }
1044 }
1045
1046 dol_syslog(get_class($this).':: upload_dir='.$filetomerge_dir, $filetomerge_dir === null ? LOG_ERR : LOG_DEBUG);
1047 if ($filetomerge_dir === null) {
1048 // Skip loop
1049 continue;
1050 }
1051
1052 $infile = $filetomerge_dir.'/'.$linefile->file_name;
1053 if (file_exists($infile) && is_readable($infile)) {
1054 $pagecount = $pdf->setSourceFile($infile);
1055 for ($i = 1; $i <= $pagecount; $i++) {
1056 $tplIdx = $pdf->importPage($i);
1057 if ($tplIdx !== false) {
1058 $s = $pdf->getTemplatesize($tplIdx);
1059 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1060 $pdf->useTemplate($tplIdx);
1061 } else {
1062 setEventMessages(null, array($infile.' cannot be added, probably protected PDF'), 'warnings');
1063 }
1064 }
1065 }
1066 }
1067 }
1068 }
1069 }
1070 }
1071 }
1072
1073 $pdf->Close();
1074
1075 $pdf->Output($file, 'F');
1076
1077 //Add pdfgeneration hook
1078 $hookmanager->initHooks(array('pdfgeneration'));
1079 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1080 global $action;
1081 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1082 $this->warnings = $hookmanager->warnings;
1083 if ($reshook < 0) {
1084 $this->error = $hookmanager->error;
1085 $this->errors = $hookmanager->errors;
1086 dolChmod($file);
1087 return -1;
1088 }
1089
1090 dolChmod($file);
1091
1092 $this->result = array('fullpath' => $file);
1093
1094 return 1; // No error
1095 } else {
1096 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
1097 return 0;
1098 }
1099 } else {
1100 $this->error = $langs->trans("ErrorConstantNotDefined", "PROP_OUTPUTDIR");
1101 return 0;
1102 }
1103 }
1104
1114 public function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
1115 {
1116 global $mysoc;
1117
1118 $default_font_size = pdf_getPDFFontSize($outputlangs);
1119
1120 $pdf->SetFont('', '', $default_font_size - 1);
1121
1122 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1123
1124 // If France, show VAT mention if not applicable
1125 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1126 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1127 $pdf->SetXY($this->marge_gauche, $posy);
1128 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1129
1130 $posy = $pdf->GetY() + 4;
1131 }
1132
1133 $posxval = 52;
1134 if (getDolGlobalString('MAIN_PDF_DELIVERY_DATE_TEXT')) {
1135 $displaydate = "daytext";
1136 } else {
1137 $displaydate = "day";
1138 }
1139
1140 // Show shipping date
1141 if (!empty($object->delivery_date)) {
1142 $outputlangs->load("sendings");
1143 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1144 $pdf->SetXY($this->marge_gauche, $posy);
1145 $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
1146 $pdf->MultiCell(80, 4, $titre, 0, 'L');
1147 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1148 $pdf->SetXY($posxval, $posy);
1149 $dlp = dol_print_date($object->delivery_date, $displaydate, false, $outputlangs, true);
1150 $pdf->MultiCell(80, 4, $dlp, 0, 'L');
1151
1152 $posy = $pdf->GetY() + 1;
1153 } elseif ($object->availability_code || $object->availability) { // Show availability conditions
1154 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1155 $pdf->SetXY($this->marge_gauche, $posy);
1156 $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
1157 $pdf->MultiCell(80, 4, $titre, 0, 'L');
1158 $pdf->SetTextColor(0, 0, 0);
1159 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1160 $pdf->SetXY($posxval, $posy);
1161 $lib_availability = ($outputlangs->transnoentities("AvailabilityType".$object->availability_code) != 'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset($object->availability);
1162 $lib_availability = str_replace('\n', "\n", $lib_availability);
1163 $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
1164
1165 $posy = $pdf->GetY() + 1;
1166 }
1167
1168 // Show delivery mode
1169 if (!getDolGlobalString('PROPOSAL_PDF_HIDE_DELIVERYMODE') && $object->shipping_method_id > 0) {
1170 $outputlangs->load("sendings");
1171
1172 $shipping_method_id = $object->shipping_method_id;
1173 if (getDolGlobalString('SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1174 $shipping_method_id = $this->emetteur->shipping_method_id;
1175 }
1176 $shipping_method_code = dol_getIdFromCode($this->db, (string) $shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
1177 $shipping_method_label = dol_getIdFromCode($this->db, (string) $shipping_method_id, 'c_shipment_mode', 'rowid', 'libelle');
1178
1179 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1180 $pdf->SetXY($this->marge_gauche, $posy);
1181 $titre = $outputlangs->transnoentities("SendingMethod").':';
1182 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1183
1184 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1185 $pdf->SetXY($posxval, $posy);
1186 $lib_condition_paiement = ($outputlangs->transnoentities("SendingMethod".strtoupper($shipping_method_code)) != "SendingMethod".strtoupper($shipping_method_code)) ? $outputlangs->trans("SendingMethod".strtoupper($shipping_method_code)) : $shipping_method_label;
1187 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1188 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1189
1190 $posy = $pdf->GetY() + 1;
1191 }
1192
1193 // Show payments conditions
1194 if (!getDolGlobalString('PROPOSAL_PDF_HIDE_PAYMENTTERM') && $object->cond_reglement_code) {
1195 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1196 $pdf->SetXY($this->marge_gauche, $posy);
1197 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1198 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1199
1200 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1201 $pdf->SetXY($posxval, $posy);
1202 $lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != 'PaymentCondition'.$object->cond_reglement_code ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
1203 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1204 if ($object->deposit_percent > 0) {
1205 $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
1206 }
1207 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1208
1209 $posy = $pdf->GetY() + 3;
1210 }
1211
1212 if (!getDolGlobalString('PROPOSAL_PDF_HIDE_PAYMENTMODE')) {
1213 // Show payment mode
1214 if ($object->mode_reglement_code
1215 && $object->mode_reglement_code != 'CHQ'
1216 && $object->mode_reglement_code != 'VIR') {
1217 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1218 $pdf->SetXY($this->marge_gauche, $posy);
1219 $titre = $outputlangs->transnoentities("PaymentMode").':';
1220 $pdf->MultiCell(80, 5, $titre, 0, 'L');
1221 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1222 $pdf->SetXY($posxval, $posy);
1223 $lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != 'PaymentType'.$object->mode_reglement_code ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1224 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1225
1226 $posy = $pdf->GetY() + 2;
1227 }
1228
1229 // Show payment mode CHQ
1230 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1231 // Si mode reglement non force ou si force a CHQ
1232 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1233 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1234 $account = new Account($this->db);
1235 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1236
1237 $pdf->SetXY($this->marge_gauche, $posy);
1238 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1239 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1240 $posy = $pdf->GetY() + 1;
1241
1242 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1243 $pdf->SetXY($this->marge_gauche, $posy);
1244 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1245 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1246 $posy = $pdf->GetY() + 2;
1247 }
1248 }
1249 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1250 $pdf->SetXY($this->marge_gauche, $posy);
1251 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1252 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1253 $posy = $pdf->GetY() + 1;
1254
1255 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1256 $pdf->SetXY($this->marge_gauche, $posy);
1257 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1258 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1259 $posy = $pdf->GetY() + 2;
1260 }
1261 }
1262 }
1263 }
1264
1265 // If payment mode not forced or forced to VIR, show payment with BAN
1266 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1267 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1268 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1269 if ($object->fk_bank > 0) {
1270 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1271 }
1272 $account = new Account($this->db);
1273 $account->fetch((int) $bankid);
1274
1275 $curx = $this->marge_gauche;
1276 $cury = $posy;
1277
1278 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1279
1280 $posy += 2;
1281 }
1282 }
1283 }
1284
1285 return $posy;
1286 }
1287
1288
1300 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
1301 {
1302 global $conf, $mysoc, $hookmanager;
1303
1304 $default_font_size = pdf_getPDFFontSize($outputlangs);
1305
1306 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1307 $outputlangsbis = new Translate('', $conf);
1308 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1309 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1310 $default_font_size--;
1311 }
1312
1313 $tab2_top = $posy;
1314 $tab2_hl = 4;
1315 $pdf->SetFont('', '', $default_font_size - 1);
1316
1317 // Total table
1318 $col1x = 120;
1319 $col2x = 170;
1320 if ($this->page_largeur < 210) { // To work with US executive format
1321 $col2x -= 20;
1322 }
1323 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1324
1325 $useborder = 0;
1326 $index = 0;
1327
1328 // Get Total HT
1329 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1330
1331 // Total discount
1332 $total_discount_on_lines = 0;
1333 $multicurrency_total_discount_on_lines = 0;
1334 foreach ($object->lines as $i => $line) {
1335 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1336 $multicurrency_resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2, 1);
1337
1338 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1339 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1340 // If line was a negative line, we do not count the discount as a discount
1341 if ($line->total_ht < 0) {
1342 $total_discount_on_lines += -$line->total_ht;
1343 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1344 }
1345 }
1346
1347 if ($total_discount_on_lines > 0) {
1348 // Show total NET before discount
1349 $pdf->SetFillColor(255, 255, 255);
1350 $pdf->SetXY($col1x, $tab2_top);
1351 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', true);
1352 $pdf->SetXY($col2x, $tab2_top);
1353
1354 $total_before_discount_to_show = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? ($object->multicurrency_total_ht + $multicurrency_total_discount_on_lines) : ($object->total_ht + $total_discount_on_lines));
1355 $pdf->MultiCell($largcol2, $tab2_hl, price($total_before_discount_to_show, 0, $outputlangs), 0, 'R', true);
1356
1357 $index++;
1358
1359 $pdf->SetFillColor(255, 255, 255);
1360 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1361 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', true);
1362 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1363
1364 $total_discount_to_show = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1365 $pdf->MultiCell($largcol2, $tab2_hl, price($total_discount_to_show, 0, $outputlangs), 0, 'R', true);
1366
1367 $index++;
1368 }
1369
1370 // Total HT
1371 $pdf->SetFillColor(255, 255, 255);
1372 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1373 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', true);
1374
1375 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1376 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1377 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', true);
1378
1379 // Show VAT by rates and total
1380 $pdf->SetFillColor(248, 248, 248);
1381
1382 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1383 $total_ttc_origin = $object->total_ttc;
1384
1385 $this->atleastoneratenotnull = 0;
1386 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1387 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1388 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1389 // Nothing to do
1390 } else {
1391 //Local tax 1 before VAT
1392 //if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on')
1393 //{
1394 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1395 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1396 continue;
1397 }
1398
1399 foreach ($localtax_rate as $tvakey => $tvaval) {
1400 if ($tvakey != 0) { // On affiche pas taux 0
1401 //$this->atleastoneratenotnull++;
1402
1403 $index++;
1404 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1405
1406 $tvacompl = '';
1407 if (preg_match('/\*/', $tvakey)) {
1408 $tvakey = str_replace('*', '', $tvakey);
1409 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1410 }
1411 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1412 $totalvat .= ' ';
1413 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1414 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1415
1416 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1417
1418 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1419 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1420 }
1421 }
1422 }
1423 //}
1424 //Local tax 2 before VAT
1425 //if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on')
1426 //{
1427 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1428 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1429 continue;
1430 }
1431
1432 foreach ($localtax_rate as $tvakey => $tvaval) {
1433 if ($tvakey != 0) { // On affiche pas taux 0
1434 //$this->atleastoneratenotnull++;
1435
1436 $index++;
1437 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1438
1439 $tvacompl = '';
1440 if (preg_match('/\*/', $tvakey)) {
1441 $tvakey = str_replace('*', '', $tvakey);
1442 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1443 }
1444 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1445 $totalvat .= ' ';
1446 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1447 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1448
1449 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1450
1451 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1452 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1453 }
1454 }
1455 }
1456 //}
1457
1458 // VAT
1459 foreach ($this->tva as $tvakey => $tvaval) {
1460 if ($tvakey != 0) { // On affiche pas taux 0
1461 $this->atleastoneratenotnull++;
1462
1463 $index++;
1464 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1465
1466 $tvacompl = '';
1467 if (preg_match('/\*/', $tvakey)) {
1468 $tvakey = str_replace('*', '', $tvakey);
1469 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1470 }
1471 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1472 $totalvat .= ' ';
1473 $totalvat .= vatrate($tvakey, true).$tvacompl;
1474 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1475
1476 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1477 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', true);
1478 }
1479 }
1480
1481 //Local tax 1 after VAT
1482 //if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on')
1483 //{
1484 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1485 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1486 continue;
1487 }
1488
1489 foreach ($localtax_rate as $tvakey => $tvaval) {
1490 if ($tvakey != 0) { // On affiche pas taux 0
1491 //$this->atleastoneratenotnull++;
1492
1493 $index++;
1494 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1495
1496 $tvacompl = '';
1497 if (preg_match('/\*/', $tvakey)) {
1498 $tvakey = str_replace('*', '', $tvakey);
1499 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1500 }
1501 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1502 $totalvat .= ' ';
1503
1504 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1505 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1506
1507 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1508
1509 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1510 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1511 }
1512 }
1513 }
1514 //}
1515 //Local tax 2 after VAT
1516 //if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on')
1517 //{
1518 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1519 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1520 continue;
1521 }
1522
1523 foreach ($localtax_rate as $tvakey => $tvaval) {
1524 // retrieve global local tax
1525 if ($tvakey != 0) { // On affiche pas taux 0
1526 //$this->atleastoneratenotnull++;
1527
1528 $index++;
1529 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1530
1531 $tvacompl = '';
1532 if (preg_match('/\*/', $tvakey)) {
1533 $tvakey = str_replace('*', '', $tvakey);
1534 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1535 }
1536 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1537 $totalvat .= ' ';
1538
1539 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1540 $totalvat .= $tvacompl;
1541 } else {
1542 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1543 }
1544
1545 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1546
1547 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1548
1549 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1550 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1551 }
1552 }
1553 }
1554 //}
1555
1556 // Total TTC
1557 $index++;
1558 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1559 $pdf->SetTextColor(0, 0, 60);
1560 $pdf->SetFillColor(224, 224, 224);
1561 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', true);
1562
1563 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1564 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1565 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', true);
1566 } else {
1567 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', true);
1568
1569 //$pdf->writeHTMLCell($largcol2, $tab2_hl, null, null, '<font size="-2">('.price($sign * $object->total_ttc, 0, $outputlangs, 1, -1, 'MT', $mysoc->currency_code).')</font> &nbsp; '.price($sign * $total_ttc, 0, $outputlangs), $useborder, 1, true, true, 'R');
1570 $index++;
1571 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1572 $pdf->SetTextColor(0, 0, 60);
1573 $pdf->SetFillColor(224, 224, 224);
1574 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
1575
1576 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1577 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
1578 }
1579 }
1580 }
1581
1582 $pdf->SetTextColor(0, 0, 0);
1583
1584 $resteapayer = 0;
1585 /*
1586 $resteapayer = $object->total_ttc - $deja_regle;
1587 if (!empty($object->paye)) $resteapayer=0;
1588 */
1589
1590 if ($deja_regle > 0) {
1591 // Already paid + Deposits
1592 $index++;
1593
1594 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1595 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', false);
1596
1597 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1598 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', false);
1599
1600 /*
1601 if ($object->close_code == 'discount_vat') {
1602 $index++;
1603 $pdf->SetFillColor(255,255,255);
1604
1605 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1606 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1607
1608 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1609 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1610
1611 $resteapayer=0;
1612 }
1613 */
1614
1615 $index++;
1616 $pdf->SetTextColor(0, 0, 60);
1617 $pdf->SetFillColor(224, 224, 224);
1618 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1619 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', true);
1620
1621 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1622 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
1623
1624 $pdf->SetFont('', '', $default_font_size - 1);
1625 $pdf->SetTextColor(0, 0, 0);
1626 }
1627
1628 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
1629
1630 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
1631 if ($reshook < 0) {
1632 $this->error = $hookmanager->error;
1633 $this->errors = $hookmanager->errors;
1634 }
1635
1636 $index++;
1637 return ($tab2_top + ($tab2_hl * $index));
1638 }
1639
1640 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1655 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
1656 {
1657 global $conf;
1658
1659 // Force to disable hidetop and hidebottom
1660 $hidebottom = 0;
1661 if ($hidetop) {
1662 $hidetop = -1;
1663 }
1664
1665 $currency = !empty($currency) ? $currency : $conf->currency;
1666 $default_font_size = pdf_getPDFFontSize($outputlangs);
1667
1668 // Amount in (at tab_top - 1)
1669 $pdf->SetTextColor(0, 0, 0);
1670 $pdf->SetFont('', '', $default_font_size - 2);
1671
1672 if (empty($hidetop)) {
1673 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1674 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1675 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
1676 }
1677
1678 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1679 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1680
1681 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1682 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1683 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
1684 }
1685 }
1686
1687 $pdf->SetDrawColor(128, 128, 128);
1688 $pdf->SetFont('', '', $default_font_size - 1);
1689
1690 // Output Rect
1691 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
1692
1693 if (getDolGlobalString('MAIN_PDF_TITLE_TEXT_COLOR')) {
1694 $arrayColorTextTitle = explode(',', getDolGlobalString('MAIN_PDF_TITLE_TEXT_COLOR'));
1695 $pdf->SetTextColor((float) $arrayColorTextTitle[0], (float) $arrayColorTextTitle[1], (float) $arrayColorTextTitle[2]);
1696 }
1697
1698 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1699
1700 if (getDolGlobalString('MAIN_PDF_TITLE_TEXT_COLOR')) {
1701 $pdf->SetTextColor(0, 0, 0);
1702 }
1703
1704 if (empty($hidetop)) {
1705 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
1706 }
1707 }
1708
1709 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1720 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
1721 {
1722 global $conf, $langs;
1723
1724 $ltrdirection = 'L';
1725 if ($outputlangs->trans("DIRECTION") == 'rtl') {
1726 $ltrdirection = 'R';
1727 }
1728
1729 // Load traductions files required by page
1730 $outputlangs->loadLangs(array("main", "propal", "companies", "bills"));
1731
1732 $default_font_size = pdf_getPDFFontSize($outputlangs);
1733
1734 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1735
1736 $pdf->SetTextColor(0, 0, 60);
1737 $pdf->SetFont('', 'B', $default_font_size + 3);
1738
1739 $w = 100;
1740
1741 $posy = $this->marge_haute;
1742 $posx = $this->page_largeur - $this->marge_droite - $w;
1743
1744 $pdf->SetXY($this->marge_gauche, $posy);
1745
1746 // Logo
1747 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1748 if ($this->emetteur->logo) {
1749 $logodir = $conf->mycompany->dir_output;
1750 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
1751 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
1752 }
1753 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1754 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1755 } else {
1756 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1757 }
1758 if (is_readable($logo)) {
1759 $height = pdf_getHeightForLogo($logo);
1760 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1761 } else {
1762 $pdf->SetTextColor(200, 0, 0);
1763 $pdf->SetFont('', 'B', $default_font_size - 2);
1764 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1765 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1766 }
1767 } else {
1768 $text = $this->emetteur->name;
1769 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1770 }
1771 }
1772
1773 $pdf->SetFont('', 'B', $default_font_size + 3);
1774 $pdf->SetXY($posx, $posy);
1775 $pdf->SetTextColor(0, 0, 60);
1776 $title = $outputlangs->transnoentities("PdfCommercialProposalTitle");
1777 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1778 if ($object->status == $object::STATUS_DRAFT) {
1779 $pdf->SetTextColor(128, 0, 0);
1780 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1781 }
1782
1783 $pdf->MultiCell($w, 4, $title, '', 'R');
1784
1785 $pdf->SetFont('', 'B', $default_font_size);
1786
1787 /*
1788 $posy += 5;
1789 $pdf->SetXY($posx, $posy);
1790 $pdf->SetTextColor(0, 0, 60);
1791 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1792 if ($object->status == $object::STATUS_DRAFT) {
1793 $pdf->SetTextColor(128, 0, 0);
1794 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1795 }
1796 $pdf->MultiCell($w, 4, $textref, '', 'R');
1797 */
1798
1799 $posy += 3;
1800 $pdf->SetFont('', '', $default_font_size - 2);
1801
1802 $ref_customer = $object->ref_customer ?: $object->ref_client;
1803 if ($ref_customer) {
1804 $posy += 4;
1805 $pdf->SetXY($posx, $posy);
1806 $pdf->SetTextColor(0, 0, 60);
1807 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65), '', 'R');
1808 }
1809
1810 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1811 $object->fetchProject();
1812 if (!empty($object->project->ref)) {
1813 $posy += 3;
1814 $pdf->SetXY($posx, $posy);
1815 $pdf->SetTextColor(0, 0, 60);
1816 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1817 $posy = $pdf->getY();
1818 }
1819 }
1820
1821 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1822 $object->fetchProject();
1823 if (!empty($object->project->ref)) {
1824 $outputlangs->load("projects");
1825 $posy += 3;
1826 $pdf->SetXY($posx, $posy);
1827 $pdf->SetTextColor(0, 0, 60);
1828 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1829 }
1830 }
1831
1832 if (getDolGlobalString('MAIN_PDF_DATE_TEXT')) {
1833 $displaydate = "daytext";
1834 } else {
1835 $displaydate = "day";
1836 }
1837
1838 //$posy += 4;
1839 $posy = $pdf->getY();
1840 $pdf->SetXY($posx, $posy);
1841 $pdf->SetTextColor(0, 0, 60);
1842 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, $displaydate, false, $outputlangs, true), '', 'R');
1843
1844 $posy += 4;
1845 $pdf->SetXY($posx, $posy);
1846 $pdf->SetTextColor(0, 0, 60);
1847
1848 $title = $outputlangs->transnoentities("DateEndPropal");
1849 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1850 $title .= ' - '.$outputlangsbis->transnoentities("DateEndPropal");
1851 }
1852 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->fin_validite, $displaydate, false, $outputlangs, true), '', 'R');
1853
1854 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
1855 $posy += 4;
1856 $pdf->SetXY($posx, $posy);
1857 $pdf->SetTextColor(0, 0, 60);
1858 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1859 }
1860
1861 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
1862 $posy += 4;
1863 $pdf->SetXY($posx, $posy);
1864 $pdf->SetTextColor(0, 0, 60);
1865 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
1866 }
1867
1868 // Get contact
1869 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1870 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1871 if (count($arrayidcontact) > 0) {
1872 $usertmp = new User($this->db);
1873 $usertmp->fetch($arrayidcontact[0]);
1874 $posy += 4;
1875 $pdf->SetXY($posx, $posy);
1876 $pdf->SetTextColor(0, 0, 60);
1877 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1878 }
1879 }
1880
1881 $posy += 2;
1882 $shipp_shift = 0;
1883 $top_shift = 0;
1884 // Show list of linked objects
1885 $current_y = $pdf->getY();
1886 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size); // May modify $object->note_public
1887 if ($current_y < $pdf->getY()) {
1888 $top_shift = $pdf->getY() - $current_y;
1889 }
1890
1891 if ($showaddress) {
1892 // Sender properties
1893 $carac_emetteur = '';
1894 // Add internal contact of object if defined
1895 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1896 if (count($arrayidcontact) > 0) {
1897 $object->fetch_user($arrayidcontact[0]);
1898 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1899 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1900 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1901 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1902 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1903 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1904 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1905 $carac_emetteur .= "\n";
1906 }
1907
1908 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1909
1910 // Show sender
1911 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1912 $posy += $top_shift;
1913 $posx = $this->marge_gauche;
1914 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1915 $posx = $this->page_largeur - $this->marge_droite - 80;
1916 }
1917
1918 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1919 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1920
1921
1922 // Show sender frame
1923 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1924 $pdf->SetTextColor(0, 0, 0);
1925 $pdf->SetFont('', '', $default_font_size - 2);
1926 $pdf->SetXY($posx, $posy - 5);
1927 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1928 $pdf->SetXY($posx, $posy);
1929 $pdf->SetFillColor(230, 230, 230);
1930 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1931 $pdf->SetTextColor(0, 0, 60);
1932 }
1933
1934 // Show sender name
1935 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1936 $pdf->SetXY($posx + 2, $posy + 3);
1937 $pdf->SetFont('', 'B', $default_font_size);
1938 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1939 $posy = $pdf->getY();
1940 }
1941
1942 // Show sender information
1943 $pdf->SetXY($posx + 2, $posy);
1944 $pdf->SetFont('', '', $default_font_size - 1);
1945 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1946
1947
1948 // If CUSTOMER contact defined, we use it
1949 $usecontact = false;
1950 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1951 if (count($arrayidcontact) > 0) {
1952 $usecontact = true;
1953 $result = $object->fetch_contact($arrayidcontact[0]);
1954 }
1955
1956 // Recipient name
1957 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1958 $thirdparty = $object->contact;
1959 } else {
1960 $thirdparty = $object->thirdparty;
1961 }
1962
1963 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1964
1965 $mode = 'target';
1966 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
1967
1968 // Show recipient
1969 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1970 if ($this->page_largeur < 210) {
1971 $widthrecbox = 84; // To work with US executive format
1972 }
1973 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1974 $posy += $top_shift;
1975 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1976 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1977 $posx = $this->marge_gauche;
1978 }
1979
1980 // Show recipient frame
1981 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1982 $pdf->SetTextColor(0, 0, 0);
1983 $pdf->SetFont('', '', $default_font_size - 2);
1984 $pdf->SetXY($posx + 2, $posy - 5);
1985 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1986 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1987 }
1988
1989 // Show recipient name
1990 $pdf->SetXY($posx + 2, $posy + 3);
1991 $pdf->SetFont('', 'B', $default_font_size);
1992 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1993 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1994
1995 $posy = $pdf->getY();
1996
1997 // Show recipient information
1998 $pdf->SetFont('', '', $default_font_size - 1);
1999 $pdf->SetXY($posx + 2, $posy);
2000 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2001 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
2002 // Show shipping/delivery addressAdd commentMore actions
2003 if (getDolGlobalInt('PROPOSAL_SHOW_SHIPPING_ADDRESS')) {
2004 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2005
2006 if (!empty($idaddressshipping)) {
2007 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2008 $companystatic = new Societe($this->db);
2009 $companystatic->fetch($object->contact->fk_soc);
2010 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2011 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
2012 } else {
2013 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2014 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2015 }
2016 if (!empty($carac_client_shipping)) {
2017 $posy += $hautcadre;
2018
2019 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2020
2021 // Show shipping frame
2022 $pdf->SetXY($posx + 2, $posy - 5);
2023 $pdf->SetFont('', '', $default_font_size - 2);
2024 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', false);
2025 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2026
2027 // Show shipping name
2028 $pdf->SetXY($posx + 2, $posy + 3);
2029 $pdf->SetFont('', 'B', $default_font_size);
2030 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2031
2032 $posy = $pdf->getY();
2033
2034 // Show shipping information
2035 $pdf->SetXY($posx + 2, $posy);
2036 $pdf->SetFont('', '', $default_font_size - 1);
2037 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2038
2039 $shipp_shift += $hautcadre + 10;
2040 }
2041 }
2042 }
2043 $pdf->SetTextColor(0, 0, 0);
2044
2045 return array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2046 }
2047
2048 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2058 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2059 {
2060 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2061 return pdf_pagefoot($pdf, $outputlangs, 'PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2062 }
2063
2073 protected function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
2074 {
2075 $default_font_size = pdf_getPDFFontSize($outputlangs);
2076 $tab_top = $posy + 4;
2077 $tab_hl = 4;
2078
2079 $posx = 120;
2080 $largcol = ($this->page_largeur - $this->marge_droite - $posx);
2081
2082 // Total HT
2083 $pdf->SetFillColor(255, 255, 255);
2084 $pdf->SetXY($posx, $tab_top);
2085 $pdf->SetFont('', '', $default_font_size - 2);
2086 $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', true);
2087
2088 $pdf->SetXY($posx, $tab_top + $tab_hl + 3);
2089 //$pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
2090 $pdf->RoundedRect($posx, $tab_top + $tab_hl + 3, $largcol, $tab_hl * 3, $this->corner_radius, '1234', 'D');
2091
2092
2093 if (getDolGlobalString('MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING')) {
2094 // Can be retrieve with getSignatureAppearanceArray()
2095 // Can be also detected by putting the mouse over the area when using evince pdf reader
2096 $pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
2097 }
2098
2099 return ($tab_hl * 7);
2100 }
2101
2102
2113 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2114 {
2115 global $hookmanager;
2116
2117 // Default field style for content
2118 $this->defaultContentsFieldsStyle = array(
2119 'align' => 'R', // R,C,L
2120 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2121 );
2122
2123 // Default field style for content
2124 $this->defaultTitlesFieldsStyle = array(
2125 'align' => 'C', // R,C,L
2126 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2127 );
2128
2129 /*
2130 * For example
2131 $this->cols['theColKey'] = array(
2132 'rank' => $rank, // int : use for ordering columns
2133 'width' => 20, // the column width in mm
2134 'title' => array(
2135 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2136 'label' => ' ', // the final label : used fore final generated text
2137 'align' => 'L', // text alignment : R,C,L
2138 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2139 ),
2140 'content' => array(
2141 'align' => 'L', // text alignment : R,C,L
2142 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2143 ),
2144 );
2145 */
2146
2147 $rank = 0; // do not use negative rank
2148 $this->cols['position'] = array(
2149 'rank' => $rank,
2150 'width' => 10,
2151 'status' => getDolGlobalInt('PDF_CYAN_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2152 'title' => array(
2153 'textkey' => '#', // use lang key is useful in some case with module
2154 'align' => 'C',
2155 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2156 // 'label' => ' ', // the final label
2157 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2158 ),
2159 'content' => array(
2160 'align' => 'C',
2161 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2162 ),
2163 );
2164
2165 $rank = 5; // do not use negative rank
2166 $this->cols['desc'] = array(
2167 'rank' => $rank,
2168 'width' => false, // only for desc
2169 'status' => true,
2170 'title' => array(
2171 'textkey' => 'Designation', // use lang key is useful in some case with module
2172 'align' => 'L',
2173 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2174 // 'label' => ' ', // the final label
2175 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2176 ),
2177 'content' => array(
2178 'align' => 'L',
2179 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2180 ),
2181 );
2182
2183 // Image of product
2184 $rank += 10;
2185 $this->cols['photo'] = array(
2186 'rank' => $rank,
2187 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2188 'status' => false,
2189 'title' => array(
2190 'textkey' => 'Photo',
2191 'label' => ' '
2192 ),
2193 'content' => array(
2194 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2195 ),
2196 'border-left' => false, // remove left line separator
2197 );
2198
2199 if (getDolGlobalString('MAIN_GENERATE_PROPOSALS_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2200 $this->cols['photo']['status'] = true;
2201 $this->cols['photo']['border-left'] = true;
2202 }
2203
2204
2205 $rank += 10;
2206 $this->cols['vat'] = array(
2207 'rank' => $rank,
2208 'status' => false,
2209 'width' => 16, // in mm
2210 'title' => array(
2211 'textkey' => 'VAT'
2212 ),
2213 'border-left' => true, // add left line separator
2214 );
2215
2216 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2217 $this->cols['vat']['status'] = true;
2218 }
2219
2220 $rank += 10;
2221 $this->cols['subprice'] = array(
2222 'rank' => $rank,
2223 'width' => 19, // in mm
2224 'status' => true,
2225 'title' => array(
2226 'textkey' => 'PriceUHT'
2227 ),
2228 'border-left' => true, // add left line separator
2229 );
2230
2231 // Adapt dynamically the width of subprice, if text is too long.
2232 $tmpwidth = 0;
2233 $nblines = count($object->lines);
2234 for ($i = 0; $i < $nblines; $i++) {
2235 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2236 $tmpwidth = max($tmpwidth, $tmpwidth2);
2237 }
2238 if ($tmpwidth > 10) {
2239 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2240 }
2241
2242 $rank += 10;
2243 $this->cols['qty'] = array(
2244 'rank' => $rank,
2245 'width' => 16, // in mm
2246 'status' => true,
2247 'title' => array(
2248 'textkey' => 'Qty'
2249 ),
2250 'border-left' => true, // add left line separator
2251 );
2252
2253 $rank += 10;
2254 $this->cols['unit'] = array(
2255 'rank' => $rank,
2256 'width' => 11, // in mm
2257 'status' => false,
2258 'title' => array(
2259 'textkey' => 'Unit'
2260 ),
2261 'border-left' => true, // add left line separator
2262 );
2263 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2264 $this->cols['unit']['status'] = true;
2265 }
2266
2267 $rank += 10;
2268 $this->cols['discount'] = array(
2269 'rank' => $rank,
2270 'width' => 13, // in mm
2271 'status' => false,
2272 'title' => array(
2273 'textkey' => 'ReductionShort'
2274 ),
2275 'border-left' => true, // add left line separator
2276 );
2277 if ($this->atleastonediscount) {
2278 $this->cols['discount']['status'] = true;
2279 }
2280
2281 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2282 $this->cols['totalexcltax'] = array(
2283 'rank' => $rank,
2284 'width' => 26, // in mm
2285 'status' => !getDolGlobalString('PDF_PROPAL_HIDE_PRICE_EXCL_TAX'),
2286 'title' => array(
2287 'textkey' => 'TotalHTShort'
2288 ),
2289 'border-left' => true, // add left line separator
2290 );
2291
2292 $rank += 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2293 $this->cols['totalincltax'] = array(
2294 'rank' => $rank,
2295 'width' => 26, // in mm
2296 'status' => getDolGlobalBool('PDF_PROPAL_SHOW_PRICE_INCL_TAX'),
2297 'title' => array(
2298 'textkey' => 'TotalTTCShort'
2299 ),
2300 'border-left' => true, // add left line separator
2301 );
2302
2303 // Add extrafields cols
2304 if (!empty($object->lines)) {
2305 $line = reset($object->lines);
2306 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2307 }
2308
2309 $parameters = array(
2310 'object' => $object,
2311 'outputlangs' => $outputlangs,
2312 'hidedetails' => $hidedetails,
2313 'hidedesc' => $hidedesc,
2314 'hideref' => $hideref
2315 );
2316
2317 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2318 if ($reshook < 0) {
2319 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2320 } elseif (empty($reshook)) {
2321 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2322 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2323 } else {
2324 $this->cols = $hookmanager->resArray;
2325 }
2326 }
2327}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage bank accounts.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
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
getMaxAfterColsLinePositionsData()
Get position in PDF after col display.
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
Used for to set afterColsLinePositions var in a pdf draw line loop.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
resetAfterColsLinePositionsData(float $y, int $pageNumb)
Used for reset afterColsLinePositions var in start of a new pdf draw line loop.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage hooks.
Class mere des modeles de propale.
Class to manage products or services.
Put here description of your class.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class to generate PDF proposal Cyan.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis=null)
Show total to pay.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
__construct($db)
Constructor.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
Show area for the customer to sign.
drawInfoTable(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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 '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:2881
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2580
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0, $multicurrency=0)
Return line total amount discount.
Definition pdf.lib.php:2913
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:312
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition pdf.lib.php:2630
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1110
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2169
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2107
pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
Function to try to calculate height of a HTML Content.
Definition pdf.lib.php:337
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:742
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1497
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:928
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:268
pdf_render_subtotals(TCPDF $pdf, CommonDocGenerator $generator, float $curY, CommonObject $object, int $i, Translate $outputlangs, int $hideref, int $hidedesc, array $bgColor, bool $isSubtotal=false, bool $applySubtotalLogic=true)
Render subtotals line with a colored background and adapted text color .
Definition pdf.lib.php:3011
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:433
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2414
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2457
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2254
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:824
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:388
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:132
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:135