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