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