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