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 for ($i = 0; $i < $nblines; $i++) {
719 $linePosition = $i + 1;
720 $curY = $nexY;
721
722 $sub_options = $object->lines[$i]->extraparams["subtotal"] ?? array();
723
724 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
725 $level = $object->lines[$i]->qty;
726 if ($sub_options) {
727 if (isset($sub_options['titleshowuponpdf'])) {
728 $pdf_sub_options['titleshowuponpdf'] = isset($pdf_sub_options['titleshowuponpdf']) && $pdf_sub_options['titleshowuponpdf'] < $level ? $pdf_sub_options['titleshowuponpdf'] : $level;
729 } elseif (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
730 unset($pdf_sub_options['titleshowuponpdf']);
731 }
732 if (isset($sub_options['titleshowtotalexludingvatonpdf'])) {
733 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && $pdf_sub_options['titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options['titleshowtotalexludingvatonpdf'] : $level;
734 } elseif (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
735 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
736 }
737 } else {
738 if (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
739 unset($pdf_sub_options['titleshowuponpdf']);
740 }
741 if (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
742 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
743 }
744 }
745 }
746
747 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options['titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
748 $object->lines[$i]->pagebreak = true;
749 }
750
751 // in First Check line page break and add page if needed
752 if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
753 // New page
754 $pdf->AddPage();
755 if (!empty($tplidx)) {
756 $pdf->useTemplate($tplidx);
757 }
758
759 $pdf->setPage($pdf->getNumPages());
760 $nexY = $curY = $this->tab_top_newpage;
761 }
762
763 $this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
764
765 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
766 $pdf->SetTextColor(0, 0, 0);
767
768 // Define size of image if we need it
769 $imglinesize = array();
770 if (!empty($realpatharray[$i])) {
771 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
772 }
773
774 $pdf->setTopMargin($this->tab_top_newpage);
775 $pdf->setPageOrientation('', true, $this->heightforfooter);
776 $pageposbefore = $pdf->getPage();
777 $curYBefore = $curY;
778
779 // Allows data in the first page if description is long enough to break in multiples pages
780 $showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
781
782 if ($this->getColumnStatus('photo')) {
783 // We start with Photo of product line
784 $imageTopMargin = 1;
785 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
786 $pdf->AddPage('', '', true);
787 if (!empty($tplidx)) {
788 $pdf->useTemplate($tplidx);
789 }
790 $pdf->setPage($pageposbefore + 1);
791 $pdf->setPageOrientation('', true, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
792 $curY = $this->tab_top_newpage;
793 $showpricebeforepagebreak = 0;
794 }
795
796 $pdf->setPageOrientation('', false, $this->heightforfooter + $this->heightforfreetext); // The only function to edit the bottom margin of current page to set it.
797 // @phan-suppress-next-line PhanTypeMismatchProperty
798 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
799 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
800 // $pdf->Image does not increase value return by getY, so we save it manually
801 $posYAfterImage = $curY + $imglinesize['height'];
802
803 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
804 }
805 }
806
807 // restore Page orientation for text
808 $pdf->setPageOrientation('', true, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
809
810 // Description of product line
811 if ($this->getColumnStatus('desc')) {
812 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
813 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
814 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
815 } else {
816 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty), 'ffffff'));
817 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
818 }
819 }
820
821
822 $afterPosData = $this->getMaxAfterColsLinePositionsData();
823 $pdf->setPage($pageposbefore);
824 $pdf->setTopMargin($this->marge_haute);
825 $curY = $curYBefore;
826 $pdf->setPageOrientation('', false, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
827
828 // We suppose that a too long description or photo were moved completely on next page
829 if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
830 $pdf->setPage($afterPosData['page']);
831 $curY = $this->tab_top_newpage;
832 }
833
834 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
835
836 // Line position
837 if ($this->getColumnStatus('position')) {
838 $this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
839 }
840
841 // VAT Rate
842 if ($this->getColumnStatus('vat') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
843 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
844 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
845 }
846
847 // Unit price before discount
848 if ($this->getColumnStatus('subprice') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowuponpdf'])) {
849 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
850 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
851 }
852
853 // Quantity
854 // Enough for 6 chars
855 if ($this->getColumnStatus('qty') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
856 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
857 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
858 }
859
860 // Situation progress
861 if ($this->getColumnStatus('progress') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
862 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
863 $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
864 }
865
866 // Unit
867 if ($this->getColumnStatus('unit') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
868 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
869 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
870 }
871
872 // Discount on line
873 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
874 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
875 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
876 }
877
878 // Total excl tax line (HT)
879 if ($this->getColumnStatus('totalexcltax')) {
880 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowtotalexludingvatonpdf'])) {
881 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
882 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
883 } elseif ($object->lines[$i]->qty < 0 && isset($sub_options['subtotalshowtotalexludingvatonpdf'])) {
884 if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency) {
885 $total_excl_tax = $object->getSubtotalLineMulticurrencyAmount($object->lines[$i]);
886 } else {
887 $total_excl_tax = $object->getSubtotalLineAmount($object->lines[$i]);
888 }
889 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
890 }
891 }
892
893 // Total with tax line (TTC)
894 if ($this->getColumnStatus('totalincltax')) {
895 $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
896 $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
897 }
898
899 // Extrafields
900 if (!empty($object->lines[$i]->array_options)) {
901 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
902 if ($this->getColumnStatus($extrafieldColKey)) {
903 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
904 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
905
906 $this->setAfterColsLinePositionsData('options_' . $extrafieldColKey, $pdf->GetY(), $pdf->getPage());
907 }
908 }
909 }
910
911 $afterPosData = $this->getMaxAfterColsLinePositionsData();
912 $parameters = array(
913 'object' => $object,
914 'i' => $i,
915 'pdf' => & $pdf,
916 'curY' => & $curY,
917 'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
918 'outputlangs' => $outputlangs,
919 'hidedetails' => $hidedetails
920 );
921 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
922
923
924 $sign = 1;
925 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
926 $sign = -1;
927 }
928
929 // Collect total by value of vat rate into $this->tva_array
930 // 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())
931 $prev_progress = getDolGlobalInt('INVOICE_USE_SITUATION') == 2 ? 0 : $object->lines[$i]->get_prev_progress($object->id);
932
933 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
934 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
935 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
936 } else {
937 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
938 }
939 } else {
940 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
941 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
942 } else {
943 $tvaligne = $sign * $object->lines[$i]->total_tva;
944 }
945 }
946
947 $localtax1ligne = $object->lines[$i]->total_localtax1;
948 $localtax2ligne = $object->lines[$i]->total_localtax2;
949 $localtax1_rate = $object->lines[$i]->localtax1_tx;
950 $localtax2_rate = $object->lines[$i]->localtax2_tx;
951 $localtax1_type = $object->lines[$i]->localtax1_type;
952 $localtax2_type = $object->lines[$i]->localtax2_type;
953
954 $vatrate = (string) $object->lines[$i]->tva_tx;
955
956 // Retrieve type from database for backward compatibility with old records
957 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
958 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
959 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
960 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
961 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
962 }
963
964 // retrieve global local tax
965 if ($localtax1_type && $localtax1ligne != 0) {
966 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
967 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
968 } else {
969 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
970 }
971 }
972 if ($localtax2_type && $localtax2ligne != 0) {
973 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
974 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
975 } else {
976 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
977 }
978 }
979
980 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
981 $vatrate .= '*';
982 }
983
984 // Fill $this->tva and $this->tva_array
985 if (!isset($this->tva[$vatrate])) {
986 $this->tva[$vatrate] = 0;
987 }
988 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
989 $vatcode = $object->lines[$i]->vat_src_code;
990 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
991 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
992 }
993 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
994 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
995 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
996 }
997 $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);
998 } else {
999 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
1000 }
1001
1002 $afterPosData = $this->getMaxAfterColsLinePositionsData();
1003 $pdf->setPage($afterPosData['page']);
1004 $nexY = $afterPosData['y'];
1005
1006 // Add line
1007 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1008 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
1009 //$pdf->SetDrawColor(190,190,200);
1010 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1011 $pdf->SetLineStyle(array('dash' => 0));
1012 }
1013
1014 $nexY += 0; // Add space between lines
1015 }
1016
1017 // Add last page for document footer if there are not enough size left
1018 $afterPosData = $this->getMaxAfterColsLinePositionsData();
1019 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
1020
1021 if (isset($afterPosData['y']) && $afterPosData['y'] > $this->page_hauteur - $page_bottom_margin) {
1022 $pdf->AddPage();
1023 if (!empty($tplidx)) {
1024 $pdf->useTemplate($tplidx);
1025 }
1026 $pagenb++;
1027 $pdf->setPage($pagenb);
1028 }
1029
1030 // Draw table frames and columns borders
1031 $drawTabNumbPage = $pdf->getNumPages();
1032 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1033 $pdf->setPage($i);
1034 // reset page orientation each loop to override it if it was changed
1035 $pdf->setPageOrientation('', false, 0); // The only function to edit the bottom margin of current page to set it.
1036
1037 $drawTabHideTop = $hidetop;
1038 $drawTabTop = $this->tab_top_newpage;
1039 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1040 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
1041
1042 if ($i == $pageposbeforeprintlines) {
1043 // first page need to start after notes
1044 $drawTabTop = $this->tab_top;
1045 } elseif (!$drawTabHideTop) {
1046 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
1047 $drawTabTop -= $this->tabTitleHeight;
1048 } else {
1049 $drawTabHideTop = 1;
1050 }
1051 }
1052
1053 // last page need to include document footer
1054 if ($i == $pdf->getNumPages()) {
1055 // remove document footer height to tab bottom position
1056 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs);
1057 }
1058
1059 $drawTabHeight = $drawTabBottom - $drawTabTop;
1060 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object, $outputlangsbis);
1061
1062 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
1063
1064 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1065
1066 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
1067
1068 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
1069 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
1070
1071 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
1072 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1073 $this->_pagehead($pdf, $object, 0, $outputlangs);
1074 }
1075 if (!empty($tplidx)) {
1076 $pdf->useTemplate($tplidx);
1077 }
1078 }
1079
1080
1081 // reset text color before print footers
1082 $pdf->SetTextColor(0, 0, 0);
1083
1084 $pdf->setPage($pdf->getNumPages());
1085
1086 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1087
1088 // Display infos area
1089 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1090
1091 // Display total zone
1092 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1093
1094 // Display payment area
1095 $listofpayments = $object->getListOfPayments('', 0, 1);
1096 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1097 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1098 }
1099
1100 // Add number of pages in footer
1101 if (method_exists($pdf, 'AliasNbPages')) {
1102 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1103 }
1104
1105 // Add terms to sale
1106 $termsofsalefilename = getDolGlobalString('MAIN_INFO_INVOICE_TERMSOFSALE');
1107 if (getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1108 $termsofsale = $conf->invoice->dir_output.'/'.$termsofsalefilename;
1109 if (!empty($conf->invoice->multidir_output[$object->entity ?? $conf->entity])) {
1110 $termsofsale = $conf->invoice->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
1111 }
1112
1113 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1114 $pagecount = $pdf->setSourceFile($termsofsale);
1115 for ($i = 1; $i <= $pagecount; $i++) {
1116 $tplIdx = $pdf->importPage($i);
1117 if ($tplIdx !== false) {
1118 $s = $pdf->getTemplatesize($tplIdx);
1119 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1120 $pdf->useTemplate($tplIdx);
1121 } else {
1122 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
1123 }
1124 }
1125 }
1126 }
1127
1128 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
1129 $this->addBottomQRInvoice($pdf, $object, $outputlangs);
1130 }
1131
1132 $pdf->Close();
1133
1134 $pdf->Output($file, 'F');
1135
1136 // Add pdfgeneration hook
1137 $hookmanager->initHooks(array('pdfgeneration'));
1138 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1139 global $action;
1140 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1141 $this->warnings = $hookmanager->warnings;
1142 if ($reshook < 0) {
1143 $this->error = $hookmanager->error;
1144 $this->errors = $hookmanager->errors;
1145 dolChmod($file);
1146 return -1;
1147 }
1148
1149 dolChmod($file);
1150
1151 $this->result = array('fullpath' => $file);
1152
1153 return 1; // No error
1154 } else {
1155 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1156 return 0;
1157 }
1158 } else {
1159 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1160 return 0;
1161 }
1162 }
1163
1164
1174 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1175 {
1176 $sign = 1;
1177 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1178 $sign = -1;
1179 }
1180
1181 $tab3_posx = 120;
1182 $tab3_top = $posy + 8;
1183 $tab3_width = 80;
1184 $tab3_height = 4;
1185 if ($this->page_largeur < 210) { // To work with US executive format
1186 $tab3_posx -= 15;
1187 }
1188
1189 $default_font_size = pdf_getPDFFontSize($outputlangs);
1190
1191 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1192 if ($object->type == 2) {
1193 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1194 }
1195
1196 $pdf->SetFont('', '', $default_font_size - 3);
1197 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1198 $pdf->MultiCell(60, 3, $title, 0, 'L', false);
1199
1200 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1201
1202 $pdf->SetFont('', '', $default_font_size - 4);
1203 $pdf->SetXY($tab3_posx, $tab3_top);
1204 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
1205 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1206 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
1207 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1208 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
1209 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1210 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
1211
1212 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1213
1214 $y = 0;
1215
1216 $pdf->SetFont('', '', $default_font_size - 4);
1217
1218
1219 // Loop on each discount available (deposits and credit notes and excess of payment included)
1220 $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,";
1221 $sql .= " re.description, re.fk_facture_source,";
1222 $sql .= " f.type, f.datef";
1223 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1224 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1225 $resql = $this->db->query($sql);
1226 if ($resql) {
1227 $num = $this->db->num_rows($resql);
1228 $i = 0;
1229 $invoice = new Facture($this->db);
1230 while ($i < $num) {
1231 $y += 3;
1232 $obj = $this->db->fetch_object($resql);
1233
1234 if ($obj->type == 2) {
1235 $text = $outputlangs->transnoentities("CreditNote");
1236 } elseif ($obj->type == 3) {
1237 $text = $outputlangs->transnoentities("Deposit");
1238 } elseif ($obj->type == 0) {
1239 $text = $outputlangs->transnoentities("ExcessReceived");
1240 } else {
1241 $text = $outputlangs->transnoentities("UnknownType");
1242 }
1243
1244 $invoice->fetch($obj->fk_facture_source);
1245
1246 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1247 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', false);
1248 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1249 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', false);
1250 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1251 $pdf->MultiCell(20, 3, $text, 0, 'L', false);
1252 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1253 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', false);
1254
1255 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1256
1257 $i++;
1258 }
1259 } else {
1260 $this->error = $this->db->lasterror();
1261 return -1;
1262 }
1263
1264 // Loop on each payment
1265 // TODO Call getListOfPayments instead of hard coded sql
1266 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1267 $sql .= " cp.code";
1268 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1269 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1270 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1271 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1272 $sql .= " ORDER BY p.datep";
1273
1274 $resql = $this->db->query($sql);
1275 if ($resql) {
1276 $num = $this->db->num_rows($resql);
1277 $i = 0;
1278 $y += 3;
1279 $maxY = $y;
1280 while ($i < $num) {
1281 $row = $this->db->fetch_object($resql);
1282 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1283 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1284 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1285 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', false);
1286 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1287 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1288
1289 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1290 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1291 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1292 $pdf->MultiCell(30, 3, $row->num, 0, 'L', false);
1293 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1294 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1295 $y += 3;
1296 $i++;
1297 }
1298
1299 return $tab3_top + $y + 3;
1300 } else {
1301 $this->error = $this->db->lasterror();
1302 return -1;
1303 }
1304 }
1305
1306
1317 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1318 {
1319 global $mysoc;
1320
1321 $default_font_size = pdf_getPDFFontSize($outputlangs);
1322
1323 $pdf->SetFont('', '', $default_font_size - 1);
1324
1325 krsort($this->tva_array);
1326
1327 // Clean data type
1328 $object->total_tva = (float) $object->total_tva;
1329
1330 // Show VAT details
1331 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1332 $pdf->SetFillColor(224, 224, 224);
1333
1334 $pdf->SetFont('', '', $default_font_size - 2);
1335 $pdf->SetXY($this->marge_gauche, $posy);
1336 $titre = $outputlangs->transnoentities("VAT");
1337 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1338
1339 $pdf->SetFont('', '', $default_font_size - 2);
1340 $pdf->SetXY($this->marge_gauche + 25, $posy);
1341 $titre = $outputlangs->transnoentities("NetTotal");
1342 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1343
1344 $pdf->SetFont('', '', $default_font_size - 2);
1345 $pdf->SetXY($this->marge_gauche + 50, $posy);
1346 $titre = $outputlangs->transnoentities("VATAmount");
1347 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1348
1349 $pdf->SetFont('', '', $default_font_size - 2);
1350 $pdf->SetXY($this->marge_gauche + 75, $posy);
1351 $titre = $outputlangs->transnoentities("AmountTotal");
1352 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1353
1354 $posy = $pdf->GetY();
1355 $tot_ht = 0;
1356 $tot_tva = 0;
1357 $tot_ttc = 0;
1358
1359 foreach ($this->tva_array as $tvakey => $tvaval) {
1360 $pdf->SetFont('', '', $default_font_size - 2);
1361 $pdf->SetXY($this->marge_gauche, $posy);
1362 $titre = round((float) $tvakey, 2) . "%";
1363 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1364
1365 $pdf->SetFont('', '', $default_font_size - 2);
1366 $pdf->SetXY($this->marge_gauche + 25, $posy);
1367 $titre = price($tvaval['tot_ht']);
1368 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1369 $tot_ht += $tvaval['tot_ht'];
1370
1371 $pdf->SetFont('', '', $default_font_size - 2);
1372 $pdf->SetXY($this->marge_gauche + 50, $posy);
1373 $titre = price($tvaval['amount']);
1374 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1375 $tot_tva += $tvaval['amount'];
1376
1377 $pdf->SetFont('', '', $default_font_size - 2);
1378 $pdf->SetXY($this->marge_gauche + 75, $posy);
1379 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1380 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1381 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1382
1383 $posy = $pdf->GetY();
1384 }
1385 }
1386
1387 // If France, show VAT mention if applicable
1388 $showvatmention = 0;
1389 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1390 $pdf->SetFont('', '', $default_font_size - 2);
1391 $pdf->SetXY($this->marge_gauche, $posy);
1392 if (empty($mysoc->tva_assuj)) {
1393 if ($mysoc->forme_juridique_code == 92) {
1394 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', false);
1395 } else {
1396 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1397 }
1398 $showvatmention++;
1399 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1400 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', false);
1401 $showvatmention++;
1402 }
1403 $posy = $pdf->GetY();
1404 }
1405
1406 $showvatmention += pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1407
1408 if ($showvatmention) {
1409 $posy += 3;
1410 }
1411
1412 $posxval = 52; // Position of values of properties shown on left side
1413 $posxend = 110; // End of x for text on left side
1414 if ($this->page_largeur < 210) { // To work with US executive format
1415 $posxend -= 10;
1416 }
1417
1418 // Show previous and new balance
1419 if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) {
1420 // All customer previous invoices
1421 $sql = "SELECT f.rowid, f.datef, f.total_ttc";
1422 $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
1423 $sql .= " WHERE f.fk_soc = " . ((int) $object->socid);
1424 $sql .= " AND f.entity IN (" . getEntity('invoice') . ")";
1425 $sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
1426 $sql .= " AND f.rowid < " . ((int) $object->id);
1427 $sql .= " AND f.fk_statut > 0";
1428 $sql .= " ORDER BY f.datef ASC";
1429
1430 $old_balance = 0;
1431 $invoices = array();
1432 $resql = $this->db->query($sql);
1433 if ($resql) {
1434 while ($obj = $this->db->fetch_object($resql)) {
1435 $invoices[] = $obj;
1436 $old_balance += $obj->total_ttc;
1437 }
1438 $this->db->free($resql);
1439 }
1440
1441 // All payments before current date
1442 $sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1443 $sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1444 $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1445 $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1446 $sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
1447 $sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'";
1448 $sql_payments .= " ORDER BY p.datep ASC";
1449
1450 $total_payments = 0;
1451 $resql_payments = $this->db->query($sql_payments);
1452 if ($resql_payments) {
1453 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1454 $total_payments += $obj_payment->amount;
1455 }
1456 $this->db->free($resql_payments);
1457 }
1458
1459 // Payments made on current invoice date (including current invoice)
1460 $sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1461 $sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1462 $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1463 $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1464 $sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
1465 $sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
1466
1467 $current_date_payments = 0;
1468 $resql_current_date = $this->db->query($sql_current_date_payments);
1469 if ($resql_current_date) {
1470 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1471 $current_date_payments += $obj_current->amount;
1472 }
1473 $this->db->free($resql_current_date);
1474 }
1475
1476 // Previous balance
1477 $old_balance -= $total_payments;
1478
1479 // New balance
1480 $new_balance = $old_balance + $object->total_ttc - $current_date_payments;
1481
1482 $pdf->SetFillColor(224, 224, 224);
1483 $pdf->SetFont('', '', $default_font_size - 2);
1484 $pdf->SetXY($this->marge_gauche, $posy);
1485 $titre = $outputlangs->transnoentities("PreviousBalance").' : '.price($old_balance);
1486 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true);
1487
1488 $pdf->SetFont('', '', $default_font_size - 2);
1489 $pdf->SetXY($posxval + 8, $posy);
1490 $titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance);
1491 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true);
1492
1493 $posy = $pdf->GetY() + 1;
1494 }
1495
1496 // Show payments conditions
1497 if ($object->type != 2 && $object->cond_reglement_code) {
1498 $pdf->SetFont('', '', $default_font_size - 2);
1499 $pdf->SetXY($this->marge_gauche, $posy);
1500 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1501 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1502
1503 $pdf->SetFont('', '', $default_font_size - 2);
1504 $pdf->SetXY($posxval, $posy);
1505 $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);
1506 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1507 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1508
1509 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1510 }
1511
1512 // Show category of operations
1513 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1514 $pdf->SetFont('', '', $default_font_size - 2);
1515 $pdf->SetXY($this->marge_gauche, $posy);
1516 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1517 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1518
1519 $pdf->SetFont('', '', $default_font_size - 2);
1520 $pdf->SetXY($posxval, $posy);
1521 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1522 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1523
1524 $posy = $pdf->GetY() + 3; // for 2 lines
1525 }
1526
1527 if ($object->type != 2) {
1528 // Check a payment mode is defined
1529 if (empty($object->mode_reglement_code)
1530 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1531 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1532 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1533 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1534 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1535 // Avoid having any valid PDF with setup that is not complete
1536 $outputlangs->load("errors");
1537
1538 $pdf->SetXY($this->marge_gauche, $posy);
1539 $pdf->SetTextColor(200, 0, 0);
1540 $pdf->SetFont('', '', $default_font_size - 2);
1541 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1542 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', false);
1543 $pdf->SetTextColor(0, 0, 0);
1544
1545 $posy = $pdf->GetY() + 1;
1546 }
1547
1548 // Show payment mode
1549 if (!empty($object->mode_reglement_code)
1550 && $object->mode_reglement_code != 'CHQ'
1551 && $object->mode_reglement_code != 'VIR') {
1552 $pdf->SetFont('', '', $default_font_size - 2);
1553 $pdf->SetXY($this->marge_gauche, $posy);
1554 $titre = $outputlangs->transnoentities("PaymentMode").':';
1555 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1556
1557 $pdf->SetFont('', '', $default_font_size - 2);
1558 $pdf->SetXY($posxval, $posy);
1559 $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);
1560
1561 //#21654: add account number used for the debit
1562 if ($object->mode_reglement_code == "PRE") {
1563 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1564 $bac = new CompanyBankAccount($this->db);
1565 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1566 $bac->fetch(0, '', $object->thirdparty->id);
1567 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1568 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1569 }
1570
1571 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1572
1573 $posy = $pdf->GetY();
1574 }
1575
1576 // Show if Option VAT debit option is on also if transmitter is french
1577 // Decret n°2099-1299 2022-10-07
1578 // French legal mention: "Option pour le paiement de la taxe d'apres les debits"
1579 if ($this->emetteur->country_code == 'FR') {
1580 if (getDolGlobalInt('TAX_MODE') == 1) {
1581 $pdf->SetXY($this->marge_gauche, $posy);
1582 $pdf->writeHTMLCell(80, 5, null, null, $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1583
1584 $posy = $pdf->GetY() + 1;
1585 }
1586 }
1587
1588 // Show online payment link
1589 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1590 $useonlinepayment = 0;
1591 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1592 // Show online payment link
1593 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1594 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1595 $validpaymentmethod = getValidOnlinePaymentMethods('');
1596 $useonlinepayment = count($validpaymentmethod);
1597 }
1598
1599
1600 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1601 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1602 global $langs;
1603
1604 $langs->loadLangs(array('payment', 'stripe'));
1605 $servicename = $langs->transnoentities('Online');
1606 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1607 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1608
1609 $pdf->SetXY($this->marge_gauche, $posy);
1610 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, null, null, dol_htmlentitiesbr($linktopay), 0, 1);
1611
1612 $posy = $pdf->GetY() + 1;
1613 }
1614 }
1615
1616 // Show payment mode CHQ
1617 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1618 // If payment mode unregulated or payment mode forced to CHQ
1619 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1620 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1621
1622 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1623 $account = new Account($this->db);
1624 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1625
1626 $pdf->SetXY($this->marge_gauche, $posy);
1627 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1628 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1629 $posy = $pdf->GetY() + 1;
1630
1631 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1632 $pdf->SetXY($this->marge_gauche, $posy);
1633 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1634 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1635 $posy = $pdf->GetY() + 2;
1636 }
1637 }
1638 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1639 $pdf->SetXY($this->marge_gauche, $posy);
1640 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1641 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1642 $posy = $pdf->GetY() + 1;
1643
1644 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1645 $pdf->SetXY($this->marge_gauche, $posy);
1646 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1647 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1648 $posy = $pdf->GetY() + 2;
1649 }
1650 }
1651 }
1652 }
1653
1654 // If payment mode not forced or forced to VIR, show payment with BAN
1655 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1656 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1657 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : (int) $object->fk_account);
1658 if ($object->fk_bank > 0) {
1659 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1660 }
1661 $account = new Account($this->db);
1662 $account->fetch($bankid);
1663
1664 $curx = $this->marge_gauche;
1665 $cury = $posy;
1666
1667 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1668
1669 $posy += 2;
1670
1671 // SHOW EPC QR CODE at bottom, but only if unpaid amount exists
1672 if ((getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == 'bottom') && ($object->getRemainToPay() > 0)) {
1673 $qrPosX = $this->marge_gauche + 5;
1674 $qrPosY = $posy;
1675 $qrCodeColor = array('25', '25', '25');
1676 $styleQr = array(
1677 'border' => false,
1678 'padding' => 0,
1679 'fgcolor' => $qrCodeColor,
1680 'bgcolor' => false, //array(255,255,255)
1681 'module_width' => 1, // width of a single module in points
1682 'module_height' => 1 // height of a single module in points
1683 );
1684
1685 $EPCQrCodeString = $object->buildEPCQrCodeString();
1686 $pdf->write2DBarcode($EPCQrCodeString, 'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr, 'N');
1687
1688 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1689 $pdf->SetFont('', '', $default_font_size - 5);
1690 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', false);
1691 $posy = $pdf->GetY() + 2;
1692 }
1693
1694 // Show structured communication
1695 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1696 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1697 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1698
1699 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', false);
1700 }
1701 }
1702 }
1703 }
1704
1705 return $posy;
1706 }
1707
1708
1720 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1721 {
1722 global $mysoc, $hookmanager;
1723
1724 $sign = 1;
1725 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1726 $sign = -1;
1727 }
1728
1729 $default_font_size = pdf_getPDFFontSize($outputlangs);
1730
1731 $tab2_top = $posy;
1732 $tab2_hl = 4;
1733 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1734 $pdf->SetFont('', '', $default_font_size - 2);
1735 } else {
1736 $pdf->SetFont('', '', $default_font_size - 1);
1737 }
1738
1739 // Total table
1740 $col1x = 120;
1741 $col2x = 170;
1742 if ($this->page_largeur < 210) { // To work with US executive format
1743 $col1x -= 15;
1744 $col2x -= 10;
1745 }
1746 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1747
1748 $useborder = 0;
1749 $index = 0;
1750
1751 // Add trigger to allow to edit $object
1752 $parameters = array(
1753 'object' => &$object,
1754 'outputlangs' => $outputlangs,
1755 );
1756 $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1757
1758 // overall percentage of advancement
1759 $percent = 0;
1760 $i = 0;
1761 foreach ($object->lines as $line) {
1762 if ($line->product_type != 9) {
1763 $percent += $line->situation_percent;
1764 $i++;
1765 }
1766 }
1767
1768 if (!empty($i)) {
1769 $avancementGlobal = $percent / $i;
1770 } else {
1771 $avancementGlobal = 0;
1772 }
1773
1774 $object->fetchPreviousNextSituationInvoice();
1775 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1776
1777 $total_a_payer = 0;
1778 $total_a_payer_ttc = 0;
1779 foreach ($TPreviousIncoice as &$fac) {
1780 $total_a_payer += $fac->total_ht;
1781 $total_a_payer_ttc += $fac->total_ttc;
1782 }
1783 $total_a_payer += $object->total_ht;
1784 $total_a_payer_ttc += $object->total_ttc;
1785
1786 if (!empty($avancementGlobal)) {
1787 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1788 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1789 } else {
1790 $total_a_payer = 0;
1791 $total_a_payer_ttc = 0;
1792 }
1793
1794 $i = 1;
1795 if (!empty($TPreviousIncoice)) {
1796 $pdf->setY($tab2_top);
1797 $posy = $pdf->GetY();
1798
1799 foreach ($TPreviousIncoice as &$fac) {
1800 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1801 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1802 $pdf->addPage();
1803 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1804 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1805 $pdf->setY($this->tab_top_newpage);
1806 } else {
1807 $pdf->setY($this->marge_haute);
1808 }
1809 $posy = $pdf->GetY();
1810 }
1811
1812 // Cumulate preceding VAT
1813 $index++;
1814 $pdf->SetFillColor(255, 255, 255);
1815 $pdf->SetXY($col1x, $posy);
1816 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", (string) $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', true);
1817
1818 $pdf->SetXY($col2x, $posy);
1819
1820 $facSign = '';
1821 if ($i > 1) {
1822 $facSign = $fac->total_ht >= 0 ? '+' : '';
1823 }
1824
1825 $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1826
1827 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', true);
1828
1829 $i++;
1830 $posy += $tab2_hl;
1831
1832 $pdf->setY($posy);
1833 }
1834
1835 // Display current total
1836 $pdf->SetFillColor(255, 255, 255);
1837 $pdf->SetXY($col1x, $posy);
1838 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", (string) $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', true);
1839
1840 $pdf->SetXY($col2x, $posy);
1841 $facSign = '';
1842 if ($i > 1) {
1843 $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1844 }
1845
1846 if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1847 $facSign = '-';
1848 }
1849
1850
1851 $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1852 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', true);
1853
1854 $posy += $tab2_hl;
1855
1856 // Display all total
1857 $pdf->SetFont('', '', $default_font_size - 1);
1858 $pdf->SetFillColor(255, 255, 255);
1859 $pdf->SetXY($col1x, $posy);
1860 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", (string) $avancementGlobal), 0, 'L', true);
1861
1862 $pdf->SetXY($col2x, $posy);
1863 $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', true);
1864 $pdf->SetFont('', '', $default_font_size - 2);
1865
1866 $posy += $tab2_hl;
1867
1868 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1869 $pdf->addPage();
1870 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1871 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1872 $pdf->setY($this->tab_top_newpage);
1873 } else {
1874 $pdf->setY($this->marge_haute);
1875 }
1876
1877 $posy = $pdf->GetY();
1878 }
1879
1880 $tab2_top = $posy;
1881 $index = 0;
1882
1883 $tab2_top += 3;
1884 }
1885
1886
1887 // Get Total HT
1888 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1889
1890 // Total discount
1891 $total_discount_on_lines = 0;
1892 $multicurrency_total_discount_on_lines = 0;
1893 foreach ($object->lines as $i => $line) {
1894 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1895 $multicurrency_resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2, 1);
1896
1897 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1898 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1899 // If line was a negative line, we do not count the discount as a discount
1900 if ($line->total_ht < 0) {
1901 $total_discount_on_lines += -$line->total_ht;
1902 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1903 }
1904 }
1905
1906 // Show total discount only if there is some discount on lines
1907 if ($total_discount_on_lines > 0 && !$object->isSituationInvoice()) {
1908 // Show discount except on credit note type invoices
1909 if ($this->showAmountBeforeDiscount && $object->type != 2) {
1910 $pdf->SetFillColor(255, 255, 255);
1911 $pdf->SetXY($col1x, $tab2_top);
1912 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', true);
1913 $pdf->SetXY($col2x, $tab2_top);
1914
1915 $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));
1916 $pdf->MultiCell($largcol2, $tab2_hl, price($total_before_discount_to_show, 0, $outputlangs), 0, 'R', true);
1917
1918 $index++;
1919 }
1920
1921 // Show total NET before discount except on credit note type invoices
1922 if ($this->showDiscountAmount && $object->type != 2) {
1923 $pdf->SetFillColor(255, 255, 255);
1924 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1925 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', true);
1926 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1927
1928 $total_discount_to_show = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1929 $pdf->MultiCell($largcol2, $tab2_hl, price($total_discount_to_show, 0, $outputlangs), 0, 'R', true);
1930
1931 $index++;
1932 }
1933 }
1934
1935 // Total HT
1936 $pdf->SetFillColor(255, 255, 255);
1937 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1938 $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);
1939
1940 $total_ht = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1941 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1942 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ht, 0, $outputlangs), 0, 'R', true);
1943
1944 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1945 $index++;
1946 $pdf->SetFillColor(255, 255, 255);
1947 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1948 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', true);
1949
1950 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1951 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', true);
1952 }
1953
1954 // Show VAT by rates and total
1955 $pdf->SetFillColor(248, 248, 248);
1956
1957 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1958 $total_ttc_origin = $object->total_ttc;
1959
1960 $this->atleastoneratenotnull = 0;
1961
1962
1963 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1964 $tvaisnull = false;
1965 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
1966 $tva_el = reset($this->tva_array);
1967 if ($tva_el['vatrate'] == '0.000' && is_float($tva_el['amount'])) $tvaisnull = true;
1968 }
1969 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1970 // Nothing to do
1971 } else {
1972 // Show VAT lines
1973 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1974
1975 // Revenue stamp
1976 if (price2num($object->revenuestamp, 'MT') != 0) {
1977 $index++;
1978 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1979 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', true);
1980
1981 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1982 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', true);
1983 }
1984
1985 // Total TTC
1986 $index++;
1987 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1988 $pdf->SetTextColor(0, 0, 60);
1989 $pdf->SetFillColor(224, 224, 224);
1990 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', true);
1991
1992 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1993 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1994 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
1995 } else {
1996 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
1997
1998 //$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');
1999 $index++;
2000 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2001 $pdf->SetTextColor(0, 0, 60);
2002 $pdf->SetFillColor(224, 224, 224);
2003 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
2004
2005 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2006 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
2007 }
2008
2009 // Retained warranty
2010 if ($object->displayRetainedWarranty()) {
2011 $pdf->SetTextColor(40, 40, 40);
2012 $pdf->SetFillColor(255, 255, 255);
2013
2014 $retainedWarranty = $object->getRetainedWarrantyAmount('MT');
2015 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
2016
2017 // Billed - retained warranty
2018 $index++;
2019 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2020 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', true);
2021
2022 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2023 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', true);
2024
2025 // retained warranty
2026 $index++;
2027 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2028
2029 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
2030 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
2031
2032 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', true);
2033 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2034 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', true);
2035 }
2036 }
2037 }
2038
2039 $pdf->SetTextColor(0, 0, 0);
2040
2041 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
2042 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
2043
2044 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
2045 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2046 // Not used in this case, initialized to avoid CI warnings
2047 $deja_regle_origin = 0;
2048 $creditnoteamount_origin = 0;
2049 $depositsamount_origin = 0;
2050 $resteapayer_origin = 0;
2051 } else {
2052 $deja_regle_origin = $object->getSommePaiement(0);
2053 $creditnoteamount_origin = $object->getSumCreditNotesUsed(0); // Warning, this also include excess received
2054 $depositsamount_origin = $object->getSumDepositsUsed(0);
2055 $resteapayer_origin = price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin, 'MT');
2056 }
2057 if (!empty($object->paye)) {
2058 $resteapayer = 0;
2059 $resteapayer_origin = 0;
2060 }
2061
2062 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2063
2064 $pdf->SetFont('', '', $default_font_size - 1);
2065 $pdf->SetTextColor(0, 0, 0);
2066
2067 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2068
2069 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2070 if ($reshook < 0) {
2071 $this->error = $hookmanager->error;
2072 $this->errors = $hookmanager->errors;
2073 }
2074
2075 $index++;
2076 return ($tab2_top + ($tab2_hl * $index));
2077 }
2078
2079 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2087 public static function liste_modeles($db, $maxfilenamelength = 0)
2088 {
2089 // phpcs:enable
2090 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2091 }
2092
2093 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2108 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $object = '', $outputlangsbis = null)
2109 {
2110 // Force to disable hidetop and hidebottom
2111 $hidebottom = 0;
2112 if ($hidetop) {
2113 $hidetop = -1;
2114 }
2115
2116 if ($object instanceOf Facture) {
2117 $currency = $object->multicurrency_code;
2118 } else {
2119 $currency = $object;
2120 }
2121 if (empty($currency)) {
2122 $currency = getDolCurrency();
2123 }
2124
2125 $default_font_size = pdf_getPDFFontSize($outputlangs);
2126
2127 // Amount in (at tab_top - 1)
2128 $pdf->SetTextColor(0, 0, 0);
2129 $pdf->SetFont('', '', $default_font_size - 2);
2130
2131 if (empty($hidetop)) {
2132 // Show category of operations
2133 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2134 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2135 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2136 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2137 }
2138
2139 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2140 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2141 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2142 }
2143 if ($currency != getDolCurrency()) {
2144 // Use nb of digit of the total price of main currency + nb of digit for total price of foreign currency + 1
2145 $maxnbofdec = getDolGlobalInt('MAIN_MAX_DECIMALS_TOT') + getDolGlobalInt('MAIN_MAX_DECIMALS_CURRENCY_TOT', getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')) + 1;
2146 $pricetoshow1 = price($object->multicurrency_tx, 0, $outputlangs, 1, 0, $maxnbofdec, $currency);
2147 $pricetoshow2 = price($object->multicurrency_tx, 0, $outputlangs, 1, 0, -2, $currency);
2148 $pricetoshow = ((strlen($pricetoshow1) < strlen($pricetoshow2)) ? $pricetoshow1 : $pricetoshow2);
2149 $titre .= ' ('.$pricetoshow.' = '.price(1, 0, $outputlangs, 1, 0, 0, getDolCurrency()).')';
2150 }
2151
2152 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2153 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2154
2155 // MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2156 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2157 $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')));
2158 }
2159 }
2160
2161 $pdf->SetDrawColor(128, 128, 128);
2162 $pdf->SetFont('', '', $default_font_size - 1);
2163
2164 // Output Rect
2165 $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
2166
2167
2168 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2169
2170 if (empty($hidetop)) {
2171 $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
2172 }
2173 }
2174
2175 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2186 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2187 {
2188 // phpcs:enable
2189 global $conf, $langs;
2190
2191 $ltrdirection = 'L';
2192 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2193 $ltrdirection = 'R';
2194 }
2195
2196 // Load traductions files required by page
2197 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2198
2199 $default_font_size = pdf_getPDFFontSize($outputlangs);
2200
2201 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2202
2203 $pdf->SetTextColor(0, 0, 60);
2204 $pdf->SetFont('', 'B', $default_font_size + 3);
2205
2206 $w = 110;
2207
2208 $posy = $this->marge_haute;
2209 $posx = $this->page_largeur - $this->marge_droite - $w;
2210
2211 $pdf->SetXY($this->marge_gauche, $posy);
2212
2213 // Logo
2214 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2215 if ($this->emetteur->logo) {
2216 $logodir = $conf->mycompany->dir_output;
2217 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
2218 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
2219 }
2220 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2221 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2222 } else {
2223 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2224 }
2225 if (is_readable($logo)) {
2226 $height = pdf_getHeightForLogo($logo);
2227 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2228 } else {
2229 $pdf->SetTextColor(200, 0, 0);
2230 $pdf->SetFont('', 'B', $default_font_size - 2);
2231 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2232 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2233 }
2234 } else {
2235 $text = $this->emetteur->name;
2236 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2237 }
2238 }
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,...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:3162
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2863
pdfCertifMention($pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal certificate mention.
Definition pdf.lib.php:1221
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:3194
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1810
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:294
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:1241
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:317
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:812
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition pdf.lib.php:2913
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2466
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2797
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2404
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:749
pdf_pagefoot($pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1423
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:273
pdf_render_subtotals(TCPDF $pdf, CommonDocGenerator $generator, float $curY, CommonObject $object, int $i, Translate $outputlangs, int $hideref, int $hidedesc, array $bgColor, bool $isSubtotal=false, bool $applySubtotalLogic=true)
Render subtotals line with a colored background and adapted text color .
Definition pdf.lib.php:3292
pdfWriteAdditionnalTitle($pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
Definition pdf.lib.php:787
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:1052
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:438
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2711
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2754
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2551
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1137
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:393
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133