dolibarr 24.0.3
pdf_eratosthene.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-2013 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-2026 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 Joachim Kueter <git-jk@bloxera.com>
15 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 * or see https://www.gnu.org/
30 */
31
38require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
39require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
43
48{
52 public $db;
53
57 public $entity;
58
62 public $name;
63
67 public $description;
68
72 public $update_main_doc_field;
73
77 public $type;
78
83 public $version = 'dolibarr';
84
88 public $cols;
89
90
96 public function __construct(DoliDB $db)
97 {
98 global $conf, $langs, $mysoc;
99
100 // Translations
101 $langs->loadLangs(array("main", "bills", "products"));
102
103 $this->db = $db;
104 $this->name = "eratosthene";
105 $this->description = $langs->trans('PDFEratostheneDescription');
106 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
107
108 // Dimension page
109 $this->type = 'pdf';
110 $formatarray = pdf_getFormat();
111 $this->page_largeur = $formatarray['width'];
112 $this->page_hauteur = $formatarray['height'];
113 $this->format = array($this->page_largeur, $this->page_hauteur);
114 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
115 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
116 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
117 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
118 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
119 $this->option_logo = 1; // Display logo
120 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
121 $this->option_modereg = 1; // Display payment mode
122 $this->option_condreg = 1; // Display payment terms
123 $this->option_multilang = 1; // Available in several languages
124 $this->option_escompte = 0; // Displays if there has been a discount
125 $this->option_credit_note = 0; // Support credit notes
126 $this->option_freetext = 1; // Support add of a personalised text
127 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
128 $this->watermark = '';
129
130 $this->showAmountBeforeDiscount = getDolGlobalInt('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT') || getDolGlobalInt('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT_ORDER') ? 0 : 1;
131 $this->showDiscountAmount = getDolGlobalInt('MAIN_HIDE_AMOUNT_DISCOUNT') || getDolGlobalInt('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT_ORDER') ? 0 : 1;
132
133
134 if ($mysoc === null) {
135 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
136 return;
137 }
138
139 // Get source company
140 $this->emetteur = $mysoc;
141 if (empty($this->emetteur->country_code)) {
142 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
143 }
144
145 // Define position of columns
146 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
147
148
149 $this->tabTitleHeight = 5; // default height
150
151 // Use new system for position of columns, view $this->defineColumnField()
152
153 $this->tva = array();
154 $this->tva_array = array();
155 $this->localtax1 = array();
156 $this->localtax2 = array();
157 $this->atleastoneratenotnull = 0;
158 $this->atleastonediscount = 0;
159 }
160
161 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
173 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
174 {
175 // phpcs:enable
176 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
177
178 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
179
180 if (!is_object($outputlangs)) {
181 $outputlangs = $langs;
182 }
183 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
184 if (getDolGlobalInt('MAIN_USE_FPDF')) {
185 $outputlangs->charset_output = 'ISO-8859-1';
186 }
187
188 // Load translation files required by the page
189 $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "sendginds", "compta"));
190
191 // Show Draft Watermark
192 if ($object->statut == $object::STATUS_DRAFT && getDolGlobalString('COMMANDE_DRAFT_WATERMARK')) {
193 $this->watermark = getDolGlobalString('COMMANDE_DRAFT_WATERMARK');
194 }
195
196 global $outputlangsbis;
197 $outputlangsbis = null;
198 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
199 $outputlangsbis = new Translate('', $conf);
200 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
201 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "sendginds", "compta"));
202 }
203
204 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
205
206 $hidetop = getDolGlobalInt('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
207
208 // Loop on each lines to detect if there is at least one image to show
209 $realpatharray = array();
210 $this->atleastonephoto = false;
211 if (getDolGlobalInt('MAIN_GENERATE_ORDERS_WITH_PICTURE')) {
212 $objphoto = new Product($this->db);
213
214 for ($i = 0; $i < $nblines; $i++) {
215 if (empty($object->lines[$i]->fk_product)) {
216 continue;
217 }
218
219 $pdir = array();
220
221 $objphoto->fetch($object->lines[$i]->fk_product);
222 //var_dump($objphoto->ref);exit;
223 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
224 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
225 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
226 } else {
227 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
228 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
229 }
230
231 $arephoto = false;
232 $realpath = null;
233 foreach ($pdir as $midir) {
234 if (!$arephoto) {
235 $entity = $objphoto->entity;
236 if ($entity !== null && $conf->entity != $entity) {
237 $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
238 } else {
239 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
240 }
241
242 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
243 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
244 if ($obj['photo_vignette']) {
245 $filename = $obj['photo_vignette'];
246 } else {
247 $filename = $obj['photo'];
248 }
249 } else {
250 $filename = $obj['photo'];
251 }
252
253 $realpath = $dir.$filename;
254 $arephoto = true;
255 $this->atleastonephoto = true;
256 }
257 }
258 }
259
260 if ($realpath && $arephoto) {
261 $realpatharray[$i] = $realpath;
262 }
263 }
264 }
265
266
267
269 $object->fetch_thirdparty();
270
271 $deja_regle = 0;
272
273 // Definition of $dir and $file
274 if ($object->specimen) {
276 $file = $dir."/SPECIMEN.pdf";
277 } else {
278 $objectref = dol_sanitizeFileName($object->ref);
279 $dir = getMultidirOutput($object)."/".$objectref;
280 $file = $dir."/".$objectref.".pdf";
281 }
282
283 if ($dir === null) {
284 dol_syslog(get_class($this).'::'.__METHOD__."Target directory should not be null.". getCallerInfoString(), LOG_ERR);
285 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", "Null dir");
286 return 0;
287 }
288
289 if (!file_exists($dir)) {
290 if (dol_mkdir($dir) < 0) {
291 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
292 return 0;
293 }
294 }
295
296 if (file_exists($dir)) {
297 // Add pdfgeneration hook
298 if (!is_object($hookmanager)) {
299 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
300 $hookmanager = new HookManager($this->db);
301 }
302 $hookmanager->initHooks(array('pdfgeneration'));
303 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
304 global $action;
305 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
306
307 // Set nblines with the new lines content after hook
308 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
309
310 // Create pdf instance
311 $pdf = pdf_getInstance($this->format);
312 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
313 $pdf->setAutoPageBreak(true, 0);
314
315 $heightforinfotot = 40; // Height reserved to output the info and total part
316 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
317 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
318 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
319 $heightforfooter += 6;
320 }
321
322 if (class_exists('TCPDF')) {
323 $pdf->setPrintHeader(false);
324 $pdf->setPrintFooter(false);
325 }
326 $pdf->SetFont(pdf_getPDFFont($outputlangs));
327 // Set path to the background PDF File
328 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
329 $logodir = $conf->mycompany->dir_output;
330 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
331 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
332 }
333 $pagecount = $pdf->setSourceFile($logodir.'/'.getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
334 $tplidx = $pdf->importPage(1);
335 }
336
337 $pdf->Open();
338 $pagenb = 0;
339 $pdf->SetDrawColor(128, 128, 128);
340
341 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
342 $pdf->SetSubject($outputlangs->transnoentities("PdfOrderTitle"));
343 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
344 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
345 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfOrderTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
346 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
347 $pdf->SetCompression(false);
348 }
349
350 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
351 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
352
353 // Set $this->atleastonediscount if you have at least one discount
354 for ($i = 0; $i < $nblines; $i++) {
355 if ($object->lines[$i]->remise_percent) {
356 $this->atleastonediscount++;
357 }
358 }
359
360
361 // New page
362 $pdf->AddPage();
363 if (!empty($tplidx)) {
364 $pdf->useTemplate($tplidx);
365 }
366 $pagenb++;
367 $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
368 $top_shift = $pagehead['top_shift'];
369 $shipp_shift = $pagehead['shipp_shift'];
370 $pdf->SetFont('', '', $default_font_size - 1);
371 $pdf->MultiCell(0, 3, ''); // Set interline to 3
372 $pdf->SetTextColor(0, 0, 0);
373
374
375 $tab_top = 80 + $this->marge_haute + $top_shift + $shipp_shift;
376 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
377 if (!$hidetop && getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
378 // TODO : make this hidden conf the default behavior for each PDF when each PDF managed this new Display
379 $tab_top_newpage += $this->tabTitleHeight;
380 }
381
382 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
383
384 $nexY = $tab_top - 1;
385
386 // Incoterm
387 $height_incoterms = 0;
388 if (isModEnabled('incoterm')) {
389 $desc_incoterms = $object->getIncotermsForPDF();
390 if ($desc_incoterms) {
391 $tab_top -= 2;
392
393 $pdf->SetFont('', '', $default_font_size - 1);
394 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
395 $nexY = max($pdf->GetY(), $nexY);
396 $height_incoterms = $nexY - $tab_top;
397
398 // Rect takes a length in 3rd parameter
399 $pdf->SetDrawColor(192, 192, 192);
400 $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');
401
402 $tab_top = $nexY + 6;
403 }
404 }
405
406 // Display notes
407 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
408 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
409 // Get first sale rep
410 if (is_object($object->thirdparty)) {
411 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
412 $salerepobj = new User($this->db);
413 $salerepobj->fetch($salereparray[0]['id']);
414 if (!empty($salerepobj->signature)) {
415 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
416 }
417 }
418 }
419 // Extrafields in note
420 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
421 if (!empty($extranote)) {
422 $notetoshow = dol_concatdesc((string) $notetoshow, $extranote);
423 }
424
425 $pagenb = $pdf->getPage();
426 if ($notetoshow) {
427 $tab_top -= 2;
428
429 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
430 $pageposbeforenote = $pagenb;
431
432 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
433 complete_substitutions_array($substitutionarray, $outputlangs, $object);
434 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
435 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
436
437 $pdf->startTransaction();
438
439 $pdf->SetFont('', '', $default_font_size - 1);
440 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
441 // Description
442 $pageposafternote = $pdf->getPage();
443 $posyafter = $pdf->GetY();
444
445 if ($pageposafternote > $pageposbeforenote) {
446 $pdf->rollbackTransaction(true);
447
448 // prepare pages to receive notes
449 while ($pagenb < $pageposafternote) {
450 $pdf->AddPage();
451 $pagenb++;
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
454 }
455 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
456 $this->_pagehead($pdf, $object, 0, $outputlangs);
457 }
458 // $this->_pagefoot($pdf,$object,$outputlangs,1);
459 $pdf->setTopMargin($tab_top_newpage);
460 // The only function to edit the bottom margin of current page to set it.
461 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
462 }
463
464 // back to start
465 $pdf->setPage($pageposbeforenote);
466 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
467 $pdf->SetFont('', '', $default_font_size - 1);
468 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
469 $pageposafternote = $pdf->getPage();
470
471 $posyafter = $pdf->GetY();
472
473 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
474 $pdf->AddPage('', '', true);
475 $pagenb++;
476 $pageposafternote++;
477 $pdf->setPage($pageposafternote);
478 $pdf->setTopMargin($tab_top_newpage);
479 // The only function to edit the bottom margin of current page to set it.
480 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
481 //$posyafter = $tab_top_newpage;
482 }
483
484
485 // apply note frame to previous pages
486 $i = $pageposbeforenote;
487 while ($i < $pageposafternote) {
488 $pdf->setPage($i);
489
490
491 $pdf->SetDrawColor(128, 128, 128);
492 // Draw note frame
493 if ($i > $pageposbeforenote) {
494 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
495 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
496 } else {
497 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
498 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
499 }
500
501 // Add footer
502 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
503 $this->_pagefoot($pdf, $object, $outputlangs, 1);
504
505 $i++;
506 }
507
508 // apply note frame to last page
509 $pdf->setPage($pageposafternote);
510 if (!empty($tplidx)) {
511 $pdf->useTemplate($tplidx);
512 }
513 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
514 $this->_pagehead($pdf, $object, 0, $outputlangs);
515 }
516 $height_note = $posyafter - $tab_top_newpage;
517 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
518 } else {
519 // No pagebreak
520 $pdf->commitTransaction();
521 $posyafter = $pdf->GetY();
522 $height_note = $posyafter - $tab_top;
523 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
524
525
526 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
527 // not enough space, need to add page
528 $pdf->AddPage('', '', true);
529 $pagenb++;
530 $pageposafternote++;
531 $pdf->setPage($pageposafternote);
532 if (!empty($tplidx)) {
533 $pdf->useTemplate($tplidx);
534 }
535 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
536 $this->_pagehead($pdf, $object, 0, $outputlangs);
537 }
538
539 $posyafter = $tab_top_newpage;
540 }
541 }
542
543 $tab_height -= $height_note;
544 $tab_top = $posyafter + 6;
545 } else {
546 $height_note = 0;
547 }
548
549
550 // Use new auto column system
551 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
552
553 // Table simulation to know the height of the title line
554 $pdf->startTransaction();
555 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
556 $pdf->rollbackTransaction(true);
557
558 $nexY = $tab_top + $this->tabTitleHeight;
559
560 // Loop on each lines
561 $pageposbeforeprintlines = $pdf->getPage();
562 $pagenb = $pageposbeforeprintlines;
563
564 $pdf_sub_options = array();
565 $pdf_sub_options['titleshowuponpdf'] = 1;
566 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = 1;
567 $pdf_sub_options_before_title = array(); // Options in use before each title line, by level
568
569 $hidenextline = 0;
570
571 for ($i = 0; $i < $nblines; $i++) {
572 $linePosition = $i + 1;
573 $curY = $nexY;
574
575 $sub_options = $object->lines[$i]->extraparams["subtotal"] ?? array();
576
577 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
578 $level = $object->lines[$i]->qty;
579 // Keep the options in use before a title line, to restore them after the subtotal line that closes its block
580 if ($level > 0 && !isset($pdf_sub_options_before_title[(int) $level])) {
581 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
582 }
583 if ($sub_options) {
584 $hidenextline = 0;
585 if (isset($sub_options['titleshowuponpdf'])) {
586 $pdf_sub_options['titleshowuponpdf'] = isset($pdf_sub_options['titleshowuponpdf']) && $pdf_sub_options['titleshowuponpdf'] < $level ? $pdf_sub_options['titleshowuponpdf'] : $level;
587 } elseif (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
588 unset($pdf_sub_options['titleshowuponpdf']);
589 }
590 if (isset($sub_options['titleshowtotalexludingvatonpdf'])) {
591 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && $pdf_sub_options['titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options['titleshowtotalexludingvatonpdf'] : $level;
592 } elseif (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
593 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
594 }
595 } else {
596 if (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
597 unset($pdf_sub_options['titleshowuponpdf']);
598 }
599 if (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
600 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
601 }
602 }
603 // 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
604 if ($level < 0 && isset($pdf_sub_options_before_title[(int) abs($level)])) {
605 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
606 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
607 if ($tmplevel >= abs($level)) {
608 unset($pdf_sub_options_before_title[$tmplevel]);
609 }
610 }
611 }
612 }
613
614 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
615 $hidenextline = 0;
616 $pdf_sub_options = array();
617 $pdf_sub_options['titleshowuponpdf'] = 1;
618 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = 1;
619 }
620
621 //var_dump($i, $sub_options, $hidenextline);
622 if ($hidenextline) {
623 $linePosition--;
624 } else {
625 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options['titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
626 $object->lines[$i]->pagebreak = true;
627 }
628
629 // in First Check line page break and add page if needed
630 if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
631 // New page
632 $pdf->AddPage();
633 if (!empty($tplidx)) {
634 $pdf->useTemplate($tplidx);
635 }
636
637 $pdf->setPage($pdf->getNumPages());
638 $nexY = $curY = $tab_top_newpage;
639 }
640
641 $this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
642
643
644 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
645 $pdf->SetTextColor(0, 0, 0);
646
647 // Define size of image if we need it
648 $imglinesize = array();
649 if (!empty($realpatharray[$i])) {
650 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
651 }
652
653 $pdf->setTopMargin($tab_top_newpage);
654 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
655 $pageposbefore = $pdf->getPage();
656 $curYBefore = $curY;
657
658 // Allows data in the first page if description is long enough to break in multiples pages
659 $showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
660 $posYAfterImage = 0;
661
662 if ($this->getColumnStatus('photo')) {
663 // We start with Photo of product line
664 $imageTopMargin = 1;
665 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
666 $pdf->AddPage('', '', true);
667 if (!empty($tplidx)) {
668 $pdf->useTemplate($tplidx);
669 }
670 $pdf->setPage($pageposbefore + 1);
671 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
672 $curY = $tab_top_newpage;
673 $showpricebeforepagebreak = 0;
674 }
675
676 // I remove the line commented below because it probably uselesss (or bug source) no need to change bottom margin because we have checked image fit
677 //$pdf->setPageOrientation('', 0, $heightforfooter + $heightforfreetext); // The only function to edit the bottom margin of current page to set it.
678
679 // @phan-suppress-next-line PhanTypeMismatchProperty
680 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
681 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
682 // $pdf->Image does not increase value return by getY, so we save it manually
683 $posYAfterImage = $curY + $imglinesize['height'];
684 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
685 }
686 }
687
688 // restore Page orientation for text
689 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
690
691 // Description of product line
692 if ($this->getColumnStatus('desc')) {
693 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
694 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
695 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
696 } else {
697 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty), 'ffffff'));
698 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
699 }
700 }
701
702 $afterPosData = $this->getMaxAfterColsLinePositionsData();
703 $pdf->setPage($pageposbefore);
704 $pdf->setTopMargin($this->marge_haute);
705 $pdf->setPageOrientation('', false, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
706
707 // We suppose that a too long description or photo were moved completely on next page
708 if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
709 $pdf->setPage($afterPosData['page']);
710 $curY = $tab_top_newpage;
711 }
712
713 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
714
715 // Line position
716 if ($this->getColumnStatus('position')) {
717 $this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
718 }
719
720 // VAT Rate
721 if ($this->getColumnStatus('vat') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
722 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
723 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
724 }
725
726 // Unit price before discount
727 if ($this->getColumnStatus('subprice') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowuponpdf'])) {
728 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
729 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
730 }
731
732 // Quantity
733 // Enough for 6 chars
734 if ($this->getColumnStatus('qty') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
735 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
736 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
737 }
738
739
740 // Unit
741 if ($this->getColumnStatus('unit') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
742 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
743 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
744 }
745
746 // Discount on line
747 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
748 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
749 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
750 }
751
752 // Total excl tax line (HT)
753 if ($this->getColumnStatus('totalexcltax')) {
754 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowtotalexludingvatonpdf'])) {
755 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
756 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
757 } elseif ($object->lines[$i]->qty < 0 && isset($sub_options['subtotalshowtotalexludingvatonpdf'])) {
758 if (isModEnabled('multicurrency') && $object->multicurrency_code != getDolCurrency()) {
759 $total_excl_tax = $object->getSubtotalLineMulticurrencyAmount($object->lines[$i]);
760 } else {
761 $total_excl_tax = $object->getSubtotalLineAmount($object->lines[$i]);
762 }
763 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
764 }
765 }
766
767 // Total with tax line (TTC)
768 if ($this->getColumnStatus('totalincltax') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
769 $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
770 $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
771 }
772
773 // Extrafields
774 if (!empty($object->lines[$i]->array_options)) {
775 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
776 if ($this->getColumnStatus($extrafieldColKey)) {
777 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
778 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
779 $this->setAfterColsLinePositionsData('options_'.$extrafieldColKey, $pdf->GetY(), $pdf->getPage());
780 }
781 }
782 }
783
784 $afterPosData = $this->getMaxAfterColsLinePositionsData();
785 $parameters = array(
786 'object' => $object,
787 'i' => $i,
788 'pdf' => & $pdf,
789 'curY' => & $curY,
790 'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
791 'outputlangs' => $outputlangs,
792 'hidedetails' => $hidedetails
793 );
794 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
795 }
796
797 // Collection of totals by value of vat in $this->tva["rate"] = total_tva
798 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
799 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
800 } else {
801 $tvaligne = $object->lines[$i]->total_tva;
802 }
803
804 $localtax1ligne = $object->lines[$i]->total_localtax1;
805 $localtax2ligne = $object->lines[$i]->total_localtax2;
806 $localtax1_rate = $object->lines[$i]->localtax1_tx;
807 $localtax2_rate = $object->lines[$i]->localtax2_tx;
808 $localtax1_type = $object->lines[$i]->localtax1_type;
809 $localtax2_type = $object->lines[$i]->localtax2_type;
810
811 $vatrate = (string) $object->lines[$i]->tva_tx;
812
813 // Retrieve type from database for backward compatibility with old records
814 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
815 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
816 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
817 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
818 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
819 }
820
821 // retrieve global local tax
822 if ($localtax1_type && $localtax1ligne != 0) {
823 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
824 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
825 } else {
826 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
827 }
828 }
829 if ($localtax2_type && $localtax2ligne != 0) {
830 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
831 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
832 } else {
833 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
834 }
835 }
836
837 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
838 $vatrate .= '*';
839 }
840
841 // Fill $this->tva and $this->tva_array
842 if (!isset($this->tva[$vatrate])) {
843 $this->tva[$vatrate] = 0;
844 }
845 $this->tva[$vatrate] += $tvaligne;
846 $vatcode = $object->lines[$i]->vat_src_code;
847 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
848 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
849 }
850 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
851
852
853 if (!$hidenextline) {
854 $afterPosData = $this->getMaxAfterColsLinePositionsData();
855 $pdf->setPage($afterPosData['page']);
856 $nexY = $afterPosData['y'];
857
858 // Add line
859 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $heightforfooter - 5) {
860 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
861 //$pdf->SetDrawColor(190,190,200);
862 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
863 $pdf->SetLineStyle(array('dash' => 0));
864 }
865 }
866 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
867 $hidenextline = 1;
868 }
869
870 $nexY += 0; // Add space between lines
871 }
872
873 // Add last page for document footer if there are not enough size left
874 $afterPosData = $this->getMaxAfterColsLinePositionsData();
875 if (isset($afterPosData['y']) && $afterPosData['y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
876 $pdf->AddPage();
877 if (!empty($tplidx)) {
878 $pdf->useTemplate($tplidx);
879 }
880 $pagenb++;
881 $pdf->setPage($pagenb);
882 }
883
884 // Draw table frames and columns borders
885 $drawTabNumbPage = $pdf->getNumPages();
886 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
887 $pdf->setPage($i);
888 // reset page orientation each loop to override it if it was changed
889 $pdf->setPageOrientation('', false, 0); // The only function to edit the bottom margin of current page to set it.
890
891 $drawTabHideTop = $hidetop;
892 $drawTabTop = $tab_top_newpage;
893 $drawTabBottom = $this->page_hauteur - $heightforfooter;
894 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
895
896 if ($i == $pageposbeforeprintlines) {
897 // first page need to start after notes
898 $drawTabTop = $tab_top;
899 } elseif (!$drawTabHideTop) {
900 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
901 $drawTabTop -= $this->tabTitleHeight;
902 } else {
903 $drawTabHideTop = 1;
904 }
905 }
906
907 // last page need to include document footer
908 if ($i == $pdf->getNumPages()) {
909 // remove document footer height to tab bottom position
910 $drawTabBottom -= $heightforfreetext + $heightforinfotot;
911 }
912
913 $drawTabHeight = $drawTabBottom - $drawTabTop;
914 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object->multicurrency_code, $outputlangsbis);
915
916 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
917 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText);
918
919 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
920
921 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
922 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
923
924 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
925 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
926 $this->_pagehead($pdf, $object, 0, $outputlangs);
927 }
928 if (!empty($tplidx)) {
929 $pdf->useTemplate($tplidx);
930 }
931 }
932
933 // reset text color before print footers
934 $pdf->SetTextColor(0, 0, 0);
935
936 $pdf->setPage($pdf->getNumPages());
937
938 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
939
940 // Display infos area
941 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
942
943 // Display total zone
944 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
945
946
947 // Add number of pages in footer
948 if (method_exists($pdf, 'AliasNbPages')) {
949 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
950 }
951
952 // Add terms to sale
953 $termsofsalefilename = getDolGlobalString('MAIN_INFO_ORDER_TERMSOFSALE');
954 if (getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_ORDER') && $termsofsalefilename) {
955 $termsofsale = $conf->order->dir_output.'/'.$termsofsalefilename;
956 if (!empty($conf->order->multidir_output[$conf->entity])) {
957 $termsofsale = $conf->order->multidir_output[$conf->entity].'/'.$termsofsalefilename;
958 }
959 if (file_exists($termsofsale) && is_readable($termsofsale)) {
960 $pagecount = $pdf->setSourceFile($termsofsale);
961 for ($i = 1; $i <= $pagecount; $i++) {
962 $tplIdx = $pdf->importPage($i);
963 if ($tplIdx !== false) {
964 $s = $pdf->getTemplatesize($tplIdx);
965 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
966 $pdf->useTemplate($tplIdx);
967 } else {
968 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
969 }
970 }
971 }
972 }
973
974 $pdf->Close();
975
976 $pdf->Output($file, 'F');
977
978 // Add pdfgeneration hook
979 $hookmanager->initHooks(array('pdfgeneration'));
980 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
981 global $action;
982 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
983 $this->warnings = $hookmanager->warnings;
984 if ($reshook < 0) {
985 $this->error = $hookmanager->error;
986 $this->errors = $hookmanager->errors;
987 dolChmod($file);
988 return -1;
989 }
990
991 dolChmod($file);
992
993 $this->result = array('fullpath' => $file);
994
995 return 1; // No error
996 } else {
997 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
998 return 0;
999 }
1000 } else {
1001 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
1002 return 0;
1003 }
1004 }
1005
1015 protected function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1016 {
1017 return 0;
1018 }
1019
1029 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
1030 {
1031 global $conf, $mysoc;
1032 $default_font_size = pdf_getPDFFontSize($outputlangs);
1033
1034 $pdf->SetFont('', '', $default_font_size - 1);
1035
1036 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1037
1038 // If France, show VAT mention if not applicable
1039 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1040 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1041 $pdf->SetXY($this->marge_gauche, $posy);
1042 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1043
1044 $posy = $pdf->GetY() + 4;
1045 }
1046
1047 $posxval = 52;
1048
1049 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1050
1051 // Show payments conditions
1052 if ($object->cond_reglement_code || $object->cond_reglement) {
1053 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1054 $pdf->SetXY($this->marge_gauche, $posy);
1055 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1056 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1057
1058 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1059 $pdf->SetXY($posxval, $posy);
1060 $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);
1061 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1062 if ($object->deposit_percent > 0) {
1063 $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', (string) $object->deposit_percent, $lib_condition_paiement);
1064 }
1065 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1066
1067 $posy = $pdf->GetY() + 3;
1068 }
1069
1070 // Check a payment mode is defined
1071 /* Not used with orders
1072 if (empty($object->mode_reglement_code)
1073 && ! $conf->global->FACTURE_CHQ_NUMBER
1074 && ! $conf->global->FACTURE_RIB_NUMBER)
1075 {
1076 $pdf->SetXY($this->marge_gauche, $posy);
1077 $pdf->SetTextColor(200,0,0);
1078 $pdf->SetFont('','B', $default_font_size - 2);
1079 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
1080 $pdf->SetTextColor(0,0,0);
1081
1082 $posy=$pdf->GetY()+1;
1083 }
1084 */
1085 /* TODO
1086 else if (!empty($object->availability_code))
1087 {
1088 $pdf->SetXY($this->marge_gauche, $posy);
1089 $pdf->SetTextColor(200,0,0);
1090 $pdf->SetFont('','B', $default_font_size - 2);
1091 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
1092 $pdf->SetTextColor(0,0,0);
1093
1094 $posy=$pdf->GetY()+1;
1095 }*/
1096
1097 // Show planned date of delivery
1098 if (!empty($object->delivery_date)) {
1099 $outputlangs->load("sendings");
1100 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1101 $pdf->SetXY($this->marge_gauche, $posy);
1102 $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
1103 $pdf->MultiCell(80, 4, $titre, 0, 'L');
1104 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1105 $pdf->SetXY($posxval, $posy);
1106 $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
1107 $pdf->MultiCell(80, 4, $dlp, 0, 'L');
1108
1109 $posy = $pdf->GetY() + 1;
1110 } elseif ($object->availability_code || $object->availability) { // Show availability conditions
1111 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1112 $pdf->SetXY($this->marge_gauche, $posy);
1113 $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
1114 $pdf->MultiCell(80, 4, $titre, 0, 'L');
1115 $pdf->SetTextColor(0, 0, 0);
1116 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1117 $pdf->SetXY($posxval, $posy);
1118 $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != 'AvailabilityType'.$object->availability_code ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
1119 $lib_availability = str_replace('\n', "\n", $lib_availability);
1120 $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
1121
1122 $posy = $pdf->GetY() + 1;
1123 }
1124
1125 // Show payment mode
1126 if ($object->mode_reglement_code
1127 && $object->mode_reglement_code != 'CHQ'
1128 && $object->mode_reglement_code != 'VIR') {
1129 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1130 $pdf->SetXY($this->marge_gauche, $posy);
1131 $titre = $outputlangs->transnoentities("PaymentMode").':';
1132 $pdf->MultiCell(80, 5, $titre, 0, 'L');
1133
1134 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1135 $pdf->SetXY($posxval, $posy);
1136 $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);
1137 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1138
1139 $posy = $pdf->GetY() + 2;
1140 }
1141
1142 // Show payment mode CHQ
1143 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1144 // Si mode reglement non force ou si force a CHQ
1145 if (getDolGlobalString('FACTURE_CHQ_NUMBER')) {
1146 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1147 $account = new Account($this->db);
1148 $account->fetch(getDolGlobalString('FACTURE_CHQ_NUMBER'));
1149
1150 $pdf->SetXY($this->marge_gauche, $posy);
1151 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1152 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1153 $posy = $pdf->GetY() + 1;
1154
1155 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1156 $pdf->SetXY($this->marge_gauche, $posy);
1157 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1158 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1159 $posy = $pdf->GetY() + 2;
1160 }
1161 }
1162 if (getDolGlobalString('FACTURE_CHQ_NUMBER') == -1) {
1163 $pdf->SetXY($this->marge_gauche, $posy);
1164 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1165 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1166 $posy = $pdf->GetY() + 1;
1167
1168 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1169 $pdf->SetXY($this->marge_gauche, $posy);
1170 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1171 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1172 $posy = $pdf->GetY() + 2;
1173 }
1174 }
1175 }
1176 }
1177
1178 // If payment mode not forced or forced to VIR, show payment with BAN
1179 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1180 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1181 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1182 if ($object->fk_bank > 0) {
1183 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1184 }
1185 $account = new Account($this->db);
1186 $account->fetch($bankid);
1187
1188 $curx = $this->marge_gauche;
1189 $cury = $posy;
1190
1191 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1192
1193 $posy += 2;
1194 }
1195 }
1196
1197 return $posy;
1198 }
1199
1200
1212 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
1213 {
1214 global $conf, $mysoc, $hookmanager;
1215
1216 $default_font_size = pdf_getPDFFontSize($outputlangs);
1217
1218 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1219 $outputlangsbis = new Translate('', $conf);
1220 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1221 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1222 $default_font_size--;
1223 }
1224
1225 $tab2_top = $posy;
1226 $tab2_hl = 4;
1227 $pdf->SetFont('', '', $default_font_size - 1);
1228
1229 // Total table
1230 $col1x = 120;
1231 $col2x = 170;
1232 if ($this->page_largeur < 210) { // To work with US executive format
1233 $col2x -= 20;
1234 }
1235 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1236
1237 $useborder = 0;
1238 $index = 0;
1239
1240 // Get Total HT
1241 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1242
1243 // Total discount
1244 $total_discount_on_lines = 0;
1245 $multicurrency_total_discount_on_lines = 0;
1246 foreach ($object->lines as $i => $line) {
1247 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1248 $multicurrency_resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2, 1);
1249
1250 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1251 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1252 // If line was a negative line, we do not count the discount as a discount
1253 if ($line->total_ht < 0) {
1254 $total_discount_on_lines += -$line->total_ht;
1255 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1256 }
1257 }
1258
1259 if ($total_discount_on_lines > 0) {
1260 if ($this->showAmountBeforeDiscount) {
1261 // Show total NET before discount
1262 $pdf->SetFillColor(255, 255, 255);
1263 $pdf->SetXY($col1x, $tab2_top);
1264 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount") . (is_object($outputlangsbis) ? ' / ' . $outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', true);
1265 $pdf->SetXY($col2x, $tab2_top);
1266
1267 $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));
1268 $pdf->MultiCell($largcol2, $tab2_hl, price($total_before_discount_to_show, 0, $outputlangs), 0, 'R', true);
1269
1270 $index++;
1271 }
1272
1273 if ($this->showDiscountAmount) {
1274 $pdf->SetFillColor(255, 255, 255);
1275 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1276 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount") . (is_object($outputlangsbis) ? ' / ' . $outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', true);
1277 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1278
1279 $total_discount_to_show = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1280 $pdf->MultiCell($largcol2, $tab2_hl, price($total_discount_to_show, 0, $outputlangs), 0, 'R', true);
1281
1282 $index++;
1283 }
1284 }
1285
1286 // Total HT
1287 $pdf->SetFillColor(255, 255, 255);
1288 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1289 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', true);
1290 $total_ht = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1291 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1292 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', true);
1293
1294 // Show VAT by rates and total
1295 $pdf->SetFillColor(248, 248, 248);
1296
1297 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1298 $total_ttc_origin = $object->total_ttc;
1299
1300 $this->atleastoneratenotnull = 0;
1301 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1302 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1303 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1304 // Nothing to do
1305 } else {
1306 //Local tax 1 before VAT
1307 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1308 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1309 continue;
1310 }
1311 foreach ($localtax_rate as $tvakey => $tvaval) {
1312 if ($tvakey != 0) { // On affiche pas taux 0
1313 //$this->atleastoneratenotnull++;
1314 $index++;
1315 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1316
1317 $tvacompl = '';
1318 if (preg_match('/\*/', (string) $tvakey)) {
1319 $tvakey = str_replace('*', '', (string) $tvakey);
1320 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1321 }
1322 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1323 $totalvat .= ' ';
1324
1325 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1326 $totalvat .= $tvacompl;
1327 } else {
1328 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1329 }
1330
1331 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1332
1333 $total_localtax = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1334
1335 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1336 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1337 }
1338 }
1339 }
1340
1341 //Local tax 2 before VAT
1342 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1343 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1344 continue;
1345 }
1346 foreach ($localtax_rate as $tvakey => $tvaval) {
1347 if ($tvakey != 0) { // On affiche pas taux 0
1348 //$this->atleastoneratenotnull++;
1349
1350 $index++;
1351 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1352
1353 $tvacompl = '';
1354 if (preg_match('/\*/', (string) $tvakey)) {
1355 $tvakey = str_replace('*', '', (string) $tvakey);
1356 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1357 }
1358 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1359 $totalvat .= ' ';
1360
1361 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1362 $totalvat .= $tvacompl;
1363 } else {
1364 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1365 }
1366
1367 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1368
1369 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1370
1371 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1372 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1373 }
1374 }
1375 }
1376
1377 // VAT
1378 foreach ($this->tva_array as $tvakey => $tvaval) {
1379 if ((float) $tvakey != 0) { // On affiche pas taux 0, $tvakey can be 'rate (code)'
1380 $this->atleastoneratenotnull++;
1381
1382 $index++;
1383 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1384
1385 $tvacompl = '';
1386 if (preg_match('/\*/', $tvakey)) {
1387 $tvakey = str_replace('*', '', $tvakey);
1388 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1389 }
1390 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1391 $totalvat .= ' ';
1392 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1393 $totalvat .= vatrate((string) $tvaval['vatrate'], true).$tvacompl;
1394 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1395 $totalvat .= $tvaval['vatcode'].$tvacompl;
1396 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1397 $totalvat .= $tvacompl;
1398 } else {
1399 $totalvat .= vatrate((string) $tvaval['vatrate'], true).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1400 }
1401 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1402
1403 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1404 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', true);
1405 }
1406 }
1407
1408 //Local tax 1 after VAT
1409 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1410 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1411 continue;
1412 }
1413
1414 foreach ($localtax_rate as $tvakey => $tvaval) {
1415 if ($tvakey != 0) { // On affiche pas taux 0
1416 //$this->atleastoneratenotnull++;
1417
1418 $index++;
1419 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1420
1421 $tvacompl = '';
1422 if (preg_match('/\*/', (string) $tvakey)) {
1423 $tvakey = str_replace('*', '', (string) $tvakey);
1424 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1425 }
1426 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1427 $totalvat .= ' ';
1428
1429 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1430 $totalvat .= $tvacompl;
1431 } else {
1432 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1433 }
1434
1435 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1436
1437 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1438
1439 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1440 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1441 }
1442 }
1443 }
1444
1445 //Local tax 2 after VAT
1446 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1447 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1448 continue;
1449 }
1450
1451 foreach ($localtax_rate as $tvakey => $tvaval) {
1452 // retrieve global local tax
1453 if ($tvakey != 0) { // On affiche pas taux 0
1454 //$this->atleastoneratenotnull++;
1455
1456 $index++;
1457 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1458
1459 $tvacompl = '';
1460 if (preg_match('/\*/', (string) $tvakey)) {
1461 $tvakey = str_replace('*', '', (string) $tvakey);
1462 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1463 }
1464 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1465 $totalvat .= ' ';
1466
1467 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1468 $totalvat .= $tvacompl;
1469 } else {
1470 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1471 }
1472
1473 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1474
1475 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1476
1477 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1478 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1479 }
1480 }
1481 }
1482 //}
1483
1484 // Total TTC
1485 $index++;
1486 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1487 $pdf->SetTextColor(0, 0, 60);
1488 $pdf->SetFillColor(224, 224, 224);
1489 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', true);
1490
1491 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1492 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1493 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', true);
1494 } else {
1495 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', true);
1496
1497 //$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');
1498 $index++;
1499 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1500 $pdf->SetTextColor(0, 0, 60);
1501 $pdf->SetFillColor(224, 224, 224);
1502 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
1503
1504 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1505 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
1506 }
1507 }
1508 }
1509
1510 $pdf->SetTextColor(0, 0, 0);
1511
1512 $creditnoteamount = 0;
1513 $depositsamount = 0;
1514 //$creditnoteamount=$object->getSumCreditNotesUsed();
1515 //$depositsamount=$object->getSumDepositsUsed();
1516 //print "x".$creditnoteamount."-".$depositsamount;exit;
1517 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1518 if (!empty($object->paye)) {
1519 $resteapayer = 0;
1520 }
1521
1522 if ($deja_regle > 0) {
1523 // Already paid + Deposits
1524 $index++;
1525
1526 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1527 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', false);
1528 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1529 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', false);
1530
1531 $index++;
1532 $pdf->SetTextColor(0, 0, 60);
1533 $pdf->SetFillColor(224, 224, 224);
1534 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1535 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', true);
1536
1537 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1538 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
1539
1540 $pdf->SetFont('', '', $default_font_size - 1);
1541 $pdf->SetTextColor(0, 0, 0);
1542 }
1543
1544 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
1545
1546 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
1547 if ($reshook < 0) {
1548 $this->error = $hookmanager->error;
1549 $this->errors = $hookmanager->errors;
1550 }
1551
1552 $index++;
1553 return ($tab2_top + ($tab2_hl * $index));
1554 }
1555
1556 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1571 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
1572 {
1573 global $conf;
1574
1575 // Force to disable hidetop and hidebottom
1576 $hidebottom = 0;
1577 if ($hidetop) {
1578 $hidetop = -1;
1579 }
1580
1581 $currency = !empty($currency) ? $currency : getDolCurrency();
1582 $default_font_size = pdf_getPDFFontSize($outputlangs);
1583
1584 // Amount in (at tab_top - 1)
1585 $pdf->SetTextColor(0, 0, 0);
1586 $pdf->SetFont('', '', $default_font_size - 2);
1587
1588 if (empty($hidetop)) {
1589 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1590 if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1591 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
1592 }
1593
1594 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1595 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1596
1597 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1598 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1599 $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')));
1600 }
1601 }
1602
1603 $pdf->SetDrawColor(128, 128, 128);
1604 $pdf->SetFont('', '', $default_font_size - 1);
1605
1606 // Output Rect
1607 $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
1608
1609
1610 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1611
1612 if (empty($hidetop)) {
1613 $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
1614 }
1615 }
1616
1617 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1618 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1630 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
1631 {
1632 // phpcs:enable
1633 global $conf, $langs, $hookmanager, $mysoc;
1634
1635 $ltrdirection = 'L';
1636 if ($outputlangs->trans("DIRECTION") == 'rtl') {
1637 $ltrdirection = 'R';
1638 }
1639
1640 // Load traductions files required by page
1641 $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1642
1643 $default_font_size = pdf_getPDFFontSize($outputlangs);
1644
1645 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1646
1647 $pdf->SetTextColor(0, 0, 60);
1648 $pdf->SetFont('', 'B', $default_font_size + 3);
1649
1650 $w = 100;
1651
1652 $posy = $this->marge_haute;
1653 $posx = $this->page_largeur - $this->marge_droite - $w;
1654
1655 $pdf->SetXY($this->marge_gauche, $posy);
1656
1657 // Logo
1658 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1659 if ($this->emetteur->logo) {
1660 $logodir = $conf->mycompany->dir_output;
1661 if (!empty(getMultidirOutput($mysoc, 'mycompany'))) {
1662 $logodir = getMultidirOutput($mysoc, 'mycompany');
1663 }
1664 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1665 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1666 } else {
1667 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1668 }
1669 if (is_readable($logo)) {
1670 $height = pdf_getHeightForLogo($logo);
1671 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1672 } else {
1673 $pdf->SetTextColor(200, 0, 0);
1674 $pdf->SetFont('', 'B', $default_font_size - 2);
1675 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1676 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1677 }
1678 } else {
1679 $text = $this->emetteur->name;
1680 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1681 }
1682 }
1683
1684 $pdf->SetFont('', 'B', $default_font_size + 3);
1685 $pdf->SetXY($posx, $posy);
1686 $pdf->SetTextColor(0, 0, 60);
1687 $title = $outputlangs->transnoentities($titlekey);
1688 if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1689 $title .= ' - ';
1690 $title .= $outputlangsbis->transnoentities($titlekey);
1691 }
1692 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1693 if ($object->status == $object::STATUS_DRAFT) {
1694 $pdf->SetTextColor(128, 0, 0);
1695 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1696 }
1697
1698 $pdf->MultiCell($w, 3, $title, '', 'R');
1699
1700 $pdf->SetFont('', 'B', $default_font_size);
1701
1702 /*
1703 $posy += 5;
1704 $pdf->SetXY($posx, $posy);
1705 $pdf->SetTextColor(0, 0, 60);
1706 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1707 if ($object->statut == $object::STATUS_DRAFT) {
1708 $pdf->SetTextColor(128, 0, 0);
1709 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1710 }
1711 $pdf->MultiCell($w, 4, $textref, '', 'R');
1712 */
1713
1714 $posy += 3;
1715 $pdf->SetFont('', '', $default_font_size - 2);
1716
1717 if ($object->ref_client) {
1718 $posy += 4;
1719 $pdf->SetXY($posx, $posy);
1720 $pdf->SetTextColor(0, 0, 60);
1721 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset((string) $object->ref_client), 65), '', 'R');
1722 }
1723
1724 if (getDolGlobalInt('PDF_SHOW_PROJECT_TITLE')) {
1725 $object->fetchProject();
1726 if (!empty($object->project->ref)) {
1727 $posy += 3;
1728 $pdf->SetXY($posx, $posy);
1729 $pdf->SetTextColor(0, 0, 60);
1730 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : dol_trunc($object->project->title, 50)), '', 'R');
1731 }
1732 }
1733
1734 if (getDolGlobalInt('PDF_SHOW_PROJECT')) {
1735 $object->fetchProject();
1736 if (!empty($object->project->ref)) {
1737 $outputlangs->load("projects");
1738 $posy += 3;
1739 $pdf->SetXY($posx, $posy);
1740 $pdf->SetTextColor(0, 0, 60);
1741 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1742 }
1743 }
1744
1745 $posy += 4;
1746
1747 $pdf->SetXY($posx, $posy);
1748 $pdf->SetTextColor(0, 0, 60);
1749 $title = $outputlangs->transnoentities("OrderDate");
1750 if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1751 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
1752 }
1753 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1754
1755 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
1756 $posy += 4;
1757 $pdf->SetXY($posx, $posy);
1758 $pdf->SetTextColor(0, 0, 60);
1759 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
1760 }
1761
1762 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && !empty($object->thirdparty->code_compta_client)) {
1763 $posy += 4;
1764 $pdf->SetXY($posx, $posy);
1765 $pdf->SetTextColor(0, 0, 60);
1766 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
1767 }
1768
1769 // Get contact
1770 if (getDolGlobalInt('DOC_SHOW_FIRST_SALES_REP')) {
1771 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1772 if (count($arrayidcontact) > 0) {
1773 $usertmp = new User($this->db);
1774 $usertmp->fetch($arrayidcontact[0]);
1775 $posy += 4;
1776 $pdf->SetXY($posx, $posy);
1777 $pdf->SetTextColor(0, 0, 60);
1778 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1779 }
1780 }
1781
1782 $posy += 2;
1783
1784 $top_shift = 0;
1785 $shipp_shift = 0;
1786 // Show list of linked objects
1787 $current_y = $pdf->getY();
1788 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1789 if ($current_y < $pdf->getY()) {
1790 $top_shift = $pdf->getY() - $current_y;
1791 }
1792
1793 if ($showaddress) {
1794 // Sender properties
1795 $carac_emetteur = '';
1796 // Add internal contact of object if defined
1797 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1798 if (count($arrayidcontact) > 0) {
1799 $object->fetch_user($arrayidcontact[0]);
1800 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1801 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1802 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1803 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1804 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1805 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1806 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1807 $carac_emetteur .= "\n";
1808 }
1809
1810 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1811
1812 // Show sender
1813 $posy = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
1814 $posy += $top_shift;
1815 $posx = $this->marge_gauche;
1816 if (getDolGlobalInt('MAIN_INVERT_SENDER_RECIPIENT')) {
1817 $posx = $this->page_largeur - $this->marge_droite - 80;
1818 }
1819
1820 $hautcadre = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1821 $widthrecbox = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1822
1823
1824 // Show sender frame
1825 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1826 $pdf->SetTextColor(0, 0, 0);
1827 $pdf->SetFont('', '', $default_font_size - 2);
1828 $pdf->SetXY($posx, $posy - 5);
1829 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1830 $pdf->SetXY($posx, $posy);
1831 $pdf->SetFillColor(230, 230, 230);
1832 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1833 $pdf->SetTextColor(0, 0, 60);
1834 }
1835
1836 // Show sender name
1837 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1838 $pdf->SetXY($posx + 2, $posy + 3);
1839 $pdf->SetFont('', 'B', $default_font_size);
1840 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1841 $posy = $pdf->getY();
1842 }
1843
1844 // Show sender information
1845 $pdf->SetXY($posx + 2, $posy);
1846 $pdf->SetFont('', '', $default_font_size - 1);
1847 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1848
1849 // If CUSTOMER contact defined, we use it
1850 $usecontact = false;
1851 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1852 if (count($arrayidcontact) > 0) {
1853 $usecontact = true;
1854 $result = $object->fetch_contact($arrayidcontact[0]);
1855 }
1856
1857 //Recipient name
1858 if ($usecontact && $object->contact->socid != $object->thirdparty->id && getDolGlobalInt('MAIN_USE_COMPANY_NAME_OF_CONTACT')) {
1859 $thirdparty = $object->contact;
1860 } else {
1861 $thirdparty = $object->thirdparty;
1862 }
1863
1864 if (is_object($thirdparty)) {
1865 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1866 } else {
1867 $carac_client_name = '';
1868 }
1869
1870 $mode = 'target';
1871 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
1872
1873 // Show recipient
1874 $widthrecbox = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1875 if ($this->page_largeur < 210) {
1876 $widthrecbox = 84; // To work with US executive format
1877 }
1878 $posy = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : 32 + $this->marge_haute;
1879 $posy += $top_shift;
1880 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1881 if (getDolGlobalInt('MAIN_INVERT_SENDER_RECIPIENT')) {
1882 $posx = $this->marge_gauche;
1883 }
1884
1885 // Show recipient frame
1886 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1887 $pdf->SetTextColor(0, 0, 0);
1888 $pdf->SetFont('', '', $default_font_size - 2);
1889 $pdf->SetXY($posx + 2, $posy - 5);
1890 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1891 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1892 }
1893
1894 // Show recipient name
1895 $pdf->SetXY($posx + 2, $posy + 3);
1896 $pdf->SetFont('', 'B', $default_font_size);
1897 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1898 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1899
1900 $posy = $pdf->getY();
1901
1902 // Show recipient information
1903 $pdf->SetFont('', '', $default_font_size - 1);
1904 $pdf->SetXY($posx + 2, $posy);
1905 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1906 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1907
1908 // Show shipping address
1909 if (getDolGlobalInt('SALES_ORDER_SHOW_SHIPPING_ADDRESS')) {
1910 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
1911
1912 if (!empty($idaddressshipping)) {
1913 $contactshipping = $object->fetch_contact($idaddressshipping[0]);
1914 $companystatic = new Societe($this->db);
1915 $companystatic->fetch($object->contact->fk_soc);
1916 $carac_client_name_shipping = (($object->contact instanceof Contact) ? pdfBuildThirdpartyName($object->contact, $outputlangs) : '');
1917 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
1918 } else {
1919 $carac_client_name_shipping = ($object->thirdparty instanceof Societe ? pdfBuildThirdpartyName($object->thirdparty, $outputlangs) : '');
1920 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
1921 }
1922 if (!empty($carac_client_shipping)) {
1923 $posy += $hautcadre;
1924
1925 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
1926
1927 // Show shipping frame
1928 $pdf->SetXY($posx + 2, $posy - 5);
1929 $pdf->SetFont('', '', $default_font_size - 2);
1930 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', false);
1931 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1932
1933 // Show shipping name
1934 $pdf->SetXY($posx + 2, $posy + 1);
1935 $pdf->SetFont('', 'B', $default_font_size);
1936 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
1937
1938 $posy = $pdf->getY();
1939
1940 // Show shipping information
1941 $pdf->SetXY($posx + 2, $posy);
1942 $pdf->SetFont('', '', $default_font_size - 1);
1943 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
1944
1945 $shipp_shift += $hautcadre + 10;
1946 }
1947 }
1948 }
1949
1950 $pdf->SetTextColor(0, 0, 0);
1951
1952 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
1953
1954 return $pagehead;
1955 }
1956
1957 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1958 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1968 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1969 {
1970 // phpcs:enable
1971 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1972 return pdf_pagefoot($pdf, $outputlangs, 'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1973 }
1974
1975
1976
1987 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1988 {
1989 global $hookmanager;
1990
1991 // Default field style for content
1992 $this->defaultContentsFieldsStyle = array(
1993 'align' => 'R', // R,C,L
1994 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1995 );
1996
1997 // Default field style for content
1998 $this->defaultTitlesFieldsStyle = array(
1999 'align' => 'C', // R,C,L
2000 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2001 );
2002
2003 /*
2004 * For example
2005 $this->cols['theColKey'] = array(
2006 'rank' => $rank, // int : use for ordering columns
2007 'width' => 20, // the column width in mm
2008 'title' => array(
2009 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2010 'label' => ' ', // the final label : used fore final generated text
2011 'align' => 'L', // text alignment : R,C,L
2012 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2013 ),
2014 'content' => array(
2015 'align' => 'L', // text alignment : R,C,L
2016 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2017 ),
2018 );
2019 */
2020
2021 $rank = 0; // do not use negative rank
2022 $this->cols['position'] = array(
2023 'rank' => $rank,
2024 'width' => 10.0,
2025 'status' => (getDolGlobalInt('PDF_ERATOSTHENE_ADD_POSITION') || getDolGlobalInt('PDF_ERATOSHTENE_ADD_POSITION')) ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2026 'title' => array(
2027 'textkey' => '#', // use lang key is useful in some case with module
2028 'align' => 'C',
2029 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2030 // 'label' => ' ', // the final label
2031 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2032 ),
2033 'content' => array(
2034 'align' => 'C',
2035 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2036 ),
2037 );
2038
2039 $rank = 5; // do not use negative rank
2040 $this->cols['desc'] = array(
2041 'rank' => $rank,
2042 'width' => false, // only for desc
2043 'status' => true,
2044 'title' => array(
2045 'textkey' => 'Designation', // use lang key is useful in some case with module
2046 'align' => 'L',
2047 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2048 // 'label' => ' ', // the final label
2049 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2050 ),
2051 'content' => array(
2052 'align' => 'L',
2053 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2054 ),
2055 );
2056
2057 // Image of product
2058 $rank += 10;
2059 $this->cols['photo'] = array(
2060 'rank' => $rank,
2061 'width' => (float) (!getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH') ? 20 : getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH')), // in mm
2062 'status' => false,
2063 'title' => array(
2064 'textkey' => 'Photo',
2065 'label' => ' '
2066 ),
2067 'content' => array(
2068 'padding' => array(0.0, 0.0, 0.0, 0.0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2069 ),
2070 'border-left' => false, // remove left line separator
2071 );
2072
2073 if (getDolGlobalInt('MAIN_GENERATE_ORDERS_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2074 $this->cols['photo']['status'] = true;
2075 }
2076
2077 $rank += 10;
2078 $this->cols['vat'] = array(
2079 'rank' => $rank,
2080 'status' => false,
2081 'width' => 16.0, // in mm
2082 'title' => array(
2083 'textkey' => 'VAT'
2084 ),
2085 'border-left' => true, // add left line separator
2086 );
2087
2088 if (!getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2089 $this->cols['vat']['status'] = true;
2090 }
2091
2092 $rank += 10;
2093 $this->cols['subprice'] = array(
2094 'rank' => $rank,
2095 'width' => 19.0, // in mm
2096 'status' => true,
2097 'title' => array(
2098 'textkey' => 'PriceUHT'
2099 ),
2100 'border-left' => true, // add left line separator
2101 );
2102
2103 // Adapt dynamically the width of subprice, if text is too long.
2104 $tmpwidth = 0;
2105 $nblines = count($object->lines);
2106 for ($i = 0; $i < $nblines; $i++) {
2107 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2108 $tmpwidth = max($tmpwidth, $tmpwidth2);
2109 }
2110 if ($tmpwidth > 10) {
2111 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2112 }
2113
2114 $rank += 10;
2115 $this->cols['qty'] = array(
2116 'rank' => $rank,
2117 'width' => 16.0, // in mm
2118 'status' => true,
2119 'title' => array(
2120 'textkey' => 'Qty'
2121 ),
2122 'border-left' => true, // add left line separator
2123 );
2124
2125 $rank += 10;
2126 $this->cols['unit'] = array(
2127 'rank' => $rank,
2128 'width' => 11.0, // in mm
2129 'status' => false,
2130 'title' => array(
2131 'textkey' => 'Unit'
2132 ),
2133 'border-left' => true, // add left line separator
2134 );
2135 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2136 $this->cols['unit']['status'] = true;
2137 }
2138
2139 $rank += 10;
2140 $this->cols['discount'] = array(
2141 'rank' => $rank,
2142 'width' => 13.0, // in mm
2143 'status' => false,
2144 'title' => array(
2145 'textkey' => 'ReductionShort'
2146 ),
2147 'border-left' => true, // add left line separator
2148 );
2149 if ($this->atleastonediscount) {
2150 $this->cols['discount']['status'] = true;
2151 }
2152
2153 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2154 $this->cols['totalexcltax'] = array(
2155 'rank' => $rank,
2156 'width' => 26.0, // in mm
2157 'status' => !getDolGlobalString('PDF_ORDER_HIDE_PRICE_EXCL_TAX'),
2158 'title' => array(
2159 'textkey' => 'TotalHTShort'
2160 ),
2161 'border-left' => true, // add left line separator
2162 );
2163
2164 $rank += 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2165 $this->cols['totalincltax'] = array(
2166 'rank' => $rank,
2167 'width' => 26.0, // in mm
2168 'status' => getDolGlobalBool('PDF_ORDER_SHOW_PRICE_INCL_TAX'),
2169 'title' => array(
2170 'textkey' => 'TotalTTCShort'
2171 ),
2172 'border-left' => true, // add left line separator
2173 );
2174
2175 // Add extrafields cols
2176 if (!empty($object->lines)) {
2177 $line = reset($object->lines);
2178 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2179 }
2180
2181 $parameters = array(
2182 'object' => $object,
2183 'outputlangs' => $outputlangs,
2184 'hidedetails' => $hidedetails,
2185 'hidedesc' => $hidedesc,
2186 'hideref' => $hideref
2187 );
2188
2189 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2190 if ($reshook < 0) {
2191 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2192 } elseif (empty($reshook)) {
2193 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2194 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2195 } else {
2196 $this->cols = $hookmanager->resArray;
2197 }
2198 }
2199}
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
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 contact/addresses.
Class to manage Dolibarr database access.
Class to manage hooks.
Parent class for orders models.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class to generate PDF orders with template Eratosthene.
drawInfoTable(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="PdfOrderTitle")
Show top header of page.
__construct(DoliDB $db)
Constructor.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
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.
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(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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,...
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.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
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...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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:3194
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2893
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:3226
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1810
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:294
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:1241
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:317
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition pdf.lib.php:2943
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2482
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2420
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:749
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:1423
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:273
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:3324
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:438
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2727
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2770
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2567
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:1137
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:393
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:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140