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