dolibarr 24.0.0-beta
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 (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
472 $this->tab_top = 90 + $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') ? 42 + $top_shift : 10);
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)));
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 $prev_progress = getDolGlobalInt('INVOICE_USE_SITUATION') == 2 ? 0 : $object->lines[$i]->get_prev_progress($object->id);
931 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
932 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
933 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
934 } else {
935 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
936 }
937 } else {
938 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
939 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
940 } else {
941 $tvaligne = $sign * $object->lines[$i]->total_tva;
942 }
943 }
944
945 $localtax1ligne = $object->lines[$i]->total_localtax1;
946 $localtax2ligne = $object->lines[$i]->total_localtax2;
947 $localtax1_rate = $object->lines[$i]->localtax1_tx;
948 $localtax2_rate = $object->lines[$i]->localtax2_tx;
949 $localtax1_type = $object->lines[$i]->localtax1_type;
950 $localtax2_type = $object->lines[$i]->localtax2_type;
951
952 $vatrate = (string) $object->lines[$i]->tva_tx;
953
954 // Retrieve type from database for backward compatibility with old records
955 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
956 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
957 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
958 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
959 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
960 }
961
962 // retrieve global local tax
963 if ($localtax1_type && $localtax1ligne != 0) {
964 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
965 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
966 } else {
967 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
968 }
969 }
970 if ($localtax2_type && $localtax2ligne != 0) {
971 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
972 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
973 } else {
974 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
975 }
976 }
977
978 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
979 $vatrate .= '*';
980 }
981
982 // Fill $this->tva and $this->tva_array
983 if (!isset($this->tva[$vatrate])) {
984 $this->tva[$vatrate] = 0;
985 }
986 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
987 $vatcode = $object->lines[$i]->vat_src_code;
988 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
989 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
990 }
991 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
992 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
993 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
994 }
995 $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);
996 } else {
997 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
998 }
999
1000 $afterPosData = $this->getMaxAfterColsLinePositionsData();
1001 $pdf->setPage($afterPosData['page']);
1002 $nexY = $afterPosData['y'];
1003
1004 // Add line
1005 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1006 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
1007 //$pdf->SetDrawColor(190,190,200);
1008 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1009 $pdf->SetLineStyle(array('dash' => 0));
1010 }
1011
1012 $nexY += 0; // Add space between lines
1013 }
1014
1015 // Add last page for document footer if there are not enough size left
1016 $afterPosData = $this->getMaxAfterColsLinePositionsData();
1017 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
1018
1019 if (isset($afterPosData['y']) && $afterPosData['y'] > $this->page_hauteur - $page_bottom_margin) {
1020 $pdf->AddPage();
1021 if (!empty($tplidx)) {
1022 $pdf->useTemplate($tplidx);
1023 }
1024 $pagenb++;
1025 $pdf->setPage($pagenb);
1026 }
1027
1028 // Draw table frames and columns borders
1029 $drawTabNumbPage = $pdf->getNumPages();
1030 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1031 $pdf->setPage($i);
1032 // reset page orientation each loop to override it if it was changed
1033 $pdf->setPageOrientation('', false, 0); // The only function to edit the bottom margin of current page to set it.
1034
1035 $drawTabHideTop = $hidetop;
1036 $drawTabTop = $this->tab_top_newpage;
1037 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1038 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
1039
1040 if ($i == $pageposbeforeprintlines) {
1041 // first page need to start after notes
1042 $drawTabTop = $this->tab_top;
1043 } elseif (!$drawTabHideTop) {
1044 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
1045 $drawTabTop -= $this->tabTitleHeight;
1046 } else {
1047 $drawTabHideTop = 1;
1048 }
1049 }
1050
1051 // last page need to include document footer
1052 if ($i == $pdf->getNumPages()) {
1053 // remove document footer height to tab bottom position
1054 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs);
1055 }
1056
1057 $drawTabHeight = $drawTabBottom - $drawTabTop;
1058 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object, $outputlangsbis);
1059
1060 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
1061
1062 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1063
1064 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
1065
1066 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
1067 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
1068
1069 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
1070 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1071 $this->_pagehead($pdf, $object, 0, $outputlangs);
1072 }
1073 if (!empty($tplidx)) {
1074 $pdf->useTemplate($tplidx);
1075 }
1076 }
1077
1078
1079 // reset text color before print footers
1080 $pdf->SetTextColor(0, 0, 0);
1081
1082 $pdf->setPage($pdf->getNumPages());
1083
1084 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1085
1086 // Display infos area
1087 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1088
1089 // Display total zone
1090 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1091
1092 // Display payment area
1093 $listofpayments = $object->getListOfPayments('', 0, 1);
1094 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1095 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1096 }
1097
1098 // Add number of pages in footer
1099 if (method_exists($pdf, 'AliasNbPages')) {
1100 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1101 }
1102
1103 // Add terms to sale
1104 $termsofsalefilename = getDolGlobalString('MAIN_INFO_INVOICE_TERMSOFSALE');
1105 if (getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1106 $termsofsale = $conf->invoice->dir_output.'/'.$termsofsalefilename;
1107 if (!empty($conf->invoice->multidir_output[$object->entity ?? $conf->entity])) {
1108 $termsofsale = $conf->invoice->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
1109 }
1110
1111 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1112 $pagecount = $pdf->setSourceFile($termsofsale);
1113 for ($i = 1; $i <= $pagecount; $i++) {
1114 $tplIdx = $pdf->importPage($i);
1115 if ($tplIdx !== false) {
1116 $s = $pdf->getTemplatesize($tplIdx);
1117 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1118 $pdf->useTemplate($tplIdx);
1119 } else {
1120 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
1121 }
1122 }
1123 }
1124 }
1125
1126 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
1127 $this->addBottomQRInvoice($pdf, $object, $outputlangs);
1128 }
1129
1130 $pdf->Close();
1131
1132 $pdf->Output($file, 'F');
1133
1134 // Add pdfgeneration hook
1135 $hookmanager->initHooks(array('pdfgeneration'));
1136 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1137 global $action;
1138 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1139 $this->warnings = $hookmanager->warnings;
1140 if ($reshook < 0) {
1141 $this->error = $hookmanager->error;
1142 $this->errors = $hookmanager->errors;
1143 dolChmod($file);
1144 return -1;
1145 }
1146
1147 dolChmod($file);
1148
1149 $this->result = array('fullpath' => $file);
1150
1151 return 1; // No error
1152 } else {
1153 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1154 return 0;
1155 }
1156 } else {
1157 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1158 return 0;
1159 }
1160 }
1161
1162
1172 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1173 {
1174 $sign = 1;
1175 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1176 $sign = -1;
1177 }
1178
1179 $tab3_posx = 120;
1180 $tab3_top = $posy + 8;
1181 $tab3_width = 80;
1182 $tab3_height = 4;
1183 if ($this->page_largeur < 210) { // To work with US executive format
1184 $tab3_posx -= 15;
1185 }
1186
1187 $default_font_size = pdf_getPDFFontSize($outputlangs);
1188
1189 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1190 if ($object->type == 2) {
1191 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1192 }
1193
1194 $pdf->SetFont('', '', $default_font_size - 3);
1195 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1196 $pdf->MultiCell(60, 3, $title, 0, 'L', false);
1197
1198 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1199
1200 $pdf->SetFont('', '', $default_font_size - 4);
1201 $pdf->SetXY($tab3_posx, $tab3_top);
1202 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
1203 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1204 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
1205 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1206 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
1207 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1208 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
1209
1210 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1211
1212 $y = 0;
1213
1214 $pdf->SetFont('', '', $default_font_size - 4);
1215
1216
1217 // Loop on each discount available (deposits and credit notes and excess of payment included)
1218 $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,";
1219 $sql .= " re.description, re.fk_facture_source,";
1220 $sql .= " f.type, f.datef";
1221 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1222 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1223 $resql = $this->db->query($sql);
1224 if ($resql) {
1225 $num = $this->db->num_rows($resql);
1226 $i = 0;
1227 $invoice = new Facture($this->db);
1228 while ($i < $num) {
1229 $y += 3;
1230 $obj = $this->db->fetch_object($resql);
1231
1232 if ($obj->type == 2) {
1233 $text = $outputlangs->transnoentities("CreditNote");
1234 } elseif ($obj->type == 3) {
1235 $text = $outputlangs->transnoentities("Deposit");
1236 } elseif ($obj->type == 0) {
1237 $text = $outputlangs->transnoentities("ExcessReceived");
1238 } else {
1239 $text = $outputlangs->transnoentities("UnknownType");
1240 }
1241
1242 $invoice->fetch($obj->fk_facture_source);
1243
1244 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1245 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', false);
1246 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1247 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', false);
1248 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1249 $pdf->MultiCell(20, 3, $text, 0, 'L', false);
1250 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1251 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', false);
1252
1253 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1254
1255 $i++;
1256 }
1257 } else {
1258 $this->error = $this->db->lasterror();
1259 return -1;
1260 }
1261
1262 // Loop on each payment
1263 // TODO Call getListOfPayments instead of hard coded sql
1264 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1265 $sql .= " cp.code";
1266 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1267 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1268 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1269 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1270 $sql .= " ORDER BY p.datep";
1271
1272 $resql = $this->db->query($sql);
1273 if ($resql) {
1274 $num = $this->db->num_rows($resql);
1275 $i = 0;
1276 $y += 3;
1277 $maxY = $y;
1278 while ($i < $num) {
1279 $row = $this->db->fetch_object($resql);
1280 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1281 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1282 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1283 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', false);
1284 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1285 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1286
1287 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1288 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1289 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1290 $pdf->MultiCell(30, 3, $row->num, 0, 'L', false);
1291 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1292 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1293 $y += 3;
1294 $i++;
1295 }
1296
1297 return $tab3_top + $y + 3;
1298 } else {
1299 $this->error = $this->db->lasterror();
1300 return -1;
1301 }
1302 }
1303
1304
1315 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1316 {
1317 global $mysoc;
1318
1319 $default_font_size = pdf_getPDFFontSize($outputlangs);
1320
1321 $pdf->SetFont('', '', $default_font_size - 1);
1322
1323 krsort($this->tva_array);
1324
1325 // Clean data type
1326 $object->total_tva = (float) $object->total_tva;
1327
1328 // Show VAT details
1329 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1330 $pdf->SetFillColor(224, 224, 224);
1331
1332 $pdf->SetFont('', '', $default_font_size - 2);
1333 $pdf->SetXY($this->marge_gauche, $posy);
1334 $titre = $outputlangs->transnoentities("VAT");
1335 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1336
1337 $pdf->SetFont('', '', $default_font_size - 2);
1338 $pdf->SetXY($this->marge_gauche + 25, $posy);
1339 $titre = $outputlangs->transnoentities("NetTotal");
1340 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1341
1342 $pdf->SetFont('', '', $default_font_size - 2);
1343 $pdf->SetXY($this->marge_gauche + 50, $posy);
1344 $titre = $outputlangs->transnoentities("VATAmount");
1345 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1346
1347 $pdf->SetFont('', '', $default_font_size - 2);
1348 $pdf->SetXY($this->marge_gauche + 75, $posy);
1349 $titre = $outputlangs->transnoentities("AmountTotal");
1350 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1351
1352 $posy = $pdf->GetY();
1353 $tot_ht = 0;
1354 $tot_tva = 0;
1355 $tot_ttc = 0;
1356
1357 foreach ($this->tva_array as $tvakey => $tvaval) {
1358 $pdf->SetFont('', '', $default_font_size - 2);
1359 $pdf->SetXY($this->marge_gauche, $posy);
1360 $titre = round((float) $tvakey, 2) . "%";
1361 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1362
1363 $pdf->SetFont('', '', $default_font_size - 2);
1364 $pdf->SetXY($this->marge_gauche + 25, $posy);
1365 $titre = price($tvaval['tot_ht']);
1366 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1367 $tot_ht += $tvaval['tot_ht'];
1368
1369 $pdf->SetFont('', '', $default_font_size - 2);
1370 $pdf->SetXY($this->marge_gauche + 50, $posy);
1371 $titre = price($tvaval['amount']);
1372 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1373 $tot_tva += $tvaval['amount'];
1374
1375 $pdf->SetFont('', '', $default_font_size - 2);
1376 $pdf->SetXY($this->marge_gauche + 75, $posy);
1377 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1378 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1379 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1380
1381 $posy = $pdf->GetY();
1382 }
1383 }
1384
1385 // If France, show VAT mention if applicable
1386 $showvatmention = 0;
1387 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1388 $pdf->SetFont('', '', $default_font_size - 2);
1389 $pdf->SetXY($this->marge_gauche, $posy);
1390 if (empty($mysoc->tva_assuj)) {
1391 if ($mysoc->forme_juridique_code == 92) {
1392 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', false);
1393 } else {
1394 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1395 }
1396 $showvatmention++;
1397 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1398 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', false);
1399 $showvatmention++;
1400 }
1401 $posy = $pdf->GetY();
1402 }
1403
1404 $showvatmention += pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1405
1406 if ($showvatmention) {
1407 $posy += 3;
1408 }
1409
1410 $posxval = 52; // Position of values of properties shown on left side
1411 $posxend = 110; // End of x for text on left side
1412 if ($this->page_largeur < 210) { // To work with US executive format
1413 $posxend -= 10;
1414 }
1415
1416 // Show previous and new balance
1417 if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) {
1418 // All customer previous invoices
1419 $sql = "SELECT f.rowid, f.datef, f.total_ttc";
1420 $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
1421 $sql .= " WHERE f.fk_soc = " . ((int) $object->socid);
1422 $sql .= " AND f.entity IN (" . getEntity('invoice') . ")";
1423 $sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
1424 $sql .= " AND f.rowid < " . ((int) $object->id);
1425 $sql .= " AND f.fk_statut > 0";
1426 $sql .= " ORDER BY f.datef ASC";
1427
1428 $old_balance = 0;
1429 $invoices = array();
1430 $resql = $this->db->query($sql);
1431 if ($resql) {
1432 while ($obj = $this->db->fetch_object($resql)) {
1433 $invoices[] = $obj;
1434 $old_balance += $obj->total_ttc;
1435 }
1436 $this->db->free($resql);
1437 }
1438
1439 // All payments before current date
1440 $sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1441 $sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1442 $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1443 $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1444 $sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
1445 $sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'";
1446 $sql_payments .= " ORDER BY p.datep ASC";
1447
1448 $total_payments = 0;
1449 $resql_payments = $this->db->query($sql_payments);
1450 if ($resql_payments) {
1451 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1452 $total_payments += $obj_payment->amount;
1453 }
1454 $this->db->free($resql_payments);
1455 }
1456
1457 // Payments made on current invoice date (including current invoice)
1458 $sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1459 $sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1460 $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1461 $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1462 $sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
1463 $sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
1464
1465 $current_date_payments = 0;
1466 $resql_current_date = $this->db->query($sql_current_date_payments);
1467 if ($resql_current_date) {
1468 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1469 $current_date_payments += $obj_current->amount;
1470 }
1471 $this->db->free($resql_current_date);
1472 }
1473
1474 // Previous balance
1475 $old_balance -= $total_payments;
1476
1477 // New balance
1478 $new_balance = $old_balance + $object->total_ttc - $current_date_payments;
1479
1480 $pdf->SetFillColor(224, 224, 224);
1481 $pdf->SetFont('', '', $default_font_size - 2);
1482 $pdf->SetXY($this->marge_gauche, $posy);
1483 $titre = $outputlangs->transnoentities("PreviousBalance").' : '.price($old_balance);
1484 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true);
1485
1486 $pdf->SetFont('', '', $default_font_size - 2);
1487 $pdf->SetXY($posxval + 8, $posy);
1488 $titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance);
1489 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true);
1490
1491 $posy = $pdf->GetY() + 1;
1492 }
1493
1494 // Show payments conditions
1495 if ($object->type != 2 && $object->cond_reglement_code) {
1496 $pdf->SetFont('', '', $default_font_size - 2);
1497 $pdf->SetXY($this->marge_gauche, $posy);
1498 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1499 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1500
1501 $pdf->SetFont('', '', $default_font_size - 2);
1502 $pdf->SetXY($posxval, $posy);
1503 $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);
1504 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1505 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1506
1507 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1508 }
1509
1510 // Show category of operations
1511 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1512 $pdf->SetFont('', '', $default_font_size - 2);
1513 $pdf->SetXY($this->marge_gauche, $posy);
1514 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1515 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1516
1517 $pdf->SetFont('', '', $default_font_size - 2);
1518 $pdf->SetXY($posxval, $posy);
1519 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1520 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1521
1522 $posy = $pdf->GetY() + 3; // for 2 lines
1523 }
1524
1525 if ($object->type != 2) {
1526 // Check a payment mode is defined
1527 if (empty($object->mode_reglement_code)
1528 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1529 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1530 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1531 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1532 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1533 // Avoid having any valid PDF with setup that is not complete
1534 $outputlangs->load("errors");
1535
1536 $pdf->SetXY($this->marge_gauche, $posy);
1537 $pdf->SetTextColor(200, 0, 0);
1538 $pdf->SetFont('', '', $default_font_size - 2);
1539 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1540 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', false);
1541 $pdf->SetTextColor(0, 0, 0);
1542
1543 $posy = $pdf->GetY() + 1;
1544 }
1545
1546 // Show payment mode
1547 if (!empty($object->mode_reglement_code)
1548 && $object->mode_reglement_code != 'CHQ'
1549 && $object->mode_reglement_code != 'VIR') {
1550 $pdf->SetFont('', '', $default_font_size - 2);
1551 $pdf->SetXY($this->marge_gauche, $posy);
1552 $titre = $outputlangs->transnoentities("PaymentMode").':';
1553 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1554
1555 $pdf->SetFont('', '', $default_font_size - 2);
1556 $pdf->SetXY($posxval, $posy);
1557 $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);
1558
1559 //#21654: add account number used for the debit
1560 if ($object->mode_reglement_code == "PRE") {
1561 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1562 $bac = new CompanyBankAccount($this->db);
1563 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1564 $bac->fetch(0, '', $object->thirdparty->id);
1565 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1566 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1567 }
1568
1569 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1570
1571 $posy = $pdf->GetY();
1572 }
1573
1574 // Show if Option VAT debit option is on also if transmitter is french
1575 // Decret n°2099-1299 2022-10-07
1576 // French mention : "Option pour le paiement de la taxe d'après les débits"
1577 if ($this->emetteur->country_code == 'FR') {
1578 if (getDolGlobalInt('TAX_MODE') == 1) {
1579 $pdf->SetXY($this->marge_gauche, $posy);
1580 $pdf->writeHTMLCell(80, 5, null, null, $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1581
1582 $posy = $pdf->GetY() + 1;
1583 }
1584 }
1585
1586 // Show online payment link
1587 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1588 $useonlinepayment = 0;
1589 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1590 // Show online payment link
1591 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1592 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1593 $validpaymentmethod = getValidOnlinePaymentMethods('');
1594 $useonlinepayment = count($validpaymentmethod);
1595 }
1596
1597
1598 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1599 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1600 global $langs;
1601
1602 $langs->loadLangs(array('payment', 'stripe'));
1603 $servicename = $langs->transnoentities('Online');
1604 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1605 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1606
1607 $pdf->SetXY($this->marge_gauche, $posy);
1608 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, null, null, dol_htmlentitiesbr($linktopay), 0, 1);
1609
1610 $posy = $pdf->GetY() + 1;
1611 }
1612 }
1613
1614 // Show payment mode CHQ
1615 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1616 // If payment mode unregulated or payment mode forced to CHQ
1617 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1618 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1619
1620 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1621 $account = new Account($this->db);
1622 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1623
1624 $pdf->SetXY($this->marge_gauche, $posy);
1625 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1626 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1627 $posy = $pdf->GetY() + 1;
1628
1629 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1630 $pdf->SetXY($this->marge_gauche, $posy);
1631 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1632 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1633 $posy = $pdf->GetY() + 2;
1634 }
1635 }
1636 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1637 $pdf->SetXY($this->marge_gauche, $posy);
1638 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1639 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1640 $posy = $pdf->GetY() + 1;
1641
1642 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1643 $pdf->SetXY($this->marge_gauche, $posy);
1644 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1645 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1646 $posy = $pdf->GetY() + 2;
1647 }
1648 }
1649 }
1650 }
1651
1652 // If payment mode not forced or forced to VIR, show payment with BAN
1653 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1654 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1655 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : (int) $object->fk_account);
1656 if ($object->fk_bank > 0) {
1657 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1658 }
1659 $account = new Account($this->db);
1660 $account->fetch($bankid);
1661
1662 $curx = $this->marge_gauche;
1663 $cury = $posy;
1664
1665 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1666
1667 $posy += 2;
1668
1669 // SHOW EPC QR CODE at bottom, but only if unpaid amount exists
1670 if ((getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == 'bottom') && ($object->getRemainToPay() > 0)) {
1671 $qrPosX = $this->marge_gauche + 5;
1672 $qrPosY = $posy;
1673 $qrCodeColor = array('25', '25', '25');
1674 $styleQr = array(
1675 'border' => false,
1676 'padding' => 0,
1677 'fgcolor' => $qrCodeColor,
1678 'bgcolor' => false, //array(255,255,255)
1679 'module_width' => 1, // width of a single module in points
1680 'module_height' => 1 // height of a single module in points
1681 );
1682
1683 $EPCQrCodeString = $object->buildEPCQrCodeString();
1684 $pdf->write2DBarcode($EPCQrCodeString, 'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr, 'N');
1685
1686 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1687 $pdf->SetFont('', '', $default_font_size - 5);
1688 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', false);
1689 $posy = $pdf->GetY() + 2;
1690 }
1691
1692 // Show structured communication
1693 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1694 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1695 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1696
1697 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', false);
1698 }
1699 }
1700 }
1701 }
1702
1703 return $posy;
1704 }
1705
1706
1718 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1719 {
1720 global $mysoc, $hookmanager;
1721
1722 $sign = 1;
1723 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1724 $sign = -1;
1725 }
1726
1727 $default_font_size = pdf_getPDFFontSize($outputlangs);
1728
1729 $tab2_top = $posy;
1730 $tab2_hl = 4;
1731 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1732 $pdf->SetFont('', '', $default_font_size - 2);
1733 } else {
1734 $pdf->SetFont('', '', $default_font_size - 1);
1735 }
1736
1737 // Total table
1738 $col1x = 120;
1739 $col2x = 170;
1740 if ($this->page_largeur < 210) { // To work with US executive format
1741 $col1x -= 15;
1742 $col2x -= 10;
1743 }
1744 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1745
1746 $useborder = 0;
1747 $index = 0;
1748
1749 // Add trigger to allow to edit $object
1750 $parameters = array(
1751 'object' => &$object,
1752 'outputlangs' => $outputlangs,
1753 );
1754 $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1755
1756 // overall percentage of advancement
1757 $percent = 0;
1758 $i = 0;
1759 foreach ($object->lines as $line) {
1760 if ($line->product_type != 9) {
1761 $percent += $line->situation_percent;
1762 $i++;
1763 }
1764 }
1765
1766 if (!empty($i)) {
1767 $avancementGlobal = $percent / $i;
1768 } else {
1769 $avancementGlobal = 0;
1770 }
1771
1772 $object->fetchPreviousNextSituationInvoice();
1773 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1774
1775 $total_a_payer = 0;
1776 $total_a_payer_ttc = 0;
1777 foreach ($TPreviousIncoice as &$fac) {
1778 $total_a_payer += $fac->total_ht;
1779 $total_a_payer_ttc += $fac->total_ttc;
1780 }
1781 $total_a_payer += $object->total_ht;
1782 $total_a_payer_ttc += $object->total_ttc;
1783
1784 if (!empty($avancementGlobal)) {
1785 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1786 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1787 } else {
1788 $total_a_payer = 0;
1789 $total_a_payer_ttc = 0;
1790 }
1791
1792 $i = 1;
1793 if (!empty($TPreviousIncoice)) {
1794 $pdf->setY($tab2_top);
1795 $posy = $pdf->GetY();
1796
1797 foreach ($TPreviousIncoice as &$fac) {
1798 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1799 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1800 $pdf->addPage();
1801 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1802 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1803 $pdf->setY($this->tab_top_newpage);
1804 } else {
1805 $pdf->setY($this->marge_haute);
1806 }
1807 $posy = $pdf->GetY();
1808 }
1809
1810 // Cumulate preceding VAT
1811 $index++;
1812 $pdf->SetFillColor(255, 255, 255);
1813 $pdf->SetXY($col1x, $posy);
1814 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", (string) $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', true);
1815
1816 $pdf->SetXY($col2x, $posy);
1817
1818 $facSign = '';
1819 if ($i > 1) {
1820 $facSign = $fac->total_ht >= 0 ? '+' : '';
1821 }
1822
1823 $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1824
1825 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', true);
1826
1827 $i++;
1828 $posy += $tab2_hl;
1829
1830 $pdf->setY($posy);
1831 }
1832
1833 // Display current total
1834 $pdf->SetFillColor(255, 255, 255);
1835 $pdf->SetXY($col1x, $posy);
1836 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", (string) $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', true);
1837
1838 $pdf->SetXY($col2x, $posy);
1839 $facSign = '';
1840 if ($i > 1) {
1841 $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1842 }
1843
1844 if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1845 $facSign = '-';
1846 }
1847
1848
1849 $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1850 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', true);
1851
1852 $posy += $tab2_hl;
1853
1854 // Display all total
1855 $pdf->SetFont('', '', $default_font_size - 1);
1856 $pdf->SetFillColor(255, 255, 255);
1857 $pdf->SetXY($col1x, $posy);
1858 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", (string) $avancementGlobal), 0, 'L', true);
1859
1860 $pdf->SetXY($col2x, $posy);
1861 $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', true);
1862 $pdf->SetFont('', '', $default_font_size - 2);
1863
1864 $posy += $tab2_hl;
1865
1866 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1867 $pdf->addPage();
1868 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1869 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1870 $pdf->setY($this->tab_top_newpage);
1871 } else {
1872 $pdf->setY($this->marge_haute);
1873 }
1874
1875 $posy = $pdf->GetY();
1876 }
1877
1878 $tab2_top = $posy;
1879 $index = 0;
1880
1881 $tab2_top += 3;
1882 }
1883
1884
1885 // Get Total HT
1886 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1887
1888 // Total discount
1889 $total_discount_on_lines = 0;
1890 $multicurrency_total_discount_on_lines = 0;
1891 foreach ($object->lines as $i => $line) {
1892 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1893 $multicurrency_resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2, 1);
1894
1895 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1896 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1897 // If line was a negative line, we do not count the discount as a discount
1898 if ($line->total_ht < 0) {
1899 $total_discount_on_lines += -$line->total_ht;
1900 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1901 }
1902 }
1903
1904 // Show total discount only if there is some discount on lines
1905 if ($total_discount_on_lines > 0 && !$object->isSituationInvoice()) {
1906 // Show discount except on credit note type invoices
1907 if ($this->showAmountBeforeDiscount && $object->type != 2) {
1908 $pdf->SetFillColor(255, 255, 255);
1909 $pdf->SetXY($col1x, $tab2_top);
1910 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', true);
1911 $pdf->SetXY($col2x, $tab2_top);
1912
1913 $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));
1914 $pdf->MultiCell($largcol2, $tab2_hl, price($total_before_discount_to_show, 0, $outputlangs), 0, 'R', true);
1915
1916 $index++;
1917 }
1918
1919 // Show total NET before discount except on credit note type invoices
1920 if ($this->showDiscountAmount && $object->type != 2) {
1921 $pdf->SetFillColor(255, 255, 255);
1922 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1923 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', true);
1924 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1925
1926 $total_discount_to_show = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1927 $pdf->MultiCell($largcol2, $tab2_hl, price($total_discount_to_show, 0, $outputlangs), 0, 'R', true);
1928
1929 $index++;
1930 }
1931 }
1932
1933 // Total HT
1934 $pdf->SetFillColor(255, 255, 255);
1935 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1936 $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);
1937
1938 $total_ht = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1939 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1940 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ht, 0, $outputlangs), 0, 'R', true);
1941
1942 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1943 $index++;
1944 $pdf->SetFillColor(255, 255, 255);
1945 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1946 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', true);
1947
1948 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1949 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', true);
1950 }
1951
1952 // Show VAT by rates and total
1953 $pdf->SetFillColor(248, 248, 248);
1954
1955 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1956 $total_ttc_origin = $object->total_ttc;
1957
1958 $this->atleastoneratenotnull = 0;
1959
1960
1961 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1962 $tvaisnull = false;
1963 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
1964 $tva_el = reset($this->tva_array);
1965 if ($tva_el['vatrate'] == '0.000' && is_float($tva_el['amount'])) $tvaisnull = true;
1966 }
1967 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1968 // Nothing to do
1969 } else {
1970 // Show VAT lines
1971 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1972
1973 // Revenue stamp
1974 if (price2num($object->revenuestamp, 'MT') != 0) {
1975 $index++;
1976 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1977 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', true);
1978
1979 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1980 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', true);
1981 }
1982
1983 // Total TTC
1984 $index++;
1985 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1986 $pdf->SetTextColor(0, 0, 60);
1987 $pdf->SetFillColor(224, 224, 224);
1988 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', true);
1989
1990 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1991 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1992 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
1993 } else {
1994 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
1995
1996 //$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');
1997 $index++;
1998 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $pdf->SetFillColor(224, 224, 224);
2001 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
2002
2003 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2004 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
2005 }
2006
2007 // Retained warranty
2008 if ($object->displayRetainedWarranty()) {
2009 $pdf->SetTextColor(40, 40, 40);
2010 $pdf->SetFillColor(255, 255, 255);
2011
2012 $retainedWarranty = $object->getRetainedWarrantyAmount('MT');
2013 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
2014
2015 // Billed - retained warranty
2016 $index++;
2017 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2018 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', true);
2019
2020 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2021 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', true);
2022
2023 // retained warranty
2024 $index++;
2025 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2026
2027 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
2028 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
2029
2030 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', true);
2031 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2032 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', true);
2033 }
2034 }
2035 }
2036
2037 $pdf->SetTextColor(0, 0, 0);
2038
2039 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
2040 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
2041
2042 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
2043 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2044 // Not used in this case, initialized to avoid CI warnings
2045 $deja_regle_origin = 0;
2046 $creditnoteamount_origin = 0;
2047 $depositsamount_origin = 0;
2048 $resteapayer_origin = 0;
2049 } else {
2050 $deja_regle_origin = $object->getSommePaiement(0);
2051 $creditnoteamount_origin = $object->getSumCreditNotesUsed(0); // Warning, this also include excess received
2052 $depositsamount_origin = $object->getSumDepositsUsed(0);
2053 $resteapayer_origin = price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin, 'MT');
2054 }
2055 if (!empty($object->paye)) {
2056 $resteapayer = 0;
2057 $resteapayer_origin = 0;
2058 }
2059
2060 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2061
2062 $pdf->SetFont('', '', $default_font_size - 1);
2063 $pdf->SetTextColor(0, 0, 0);
2064
2065 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2066
2067 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2068 if ($reshook < 0) {
2069 $this->error = $hookmanager->error;
2070 $this->errors = $hookmanager->errors;
2071 }
2072
2073 $index++;
2074 return ($tab2_top + ($tab2_hl * $index));
2075 }
2076
2077 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2085 public static function liste_modeles($db, $maxfilenamelength = 0)
2086 {
2087 // phpcs:enable
2088 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2089 }
2090
2091 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2106 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $object = '', $outputlangsbis = null)
2107 {
2108 // Force to disable hidetop and hidebottom
2109 $hidebottom = 0;
2110 if ($hidetop) {
2111 $hidetop = -1;
2112 }
2113
2114 if ($object instanceOf Facture) {
2115 $currency = $object->multicurrency_code;
2116 } else {
2117 $currency = $object;
2118 }
2119 if (empty($currency)) {
2120 $currency = getDolCurrency();
2121 }
2122
2123 $default_font_size = pdf_getPDFFontSize($outputlangs);
2124
2125 // Amount in (at tab_top - 1)
2126 $pdf->SetTextColor(0, 0, 0);
2127 $pdf->SetFont('', '', $default_font_size - 2);
2128
2129 if (empty($hidetop)) {
2130 // Show category of operations
2131 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2132 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2133 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2134 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2135 }
2136
2137 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2138 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2139 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2140 }
2141 if ($currency != getDolCurrency()) {
2142 // Use nb of digit of the total price of main currency + nb of digit for total price of foreign currency + 1
2143 $maxnbofdec = getDolGlobalInt('MAIN_MAX_DECIMALS_TOT') + getDolGlobalInt('MAIN_MAX_DECIMALS_CURRENCY_TOT', getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')) + 1;
2144 $pricetoshow1 = price($object->multicurrency_tx, 0, $outputlangs, 1, 0, $maxnbofdec, $currency);
2145 $pricetoshow2 = price($object->multicurrency_tx, 0, $outputlangs, 1, 0, -2, $currency);
2146 $pricetoshow = ((strlen($pricetoshow1) < strlen($pricetoshow2)) ? $pricetoshow1 : $pricetoshow2);
2147 $titre .= ' ('.$pricetoshow.' = '.price(1, 0, $outputlangs, 1, 0, 0, getDolCurrency()).')';
2148 }
2149
2150 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2151 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2152
2153 // MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2154 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2155 $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')));
2156 }
2157 }
2158
2159 $pdf->SetDrawColor(128, 128, 128);
2160 $pdf->SetFont('', '', $default_font_size - 1);
2161
2162 // Output Rect
2163 $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
2164
2165
2166 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2167
2168 if (empty($hidetop)) {
2169 $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
2170 }
2171 }
2172
2173 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2184 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2185 {
2186 // phpcs:enable
2187 global $conf, $langs;
2188
2189 $ltrdirection = 'L';
2190 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2191 $ltrdirection = 'R';
2192 }
2193
2194 // Load traductions files required by page
2195 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2196
2197 $default_font_size = pdf_getPDFFontSize($outputlangs);
2198
2199 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2200
2201 $pdf->SetTextColor(0, 0, 60);
2202 $pdf->SetFont('', 'B', $default_font_size + 3);
2203
2204 $w = 110;
2205
2206 $posy = $this->marge_haute;
2207 $posx = $this->page_largeur - $this->marge_droite - $w;
2208
2209 $pdf->SetXY($this->marge_gauche, $posy);
2210
2211 // Logo
2212 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2213 if ($this->emetteur->logo) {
2214 $logodir = $conf->mycompany->dir_output;
2215 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
2216 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
2217 }
2218 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2219 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2220 } else {
2221 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2222 }
2223 if (is_readable($logo)) {
2224 $height = pdf_getHeightForLogo($logo);
2225 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2226 } else {
2227 $pdf->SetTextColor(200, 0, 0);
2228 $pdf->SetFont('', 'B', $default_font_size - 2);
2229 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2230 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2231 }
2232 } else {
2233 $text = $this->emetteur->name;
2234 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2235 }
2236 }
2237
2238 $pdf->SetFont('', 'B', $default_font_size + 3);
2239 $pdf->SetXY($posx, $posy);
2240 $pdf->SetTextColor(0, 0, 60);
2241 $subtitle = "";
2242 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2243 if ($object->type == 1) {
2244 $title = $outputlangs->transnoentities("InvoiceReplacement");
2245 }
2246 if ($object->type == 2) {
2247 $title = $outputlangs->transnoentities("InvoiceAvoir");
2248 }
2249 if ($object->type == 3) {
2250 $title = $outputlangs->transnoentities("PdfInvoiceDepositTitle");
2251 }
2252 if ($this->situationinvoice) {
2253 $outputlangs->loadLangs(array("other"));
2254 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2255 $subtitle = $outputlangs->transnoentities("PDFSituationTitle", (string) $object->situation_counter);
2256 }
2257 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2258 $title .= ' - ';
2259 if ($object->type == 0) {
2260 if ($this->situationinvoice) {
2261 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2262 }
2263 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2264 } elseif ($object->type == 1) {
2265 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2266 } elseif ($object->type == 2) {
2267 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2268 } elseif ($object->type == 3) {
2269 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2270 } elseif ($object->type == 4) {
2271 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2272 }
2273 }
2274 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2275 if ($object->status == $object::STATUS_DRAFT) {
2276 $pdf->SetTextColor(128, 0, 0);
2277 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2278 }
2279
2280 $pdf->MultiCell($w, 3, $title, '', 'R');
2281 $posy = $pdf->GetY();
2282
2283 if (!empty($subtitle)) {
2284 $pdf->SetFont('', 'B', $default_font_size);
2285 $pdf->SetXY($posx, $posy);
2286 $pdf->MultiCell($w, 6, $subtitle, '', 'R');
2287 $posy = $pdf->GetY();
2288 }
2289
2290 $pdf->SetFont('', '', $default_font_size - 2);
2291
2292 pdfWriteAdditionnalTitle($pdf, $outputlangs, $this->page_hauteur, $object, $w, $posx, $posy);
2293
2294 /*
2295 $posy += 5;
2296 $pdf->SetXY($posx, $posy);
2297 $pdf->SetTextColor(0, 0, 60);
2298 $pdf->SetFont('', 'B', $default_font_size);
2299 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2300 if ($object->status == $object::STATUS_DRAFT) {
2301 $pdf->SetTextColor(128, 0, 0);
2302 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2303 }
2304 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2305
2306 $posy += 3;
2307 $pdf->SetFont('', '', $default_font_size - 2);
2308
2309 if ($object->ref_customer) {
2310 $posy += 4;
2311 $pdf->SetXY($posx, $posy);
2312 $pdf->SetTextColor(0, 0, 60);
2313 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2314 }
2315
2316 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2317 $object->fetchProject();
2318 if (!empty($object->project->title)) {
2319 $posy += 3;
2320 $pdf->SetXY($posx, $posy);
2321 $pdf->SetTextColor(0, 0, 60);
2322 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".$object->project->title, '', 'R');
2323 }
2324 }
2325
2326 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2327 $object->fetchProject();
2328 if (!empty($object->project->ref)) {
2329 $outputlangs->load("projects");
2330 $posy += 3;
2331 $pdf->SetXY($posx, $posy);
2332 $pdf->SetTextColor(0, 0, 60);
2333 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".$object->project->ref, '', 'R');
2334 }
2335 }
2336
2337 $objectidnext = $object->getIdReplacingInvoice('validated');
2338 if ($object->type == 0 && $objectidnext) {
2339 $objectreplacing = new Facture($this->db);
2340 $objectreplacing->fetch($objectidnext);
2341
2342 $posy += 3;
2343 $pdf->SetXY($posx, $posy);
2344 $pdf->SetTextColor(0, 0, 60);
2345 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2346 }
2347 if ($object->type == 1) {
2348 $objectreplaced = new Facture($this->db);
2349 $objectreplaced->fetch($object->fk_facture_source);
2350
2351 $posy += 4;
2352 $pdf->SetXY($posx, $posy);
2353 $pdf->SetTextColor(0, 0, 60);
2354 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2355 }
2356 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2357 $objectreplaced = new Facture($this->db);
2358 $objectreplaced->fetch($object->fk_facture_source);
2359
2360 $posy += 3;
2361 $pdf->SetXY($posx, $posy);
2362 $pdf->SetTextColor(0, 0, 60);
2363 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2364 }
2365
2366 $posy += 4;
2367 $pdf->SetXY($posx, $posy);
2368 $pdf->SetTextColor(0, 0, 60);
2369
2370 $title = $outputlangs->transnoentities("DateInvoice");
2371 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2372 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2373 }
2374 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2375
2376 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2377 $posy += 4;
2378 $pdf->SetXY($posx, $posy);
2379 $pdf->SetTextColor(0, 0, 60);
2380 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2381 }
2382
2383 if ($object->type != 2) {
2384 $posy += 3;
2385 $pdf->SetXY($posx, $posy);
2386 $pdf->SetTextColor(0, 0, 60);
2387 $title = $outputlangs->transnoentities("DateDue");
2388 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2389 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2390 }
2391 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2392 }
2393
2394 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2395 $posy += 3;
2396 $pdf->SetXY($posx, $posy);
2397 $pdf->SetTextColor(0, 0, 60);
2398 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
2399 }
2400
2401 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2402 $posy += 3;
2403 $pdf->SetXY($posx, $posy);
2404 $pdf->SetTextColor(0, 0, 60);
2405 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
2406 }
2407
2408 // Get contact
2409 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2410 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2411 if (count($arrayidcontact) > 0) {
2412 $usertmp = new User($this->db);
2413 $usertmp->fetch($arrayidcontact[0]);
2414 $posy += 4;
2415 $pdf->SetXY($posx, $posy);
2416 $pdf->SetTextColor(0, 0, 60);
2417 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2418 }
2419 }
2420
2421 $posy += 1;
2422
2423 $top_shift = 0;
2424 $shipp_shift = 0;
2425 // Show list of linked objects
2426 if (!getDolGlobalString('INVOICE_HIDE_LINKED_OBJECT')) {
2427 $current_y = $pdf->getY();
2428 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2429 if ($current_y < $pdf->getY()) {
2430 $top_shift = $pdf->getY() - $current_y;
2431 }
2432 }
2433
2434 if ($showaddress) {
2435 // Sender properties
2436 $carac_emetteur = '';
2437 // Add internal contact of object if defined
2438 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2439 if (count($arrayidcontact) > 0) {
2440 $object->fetch_user($arrayidcontact[0]);
2441 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2442 $carac_emetteur .= $labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2443 $carac_emetteur .= "\n";
2444 }
2445
2446 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2447
2448 // Show sender
2449 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2450 $posy += $top_shift;
2451 $posx = $this->marge_gauche;
2452 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2453 $posx = $this->page_largeur - $this->marge_droite - 80;
2454 }
2455
2456 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2457 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2458
2459 // Show sender frame
2460 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2461 $pdf->SetTextColor(0, 0, 0);
2462 $pdf->SetFont('', '', $default_font_size - 2);
2463 $pdf->SetXY($posx, $posy - 5);
2464 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2465 $pdf->SetXY($posx, $posy);
2466 $pdf->SetFillColor(230, 230, 230);
2467 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2468 $pdf->SetTextColor(0, 0, 60);
2469 }
2470
2471 // Show sender name
2472 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2473 $pdf->SetXY($posx + 2, $posy + 3);
2474 $pdf->SetFont('', 'B', $default_font_size);
2475 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2476 $posy = $pdf->getY();
2477 }
2478
2479 // Show sender information
2480 $pdf->SetXY($posx + 2, $posy);
2481 $pdf->SetFont('', '', $default_font_size - 1);
2482 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2483
2484 // If BILLING contact defined on invoice, we use it
2485 $usecontact = false;
2486 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2487 if (count($arrayidcontact) > 0) {
2488 $usecontact = true;
2489 $result = $object->fetch_contact($arrayidcontact[0]);
2490 }
2491
2492 // Recipient name
2493 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2494 $thirdparty = $object->contact;
2495 } else {
2496 $thirdparty = $object->thirdparty;
2497 }
2498
2499 $carac_client_name = is_object($thirdparty) ? pdfBuildThirdpartyName($thirdparty, $outputlangs) : '';
2500
2501 $mode = 'target';
2502 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2503
2504 // Show recipient
2505 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2506 if ($this->page_largeur < 210) {
2507 $widthrecbox = 84; // To work with US executive format
2508 }
2509 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2510 $posy += $top_shift;
2511 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2512 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2513 $posx = $this->marge_gauche;
2514 }
2515
2516 // Show recipient frame
2517 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2518 $pdf->SetTextColor(0, 0, 0);
2519 $pdf->SetFont('', '', $default_font_size - 2);
2520 $pdf->SetXY($posx + 2, $posy - 5);
2521 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2522 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2523 }
2524
2525 // Show recipient name
2526 $pdf->SetXY($posx + 2, $posy + 3);
2527 $pdf->SetFont('', 'B', $default_font_size);
2528 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2529 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2530
2531 $posy = $pdf->getY();
2532
2533 // Show recipient information
2534 $pdf->SetFont('', '', $default_font_size - 1);
2535 $pdf->SetXY($posx + 2, $posy);
2536 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2537 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2538
2539 // Show shipping/delivery address
2540 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2541 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2542
2543 if (!empty($idaddressshipping)) {
2544 $object->fetch_contact($idaddressshipping[0]); // Load $object->contact
2545 $companystatic = new Societe($this->db);
2546 $companystatic->fetch($object->contact->fk_soc);
2547 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2548 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
2549 } else {
2550 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2551 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2552 }
2553 if (!empty($carac_client_shipping)) {
2554 $posy += $hautcadre;
2555
2556 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2557
2558 // Show shipping frame
2559 $pdf->SetXY($posx + 2, $posy - 5);
2560 $pdf->SetFont('', '', $default_font_size - 2);
2561 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', false);
2562 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2563
2564 // Show shipping name
2565 $pdf->SetXY($posx + 2, $posy + 3);
2566 $pdf->SetFont('', 'B', $default_font_size);
2567 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2568
2569 $posy = $pdf->getY();
2570
2571 // Show shipping information
2572 $pdf->SetXY($posx + 2, $posy);
2573 $pdf->SetFont('', '', $default_font_size - 1);
2574 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2575
2576 $shipp_shift += $hautcadre + 10;
2577 }
2578 }
2579 }
2580
2581 $pdf->SetTextColor(0, 0, 0);
2582
2583 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2584
2585 return $pagehead;
2586 }
2587
2588 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2599 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2600 {
2601 // phpcs:enable
2602 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2603 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);
2604 }
2605
2616 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2617 {
2618 global $hookmanager;
2619
2620 // Default field style for content
2621 $this->defaultContentsFieldsStyle = array(
2622 'align' => 'R', // R,C,L
2623 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2624 );
2625
2626 // Default field style for content
2627 $this->defaultTitlesFieldsStyle = array(
2628 'align' => 'C', // R,C,L
2629 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2630 );
2631
2632 /*
2633 * For example
2634 $this->cols['theColKey'] = array(
2635 'rank' => $rank, // int : use for ordering columns
2636 'width' => 20, // the column width in mm
2637 'title' => array(
2638 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2639 'label' => ' ', // the final label : used fore final generated text
2640 'align' => 'L', // text alignment : R,C,L
2641 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2642 ),
2643 'content' => array(
2644 'align' => 'L', // text alignment : R,C,L
2645 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2646 ),
2647 );
2648 */
2649
2650 $rank = 0; // do not use negative rank
2651 $this->cols['position'] = array(
2652 'rank' => $rank,
2653 'width' => 10,
2654 'status' => getDolGlobalInt('PDF_SPONGE_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2655 'title' => array(
2656 'textkey' => '#', // use lang key is useful in some case with module
2657 'align' => 'C',
2658 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2659 // 'label' => ' ', // the final label
2660 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2661 ),
2662 'content' => array(
2663 'align' => 'C',
2664 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2665 ),
2666 );
2667
2668 $rank = 5; // do not use negative rank
2669 $this->cols['desc'] = array(
2670 'rank' => $rank,
2671 'width' => false, // only for desc
2672 'status' => true,
2673 'title' => array(
2674 'textkey' => 'Designation', // use lang key is useful in some case with module
2675 'align' => 'L',
2676 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2677 // 'label' => ' ', // the final label
2678 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2679 ),
2680 'content' => array(
2681 'align' => 'L',
2682 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2683 ),
2684 );
2685
2686 // Image of product
2687 $rank += 10;
2688 $this->cols['photo'] = array(
2689 'rank' => $rank,
2690 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2691 'status' => false,
2692 'title' => array(
2693 'textkey' => 'Photo',
2694 'label' => ' '
2695 ),
2696 'content' => array(
2697 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2698 ),
2699 'border-left' => false, // remove left line separator
2700 );
2701
2702 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2703 $this->cols['photo']['status'] = true;
2704 }
2705
2706
2707 $rank += 10;
2708 $this->cols['vat'] = array(
2709 'rank' => $rank,
2710 'status' => false,
2711 'width' => 16, // in mm
2712 'title' => array(
2713 'textkey' => 'VAT'
2714 ),
2715 'border-left' => true, // add left line separator
2716 );
2717
2718 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2719 $this->cols['vat']['status'] = true;
2720 }
2721
2722 $rank += 10;
2723 $this->cols['subprice'] = array(
2724 'rank' => $rank,
2725 'width' => 19, // in mm
2726 'status' => true,
2727 'title' => array(
2728 'textkey' => 'PriceUHT'
2729 ),
2730 'border-left' => true, // add left line separator
2731 );
2732
2733 // Adapt dynamically the width of subprice, if text is too long.
2734 $tmpwidth = 0;
2735 $nblines = count($object->lines);
2736 for ($i = 0; $i < $nblines; $i++) {
2737 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2738 $tmpwidth = max($tmpwidth, $tmpwidth2);
2739 }
2740 if ($tmpwidth > 10) {
2741 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2742 }
2743
2744 $rank += 10;
2745 $this->cols['qty'] = array(
2746 'rank' => $rank,
2747 'width' => 16, // in mm
2748 'status' => true,
2749 'title' => array(
2750 'textkey' => 'Qty'
2751 ),
2752 'border-left' => true, // add left line separator
2753 );
2754
2755 $rank += 10;
2756 $this->cols['progress'] = array(
2757 'rank' => $rank,
2758 'width' => 19, // in mm
2759 'status' => false,
2760 'title' => array(
2761 'textkey' => 'ProgressShort'
2762 ),
2763 'border-left' => true, // add left line separator
2764 );
2765
2766 if ($this->situationinvoice) {
2767 $this->cols['progress']['status'] = true;
2768 }
2769
2770 $rank += 10;
2771 $this->cols['unit'] = array(
2772 'rank' => $rank,
2773 'width' => 11, // in mm
2774 'status' => false,
2775 'title' => array(
2776 'textkey' => 'Unit'
2777 ),
2778 'border-left' => true, // add left line separator
2779 );
2780 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2781 $this->cols['unit']['status'] = true;
2782 }
2783
2784 $rank += 10;
2785 $this->cols['discount'] = array(
2786 'rank' => $rank,
2787 'width' => 13, // in mm
2788 'status' => false,
2789 'title' => array(
2790 'textkey' => 'ReductionShort'
2791 ),
2792 'border-left' => true, // add left line separator
2793 );
2794 if ($this->atleastonediscount) {
2795 $this->cols['discount']['status'] = true;
2796 }
2797
2798 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2799 $this->cols['totalexcltax'] = array(
2800 'rank' => $rank,
2801 'width' => 26, // in mm
2802 'status' => !getDolGlobalBool('PDF_INVOICE_HIDE_PRICE_EXCL_TAX') && !getDolGlobalBool('PDF_PURCHASE_INVOICE_HIDE_PRICE_EXCL_TAX'),
2803 'title' => array(
2804 'textkey' => 'TotalHTShort'
2805 ),
2806 'border-left' => true, // add left line separator
2807 );
2808
2809 $rank += 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2810 $this->cols['totalincltax'] = array(
2811 'rank' => $rank,
2812 'width' => 26, // in mm
2813 'status' => getDolGlobalBool('PDF_INVOICE_SHOW_PRICE_INCL_TAX') && !getDolGlobalBool('PDF_PURCHASE_INVOICE_SHOW_PRICE_INCL_TAX'),
2814 'title' => array(
2815 'textkey' => 'TotalTTCShort'
2816 ),
2817 'border-left' => true, // add left line separator
2818 );
2819
2820 // Add extrafields cols
2821 if (!empty($object->lines)) {
2822 $line = reset($object->lines);
2823 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2824 }
2825
2826 $parameters = array(
2827 'object' => $object,
2828 'outputlangs' => $outputlangs,
2829 'hidedetails' => $hidedetails,
2830 'hidedesc' => $hidedesc,
2831 'hideref' => $hideref
2832 );
2833
2834 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2835 if ($reshook < 0) {
2836 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2837 } elseif (empty($reshook)) {
2838 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2839 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2840 } else {
2841 $this->cols = $hookmanager->resArray;
2842 }
2843 }
2844}
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:3160
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2861
pdfCertifMention($pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal certificate mention.
Definition pdf.lib.php:1219
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:3192
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1808
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:1239
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:810
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition pdf.lib.php:2911
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2464
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2795
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2402
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:747
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:1421
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:3288
pdfWriteAdditionnalTitle($pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
Definition pdf.lib.php:785
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:1050
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:2709
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2752
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2549
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:1135
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