dolibarr 25.0.0-alpha
pdf_sponge.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2024 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-2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2018-2024 Anthony Berton <anthony.berton@bb2a.fr>
13 * Copyright (C) 2022-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
14 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024-2026 Nick Fragoulis
16 * Copyright (C) 2024 Franck Moreau
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 * or see https://www.gnu.org/
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
40require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
44
49{
53 public $db;
54
58 public $name;
59
63 public $description;
64
68 public $update_main_doc_field;
69
73 public $type;
74
79 public $version = 'dolibarr';
80
84 public $position = 50;
85
86
90 public $heightforinfotot;
91
95 public $heightforfreetext;
96
100 public $heightforfooter;
101
105 public $tab_top;
106
110 public $tab_top_newpage;
111
115 public $situationinvoice;
116
117
121 public $cols;
122
126 public $categoryOfOperation = -1; // unknown by default
127
128
134 public function __construct($db)
135 {
136 global $langs, $mysoc;
137
138 // Translations
139 $langs->loadLangs(array("main", "bills"));
140
141 $this->db = $db;
142 $this->name = "sponge";
143 $this->description = $langs->trans('PDFSpongeDescription');
144 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
145
146 // Dimension page
147 $this->type = 'pdf';
148 $formatarray = pdf_getFormat();
149 $this->page_largeur = $formatarray['width'];
150 $this->page_hauteur = $formatarray['height'];
151 $this->format = array($this->page_largeur, $this->page_hauteur);
152 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
153 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
154 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
155 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
156 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
157 $this->option_logo = 1; // Display logo
158 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
159 $this->option_modereg = 1; // Display payment mode
160 $this->option_condreg = 1; // Display payment terms
161 $this->option_multilang = 1; // Available in several languages
162 $this->option_escompte = 1; // Displays if there has been a discount
163 $this->option_credit_note = 1; // Support credit notes
164 $this->option_freetext = 1; // Support add of a personalised text
165 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
166 $this->watermark = '';
167
168 $this->showAmountBeforeDiscount = (getDolGlobalInt('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT') || getDolGlobalInt('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT_INVOICE')) ? 0 : 1;
169 $this->showDiscountAmount = (getDolGlobalInt('MAIN_HIDE_AMOUNT_DISCOUNT') || getDolGlobalInt('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT_INVOICE')) ? 0 : 1;
170
171 if ($mysoc === null) {
172 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
173 return;
174 }
175
176 // Get source company
177 $this->emetteur = $mysoc;
178 if (empty($this->emetteur->country_code)) {
179 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
180 }
181
182 // Define position of columns
183 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
184
185
186 $this->tabTitleHeight = 5; // default height
187
188 // Use new system for position of columns, view $this->defineColumnField()
189
190 $this->tva = array();
191 $this->tva_array = array();
192 $this->localtax1 = array();
193 $this->localtax2 = array();
194 $this->atleastoneratenotnull = 0;
195 $this->atleastonediscount = 0;
196 $this->situationinvoice = false;
197 }
198
199
200 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
212 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
213 {
214 // phpcs:enable
215 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
216
217 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
218
219 if (!is_object($outputlangs)) {
220 $outputlangs = $langs;
221 }
222 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
223 if (getDolGlobalString('MAIN_USE_FPDF')) {
224 $outputlangs->charset_output = 'ISO-8859-1';
225 }
226
227 // Load translation files required by the page
228 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
229
230 global $outputlangsbis;
231 $outputlangsbis = null;
232 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
233 $outputlangsbis = new Translate('', $conf);
234 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
235 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
236 }
237
238 // Show Draft Watermark
239 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
240 $this->watermark = getDolGlobalString('FACTURE_DRAFT_WATERMARK');
241 }
242
243 $nblines = count($object->lines);
244
245 $hidetop = 0;
246 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
247 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
248 }
249
250 // Loop on each lines to detect if there is at least one image to show
251 $realpatharray = array();
252 $this->atleastonephoto = false;
253 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
254 $objphoto = new Product($this->db);
255
256 for ($i = 0; $i < $nblines; $i++) {
257 if (empty($object->lines[$i]->fk_product)) {
258 continue;
259 }
260
261 $objphoto->fetch($object->lines[$i]->fk_product);
262 //var_dump($objphoto->ref);exit;
263 $pdir = array();
264 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
265 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
266 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
267 } else {
268 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
269 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
270 }
271
272 $arephoto = false;
273 $realpath = false;
274 foreach ($pdir as $midir) {
275 if (!$arephoto) {
276 $entity = $objphoto->entity;
277 if ($entity !== null && $conf->entity != $entity) {
278 $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
279 } else {
280 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
281 }
282
283 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
284 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
285 if ($obj['photo_vignette']) {
286 $filename = $obj['photo_vignette'];
287 } else {
288 $filename = $obj['photo'];
289 }
290 } else {
291 $filename = $obj['photo'];
292 }
293
294 $realpath = $dir.$filename;
295 $arephoto = true;
296 $this->atleastonephoto = true;
297 }
298 }
299 }
300
301 if (!empty($realpath) && $arephoto) {
302 $realpatharray[$i] = $realpath;
303 }
304 }
305 }
306
307 //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
308
309 if ($conf->facture->multidir_output[$conf->entity]) {
310 $object->fetch_thirdparty();
311
312 $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
313 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
314 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
315
316 // Definition of $dir and $file
317 if ($object->specimen) {
318 $dir = $conf->facture->multidir_output[$conf->entity];
319 $file = $dir."/SPECIMEN.pdf";
320 } else {
321 $objectref = dol_sanitizeFileName($object->ref);
322 $dir = $conf->facture->multidir_output[$object->entity ?? $conf->entity]."/".$objectref;
323 $file = $dir."/".$objectref.".pdf";
324 }
325 if (!file_exists($dir)) {
326 if (dol_mkdir($dir) < 0) {
327 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
328 return 0;
329 }
330 }
331
332 if (file_exists($dir)) {
333 // Add pdfgeneration hook
334 if (!is_object($hookmanager)) {
335 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
336 $hookmanager = new HookManager($this->db);
337 }
338 $hookmanager->initHooks(array('pdfgeneration'));
339 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
340 global $action;
341 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
342
343 // Set nblines with the new facture lines content after hook
344 $nblines = count($object->lines);
345 $nbpayments = count($object->getListOfPayments());
346
347 // Create pdf instance
348 $pdf = pdf_getInstance($this->format); // Will also define if we use format 1.7, 1.4/A-1b or 1.7/A-3b (embedded fonts)
349 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
350 $pdf->setAutoPageBreak(true, 0);
351
352 // Compute height for total, free text and footer
353 $this->heightforinfotot = 50; // Height reserved to output the info and total part and payment part
354 if (!getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS') && $nbpayments > 0) {
355 $this->heightforinfotot += (4 * $nbpayments);
356 }
357 $this->heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
358 $this->heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
359
360 $heightforqrinvoice = 0;
361 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
362 if ($this->getHeightForQRInvoice(1, $object, $langs) > 0) {
363 // Shrink infotot to a base 30
364 $this->heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
365 }
366 }
367
368 if (class_exists('TCPDF')) {
369 $pdf->setPrintHeader(false);
370 $pdf->setPrintFooter(false);
371 }
372 $pdf->SetFont(pdf_getPDFFont($outputlangs));
373
374 // Set path to the background PDF File
375 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
376 $logodir = $conf->mycompany->dir_output;
377 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
378 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
379 }
380 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
381 $tplidx = $pdf->importPage(1);
382 }
383
384 $pdf->Open();
385 $pagenb = 0;
386 $pdf->SetDrawColor(128, 128, 128);
387
388 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
389 $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
390 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
391 $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)) : ''));
392 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
393 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
394 $pdf->SetCompression(false);
395 }
396
397 // Set certificate
398 $cert = getDolUserString('CERTIFICATE_CRT', getDolGlobalString('CERTIFICATE_CRT'));
399 $certprivate = getDolUserString('CERTIFICATE_CRT_PRIVATE', getDolGlobalString('CERTIFICATE_CRT_PRIVATE'));
400
401 // If a certificate is found
402 if ($cert) {
403 $info = array(
404 'Name' => $this->emetteur->name,
405 'Location' => getCountry($this->emetteur->country_code, ''),
406 'Reason' => 'INVOICE',
407 'ContactInfo' => $this->emetteur->email
408 );
409 $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
410 }
411
412 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
413 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
414
415 // Set $this->atleastonediscount if you have at least one discount
416 // and determine category of operation
417 $categoryOfOperation = 0;
418 $nbProduct = 0;
419 $nbService = 0;
420 for ($i = 0; $i < $nblines; $i++) {
421 $line = $object->lines[$i];
422
423 if ($line->remise_percent) {
424 $this->atleastonediscount++;
425 }
426
427 // If DEPOSIT, this line is completely ignored for calculations.
428 if ($line->isDepositLine()) {
429 continue;
430 }
431
432 // determine category of operation
433 if ($categoryOfOperation < 2) {
434 $lineProductType = $line->product_type;
435 if ($lineProductType == Product::TYPE_PRODUCT) {
436 $nbProduct++;
437 } elseif ($lineProductType == Product::TYPE_SERVICE) {
438 $nbService++;
439 }
440 if ($nbProduct > 0 && $nbService > 0) {
441 // mixed products and services
442 $categoryOfOperation = 2;
443 }
444 }
445 }
446 // determine category of operation
447 if ($categoryOfOperation <= 0) {
448 // only services
449 if ($nbProduct == 0 && $nbService > 0) {
450 $categoryOfOperation = 1;
451 }
452 }
453 $this->categoryOfOperation = $categoryOfOperation;
454
455 // Situation invoice handling
456 if ($object->situation_cycle_ref) {
457 $this->situationinvoice = true;
458 }
459
460 // New page
461 $pdf->AddPage();
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
464 }
465 $pagenb++;
466
467 // Output header (logo, ref and address blocks). This is first call for first page.
468 $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
469 $top_shift = $pagehead['top_shift'];
470 $shipp_shift = $pagehead['shipp_shift'];
471 $pdf->SetFont('', '', $default_font_size - 1);
472 $pdf->MultiCell(0, 3, ''); // Set interline to 3
473 $pdf->SetTextColor(0, 0, 0);
474
475 // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher
476
477 // $this->tab_top is y where we must continue content (80 = 32 + 48: 32 is height of logo and ref, 48 is address blocks)
478 $this->tab_top = $this->marge_haute + 80 + $top_shift + $shipp_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
479 $this->tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
480
481 // You can add more thing under header here, if you increase $extra_under_address_shift too.
482 $extra_under_address_shift = 0;
483 $qrcodestring = '';
484 if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) {
485 $qrcodestring = $object->buildZATCAQRString();
486 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
487 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
488 $qrcodestring = $object->buildSwitzerlandQRString();
489 }
490 } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') && $object->getRemainToPay() > 0) {
491 // No EPC QR code once the invoice is fully paid: the amount to pay would be 0 (same rule as for INVOICE_ADD_EPC_QR_CODE == 'bottom')
492 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
493 $qrcodestring = $object->buildEPCQrCodeString();
494 }
495 }
496
497 if ($qrcodestring) {
498 $qrcodecolor = array('25', '25', '25');
499 // set style for QR-code
500 $styleQr = array(
501 'border' => false,
502 'padding' => 0,
503 'fgcolor' => $qrcodecolor,
504 'bgcolor' => false, //array(255,255,255)
505 'module_width' => 1, // width of a single module in points
506 'module_height' => 1 // height of a single module in points
507 );
508 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr, 'N');
509
510 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
511 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
512 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
513 $pdf->SetFont('', '', $default_font_size - 4);
514 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', false);
515 }
516 }
517
518 $extra_under_address_shift += 25;
519 }
520
521 // Finnish domestic payment barcode. Same data as the QR code but in the
522 // format finnish banks scan from a credit transfer form.
523 if (getDolGlobalString('INVOICE_ADD_FI_BARCODE') && $mysoc->country_code == 'FI') {
524 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_fi.lib.php';
525 $fibarcodedata = dolFIGetInvoiceBarcodeData($object);
526 if ($fibarcodedata != '') {
527 $styleBc = array(
528 'position' => '',
529 'align' => 'L',
530 'stretch' => false,
531 'fitwidth' => true,
532 'cellfitalign' => '',
533 'border' => false,
534 'hpadding' => 'auto',
535 'vpadding' => 0,
536 'fgcolor' => array(0, 0, 0),
537 'bgcolor' => false,
538 'text' => false
539 );
540 $pdf->write1DBarcode($fibarcodedata, 'C128C', $this->marge_gauche, $this->tab_top + $extra_under_address_shift, 90, 13, 0.35, $styleBc, 'N');
541 $pdf->SetXY($this->marge_gauche, $pdf->GetY());
542 $pdf->SetFont('', '', $default_font_size - 4);
543 $pdf->MultiCell(90, 3, $outputlangs->transnoentitiesnoconv("FIVirtualBarcode").': '.dolFIFormatVirtualBarcode($fibarcodedata), 0, 'L', false);
544 $extra_under_address_shift += 22;
545 }
546 }
547
548 // Call hook printUnderHeaderPDFline
549 $parameters = array(
550 'object' => $object,
551 // 'i' => $i, // we aren't in lines
552 'pdf' => &$pdf,
553 'outputlangs' => $outputlangs,
554 'hidedetails' => $hidedetails
555 );
556 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
557 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
558 $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift'];
559 }
560
561 $this->tab_top += $extra_under_address_shift;
562 $this->tab_top_newpage += 0;
563
564
565 // Define height of table for lines (for first page)
566 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->getHeightForQRInvoice(1, $object, $langs);
567
568 $nexY = $this->tab_top - 1;
569
570 // Incoterm
571 $height_incoterms = 0;
572 if (isModEnabled('incoterm')) {
573 $desc_incoterms = $object->getIncotermsForPDF();
574 if ($desc_incoterms) {
575 $this->tab_top -= 2;
576
577 $pdf->SetFont('', '', $default_font_size - 1);
578 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
579 $nexY = max($pdf->GetY(), $nexY);
580 $height_incoterms = $nexY - $this->tab_top;
581
582 // Rect takes a length in 3rd parameter
583 $pdf->SetDrawColor(192, 192, 192);
584 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
585
586 $this->tab_top = $nexY + 6;
587 $height_incoterms += 4;
588 }
589 }
590
591 // Displays notes. Here we are still on code executed only for the first page.
592 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
593 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
594 // Get first sale rep
595 if (is_object($object->thirdparty)) {
596 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
597 $salerepobj = new User($this->db);
598 $salerepobj->fetch($salereparray[0]['id']);
599 if (!empty($salerepobj->signature)) {
600 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
601 }
602 }
603 }
604
605 // Extrafields in note
606 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
607 if (!empty($extranote)) {
608 $notetoshow = dol_concatdesc((string) $notetoshow, $extranote);
609 }
610
611 $pagenb = $pdf->getPage();
612 if ($notetoshow) {
613 $this->tab_top -= 2;
614
615 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
616 $pageposbeforenote = $pagenb;
617
618 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
619 complete_substitutions_array($substitutionarray, $outputlangs, $object);
620 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
621 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
622
623 $pdf->startTransaction();
624
625 $pdf->SetFont('', '', $default_font_size - 1);
626 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
627 // Description
628 $pageposafternote = $pdf->getPage();
629 $posyafter = $pdf->GetY();
630
631 if ($pageposafternote > $pageposbeforenote) {
632 $pdf->rollbackTransaction(true);
633
634 // prepare pages to receive notes
635 while ($pagenb < $pageposafternote) {
636 $pdf->AddPage();
637 $pagenb++;
638 if (!empty($tplidx)) {
639 $pdf->useTemplate($tplidx);
640 }
641 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
642 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
643 }
644 $pdf->setTopMargin($this->tab_top_newpage);
645 // The only function to edit the bottom margin of current page to set it.
646 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext);
647 }
648
649 // back to start
650 $pdf->setPage($pageposbeforenote);
651 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext);
652 $pdf->SetFont('', '', $default_font_size - 1);
653 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
654 $pageposafternote = $pdf->getPage();
655
656 $posyafter = $pdf->GetY();
657
658 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) { // There is no space left for total+free text
659 $pdf->AddPage('', '', true);
660 $pagenb++;
661 $pageposafternote++;
662 $pdf->setPage($pageposafternote);
663 $pdf->setTopMargin($this->tab_top_newpage);
664 // The only function to edit the bottom margin of current page to set it.
665 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext);
666 //$posyafter = $this->tab_top_newpage;
667 }
668
669
670 // apply note frame to previous pages
671 $i = $pageposbeforenote;
672 while ($i < $pageposafternote) {
673 $pdf->setPage($i);
674
675
676 $pdf->SetDrawColor(128, 128, 128);
677 // Draw note frame
678 if ($i > $pageposbeforenote) {
679 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
680 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
681 } else {
682 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
683 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
684 }
685
686 // Add footer
687 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
688 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($i, $object, $outputlangs));
689
690 $i++;
691 }
692
693 // apply note frame to last page
694 $pdf->setPage($pageposafternote);
695 if (!empty($tplidx)) {
696 $pdf->useTemplate($tplidx);
697 }
698 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
699 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
700 }
701 $height_note = $posyafter - $this->tab_top_newpage;
702 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
703 } else {
704 // No pagebreak
705 $pdf->commitTransaction();
706 $posyafter = $pdf->GetY();
707 $height_note = $posyafter - $this->tab_top;
708 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
709
710
711 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
712 // not enough space, need to add page
713 $pdf->AddPage('', '', true);
714 $pagenb++;
715 $pageposafternote++;
716 $pdf->setPage($pageposafternote);
717 if (!empty($tplidx)) {
718 $pdf->useTemplate($tplidx);
719 }
720 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
721 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
722 }
723
724 $posyafter = $this->tab_top_newpage;
725 }
726 }
727
728 $tab_height -= $height_note;
729 $this->tab_top = $posyafter + 6;
730 } else {
731 $height_note = 0;
732 }
733
734 // Use new auto column system
735 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
736
737 // Table simulation to know the height of the title line (this set this->tableTitleHeight)
738 $pdf->startTransaction();
739 $this->pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
740 $pdf->rollbackTransaction(true);
741
742 $nexY = $this->tab_top + $this->tabTitleHeight;
743
744 // Loop on each lines
745 $pageposbeforeprintlines = $pdf->getPage();
746 $pagenb = $pageposbeforeprintlines;
747
748 $pdf_sub_options = array();
749 $pdf_sub_options['titleshowuponpdf'] = 1;
750 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = 1;
751 $pdf_sub_options_before_title = array(); // Options in use before each title line, by level
752
753 $hidenextline = 0;
754
755 for ($i = 0; $i < $nblines; $i++) {
756 $linePosition = $i + 1;
757 $curY = $nexY;
758
759 $sub_options = $object->lines[$i]->extraparams["subtotal"] ?? array();
760
761 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
762 $level = $object->lines[$i]->qty;
763 // Keep the options in use before a title line, to restore them after the subtotal line that closes its block
764 if ($level > 0 && !isset($pdf_sub_options_before_title[(int) $level])) {
765 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
766 }
767 if ($sub_options) {
768 $hidenextline = 0;
769 if (isset($sub_options['titleshowuponpdf'])) {
770 $pdf_sub_options['titleshowuponpdf'] = isset($pdf_sub_options['titleshowuponpdf']) && $pdf_sub_options['titleshowuponpdf'] < $level ? $pdf_sub_options['titleshowuponpdf'] : $level;
771 } elseif (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
772 unset($pdf_sub_options['titleshowuponpdf']);
773 }
774 if (isset($sub_options['titleshowtotalexludingvatonpdf'])) {
775 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && $pdf_sub_options['titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options['titleshowtotalexludingvatonpdf'] : $level;
776 } elseif (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
777 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
778 }
779 } else {
780 if (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
781 unset($pdf_sub_options['titleshowuponpdf']);
782 }
783 if (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
784 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
785 }
786 }
787 // 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
788 if ($level < 0 && isset($pdf_sub_options_before_title[(int) abs($level)])) {
789 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
790 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
791 if ($tmplevel >= abs($level)) {
792 unset($pdf_sub_options_before_title[$tmplevel]);
793 }
794 }
795 }
796 }
797
798 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
799 $hidenextline = 0;
800 $pdf_sub_options = array();
801 $pdf_sub_options['titleshowuponpdf'] = 1;
802 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = 1;
803 }
804
805 if ($hidenextline) {
806 $linePosition--;
807 } else {
808 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options['titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
809 $object->lines[$i]->pagebreak = true;
810 }
811
812 // in First Check line page break and add page if needed
813 if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
814 // New page
815 $pdf->AddPage();
816 if (!empty($tplidx)) {
817 $pdf->useTemplate($tplidx);
818 }
819
820 $pdf->setPage($pdf->getNumPages());
821 $nexY = $curY = $this->tab_top_newpage;
822 }
823
824 $this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
825
826 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
827 $pdf->SetTextColor(0, 0, 0);
828
829 // Define size of image if we need it
830 $imglinesize = array();
831 if (!empty($realpatharray[$i])) {
832 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
833 }
834
835 $pdf->setTopMargin($this->tab_top_newpage);
836 $pdf->setPageOrientation('', true, $this->heightforfooter);
837 $pageposbefore = $pdf->getPage();
838 $curYBefore = $curY;
839
840 // Allows data in the first page if description is long enough to break in multiples pages
841 $showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
842
843 if ($this->getColumnStatus('photo')) {
844 // We start with Photo of product line
845 $imageTopMargin = 1;
846 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imageTopMargin + $imglinesize['height']) > ($this->page_hauteur - $this->heightforfooter)) { // If photo too high, we moved completely on new page
847 $pdf->AddPage('', '', true);
848 if (!empty($tplidx)) {
849 $pdf->useTemplate($tplidx);
850 }
851 $pdf->setPage($pageposbefore + 1);
852 $pdf->setPageOrientation('', true, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
853 $curY = $this->tab_top_newpage;
854 $showpricebeforepagebreak = 0;
855 }
856
857 $pdf->setPageOrientation('', false, $this->heightforfooter + $this->heightforfreetext); // The only function to edit the bottom margin of current page to set it.
858 // @phan-suppress-next-line PhanTypeMismatchProperty
859 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
860 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
861 // $pdf->Image does not increase value return by getY, so we save it manually
862 $posYAfterImage = $curY + $imglinesize['height'];
863
864 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
865 }
866 }
867
868 // restore Page orientation for text
869 $pdf->setPageOrientation('', true, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
870
871 // Description of product line
872 if ($this->getColumnStatus('desc')) {
873 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
874 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
875 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
876 } else {
877 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty), 'ffffff'));
878 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
879 }
880 }
881
882
883 $afterPosData = $this->getMaxAfterColsLinePositionsData();
884 $pdf->setPage($pageposbefore);
885 $pdf->setTopMargin($this->marge_haute);
886 $curY = $curYBefore;
887 $pdf->setPageOrientation('', false, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
888
889 // We suppose that a too long description or photo were moved completely on next page
890 if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
891 $pdf->setPage($afterPosData['page']);
892 $curY = $this->tab_top_newpage;
893 }
894
895 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
896
897 // Line position
898 if ($this->getColumnStatus('position')) {
899 $this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
900 }
901
902 // VAT Rate
903 if ($this->getColumnStatus('vat') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
904 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
905 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
906 }
907
908 // Unit price before discount
909 if ($this->getColumnStatus('subprice') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowuponpdf'])) {
910 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
911 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
912 }
913
914 // Quantity
915 // Enough for 6 chars
916 if ($this->getColumnStatus('qty') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
917 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
918 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
919 }
920
921 // Situation progress
922 if ($this->getColumnStatus('progress') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
923 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
924 $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
925 }
926
927 // Unit
928 if ($this->getColumnStatus('unit') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
929 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
930 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
931 }
932
933 // Discount on line
934 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
935 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
936 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
937 }
938
939 // Total excl tax line (HT)
940 if ($this->getColumnStatus('totalexcltax')) {
941 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowtotalexludingvatonpdf'])) {
942 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
943 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
944 } elseif ($object->lines[$i]->qty < 0 && isset($sub_options['subtotalshowtotalexludingvatonpdf'])) {
945 if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency) {
946 $total_excl_tax = $object->getSubtotalLineMulticurrencyAmount($object->lines[$i]);
947 } else {
948 $total_excl_tax = $object->getSubtotalLineAmount($object->lines[$i]);
949 }
950 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
951 }
952 }
953
954 // Total with tax line (TTC)
955 if ($this->getColumnStatus('totalincltax') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
956 $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
957 $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
958 }
959
960 // Extrafields
961 if (!empty($object->lines[$i]->array_options)) {
962 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
963 if ($this->getColumnStatus($extrafieldColKey)) {
964 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
965 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
966
967 $this->setAfterColsLinePositionsData('options_' . $extrafieldColKey, $pdf->GetY(), $pdf->getPage());
968 }
969 }
970 }
971
972 $afterPosData = $this->getMaxAfterColsLinePositionsData();
973 $parameters = array(
974 'object' => $object,
975 'i' => $i,
976 'pdf' => & $pdf,
977 'curY' => & $curY,
978 'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
979 'outputlangs' => $outputlangs,
980 'hidedetails' => $hidedetails
981 );
982 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
983 }
984
985 $sign = 1;
986 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
987 $sign = -1;
988 }
989
990 // Collect total by value of vat rate into $this->tva_array
991 // Lines are already stored as delta (not cumulative) once INVOICE_USE_SITUATION=2, so no ratio must be reapplied here (same guard as CommonObject::update_price())
992 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && $object->lines[$i]->product_type != 9) {
993 $prev_progress = getDolGlobalInt('INVOICE_USE_SITUATION') == 2 ? 0 : $object->lines[$i]->get_prev_progress($object->id);
994
995 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
996 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
997 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
998 } else {
999 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
1000 }
1001 } else {
1002 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
1003 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
1004 } else {
1005 $tvaligne = $sign * $object->lines[$i]->total_tva;
1006 }
1007 }
1008
1009 $localtax1ligne = $object->lines[$i]->total_localtax1;
1010 $localtax2ligne = $object->lines[$i]->total_localtax2;
1011 $localtax1_rate = $object->lines[$i]->localtax1_tx;
1012 $localtax2_rate = $object->lines[$i]->localtax2_tx;
1013 $localtax1_type = $object->lines[$i]->localtax1_type;
1014 $localtax2_type = $object->lines[$i]->localtax2_type;
1015
1016 $vatrate = (string) $object->lines[$i]->tva_tx;
1017
1018 // Retrieve type from database for backward compatibility with old records
1019 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
1020 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
1021 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
1022 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
1023 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
1024 }
1025
1026 // retrieve global local tax
1027 if ($localtax1_type && $localtax1ligne != 0) {
1028 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
1029 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
1030 } else {
1031 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
1032 }
1033 }
1034 if ($localtax2_type && $localtax2ligne != 0) {
1035 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
1036 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
1037 } else {
1038 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1039 }
1040 }
1041
1042 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
1043 $vatrate .= '*';
1044 }
1045
1046 // Fill $this->tva and $this->tva_array
1047 if (!isset($this->tva[$vatrate])) {
1048 $this->tva[$vatrate] = 0;
1049 }
1050 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
1051 $vatcode = $object->lines[$i]->vat_src_code;
1052 if (empty($this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'])) {
1053 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] = 0;
1054 }
1055 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1056 if (empty($this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'])) {
1057 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
1058 }
1059 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] + $tvaligne, 'tot_ht' => $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] + $object->lines[$i]->total_ht);
1060 } else {
1061 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] + $tvaligne);
1062 }
1063 }
1064
1065 if (!$hidenextline) {
1066 $afterPosData = $this->getMaxAfterColsLinePositionsData();
1067 $pdf->setPage($afterPosData['page']);
1068 $nexY = $afterPosData['y'];
1069
1070 // Add line
1071 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1072 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
1073 //$pdf->SetDrawColor(190,190,200);
1074 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1075 $pdf->SetLineStyle(array('dash' => 0));
1076 }
1077 }
1078
1079 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
1080 $hidenextline = 1;
1081 }
1082
1083 $nexY += 0; // Add space between lines
1084 }
1085
1086 // Add last page for document footer if there are not enough size left
1087 $afterPosData = $this->getMaxAfterColsLinePositionsData();
1088 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
1089
1090 if (isset($afterPosData['y']) && $afterPosData['y'] > $this->page_hauteur - $page_bottom_margin) {
1091 $pdf->AddPage();
1092 if (!empty($tplidx)) {
1093 $pdf->useTemplate($tplidx);
1094 }
1095 $pagenb++;
1096 $pdf->setPage($pagenb);
1097 }
1098
1099 // Draw table frames and columns borders
1100 $drawTabNumbPage = $pdf->getNumPages();
1101 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1102 $pdf->setPage($i);
1103 // reset page orientation each loop to override it if it was changed
1104 $pdf->setPageOrientation('', false, 0); // The only function to edit the bottom margin of current page to set it.
1105
1106 $drawTabHideTop = $hidetop;
1107 $drawTabTop = $this->tab_top_newpage;
1108 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1109 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
1110
1111 if ($i == $pageposbeforeprintlines) {
1112 // first page need to start after notes
1113 $drawTabTop = $this->tab_top;
1114 } elseif (!$drawTabHideTop) {
1115 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
1116 $drawTabTop -= $this->tabTitleHeight;
1117 } else {
1118 $drawTabHideTop = 1;
1119 }
1120 }
1121
1122 // last page need to include document footer
1123 if ($i == $pdf->getNumPages()) {
1124 // remove document footer height to tab bottom position
1125 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs);
1126 }
1127
1128 $drawTabHeight = $drawTabBottom - $drawTabTop;
1129 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object, $outputlangsbis);
1130
1131 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
1132
1133 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1134
1135 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
1136
1137 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
1138 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
1139
1140 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
1141 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1142 $this->_pagehead($pdf, $object, 0, $outputlangs);
1143 }
1144 if (!empty($tplidx)) {
1145 $pdf->useTemplate($tplidx);
1146 }
1147 }
1148
1149
1150 // reset text color before print footers
1151 $pdf->SetTextColor(0, 0, 0);
1152
1153 $pdf->setPage($pdf->getNumPages());
1154
1155 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1156
1157 // Display infos area
1158 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1159
1160 // Display total zone
1161 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1162
1163 // Display payment area
1164 $listofpayments = $object->getListOfPayments('', 0, 1);
1165 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1166 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1167 }
1168
1169 // Add number of pages in footer
1170 if (method_exists($pdf, 'AliasNbPages')) {
1171 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1172 }
1173
1174 // Add terms to sale
1175 $termsofsalefilename = getDolGlobalString('MAIN_INFO_INVOICE_TERMSOFSALE');
1176 if ($this->mustAddTermsOfSale($object, 'INVOICE') && $termsofsalefilename) {
1177 $termsofsale = $conf->invoice->dir_output.'/'.$termsofsalefilename;
1178 if (!empty($conf->invoice->multidir_output[$object->entity ?? $conf->entity])) {
1179 $termsofsale = $conf->invoice->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
1180 }
1181
1182 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1183 $pagecount = $pdf->setSourceFile($termsofsale);
1184 for ($i = 1; $i <= $pagecount; $i++) {
1185 $tplIdx = $pdf->importPage($i);
1186 if ($tplIdx !== false) {
1187 $s = $pdf->getTemplatesize($tplIdx);
1188 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1189 $pdf->useTemplate($tplIdx);
1190 } else {
1191 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
1192 }
1193 }
1194 }
1195 }
1196
1197 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
1198 $this->addBottomQRInvoice($pdf, $object, $outputlangs);
1199 }
1200
1201 $pdf->Close();
1202
1203 $pdf->Output($file, 'F');
1204
1205 // Add pdfgeneration hook
1206 $hookmanager->initHooks(array('pdfgeneration'));
1207 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1208 global $action;
1209 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1210 $this->warnings = $hookmanager->warnings;
1211 if ($reshook < 0) {
1212 $this->error = $hookmanager->error;
1213 $this->errors = $hookmanager->errors;
1214 dolChmod($file);
1215 return -1;
1216 }
1217
1218 dolChmod($file);
1219
1220 $this->result = array('fullpath' => $file);
1221
1222 return 1; // No error
1223 } else {
1224 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1225 return 0;
1226 }
1227 } else {
1228 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1229 return 0;
1230 }
1231 }
1232
1233
1243 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1244 {
1245 $sign = 1;
1246 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1247 $sign = -1;
1248 }
1249
1250 $tab3_posx = 120;
1251 $tab3_top = $posy + 8;
1252 $tab3_width = 80;
1253 $tab3_height = 4;
1254 if ($this->page_largeur < 210) { // To work with US executive format
1255 $tab3_posx -= 15;
1256 }
1257
1258 $default_font_size = pdf_getPDFFontSize($outputlangs);
1259
1260 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1261 if ($object->type == 2) {
1262 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1263 }
1264
1265 $pdf->SetFont('', '', $default_font_size - 3);
1266 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1267 $pdf->MultiCell(60, 3, $title, 0, 'L', false);
1268
1269 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1270
1271 $pdf->SetFont('', '', $default_font_size - 4);
1272 $pdf->SetXY($tab3_posx, $tab3_top);
1273 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
1274 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1275 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
1276 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1277 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
1278 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1279 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
1280
1281 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1282
1283 $y = 0;
1284
1285 $pdf->SetFont('', '', $default_font_size - 4);
1286
1287
1288 // Loop on each discount available (deposits and credit notes and excess of payment included)
1289 $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
1290 $sql .= " re.description, re.fk_facture_source,";
1291 $sql .= " f.type, f.datef";
1292 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1293 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1294 $resql = $this->db->query($sql);
1295 if ($resql) {
1296 $num = $this->db->num_rows($resql);
1297 $i = 0;
1298 $invoice = new Facture($this->db);
1299 while ($i < $num) {
1300 $y += 3;
1301 $obj = $this->db->fetch_object($resql);
1302
1303 if ($obj->type == 2) {
1304 $text = $outputlangs->transnoentities("CreditNote");
1305 } elseif ($obj->type == 3) {
1306 $text = $outputlangs->transnoentities("Deposit");
1307 } elseif ($obj->type == 0) {
1308 $text = $outputlangs->transnoentities("ExcessReceived");
1309 } else {
1310 $text = $outputlangs->transnoentities("UnknownType");
1311 }
1312
1313 $invoice->fetch($obj->fk_facture_source);
1314
1315 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1316 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', false);
1317 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1318 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', false);
1319 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1320 $pdf->MultiCell(20, 3, $text, 0, 'L', false);
1321 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1322 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', false);
1323
1324 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1325
1326 $i++;
1327 }
1328 } else {
1329 $this->error = $this->db->lasterror();
1330 return -1;
1331 }
1332
1333 // Loop on each payment
1334 // TODO Call getListOfPayments instead of hard coded sql
1335 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1336 $sql .= " cp.code";
1337 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1338 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1339 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1340 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1341 $sql .= " ORDER BY p.datep";
1342
1343 $resql = $this->db->query($sql);
1344 if ($resql) {
1345 $num = $this->db->num_rows($resql);
1346 $i = 0;
1347 $y += 3;
1348 $maxY = $y;
1349 while ($i < $num) {
1350 $row = $this->db->fetch_object($resql);
1351 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1352 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1353 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1354 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', false);
1355 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1356 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1357
1358 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1359 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1360 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1361 $pdf->MultiCell(30, 3, $row->num, 0, 'L', false);
1362 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1363 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1364 $y += 3;
1365 $i++;
1366 }
1367
1368 return $tab3_top + $y + 3;
1369 } else {
1370 $this->error = $this->db->lasterror();
1371 return -1;
1372 }
1373 }
1374
1375
1386 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1387 {
1388 global $mysoc;
1389
1390 $default_font_size = pdf_getPDFFontSize($outputlangs);
1391
1392 $pdf->SetFont('', '', $default_font_size - 1);
1393
1394 krsort($this->tva_array);
1395
1396 // Clean data type
1397 $object->total_tva = (float) $object->total_tva;
1398
1399 // Show VAT details
1400 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1401 $pdf->SetFillColor(224, 224, 224);
1402
1403 $pdf->SetFont('', '', $default_font_size - 2);
1404 $pdf->SetXY($this->marge_gauche, $posy);
1405 $titre = $outputlangs->transnoentities("VAT");
1406 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1407
1408 $pdf->SetFont('', '', $default_font_size - 2);
1409 $pdf->SetXY($this->marge_gauche + 25, $posy);
1410 $titre = $outputlangs->transnoentities("NetTotal");
1411 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1412
1413 $pdf->SetFont('', '', $default_font_size - 2);
1414 $pdf->SetXY($this->marge_gauche + 50, $posy);
1415 $titre = $outputlangs->transnoentities("VATAmount");
1416 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1417
1418 $pdf->SetFont('', '', $default_font_size - 2);
1419 $pdf->SetXY($this->marge_gauche + 75, $posy);
1420 $titre = $outputlangs->transnoentities("AmountTotal");
1421 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1422
1423 $posy = $pdf->GetY();
1424 $tot_ht = 0;
1425 $tot_tva = 0;
1426 $tot_ttc = 0;
1427
1428 foreach ($this->tva_array as $tvakey => $tvaval) {
1429 $pdf->SetFont('', '', $default_font_size - 2);
1430 $pdf->SetXY($this->marge_gauche, $posy);
1431 $titre = round((float) $tvakey, 2) . "%";
1432 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1433
1434 $pdf->SetFont('', '', $default_font_size - 2);
1435 $pdf->SetXY($this->marge_gauche + 25, $posy);
1436 $titre = price($tvaval['tot_ht']);
1437 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1438 $tot_ht += $tvaval['tot_ht'];
1439
1440 $pdf->SetFont('', '', $default_font_size - 2);
1441 $pdf->SetXY($this->marge_gauche + 50, $posy);
1442 $titre = price($tvaval['amount']);
1443 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1444 $tot_tva += $tvaval['amount'];
1445
1446 $pdf->SetFont('', '', $default_font_size - 2);
1447 $pdf->SetXY($this->marge_gauche + 75, $posy);
1448 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1449 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1450 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1451
1452 $posy = $pdf->GetY();
1453 }
1454 }
1455
1456 // If France, show VAT mention if applicable
1457 $showvatmention = 0;
1458 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1459 $pdf->SetFont('', '', $default_font_size - 2);
1460 $pdf->SetXY($this->marge_gauche, $posy);
1461 if (empty($mysoc->tva_assuj)) {
1462 if ($mysoc->forme_juridique_code == 92) {
1463 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', false);
1464 } else {
1465 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1466 }
1467 $showvatmention++;
1468 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1469 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', false);
1470 $showvatmention++;
1471 }
1472 $posy = $pdf->GetY();
1473 }
1474
1475 $showvatmention += pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1476
1477 if ($showvatmention) {
1478 $posy += 3;
1479 }
1480
1481 $posxval = 52; // Position of values of properties shown on left side
1482 $posxend = 110; // End of x for text on left side
1483 if ($this->page_largeur < 210) { // To work with US executive format
1484 $posxend -= 10;
1485 }
1486
1487 // Show previous and new balance
1488 if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) {
1489 // All customer previous invoices
1490 $sql = "SELECT f.rowid, f.datef, f.total_ttc";
1491 $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
1492 $sql .= " WHERE f.fk_soc = " . ((int) $object->socid);
1493 $sql .= " AND f.entity IN (" . getEntity('invoice') . ")";
1494 $sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
1495 $sql .= " AND f.rowid < " . ((int) $object->id);
1496 $sql .= " AND f.fk_statut > 0";
1497 $sql .= " ORDER BY f.datef ASC";
1498
1499 $old_balance = 0;
1500 $invoices = array();
1501 $resql = $this->db->query($sql);
1502 if ($resql) {
1503 while ($obj = $this->db->fetch_object($resql)) {
1504 $invoices[] = $obj;
1505 $old_balance += $obj->total_ttc;
1506 }
1507 $this->db->free($resql);
1508 }
1509
1510 // All payments before current date
1511 $sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1512 $sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1513 $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1514 $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1515 $sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
1516 $sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'";
1517 $sql_payments .= " ORDER BY p.datep ASC";
1518
1519 $total_payments = 0;
1520 $resql_payments = $this->db->query($sql_payments);
1521 if ($resql_payments) {
1522 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1523 $total_payments += $obj_payment->amount;
1524 }
1525 $this->db->free($resql_payments);
1526 }
1527
1528 // Payments made on current invoice date (including current invoice)
1529 $sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1530 $sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1531 $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1532 $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1533 $sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
1534 $sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
1535
1536 $current_date_payments = 0;
1537 $resql_current_date = $this->db->query($sql_current_date_payments);
1538 if ($resql_current_date) {
1539 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1540 $current_date_payments += $obj_current->amount;
1541 }
1542 $this->db->free($resql_current_date);
1543 }
1544
1545 // Previous balance
1546 $old_balance -= $total_payments;
1547
1548 // New balance
1549 $new_balance = $old_balance + $object->total_ttc - $current_date_payments;
1550
1551 $pdf->SetFillColor(224, 224, 224);
1552 $pdf->SetFont('', '', $default_font_size - 2);
1553 $pdf->SetXY($this->marge_gauche, $posy);
1554 $titre = $outputlangs->transnoentities("PreviousBalance").' : '.price($old_balance);
1555 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true);
1556
1557 $pdf->SetFont('', '', $default_font_size - 2);
1558 $pdf->SetXY($posxval + 8, $posy);
1559 $titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance);
1560 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true);
1561
1562 $posy = $pdf->GetY() + 1;
1563 }
1564
1565 // Show payments conditions
1566 if ($object->type != 2 && $object->cond_reglement_code) {
1567 $pdf->SetFont('', '', $default_font_size - 2);
1568 $pdf->SetXY($this->marge_gauche, $posy);
1569 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1570 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1571
1572 $pdf->SetFont('', '', $default_font_size - 2);
1573 $pdf->SetXY($posxval, $posy);
1574 $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);
1575 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1576 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1577
1578 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1579 }
1580
1581 // Show category of operations
1582 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1583 $pdf->SetFont('', '', $default_font_size - 2);
1584 $pdf->SetXY($this->marge_gauche, $posy);
1585 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1586 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1587
1588 $pdf->SetFont('', '', $default_font_size - 2);
1589 $pdf->SetXY($posxval, $posy);
1590 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1591 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1592
1593 $posy = $pdf->GetY() + 3; // for 2 lines
1594 }
1595
1596 if ($object->type != 2) {
1597 // Check a payment mode is defined
1598 if (empty($object->mode_reglement_code)
1599 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1600 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1601 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1602 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1603 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1604 // Avoid having any valid PDF with setup that is not complete
1605 $outputlangs->load("errors");
1606
1607 $pdf->SetXY($this->marge_gauche, $posy);
1608 $pdf->SetTextColor(200, 0, 0);
1609 $pdf->SetFont('', '', $default_font_size - 2);
1610 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1611 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', false);
1612 $pdf->SetTextColor(0, 0, 0);
1613
1614 $posy = $pdf->GetY() + 1;
1615 }
1616
1617 // Show payment mode
1618 if (!empty($object->mode_reglement_code)
1619 && $object->mode_reglement_code != 'CHQ'
1620 && $object->mode_reglement_code != 'VIR') {
1621 $pdf->SetFont('', '', $default_font_size - 2);
1622 $pdf->SetXY($this->marge_gauche, $posy);
1623 $titre = $outputlangs->transnoentities("PaymentMode").':';
1624 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1625
1626 $pdf->SetFont('', '', $default_font_size - 2);
1627 $pdf->SetXY($posxval, $posy);
1628 $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);
1629
1630 //#21654: add account number used for the debit
1631 if ($object->mode_reglement_code == "PRE") {
1632 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1633 $bac = new CompanyBankAccount($this->db);
1634 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1635 $bac->fetch(0, '', $object->thirdparty->id);
1636 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1637 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", pdf_truncate_text($pdf, $iban, 6, 'right', ''));
1638 }
1639
1640 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1641
1642 $posy = $pdf->GetY();
1643 }
1644
1645 // Show if Option VAT debit option is on also if transmitter is french
1646 // Decret n°2099-1299 2022-10-07
1647 // French legal mention: "Option pour le paiement de la taxe d'apres les debits"
1648 if ($this->emetteur->country_code == 'FR') {
1649 if (getDolGlobalInt('TAX_MODE') == 1) {
1650 $pdf->SetXY($this->marge_gauche, $posy);
1651 $pdf->writeHTMLCell(80, 5, null, null, $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1652
1653 $posy = $pdf->GetY() + 1;
1654 }
1655 }
1656
1657 // Show online payment link
1658 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1659 $useonlinepayment = 0;
1660 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1661 // Show online payment link
1662 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1663 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1664 $validpaymentmethod = getValidOnlinePaymentMethods('');
1665 $useonlinepayment = count($validpaymentmethod);
1666 }
1667
1668
1669 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1670 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1671 global $langs;
1672
1673 $langs->loadLangs(array('payment', 'stripe'));
1674 $servicename = $langs->transnoentities('Online');
1675 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1676 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1677
1678 $pdf->SetXY($this->marge_gauche, $posy);
1679 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, null, null, dol_htmlentitiesbr($linktopay), 0, 1);
1680
1681 $posy = $pdf->GetY() + 1;
1682 }
1683 }
1684
1685 // Show payment mode CHQ
1686 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1687 // If payment mode unregulated or payment mode forced to CHQ
1688 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1689 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1690
1691 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1692 $account = new Account($this->db);
1693 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1694
1695 $pdf->SetXY($this->marge_gauche, $posy);
1696 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1697 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1698 $posy = $pdf->GetY() + 1;
1699
1700 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1701 $pdf->SetXY($this->marge_gauche, $posy);
1702 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1703 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1704 $posy = $pdf->GetY() + 2;
1705 }
1706 }
1707 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1708 $pdf->SetXY($this->marge_gauche, $posy);
1709 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1710 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1711 $posy = $pdf->GetY() + 1;
1712
1713 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1714 $pdf->SetXY($this->marge_gauche, $posy);
1715 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1716 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1717 $posy = $pdf->GetY() + 2;
1718 }
1719 }
1720 }
1721 }
1722
1723 // A structured payment reference can be paid with on its own, so when no
1724 // bank account is shown on the invoice it is printed by itself.
1725 $showbankblock = ((empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1726 && ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')));
1727 if (!empty($object->payment_reference) && !$showbankblock) {
1728 include_once DOL_DOCUMENT_ROOT.'/core/lib/paymentref.lib.php';
1729 $pdf->SetXY($this->marge_gauche, $posy);
1730 // Same weight and size as the IBAN and BIC lines drawn by pdf_bank()
1731 $pdf->SetFont('', 'B', $default_font_size - 3);
1732 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentReference').": " . $outputlangs->convToOutputCharset(dolPayRefFormatForDisplay($object->payment_reference, $mysoc->country_code)), 0, 'L', false);
1733 $posy = $pdf->GetY() + 1;
1734 }
1735
1736 // If payment mode not forced or forced to VIR, show payment with BAN
1737 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1738 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1739 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : (int) $object->fk_account);
1740 if ($object->fk_bank > 0) {
1741 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1742 }
1743 $account = new Account($this->db);
1744 $account->fetch($bankid);
1745
1746 $curx = $this->marge_gauche;
1747 $cury = $posy;
1748
1749 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1750
1751 // The payment reference belongs with the account it is paid to, so it
1752 // is shown right after the IBAN and the BIC. Grouped for reading, the
1753 // stored value stays compact for the QR code and the SEPA file.
1754 if (!empty($object->payment_reference)) {
1755 include_once DOL_DOCUMENT_ROOT.'/core/lib/paymentref.lib.php';
1756 // Same weight and size as the IBAN and BIC lines above
1757 $pdf->SetXY($this->marge_gauche, $posy);
1758 $pdf->SetFont('', 'B', $default_font_size - 3);
1759 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentReference').": " . $outputlangs->convToOutputCharset(dolPayRefFormatForDisplay($object->payment_reference, $mysoc->country_code)), 0, 'L', false);
1760 $posy = $pdf->GetY();
1761 }
1762
1763 $posy += 2;
1764
1765 // SHOW EPC QR CODE at bottom, but only if unpaid amount exists
1766 if ((getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == 'bottom') && ($object->getRemainToPay() > 0)) {
1767 $qrPosX = $this->marge_gauche + 5;
1768 $qrPosY = $posy;
1769 $qrCodeColor = array('25', '25', '25');
1770 $styleQr = array(
1771 'border' => false,
1772 'padding' => 0,
1773 'fgcolor' => $qrCodeColor,
1774 'bgcolor' => false, //array(255,255,255)
1775 'module_width' => 1, // width of a single module in points
1776 'module_height' => 1 // height of a single module in points
1777 );
1778
1779 $EPCQrCodeString = $object->buildEPCQrCodeString();
1780 $pdf->write2DBarcode($EPCQrCodeString, 'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr, 'N');
1781
1782 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1783 $pdf->SetFont('', '', $default_font_size - 5);
1784 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', false);
1785 // Continue below the QR code, which is taller than the text beside it
1786 $posy = max($pdf->GetY(), $qrPosY + 20) + 2;
1787 $pdf->SetXY($this->marge_gauche, $posy);
1788 }
1789
1790 // Show structured communication of invoices validated before the
1791 // payment reference was stored on them
1792 if (empty($object->payment_reference) && getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1793 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1794 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1795
1796 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', false);
1797 }
1798 }
1799 }
1800 }
1801
1802 return $posy;
1803 }
1804
1805
1817 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1818 {
1819 global $mysoc, $hookmanager;
1820
1821 $sign = 1;
1822 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1823 $sign = -1;
1824 }
1825
1826 $default_font_size = pdf_getPDFFontSize($outputlangs);
1827
1828 $tab2_top = $posy;
1829 $tab2_hl = 4;
1830 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1831 $pdf->SetFont('', '', $default_font_size - 2);
1832 } else {
1833 $pdf->SetFont('', '', $default_font_size - 1);
1834 }
1835
1836 // Total table
1837 $col1x = 120;
1838 $col2x = 170;
1839 if ($this->page_largeur < 210) { // To work with US executive format
1840 $col1x -= 15;
1841 $col2x -= 10;
1842 }
1843 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1844
1845 $useborder = 0;
1846 $index = 0;
1847
1848 // Add trigger to allow to edit $object
1849 $parameters = array(
1850 'object' => &$object,
1851 'outputlangs' => $outputlangs,
1852 );
1853 $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1854
1855 // overall percentage of advancement
1856 $percent = 0;
1857 $i = 0;
1858 foreach ($object->lines as $line) {
1859 if ($line->product_type != 9) {
1860 $percent += $line->situation_percent;
1861 $i++;
1862 }
1863 }
1864
1865 if (!empty($i)) {
1866 $avancementGlobal = $percent / $i;
1867 } else {
1868 $avancementGlobal = 0;
1869 }
1870
1871 $object->fetchPreviousNextSituationInvoice();
1872 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1873
1874 $total_a_payer = 0;
1875 $total_a_payer_ttc = 0;
1876 foreach ($TPreviousIncoice as &$fac) {
1877 $total_a_payer += $fac->total_ht;
1878 $total_a_payer_ttc += $fac->total_ttc;
1879 }
1880 $total_a_payer += $object->total_ht;
1881 $total_a_payer_ttc += $object->total_ttc;
1882
1883 if (!empty($avancementGlobal)) {
1884 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1885 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1886 } else {
1887 $total_a_payer = 0;
1888 $total_a_payer_ttc = 0;
1889 }
1890
1891 $i = 1;
1892 $fac = null;
1893 if (!empty($TPreviousIncoice)) {
1894 $pdf->setY($tab2_top);
1895 $posy = $pdf->GetY();
1896
1897 foreach ($TPreviousIncoice as &$fac) {
1898 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1899 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1900 $pdf->addPage();
1901 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1902 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1903 $pdf->setY($this->tab_top_newpage);
1904 } else {
1905 $pdf->setY($this->marge_haute);
1906 }
1907 $posy = $pdf->GetY();
1908 }
1909
1910 // Cumulate preceding VAT
1911 $index++;
1912 $pdf->SetFillColor(255, 255, 255);
1913 $pdf->SetXY($col1x, $posy);
1914 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", (string) $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', true);
1915
1916 $pdf->SetXY($col2x, $posy);
1917
1918 $facSign = '';
1919 if ($i > 1) {
1920 $facSign = $fac->total_ht >= 0 ? '+' : '';
1921 }
1922
1923 $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1924
1925 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', true);
1926
1927 $i++;
1928 $posy += $tab2_hl;
1929
1930 $pdf->setY($posy);
1931 }
1932
1933 // Display current total
1934 $pdf->SetFillColor(255, 255, 255);
1935 $pdf->SetXY($col1x, $posy);
1936 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", (string) $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', true);
1937
1938 $pdf->SetXY($col2x, $posy);
1939 $facSign = '';
1940 if ($i > 1) {
1941 $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1942 }
1943
1944 if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1945 $facSign = '-';
1946 }
1947
1948
1949 $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1950 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', true);
1951
1952 $posy += $tab2_hl;
1953
1954 // Display all total
1955 $pdf->SetFont('', '', $default_font_size - 1);
1956 $pdf->SetFillColor(255, 255, 255);
1957 $pdf->SetXY($col1x, $posy);
1958 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", (string) $avancementGlobal), 0, 'L', true);
1959
1960 $pdf->SetXY($col2x, $posy);
1961 $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', true);
1962 $pdf->SetFont('', '', $default_font_size - 2);
1963
1964 $posy += $tab2_hl;
1965
1966 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1967 $pdf->addPage();
1968 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1969 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1970 $pdf->setY($this->tab_top_newpage);
1971 } else {
1972 $pdf->setY($this->marge_haute);
1973 }
1974
1975 $posy = $pdf->GetY();
1976 }
1977
1978 $tab2_top = $posy;
1979 $index = 0;
1980
1981 $tab2_top += 3;
1982 }
1983
1984
1985 // Get Total HT
1986 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1987
1988 // Total discount
1989 $total_discount_on_lines = 0;
1990 $multicurrency_total_discount_on_lines = 0;
1991 foreach ($object->lines as $i => $line) {
1992 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1993 $multicurrency_resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2, 1);
1994
1995 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1996 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1997 // If line was a negative line, we do not count the discount as a discount
1998 if ($line->total_ht < 0) {
1999 $total_discount_on_lines += -$line->total_ht;
2000 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
2001 }
2002 }
2003
2004 // Show total discount only if there is some discount on lines
2005 if ($total_discount_on_lines > 0 && !$object->isSituationInvoice()) {
2006 // Show discount except on credit note type invoices
2007 if ($this->showAmountBeforeDiscount && $object->type != 2) {
2008 $pdf->SetFillColor(255, 255, 255);
2009 $pdf->SetXY($col1x, $tab2_top);
2010 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', true);
2011 $pdf->SetXY($col2x, $tab2_top);
2012
2013 $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));
2014 $pdf->MultiCell($largcol2, $tab2_hl, price($total_before_discount_to_show, 0, $outputlangs), 0, 'R', true);
2015
2016 $index++;
2017 }
2018
2019 // Show total NET before discount except on credit note type invoices
2020 if ($this->showDiscountAmount && $object->type != 2) {
2021 $pdf->SetFillColor(255, 255, 255);
2022 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
2023 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', true);
2024 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
2025
2026 $total_discount_to_show = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
2027 $pdf->MultiCell($largcol2, $tab2_hl, price($total_discount_to_show, 0, $outputlangs), 0, 'R', true);
2028
2029 $index++;
2030 }
2031 }
2032
2033 // Total HT
2034 $pdf->SetFillColor(255, 255, 255);
2035 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2036 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ? "TotalHT" : "Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities(!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ? "TotalHT" : "Total") : ''), 0, 'L', true);
2037
2038 $total_ht = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
2039 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2040 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ht, 0, $outputlangs), 0, 'R', true);
2041
2042 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
2043 $index++;
2044 $pdf->SetFillColor(255, 255, 255);
2045 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2046 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', true);
2047
2048 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2049 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', true);
2050 }
2051
2052 // Show VAT by rates and total
2053 $pdf->SetFillColor(248, 248, 248);
2054
2055 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
2056 $total_ttc_origin = $object->total_ttc;
2057
2058 $this->atleastoneratenotnull = 0;
2059
2060
2061 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
2062 $tvaisnull = false;
2063 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
2064 $tva_el = reset($this->tva_array);
2065 if ($tva_el['vatrate'] == '0.000' && is_float($tva_el['amount'])) $tvaisnull = true;
2066 }
2067 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
2068 // Nothing to do
2069 } else {
2070 // Show VAT lines
2071 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
2072
2073 // Revenue stamp
2074 if (price2num($object->revenuestamp, 'MT') != 0) {
2075 $index++;
2076 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2077 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', true);
2078
2079 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2080 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', true);
2081 }
2082
2083 // Total TTC
2084 $index++;
2085 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2086 $pdf->SetTextColor(0, 0, 60);
2087 $pdf->SetFillColor(224, 224, 224);
2088 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', true);
2089
2090 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2091 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2092 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
2093 } else {
2094 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
2095
2096 //$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');
2097 $index++;
2098 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2099 $pdf->SetTextColor(0, 0, 60);
2100 $pdf->SetFillColor(224, 224, 224);
2101 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
2102
2103 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2104 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
2105 }
2106
2107 // Retained warranty
2108 if ($object->displayRetainedWarranty()) {
2109 $pdf->SetTextColor(40, 40, 40);
2110 $pdf->SetFillColor(255, 255, 255);
2111
2112 $retainedWarranty = $object->getRetainedWarrantyAmount('MT');
2113 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
2114
2115 // Billed - retained warranty
2116 $index++;
2117 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2118 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', true);
2119
2120 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2121 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', true);
2122
2123 // retained warranty
2124 $index++;
2125 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2126
2127 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
2128 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
2129
2130 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', true);
2131 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2132 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', true);
2133 }
2134 }
2135 }
2136
2137 $pdf->SetTextColor(0, 0, 0);
2138
2139 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
2140 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
2141
2142 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
2143 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2144 // Not used in this case, initialized to avoid CI warnings
2145 $deja_regle_origin = 0;
2146 $creditnoteamount_origin = 0;
2147 $depositsamount_origin = 0;
2148 $resteapayer_origin = 0;
2149 } else {
2150 $deja_regle_origin = $object->getSommePaiement(0);
2151 $creditnoteamount_origin = $object->getSumCreditNotesUsed(0); // Warning, this also include excess received
2152 $depositsamount_origin = $object->getSumDepositsUsed(0);
2153 $resteapayer_origin = price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin, 'MT');
2154 }
2155 if (!empty($object->paye)) {
2156 $resteapayer = 0;
2157 $resteapayer_origin = 0;
2158 }
2159
2160 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2161
2162 $pdf->SetFont('', '', $default_font_size - 1);
2163 $pdf->SetTextColor(0, 0, 0);
2164
2165 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2166
2167 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2168 if ($reshook < 0) {
2169 $this->error = $hookmanager->error;
2170 $this->errors = $hookmanager->errors;
2171 }
2172
2173 $index++;
2174 return ($tab2_top + ($tab2_hl * $index));
2175 }
2176
2177 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2185 public static function liste_modeles($db, $maxfilenamelength = 0)
2186 {
2187 // phpcs:enable
2188 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2189 }
2190
2191 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2206 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $object = '', $outputlangsbis = null)
2207 {
2208 // Force to disable hidetop and hidebottom
2209 $hidebottom = 0;
2210 if ($hidetop) {
2211 $hidetop = -1;
2212 }
2213
2214 if ($object instanceOf Facture) {
2215 $currency = $object->multicurrency_code;
2216 } else {
2217 $currency = $object;
2218 }
2219 if (empty($currency)) {
2220 $currency = getDolCurrency();
2221 }
2222
2223 $default_font_size = pdf_getPDFFontSize($outputlangs);
2224
2225 // Amount in (at tab_top - 1)
2226 $pdf->SetTextColor(0, 0, 0);
2227 $pdf->SetFont('', '', $default_font_size - 2);
2228
2229 if (empty($hidetop)) {
2230 // Show category of operations
2231 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2232 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2233 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2234 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2235 }
2236
2237 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2238 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2239 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2240 }
2241 if ($currency != getDolCurrency()) {
2242 // Use nb of digit of the total price of main currency + nb of digit for total price of foreign currency + 1
2243 $maxnbofdec = getDolGlobalInt('MAIN_MAX_DECIMALS_TOT') + getDolGlobalInt('MAIN_MAX_DECIMALS_CURRENCY_TOT', getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')) + 1;
2244 $pricetoshow1 = price($object->multicurrency_tx, 0, $outputlangs, 1, 0, $maxnbofdec, $currency);
2245 $pricetoshow2 = price($object->multicurrency_tx, 0, $outputlangs, 1, 0, -2, $currency);
2246 $pricetoshow = ((strlen($pricetoshow1) < strlen($pricetoshow2)) ? $pricetoshow1 : $pricetoshow2);
2247 $titre .= ' ('.$pricetoshow.' = '.price(1, 0, $outputlangs, 1, 0, 0, getDolCurrency()).')';
2248 }
2249
2250 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2251 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2252
2253 // MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2254 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2255 $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')));
2256 }
2257 }
2258
2259 $pdf->SetDrawColor(128, 128, 128);
2260 $pdf->SetFont('', '', $default_font_size - 1);
2261
2262 // Output Rect
2263 $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
2264
2265
2266 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2267
2268 if (empty($hidetop)) {
2269 $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
2270 }
2271 }
2272
2273 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2284 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2285 {
2286 // phpcs:enable
2287 global $conf, $langs;
2288
2289 $ltrdirection = 'L';
2290 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2291 $ltrdirection = 'R';
2292 }
2293
2294 // Load traductions files required by page
2295 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2296
2297 $default_font_size = pdf_getPDFFontSize($outputlangs);
2298
2299 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2300
2301 $pdf->SetTextColor(0, 0, 60);
2302 $pdf->SetFont('', 'B', $default_font_size + 3);
2303
2304 $w = 110;
2305
2306 $posy = $this->marge_haute;
2307 $posx = $this->page_largeur - $this->marge_droite - $w;
2308
2309 $pdf->SetXY($this->marge_gauche, $posy);
2310
2311 // Logo
2312 $logodir = $conf->mycompany->dir_output;
2313 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
2314 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
2315 }
2316 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
2317
2318 $pdf->SetFont('', 'B', $default_font_size + 3);
2319 $pdf->SetXY($posx, $posy);
2320 $pdf->SetTextColor(0, 0, 60);
2321 $subtitle = "";
2322 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2323 if ($object->type == 1) {
2324 $title = $outputlangs->transnoentities("InvoiceReplacement");
2325 }
2326 if ($object->type == 2) {
2327 $title = $outputlangs->transnoentities("InvoiceAvoir");
2328 }
2329 if ($object->type == 3) {
2330 $title = $outputlangs->transnoentities("PdfInvoiceDepositTitle");
2331 }
2332 if ($this->situationinvoice) {
2333 $outputlangs->loadLangs(array("other"));
2334 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2335 $subtitle = $outputlangs->transnoentities("PDFSituationTitle", (string) $object->situation_counter);
2336 }
2337 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2338 $title .= ' - ';
2339 if ($object->type == 0) {
2340 if ($this->situationinvoice) {
2341 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2342 }
2343 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2344 } elseif ($object->type == 1) {
2345 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2346 } elseif ($object->type == 2) {
2347 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2348 } elseif ($object->type == 3) {
2349 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2350 } elseif ($object->type == 4) {
2351 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2352 }
2353 }
2354 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2355 if ($object->status == $object::STATUS_DRAFT) {
2356 $pdf->SetTextColor(128, 0, 0);
2357 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2358 }
2359
2360 $pdf->MultiCell($w, 3, $title, '', 'R');
2361 $posy = $pdf->GetY();
2362
2363 if (!empty($subtitle)) {
2364 $pdf->SetFont('', 'B', $default_font_size);
2365 $pdf->SetXY($posx, $posy);
2366 $pdf->MultiCell($w, 6, $subtitle, '', 'R');
2367 $posy = $pdf->GetY();
2368 }
2369
2370 $pdf->SetFont('', '', $default_font_size - 2);
2371
2372 pdfWriteAdditionnalTitle($pdf, $outputlangs, $this->page_hauteur, $object, $w, $posx, $posy);
2373
2374 /*
2375 $posy += 5;
2376 $pdf->SetXY($posx, $posy);
2377 $pdf->SetTextColor(0, 0, 60);
2378 $pdf->SetFont('', 'B', $default_font_size);
2379 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2380 if ($object->status == $object::STATUS_DRAFT) {
2381 $pdf->SetTextColor(128, 0, 0);
2382 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2383 }
2384 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2385
2386 $posy += 3;
2387 $pdf->SetFont('', '', $default_font_size - 2);
2388
2389 if ($object->ref_customer) {
2390 $posy += 4;
2391 $pdf->SetXY($posx, $posy);
2392 $pdf->SetTextColor(0, 0, 60);
2393 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".pdf_truncate_text($pdf, $outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2394 }
2395
2396 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2397 $object->fetchProject();
2398 if (!empty($object->project->title)) {
2399 $posy += 3;
2400 $pdf->SetXY($posx, $posy);
2401 $pdf->SetTextColor(0, 0, 60);
2402 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".pdf_truncate_text($pdf, $object->project->title, 50), '', 'R');
2403 $posy = $pdf->getY();
2404 }
2405 }
2406
2407 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2408 $object->fetchProject();
2409 if (!empty($object->project->ref)) {
2410 $outputlangs->load("projects");
2411 $posy += 3;
2412 $pdf->SetXY($posx, $posy);
2413 $pdf->SetTextColor(0, 0, 60);
2414 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".$object->project->ref, '', 'R');
2415 }
2416 }
2417
2418 $objectidnext = $object->getIdReplacingInvoice('validated');
2419 if ($object->type == 0 && $objectidnext) {
2420 $objectreplacing = new Facture($this->db);
2421 $objectreplacing->fetch($objectidnext);
2422
2423 $posy += 3;
2424 $pdf->SetXY($posx, $posy);
2425 $pdf->SetTextColor(0, 0, 60);
2426 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2427 }
2428 if ($object->type == 1) {
2429 $objectreplaced = new Facture($this->db);
2430 $objectreplaced->fetch($object->fk_facture_source);
2431
2432 $posy += 4;
2433 $pdf->SetXY($posx, $posy);
2434 $pdf->SetTextColor(0, 0, 60);
2435 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2436 }
2437 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2438 $objectreplaced = new Facture($this->db);
2439 $objectreplaced->fetch($object->fk_facture_source);
2440
2441 $posy += 3;
2442 $pdf->SetXY($posx, $posy);
2443 $pdf->SetTextColor(0, 0, 60);
2444 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2445 }
2446
2447 $posy += 4;
2448 $pdf->SetXY($posx, $posy);
2449 $pdf->SetTextColor(0, 0, 60);
2450
2451 $title = $outputlangs->transnoentities("DateInvoice");
2452 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2453 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2454 }
2455 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2456
2457 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2458 $posy += 4;
2459 $pdf->SetXY($posx, $posy);
2460 $pdf->SetTextColor(0, 0, 60);
2461 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2462 }
2463
2464 if ($object->type != 2) {
2465 $posy += 3;
2466 $pdf->SetXY($posx, $posy);
2467 $pdf->SetTextColor(0, 0, 60);
2468 $title = $outputlangs->transnoentities("DateDue");
2469 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2470 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2471 }
2472 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2473 }
2474
2475 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2476 $posy += 3;
2477 $pdf->SetXY($posx, $posy);
2478 $pdf->SetTextColor(0, 0, 60);
2479 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
2480 }
2481
2482 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2483 $posy += 3;
2484 $pdf->SetXY($posx, $posy);
2485 $pdf->SetTextColor(0, 0, 60);
2486 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
2487 }
2488
2489 // Get contact
2490 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2491 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2492 if (count($arrayidcontact) > 0) {
2493 $usertmp = new User($this->db);
2494 $usertmp->fetch($arrayidcontact[0]);
2495 $posy += 4;
2496 $pdf->SetXY($posx, $posy);
2497 $pdf->SetTextColor(0, 0, 60);
2498 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2499 }
2500 }
2501
2502 $posy += 1;
2503
2504 $top_shift = 0;
2505 $shipp_shift = 0;
2506 // Show list of linked objects
2507 if (!getDolGlobalString('INVOICE_HIDE_LINKED_OBJECT')) {
2508 $current_y = $pdf->getY();
2509 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2510 if ($current_y < $pdf->getY()) {
2511 $top_shift = $pdf->getY() - $current_y;
2512 }
2513 }
2514
2515 if ($showaddress) {
2516 // Sender properties
2517 $carac_emetteur = '';
2518 // Add internal contact of object if defined
2519 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2520 if (count($arrayidcontact) > 0) {
2521 $object->fetch_user($arrayidcontact[0]);
2522 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2523 $carac_emetteur .= $labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2524 $carac_emetteur .= "\n";
2525 }
2526
2527 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2528
2529 // Show sender
2530 // $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2531 $posy = (getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32);
2532 $posy += $top_shift;
2533 $posx = $this->marge_gauche;
2534 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2535 $posx = $this->page_largeur - $this->marge_droite - 80;
2536 }
2537
2538 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2539 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2540
2541 // Show sender frame
2542 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2543 $pdf->SetTextColor(0, 0, 0);
2544 $pdf->SetFont('', '', $default_font_size - 2);
2545 $pdf->SetXY($posx, $posy - 5);
2546 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2547 $pdf->SetXY($posx, $posy);
2548 $pdf->SetFillColor(230, 230, 230);
2549 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2550 $pdf->SetTextColor(0, 0, 60);
2551 }
2552
2553 // Show sender name
2554 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2555 $pdf->SetXY($posx + 2, $posy + 3);
2556 $pdf->SetFont('', 'B', $default_font_size);
2557 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2558 $posy = $pdf->getY();
2559 }
2560
2561 // Show sender information
2562 $pdf->SetXY($posx + 2, $posy);
2563 $pdf->SetFont('', '', $default_font_size - 1);
2564 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2565
2566 // If BILLING contact defined on invoice, we use it
2567 $usecontact = false;
2568 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2569 if (count($arrayidcontact) > 0) {
2570 $usecontact = true;
2571 $result = $object->fetch_contact($arrayidcontact[0]);
2572 }
2573
2574 // Recipient name
2575 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2576 $thirdparty = $object->contact;
2577 } else {
2578 $thirdparty = $object->thirdparty;
2579 }
2580
2581 $carac_client_name = is_object($thirdparty) ? pdfBuildThirdpartyName($thirdparty, $outputlangs) : '';
2582
2583 $mode = 'target';
2584 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2585
2586 // Show recipient
2587 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2588 if ($this->page_largeur < 210) {
2589 $widthrecbox = 84; // To work with US executive format
2590 }
2591 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2592 $posy += $top_shift;
2593 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2594 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2595 $posx = $this->marge_gauche;
2596 }
2597
2598 // Show recipient frame
2599 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2600 $pdf->SetTextColor(0, 0, 0);
2601 $pdf->SetFont('', '', $default_font_size - 2);
2602 $pdf->SetXY($posx + 2, $posy - 5);
2603 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2604 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2605 }
2606
2607 // Show recipient name
2608 $pdf->SetXY($posx + 2, $posy + 3);
2609 $pdf->SetFont('', 'B', $default_font_size);
2610 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2611 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2612
2613 $posy = $pdf->getY();
2614
2615 // Show recipient information
2616 $pdf->SetFont('', '', $default_font_size - 1);
2617 $pdf->SetXY($posx + 2, $posy);
2618 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2619 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2620
2621 // Show shipping/delivery address
2622 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2623 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2624
2625 if (!empty($idaddressshipping)) {
2626 $object->fetch_contact($idaddressshipping[0]); // Load $object->contact
2627 $companystatic = new Societe($this->db);
2628 $companystatic->fetch($object->contact->fk_soc);
2629 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2630 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'targetshipping', $object);
2631 } else {
2632 // When no explicit shipping address is defined, it means it is same than the billing address. It must not be shown twice.
2633 //$carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2634 //$carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2635 $carac_client_name_shipping = '';
2636 $carac_client_shipping = '';
2637 }
2638 if (!empty($carac_client_shipping)) {
2639 $posy += $hautcadre;
2640
2641 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2642
2643 // Show shipping frame
2644 $pdf->SetXY($posx + 2, $posy - 5);
2645 $pdf->SetFont('', '', $default_font_size - 2);
2646 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', false);
2647 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2648
2649 // Show shipping name
2650 $pdf->SetXY($posx + 2, $posy + 3);
2651 $pdf->SetFont('', 'B', $default_font_size);
2652 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2653
2654 $posy = $pdf->getY();
2655
2656 // Show shipping information
2657 $pdf->SetXY($posx + 2, $posy);
2658 $pdf->SetFont('', '', $default_font_size - 1);
2659 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2660
2661 $shipp_shift += $hautcadre + 10;
2662 }
2663 }
2664 }
2665
2666 $pdf->SetTextColor(0, 0, 0);
2667
2668 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2669
2670 return $pagehead;
2671 }
2672
2673 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2684 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2685 {
2686 // phpcs:enable
2687 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2688 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $heightforqrinvoice + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2689 }
2690
2701 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2702 {
2703 global $hookmanager;
2704
2705 // Default field style for content
2706 $this->defaultContentsFieldsStyle = array(
2707 'align' => 'R', // R,C,L
2708 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2709 );
2710
2711 // Default field style for content
2712 $this->defaultTitlesFieldsStyle = array(
2713 'align' => 'C', // R,C,L
2714 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2715 );
2716
2717 /*
2718 * For example
2719 $this->cols['theColKey'] = array(
2720 'rank' => $rank, // int : use for ordering columns
2721 'width' => 20, // the column width in mm
2722 'title' => array(
2723 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2724 'label' => ' ', // the final label : used fore final generated text
2725 'align' => 'L', // text alignment : R,C,L
2726 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2727 ),
2728 'content' => array(
2729 'align' => 'L', // text alignment : R,C,L
2730 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2731 ),
2732 );
2733 */
2734
2735 $rank = 0; // do not use negative rank
2736 $this->cols['position'] = array(
2737 'rank' => $rank,
2738 'width' => 10.0,
2739 'status' => getDolGlobalInt('PDF_SPONGE_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2740 'title' => array(
2741 'textkey' => '#', // use lang key is useful in some case with module
2742 'align' => 'C',
2743 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2744 // 'label' => ' ', // the final label
2745 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2746 ),
2747 'content' => array(
2748 'align' => 'C',
2749 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2750 ),
2751 );
2752
2753 $rank = 5; // do not use negative rank
2754 $this->cols['desc'] = array(
2755 'rank' => $rank,
2756 'width' => false, // only for desc
2757 'status' => true,
2758 'title' => array(
2759 'textkey' => 'Designation', // use lang key is useful in some case with module
2760 'align' => 'L',
2761 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2762 // 'label' => ' ', // the final label
2763 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2764 ),
2765 'content' => array(
2766 'align' => 'L',
2767 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2768 ),
2769 );
2770
2771 // Image of product
2772 $rank += 10;
2773 $this->cols['photo'] = array(
2774 'rank' => $rank,
2775 'width' => (float) getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2776 'status' => false,
2777 'title' => array(
2778 'textkey' => 'Photo',
2779 'label' => ' '
2780 ),
2781 'content' => array(
2782 'padding' => array(0.0, 0.0, 0.0, 0.0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2783 ),
2784 'border-left' => false, // remove left line separator
2785 );
2786
2787 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2788 $this->cols['photo']['status'] = true;
2789 }
2790
2791
2792 $rank += 10;
2793 $this->cols['vat'] = array(
2794 'rank' => $rank,
2795 'status' => false,
2796 'width' => 16.0, // in mm
2797 'title' => array(
2798 'textkey' => 'VAT'
2799 ),
2800 'border-left' => true, // add left line separator
2801 );
2802
2803 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2804 $this->cols['vat']['status'] = true;
2805 }
2806
2807 $rank += 10;
2808 $this->cols['subprice'] = array(
2809 'rank' => $rank,
2810 'width' => 19.0, // in mm
2811 'status' => true,
2812 'title' => array(
2813 'textkey' => 'PriceUHT'
2814 ),
2815 'border-left' => true, // add left line separator
2816 );
2817
2818 // Adapt dynamically the width of subprice, if text is too long.
2819 $tmpwidth = 0;
2820 $nblines = count($object->lines);
2821 for ($i = 0; $i < $nblines; $i++) {
2822 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2823 $tmpwidth = max($tmpwidth, $tmpwidth2);
2824 }
2825 if ($tmpwidth > 10) {
2826 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2827 }
2828
2829 $rank += 10;
2830 $this->cols['qty'] = array(
2831 'rank' => $rank,
2832 'width' => 16.0, // in mm
2833 'status' => true,
2834 'title' => array(
2835 'textkey' => 'Qty'
2836 ),
2837 'border-left' => true, // add left line separator
2838 );
2839
2840 $rank += 10;
2841 $this->cols['progress'] = array(
2842 'rank' => $rank,
2843 'width' => 19.0, // in mm
2844 'status' => false,
2845 'title' => array(
2846 'textkey' => 'ProgressShort'
2847 ),
2848 'border-left' => true, // add left line separator
2849 );
2850
2851 if ($this->situationinvoice) {
2852 $this->cols['progress']['status'] = true;
2853 }
2854
2855 $rank += 10;
2856 $this->cols['unit'] = array(
2857 'rank' => $rank,
2858 'width' => 11.0, // in mm
2859 'status' => false,
2860 'title' => array(
2861 'textkey' => 'Unit'
2862 ),
2863 'border-left' => true, // add left line separator
2864 );
2865 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2866 $this->cols['unit']['status'] = true;
2867 }
2868
2869 $rank += 10;
2870 $this->cols['discount'] = array(
2871 'rank' => $rank,
2872 'width' => 13.0, // in mm
2873 'status' => false,
2874 'title' => array(
2875 'textkey' => 'ReductionShort'
2876 ),
2877 'border-left' => true, // add left line separator
2878 );
2879 if ($this->atleastonediscount) {
2880 $this->cols['discount']['status'] = true;
2881 }
2882
2883 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2884 $this->cols['totalexcltax'] = array(
2885 'rank' => $rank,
2886 'width' => 26.0, // in mm
2887 'status' => !getDolGlobalBool('PDF_INVOICE_HIDE_PRICE_EXCL_TAX') && !getDolGlobalBool('PDF_PURCHASE_INVOICE_HIDE_PRICE_EXCL_TAX'),
2888 'title' => array(
2889 'textkey' => 'TotalHTShort'
2890 ),
2891 'border-left' => true, // add left line separator
2892 );
2893
2894 $rank += 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2895 $this->cols['totalincltax'] = array(
2896 'rank' => $rank,
2897 'width' => 26.0, // in mm
2898 'status' => getDolGlobalBool('PDF_INVOICE_SHOW_PRICE_INCL_TAX') && !getDolGlobalBool('PDF_PURCHASE_INVOICE_SHOW_PRICE_INCL_TAX'),
2899 'title' => array(
2900 'textkey' => 'TotalTTCShort'
2901 ),
2902 'border-left' => true, // add left line separator
2903 );
2904
2905 // Add extrafields cols
2906 if (!empty($object->lines)) {
2907 $line = reset($object->lines);
2908 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2909 }
2910
2911 $parameters = array(
2912 'object' => $object,
2913 'outputlangs' => $outputlangs,
2914 'hidedetails' => $hidedetails,
2915 'hidedesc' => $hidedesc,
2916 'hideref' => $hideref
2917 );
2918
2919 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2920 if ($reshook < 0) {
2921 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2922 } elseif (empty($reshook)) {
2923 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2924 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2925 } else {
2926 $this->cols = $hookmanager->resArray;
2927 }
2928 }
2929}
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 bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage hooks.
Parent class of invoice document generators.
addBottomQRInvoice(TCPDF $pdf, Facture $object, Translate $langs)
Add SwissQR invoice at bottom of page 1.
getHeightForQRInvoice(int $pagenbr, Facture $object, Translate $langs)
Get the height for bottom-page QR invoice in mm, depending on the page number.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class to manage PDF invoice template sponge.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
__construct($db)
Constructor.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $object='', $outputlangsbis=null)
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0, $heightforqrinvoice=0)
Show footer of page.
drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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,...
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.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
dolFIGetInvoiceBarcodeData($object)
Build the finnish payment barcode data of an invoice.
dolFIFormatVirtualBarcode($barcodedata)
Format the finnish payment barcode for reading, as banks print it.
dolPayRefFormatForDisplay($ref, $country_code='')
Format a payment reference the way its country prints it.
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
pdfCertifMention($pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal certificate mention.
Definition pdf.lib.php:1264
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
pdfWriteVATArray($docgenerator, &$index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl)
Add some information from the blockedlog module.
Definition pdf.lib.php:855
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_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2884
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
pdfWriteAdditionnalTitle($pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
Definition pdf.lib.php:830
pdfWriteAlreadyPaid($docgenerator, &$index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin)
Add some information from the blockedlog module.
Definition pdf.lib.php:1095
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