dolibarr 23.0.3
pdf_crabe.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2014 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-2018 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2022-2024 Anthony Berton <anthony.berton@bb2a.fr>
13 * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
14 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024-2025 Nick Fragoulis
16 * Copyright (C) 2024-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
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
45
50{
54 public $db;
55
59 public $name;
60
64 public $description;
65
69 public $update_main_doc_field;
70
74 public $type;
75
80 public $version = 'dolibarr';
81
85 public $situationinvoice;
86
90 public $posxprogress;
91
95 public $categoryOfOperation = -1; // unknown by default
96
97
103 public function __construct($db)
104 {
105 global $langs, $mysoc;
106
107 // Translations
108 $langs->loadLangs(array("main", "bills"));
109
110 $this->db = $db;
111 $this->name = "crabe";
112 $this->description = $langs->trans('PDFCrabeDescription');
113 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
114
115 // Dimension page
116 $this->type = 'pdf';
117 $formatarray = pdf_getFormat();
118 $this->page_largeur = $formatarray['width'];
119 $this->page_hauteur = $formatarray['height'];
120 $this->format = array($this->page_largeur, $this->page_hauteur);
121 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
122 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
123 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
124 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
125 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
126 $this->option_logo = 1; // Display logo
127 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
128 $this->option_modereg = 1; // Display payment mode
129 $this->option_condreg = 1; // Display payment terms
130 $this->option_multilang = 1; // Available in several languages
131 $this->option_escompte = 1; // Displays if there has been a discount
132 $this->option_credit_note = 1; // Support credit notes
133 $this->option_freetext = 1; // Support add of a personalised text
134 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
135 $this->watermark = '';
136
137 // Define position of columns
138 $this->posxdesc = $this->marge_gauche + 1;
139 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
140 $this->posxtva = 101;
141 $this->posxup = 118;
142 $this->posxqty = 135;
143 $this->posxunit = 151;
144 } else {
145 $this->posxtva = 106;
146 $this->posxup = 122;
147 $this->posxqty = 145;
148 $this->posxunit = 162;
149 }
150 $this->posxprogress = 151; // Only displayed for situation invoices
151 $this->posxdiscount = 162;
152 $this->posxprogress = 174;
153 $this->postotalht = 174;
154 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') || getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
155 $this->posxtva = $this->posxup;
156 }
157 $this->posxpicture = $this->posxtva - getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20); // width of images
158 if ($this->page_largeur < 210) { // To work with US executive format
159 $this->posxpicture -= 20;
160 $this->posxtva -= 20;
161 $this->posxup -= 20;
162 $this->posxqty -= 20;
163 $this->posxunit -= 20;
164 $this->posxdiscount -= 20;
165 $this->posxprogress -= 20;
166 $this->postotalht -= 20;
167 }
168
169 $this->tva = array();
170 $this->tva_array = array();
171 $this->localtax1 = array();
172 $this->localtax2 = array();
173 $this->atleastoneratenotnull = 0;
174 $this->atleastonediscount = 0;
175 $this->situationinvoice = false;
176
177 if ($mysoc === null) {
178 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
179 return;
180 }
181
182 // Get source company
183 $this->emetteur = $mysoc;
184 if (empty($this->emetteur->country_code)) {
185 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
186 }
187 }
188
189
190 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
202 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
203 {
204 // phpcs:enable
205 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
206
207 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
208
209 if (!is_object($outputlangs)) {
210 $outputlangs = $langs;
211 }
212 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
213 if (getDolGlobalString('MAIN_USE_FPDF')) {
214 $outputlangs->charset_output = 'ISO-8859-1';
215 }
216
217 // Load translation files required by the page
218 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
219
220 // Show Draft Watermark
221 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
222 $this->watermark = getDolGlobalString('FACTURE_DRAFT_WATERMARK');
223 }
224
225 global $outputlangsbis;
226 $outputlangsbis = null;
227 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
228 $outputlangsbis = new Translate('', $conf);
229 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
230 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
231 }
232
233 $nblines = count($object->lines);
234
235 // Loop on each lines to detect if there is at least one image to show
236 $realpatharray = array();
237 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
238 for ($i = 0; $i < $nblines; $i++) {
239 if (empty($object->lines[$i]->fk_product)) {
240 continue;
241 }
242
243 $objphoto = new Product($this->db);
244 $objphoto->fetch($object->lines[$i]->fk_product);
245
246 $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
247 $dir = $conf->product->dir_output.'/'.$pdir;
248
249 $realpath = '';
250 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
251 $filename = $obj['photo'];
252 //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
253 $realpath = $dir.$filename;
254 break;
255 }
256
257 if ($realpath) {
258 $realpatharray[$i] = $realpath;
259 }
260 }
261 }
262 if (count($realpatharray) == 0) {
263 $this->posxpicture = $this->posxtva;
264 }
265
266 if ($conf->facture->dir_output) {
267 $object->fetch_thirdparty();
268
269 $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
270 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
271 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
272
273 // Definition of $dir and $file
274 if ($object->specimen) {
275 $dir = empty($conf->facture->multidir_output[$object->entity ?? $conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity ?? $conf->entity];
276 $file = $dir."/SPECIMEN.pdf";
277 } else {
278 $objectref = dol_sanitizeFileName($object->ref);
279 $dir = (empty($conf->facture->multidir_output[$object->entity ?? $conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity ?? $conf->entity])."/".$objectref;
280 $file = $dir."/".$objectref.".pdf";
281 }
282 if (!file_exists($dir)) {
283 if (dol_mkdir($dir) < 0) {
284 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
285 return 0;
286 }
287 }
288
289 if (file_exists($dir)) {
290 // Add pdfgeneration hook
291 if (!is_object($hookmanager)) {
292 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
293 $hookmanager = new HookManager($this->db);
294 }
295 $hookmanager->initHooks(array('pdfgeneration'));
296 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
297 global $action;
298 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
299
300 // Set nblines with the new facture lines content after hook
301 $nblines = count($object->lines);
302 $nbpayments = count($object->getListOfPayments());
303
304 // Create pdf instance
305 $pdf = pdf_getInstance($this->format);
306 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
307 $pdf->setAutoPageBreak(true, 0);
308
309 $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
310 if ($heightforinfotot > 220) {
311 $heightforinfotot = 220;
312 }
313 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
314 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
315 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
316 $heightforfooter += 6;
317 }
318
319 $heightforqrinvoice_firstpage = 0;
320 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
321 $heightforqrinvoice_firstpage = $this->getHeightForQRInvoice(1, $object, $langs);
322 if ($heightforqrinvoice_firstpage > 0) {
323 // Shrink infotot to a base 30
324 $heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
325 }
326 }
327
328 if (class_exists('TCPDF')) {
329 $pdf->setPrintHeader(false);
330 $pdf->setPrintFooter(false);
331 }
332 $pdf->SetFont(pdf_getPDFFont($outputlangs));
333
334 // Set path to the background PDF File
335 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
336 $logodir = $conf->mycompany->dir_output;
337 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
338 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
339 }
340 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
341 $tplidx = $pdf->importPage(1);
342 }
343
344 $pdf->Open();
345 $pagenb = 0;
346 $pdf->SetDrawColor(128, 128, 128);
347
348 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
349 $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
350 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
351 $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
352 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
353 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
354 $pdf->SetCompression(false);
355 }
356
357 // Set certificate
358 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
359 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
360 // If user has no certificate, we try to take the company one
361 if (!$cert) {
362 $cert = getDolGlobalString('CERTIFICATE_CRT');
363 }
364 if (!$certprivate) {
365 $certprivate = getDolGlobalString('CERTIFICATE_CRT_PRIVATE');
366 }
367 // If a certificate is found
368 if ($cert) {
369 $info = array(
370 'Name' => $this->emetteur->name,
371 'Location' => getCountry($this->emetteur->country_code, ''),
372 'Reason' => 'INVOICE',
373 'ContactInfo' => $this->emetteur->email
374 );
375 $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
376 }
377
378 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
379 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
380
381 // Set $this->atleastonediscount if you have at least one discount
382 // and determine category of operation
383 $categoryOfOperation = 0;
384 $nbProduct = 0;
385 $nbService = 0;
386 for ($i = 0; $i < $nblines; $i++) {
387 if ($object->lines[$i]->remise_percent) {
388 $this->atleastonediscount++;
389 }
390
391 // Do not take into account lines of the type “deposit.”
392 $is_deposit = false;
393 $reg = array();
394 if (preg_match('/^\‍((.*)\‍)$/', $object->lines[$i]->desc, $reg)) {
395 if ($reg[1] == 'DEPOSIT') {
396 $is_deposit = true;
397 }
398 }
399
400 // If DEPOSIT, this line is completely ignored for calculations.
401 if ($is_deposit) {
402 continue;
403 }
404
405 // determine category of operation
406 $is_deposit = false;
407 if (preg_match('/^\‍((.*)\‍)$/', $object->lines[$i]->desc, $reg)) {
408 if ($reg[1] == 'DEPOSIT') {
409 $is_deposit = true;
410 }
411 }
412 // If DEPOSIT, this line is completely ignored for calculations.
413 if ($is_deposit) {
414 continue;
415 }
416
417
418 // determine category of operation
419 if ($categoryOfOperation < 2) {
420 $lineProductType = $object->lines[$i]->product_type;
421 if ($lineProductType == Product::TYPE_PRODUCT) {
422 $nbProduct++;
423 } elseif ($lineProductType == Product::TYPE_SERVICE) {
424 $nbService++;
425 }
426 if ($nbProduct > 0 && $nbService > 0) {
427 // mixed products and services
428 $categoryOfOperation = 2;
429 }
430 }
431 }
432 // determine category of operation
433 if ($categoryOfOperation <= 0) {
434 // only services
435 if ($nbProduct == 0 && $nbService > 0) {
436 $categoryOfOperation = 1;
437 }
438 }
439 $this->categoryOfOperation = $categoryOfOperation;
440 if (empty($this->atleastonediscount)) { // retrieve space not used by discount
441 $delta = ($this->posxprogress - $this->posxdiscount);
442 $this->posxpicture += $delta;
443 $this->posxtva += $delta;
444 $this->posxup += $delta;
445 $this->posxqty += $delta;
446 $this->posxunit += $delta;
447 $this->posxdiscount += $delta;
448 // post of fields after are not modified, stay at same position
449 }
450
451 $progress_width = 0;
452 // Situation invoice handling
453 if ($object->situation_cycle_ref && !getDolGlobalString('MAIN_PDF_HIDE_SITUATION')) {
454 $this->situationinvoice = true;
455 $progress_width = 10;
456 $this->posxpicture -= $progress_width;
457 $this->posxtva -= $progress_width;
458 $this->posxup -= $progress_width;
459 $this->posxqty -= $progress_width;
460 $this->posxunit -= $progress_width;
461 $this->posxdiscount -= $progress_width;
462 $this->posxprogress -= $progress_width;
463 }
464
465 // New page
466 $pdf->AddPage();
467 if (!empty($tplidx)) {
468 $pdf->useTemplate($tplidx);
469 }
470 $pagenb++;
471
472 // Output header (logo, ref and address blocks). This is first call for first page.
473 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
474 $pdf->SetFont('', '', $default_font_size - 1);
475 $pdf->MultiCell(0, 3, ''); // Set interline to 3
476 $pdf->SetTextColor(0, 0, 0);
477
478 // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher
479
480 // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
481 $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
482 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
483
484 // You can add more thing under header here, if you increase $extra_under_address_shift too.
485 $extra_under_address_shift = 0;
486 $qrcodestring = '';
487 if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) {
488 $qrcodestring = $object->buildZATCAQRString();
489 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
490 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
491 $qrcodestring = $object->buildSwitzerlandQRString();
492 }
493 } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
494 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
495 $qrcodestring = $object->buildEPCQrCodeString();
496 }
497 }
498
499 if ($qrcodestring) {
500 $qrcodecolor = array('25', '25', '25');
501 // set style for QR-code
502 $styleQr = array(
503 'border' => false,
504 'padding' => 0,
505 'fgcolor' => $qrcodecolor,
506 'bgcolor' => false, //array(255,255,255)
507 'module_width' => 1, // width of a single module in points
508 'module_height' => 1 // height of a single module in points
509 );
510 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
511
512 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
513 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
514 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
515 $pdf->SetFont('', '', $default_font_size - 4);
516 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', false);
517 }
518 }
519
520 $extra_under_address_shift += 25;
521 }
522
523 // Call hook printUnderHeaderPDFline
524 $parameters = array(
525 'object' => $object,
526 // 'i' => $i, // we aren't in lines
527 'pdf' => &$pdf,
528 'outputlangs' => $outputlangs,
529 'hidedetails' => $hidedetails
530 );
531 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
532 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
533 $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift'];
534 }
535
536 $tab_top += $extra_under_address_shift;
537 $tab_top_newpage += 0;
538
539 // Incoterm
540 $height_incoterms = 0;
541 if (isModEnabled('incoterm')) {
542 $desc_incoterms = $object->getIncotermsForPDF();
543 if ($desc_incoterms) {
544 $tab_top -= 2;
545
546 $pdf->SetFont('', '', $default_font_size - 1);
547 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
548 $nexY = $pdf->GetY();
549 $height_incoterms = $nexY - $tab_top;
550
551 // Rect takes a length in 3rd parameter
552 $pdf->SetDrawColor(192, 192, 192);
553 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
554
555 $tab_top = $nexY + 6;
556 }
557 }
558
559 // Display notes
560 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
561 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
562 // Get first sale rep
563 if (is_object($object->thirdparty)) {
564 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
565 $salerepobj = new User($this->db);
566 $salerepobj->fetch($salereparray[0]['id']);
567 if (!empty($salerepobj->signature)) {
568 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
569 }
570 }
571 }
572 // Extrafields in note
573 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
574 if (!empty($extranote)) {
575 $notetoshow = dol_concatdesc((string) $notetoshow, $extranote);
576 }
577 if ($notetoshow) {
578 $tab_top -= 2;
579
580 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
581 complete_substitutions_array($substitutionarray, $outputlangs, $object);
582
583 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
584 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
585
586 $pdf->SetFont('', '', $default_font_size - 1);
587 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
588 $nexY = $pdf->GetY();
589 $height_note = $nexY - $tab_top;
590
591 // Rect takes a length in 3rd parameter
592 $pdf->SetDrawColor(192, 192, 192);
593 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1, $this->corner_radius, '1234', 'D');
594
595 $tab_top = $nexY + 6;
596 }
597
598 $iniY = $tab_top + 7;
599 $curY = $tab_top + 7;
600 $nexY = $tab_top + 7;
601
602 // Loop on each lines
603 for ($i = 0; $i < $nblines; $i++) {
604 $curY = $nexY;
605 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
606 $pdf->SetTextColor(0, 0, 0);
607
608 // Define size of image if we need it
609 $imglinesize = array();
610 if (!empty($realpatharray[$i])) {
611 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
612 }
613
614 $pdf->setTopMargin($tab_top_newpage);
615 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
616 $pdf->setPageOrientation('', true, $page_bottom_margin);
617 $pageposbefore = $pdf->getPage();
618
619 $showpricebeforepagebreak = 1;
620 $posYAfterImage = 0;
621 $posYAfterDescription = 0;
622
623 // We start with Photo of product line
624 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - $page_bottom_margin)) { // If photo too high, we moved completely on new page
625 $pdf->AddPage('', '', true);
626 if (!empty($tplidx)) {
627 $pdf->useTemplate($tplidx);
628 }
629 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
630 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
631 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
632 }
633 $pdf->setPage($pageposbefore + 1);
634
635 $curY = $tab_top_newpage;
636
637 // Allows data in the first page if description is long enough to break in multiples pages
638 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
639 $showpricebeforepagebreak = 1;
640 } else {
641 $showpricebeforepagebreak = 0;
642 }
643 }
644
645 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
646 $curX = $this->posxpicture - 1;
647 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
648 // $pdf->Image does not increase value return by getY, so we save it manually
649 $posYAfterImage = $curY + $imglinesize['height'];
650 }
651
652 // Description of product line
653 $curX = $this->posxdesc - 1;
654
655 $pdf->startTransaction();
656 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
657 $pageposafter = $pdf->getPage();
658 if ($pageposafter > $pageposbefore) { // There is a pagebreak
659 $pdf->rollbackTransaction(true);
660 $pageposafter = $pageposbefore;
661 //print $pageposafter.'-'.$pageposbefore;exit;
662 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
663 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
664 $pageposafter = $pdf->getPage();
665 $posyafter = $pdf->GetY();
666 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
667 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text
668 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
669 $pdf->AddPage('', '', true);
670 if (!empty($tplidx)) {
671 $pdf->useTemplate($tplidx);
672 }
673 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
674 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
675 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
676 }
677 $pdf->setPage($pageposafter + 1);
678 }
679 } else {
680 // We found a page break
681
682 // Allows data in the first page if description is long enough to break in multiples pages
683 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
684 $showpricebeforepagebreak = 1;
685 } else {
686 $showpricebeforepagebreak = 0;
687 }
688 }
689 } else { // No pagebreak
690 $pdf->commitTransaction();
691 }
692 $posYAfterDescription = $pdf->GetY();
693
694 $nexY = $pdf->GetY();
695 $pageposafter = $pdf->getPage();
696 $pdf->setPage($pageposbefore);
697 $pdf->setTopMargin($this->marge_haute);
698 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
699
700 // We suppose that a too long description or photo were moved completely on next page
701 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
702 $pdf->setPage($pageposafter);
703 $curY = $tab_top_newpage;
704 }
705
706 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
707
708 // VAT Rate
709 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
710 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
711 $pdf->SetXY($this->posxtva - 5, $curY);
712 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
713 }
714
715 // Unit price before discount
716 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
717 $pdf->SetXY($this->posxup, $curY);
718 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', false);
719
720 // Quantity
721 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
722 $pdf->SetXY($this->posxqty, $curY);
723 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
724
725 // Unit
726 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
727 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
728 $pdf->SetXY($this->posxunit, $curY);
729 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
730 }
731
732 // Discount on line
733 if ($object->lines[$i]->remise_percent) {
734 $pdf->SetXY($this->posxdiscount - 2, $curY);
735 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
736 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
737 }
738
739 // Situation progress
740 if ($this->situationinvoice) {
741 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
742 $pdf->SetXY($this->posxprogress, $curY);
743 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R');
744 }
745
746 // Total HT line
747 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
748 $pdf->SetXY($this->postotalht, $curY);
749 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', false);
750
751
752 $sign = 1;
753 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
754 $sign = -1;
755 }
756 // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
757 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
758 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
759 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
760 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
761 } else {
762 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
763 }
764 } else {
765 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
766 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
767 } else {
768 $tvaligne = $sign * $object->lines[$i]->total_tva;
769 }
770 }
771
772 $localtax1ligne = $object->lines[$i]->total_localtax1;
773 $localtax2ligne = $object->lines[$i]->total_localtax2;
774 $localtax1_rate = $object->lines[$i]->localtax1_tx;
775 $localtax2_rate = $object->lines[$i]->localtax2_tx;
776 $localtax1_type = $object->lines[$i]->localtax1_type;
777 $localtax2_type = $object->lines[$i]->localtax2_type;
778
779 $vatrate = (string) $object->lines[$i]->tva_tx;
780
781 // Retrieve type from database for backward compatibility with old records
782 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
783 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
784 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
785 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
786 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
787 }
788
789 // retrieve global local tax
790 if ($localtax1_type && $localtax1ligne != 0) {
791 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
792 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
793 } else {
794 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
795 }
796 }
797 if ($localtax2_type && $localtax2ligne != 0) {
798 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
799 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
800 } else {
801 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
802 }
803 }
804
805 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
806 $vatrate .= '*';
807 }
808
809 // Fill $this->tva and $this->tva_array
810 if (!isset($this->tva[$vatrate])) {
811 $this->tva[$vatrate] = 0;
812 }
813 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
814 $vatcode = $object->lines[$i]->vat_src_code;
815 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
816 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
817 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
818 }
819 $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);
820 } else {
821 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
822 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
823 }
824 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
825 }
826
827 if ($posYAfterImage > $posYAfterDescription) {
828 $nexY = $posYAfterImage;
829 }
830
831 // Add line
832 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
833 $pdf->setPage($pageposafter);
834 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
835 //$pdf->SetDrawColor(190,190,200);
836 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
837 $pdf->SetLineStyle(array('dash' => 0));
838 }
839
840 $nexY += 2; // Add space between lines
841
842 // Detect if some page were added automatically and output _tableau for past pages
843 while ($pagenb < $pageposafter) {
844 $pdf->setPage($pagenb);
845 if ($pagenb == 1) {
846 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
847 } else {
848 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
849 }
850 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $outputlangs));
851 $pagenb++;
852 $pdf->setPage($pagenb);
853 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
854 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
855 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
856 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
857 }
858 if (!empty($tplidx)) {
859 $pdf->useTemplate($tplidx);
860 }
861 }
862 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
863 if ($pagenb == 1) {
864 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
865 } else {
866 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
867 }
868 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $outputlangs));
869 // New page
870 $pdf->AddPage();
871 if (!empty($tplidx)) {
872 $pdf->useTemplate($tplidx);
873 }
874 $pagenb++;
875 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
876 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
877 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
878 }
879 }
880 }
881
882 // Show square
883 if ($pagenb == 1) {
884 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
885 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
886 } else {
887 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
888 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
889 }
890 dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
891
892 // Display info area
893 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
894
895 // Display total area
896 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
897
898 // Display Payments area
899 $listofpayments = $object->getListOfPayments('', 0, 1);
900 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
901 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
902 }
903
904 // Pagefoot
905 $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs));
906 if (method_exists($pdf, 'AliasNbPages')) {
907 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
908 }
909
910 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
911 $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs);
912 if (!$result) {
913 $pdf->Close();
914 return 0;
915 }
916 }
917
918 // Add terms to sale
919 $termsofsalefilename = getDolGlobalString('MAIN_INFO_INVOICE_TERMSOFSALE');
920 if (getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
921 $termsofsale = $conf->invoice->dir_output.'/'.$termsofsalefilename;
922 if (!empty($conf->invoice->multidir_output[$object->entity ?? $conf->entity])) {
923 $termsofsale = $conf->invoice->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
924 }
925 if (file_exists($termsofsale) && is_readable($termsofsale)) {
926 $pagecount = $pdf->setSourceFile($termsofsale);
927 for ($i = 1; $i <= $pagecount; $i++) {
928 $tplIdx = $pdf->importPage($i);
929 if ($tplIdx !== false) {
930 $s = $pdf->getTemplatesize($tplIdx);
931 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
932 $pdf->useTemplate($tplIdx);
933 } else {
934 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
935 }
936 }
937 }
938 }
939
940 $pdf->Close();
941
942 $pdf->Output($file, 'F');
943
944 // Add pdfgeneration hook
945 $hookmanager->initHooks(array('pdfgeneration'));
946 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
947 global $action;
948 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
949 $this->warnings = $hookmanager->warnings;
950 if ($reshook < 0) {
951 $this->error = $hookmanager->error;
952 $this->errors = $hookmanager->errors;
953 dolChmod($file);
954 return -1;
955 }
956
957 dolChmod($file);
958
959 $this->result = array('fullpath' => $file);
960
961 return 1; // No error
962 } else {
963 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
964 return 0;
965 }
966 } else {
967 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
968 return 0;
969 }
970 }
971
972
973 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
974 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
985 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
986 {
987 // phpcs:enable
988
989 $sign = 1;
990 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
991 $sign = -1;
992 }
993
994 $current_page = $pdf->getPage();
995 $tab3_posx = 120;
996 $tab3_top = $posy + 8;
997 $tab3_width = 80;
998 $tab3_height = 4;
999 if ($this->page_largeur < 210) { // To work with US executive format
1000 $tab3_posx -= 15;
1001 }
1002
1003 $default_font_size = pdf_getPDFFontSize($outputlangs);
1004
1005 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
1006
1007 $y = 0;
1008
1009 $pdf->SetFont('', '', $default_font_size - 4);
1010
1011
1012 // Loop on each discount available (deposits and credit notes and excess of payment included)
1013 $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,";
1014 $sql .= " re.description, re.fk_facture_source,";
1015 $sql .= " f.type, f.datef";
1016 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1017 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1018 $resql = $this->db->query($sql);
1019 if ($resql) {
1020 $num = $this->db->num_rows($resql);
1021 $i = 0;
1022 $invoice = new Facture($this->db);
1023 while ($i < $num) {
1024 $y += 3;
1025 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1026 $y = 0;
1027 $current_page++;
1028 $pdf->AddPage('', '', true);
1029 /*if (!empty($tplidx)) {
1030 $pdf->useTemplate($tplidx);
1031 }*/
1032 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1033 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1034 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1035 }
1036 $pdf->setPage($current_page);
1037 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1038 }
1039
1040 $obj = $this->db->fetch_object($resql);
1041
1042 if ($obj->type == 2) {
1043 $text = $outputlangs->transnoentities("CreditNote");
1044 } elseif ($obj->type == 3) {
1045 $text = $outputlangs->transnoentities("Deposit");
1046 } elseif ($obj->type == 0) {
1047 $text = $outputlangs->transnoentities("ExcessReceived");
1048 } else {
1049 $text = $outputlangs->transnoentities("UnknownType");
1050 }
1051
1052 $invoice->fetch($obj->fk_facture_source);
1053
1054 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1055 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', false);
1056 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1057 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', false);
1058 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1059 $pdf->MultiCell(20, 3, $text, 0, 'L', false);
1060 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1061 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', false);
1062
1063 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1064
1065 $i++;
1066 }
1067 } else {
1068 $this->error = $this->db->lasterror();
1069 return -1;
1070 }
1071
1072 // Loop on each payment
1073 // TODO Call getListOfPayments instead of hard coded sql
1074 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1075 $sql .= " cp.code";
1076 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1077 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1078 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1079 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1080 $sql .= " ORDER BY p.datep";
1081
1082 $resql = $this->db->query($sql);
1083 if ($resql) {
1084 $num = $this->db->num_rows($resql);
1085 $i = 0;
1086 $y += 3;
1087 $maxY = $y;
1088 while ($i < $num) {
1089 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1090 $y = 0;
1091 $current_page++;
1092 $pdf->AddPage('', '', true);
1093 /*if (!empty($tplidx)) {
1094 $pdf->useTemplate($tplidx);
1095 }*/
1096 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1097 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1098 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1099 }
1100 $pdf->setPage($current_page);
1101 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1102 }
1103
1104 $row = $this->db->fetch_object($resql);
1105
1106 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1107 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1108 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1109 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', false);
1110 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1111 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1112
1113 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1114 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1115 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1116 $pdf->MultiCell(30, 3, $row->num, 0, 'L', false);
1117 $y = $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1118 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1119 $y += 3;
1120 $i++;
1121 }
1122
1123 return $tab3_top + $y + 3;
1124 } else {
1125 $this->error = $this->db->lasterror();
1126 return -1;
1127 }
1128 }
1129
1130 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1131 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1145 protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
1146 {
1147 // phpcs:enable
1148 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1149 if ($object->type == 2) {
1150 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1151 }
1152
1153 $pdf->SetFont('', '', $default_font_size - 3);
1154 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1155 $pdf->MultiCell(60, 3, $title, 0, 'L', false);
1156
1157 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1158
1159 $pdf->SetFont('', '', $default_font_size - 4);
1160 $pdf->SetXY($tab3_posx, $tab3_top);
1161 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
1162 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1163 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
1164 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1165 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
1166 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1167 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
1168
1169 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1170 }
1171
1172 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1173 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1184 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1185 {
1186 // phpcs:enable
1187 global $mysoc;
1188
1189 $default_font_size = pdf_getPDFFontSize($outputlangs);
1190
1191 $pdf->SetFont('', '', $default_font_size - 1);
1192
1193 krsort($this->tva_array);
1194
1195 // Clean data type
1196 $object->total_tva = (float) $object->total_tva;
1197
1198 // Show VAT details
1199 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1200 $pdf->SetFillColor(224, 224, 224);
1201
1202 $pdf->SetFont('', '', $default_font_size - 2);
1203 $pdf->SetXY($this->marge_gauche, $posy);
1204 $titre = $outputlangs->transnoentities("VAT");
1205 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1206
1207 $pdf->SetFont('', '', $default_font_size - 2);
1208 $pdf->SetXY($this->marge_gauche + 25, $posy);
1209 $titre = $outputlangs->transnoentities("NetTotal");
1210 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1211
1212 $pdf->SetFont('', '', $default_font_size - 2);
1213 $pdf->SetXY($this->marge_gauche + 50, $posy);
1214 $titre = $outputlangs->transnoentities("VATAmount");
1215 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1216
1217 $pdf->SetFont('', '', $default_font_size - 2);
1218 $pdf->SetXY($this->marge_gauche + 75, $posy);
1219 $titre = $outputlangs->transnoentities("AmountTotal");
1220 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1221
1222 $posy = $pdf->GetY();
1223 $tot_ht = 0;
1224 $tot_tva = 0;
1225 $tot_ttc = 0;
1226
1227 foreach ($this->tva_array as $tvakey => $tvaval) {
1228 $pdf->SetFont('', '', $default_font_size - 2);
1229 $pdf->SetXY($this->marge_gauche, $posy);
1230 $titre = round((float) $tvakey, 2) . "%";
1231 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1232
1233 $pdf->SetFont('', '', $default_font_size - 2);
1234 $pdf->SetXY($this->marge_gauche + 25, $posy);
1235 $titre = price($tvaval['tot_ht']);
1236 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1237 $tot_ht += $tvaval['tot_ht'];
1238
1239 $pdf->SetFont('', '', $default_font_size - 2);
1240 $pdf->SetXY($this->marge_gauche + 50, $posy);
1241 $titre = price($tvaval['amount']);
1242 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1243 $tot_tva += $tvaval['amount'];
1244
1245 $pdf->SetFont('', '', $default_font_size - 2);
1246 $pdf->SetXY($this->marge_gauche + 75, $posy);
1247 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1248 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1249 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1250
1251 $posy = $pdf->GetY();
1252 }
1253 }
1254
1255 // If France, show VAT mention if applicable
1256 $showvatmention = 0;
1257 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1258 $pdf->SetFont('', '', $default_font_size - 2);
1259 $pdf->SetXY($this->marge_gauche, $posy);
1260 if (empty($mysoc->tva_assuj)) {
1261 if ($mysoc->forme_juridique_code == 92) {
1262 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', false);
1263 } else {
1264 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1265 }
1266 $showvatmention++;
1267 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1268 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', false);
1269 $showvatmention++;
1270 }
1271 $posy = $pdf->GetY();
1272 }
1273
1274 $showvatmention += pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1275
1276 if ($showvatmention) {
1277 $posy += 3;
1278 }
1279
1280 $posxval = 52;
1281 $posxend = 110; // End of x for text on left side
1282 if ($this->page_largeur < 210) { // To work with US executive format
1283 $posxend -= 10;
1284 }
1285
1286 // Show previous and new balance
1287 if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) {
1288 // All customer previous invoices
1289 $sql = "SELECT f.rowid, f.datef, f.total_ttc";
1290 $sql.= " FROM " . MAIN_DB_PREFIX . "facture as f";
1291 $sql.= " WHERE f.fk_soc = " . ((int) $object->socid);
1292 $sql.= " AND f.entity IN (" . getEntity('invoice') . ")";
1293 $sql.= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
1294 $sql.= " AND f.rowid < " . ((int) $object->id);
1295 $sql.= " AND f.fk_statut > 0";
1296 $sql.= " ORDER BY f.datef ASC";
1297
1298 $old_balance = 0;
1299 $invoices = array();
1300 $resql = $this->db->query($sql);
1301 if ($resql) {
1302 while ($obj = $this->db->fetch_object($resql)) {
1303 $invoices[] = $obj;
1304 $old_balance += $obj->total_ttc;
1305 }
1306 $this->db->free($resql);
1307 }
1308
1309 // All payments before current date
1310 $sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1311 $sql_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1312 $sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1313 $sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1314 $sql_payments.= " WHERE f.fk_soc = " . ((int) $object->socid);
1315 $sql_payments.= " AND p.datep < '" . $this->db->idate($object->date) . "'";
1316 $sql_payments.= " ORDER BY p.datep ASC";
1317
1318 $total_payments = 0;
1319 $resql_payments = $this->db->query($sql_payments);
1320 if ($resql_payments) {
1321 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1322 $total_payments += $obj_payment->amount;
1323 }
1324 $this->db->free($resql_payments);
1325 }
1326
1327 // Payments made on current invoice date (including current invoice)
1328 $sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
1329 $sql_current_date_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
1330 $sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
1331 $sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
1332 $sql_current_date_payments.= " WHERE f.fk_soc = " . ((int) $object->socid);
1333 $sql_current_date_payments.= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
1334
1335 $current_date_payments = 0;
1336 $resql_current_date = $this->db->query($sql_current_date_payments);
1337 if ($resql_current_date) {
1338 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1339 $current_date_payments += $obj_current->amount;
1340 }
1341 $this->db->free($resql_current_date);
1342 }
1343
1344 // Previous balance
1345 $old_balance -= $total_payments;
1346
1347 // New balance
1348 $new_balance = $old_balance + $object->total_ttc - $current_date_payments;
1349
1350 $pdf->SetFillColor(224, 224, 224);
1351 $pdf->SetFont('', '', $default_font_size - 2);
1352 $pdf->SetXY($this->marge_gauche, $posy);
1353 $titre = $outputlangs->transnoentities("PreviousBalance").' : '.price($old_balance);
1354 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true);
1355
1356 $pdf->SetFont('', '', $default_font_size - 2);
1357 $pdf->SetXY($posxval+8, $posy);
1358 $titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance);
1359 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true);
1360
1361 $posy = $pdf->GetY() + 1;
1362 }
1363
1364 // Show payments conditions
1365 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1366 $pdf->SetFont('', 'B', $default_font_size - 2);
1367 $pdf->SetXY($this->marge_gauche, $posy);
1368 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1369 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1370
1371 $pdf->SetFont('', '', $default_font_size - 2);
1372 $pdf->SetXY($posxval, $posy);
1373 $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);
1374 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1375 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1376
1377 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1378 }
1379
1380 // Show category of operations
1381 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1382 $pdf->SetFont('', 'B', $default_font_size - 2);
1383 $pdf->SetXY($this->marge_gauche, $posy);
1384 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1385 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1386
1387 $pdf->SetFont('', '', $default_font_size - 2);
1388 $pdf->SetXY($posxval, $posy);
1389 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1390 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1391
1392 $posy = $pdf->GetY() + 3; // for 2 lines
1393 }
1394
1395 if ($object->type != 2) {
1396 // Check a payment mode is defined
1397 if (empty($object->mode_reglement_code)
1398 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1399 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1400 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1401 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1402 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1403 // Avoid having any valid PDF with setup that is not complete
1404 $outputlangs->load("errors");
1405
1406 $pdf->SetXY($this->marge_gauche, $posy);
1407 $pdf->SetTextColor(200, 0, 0);
1408 $pdf->SetFont('', 'B', $default_font_size - 2);
1409 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1410 $pdf->MultiCell(80, 3, $this->error, 0, 'L', false);
1411 $pdf->SetTextColor(0, 0, 0);
1412
1413 $posy = $pdf->GetY() + 1;
1414 }
1415
1416 // Show payment mode
1417 if (!empty($object->mode_reglement_code)
1418 && $object->mode_reglement_code != 'CHQ'
1419 && $object->mode_reglement_code != 'VIR') {
1420 $pdf->SetFont('', 'B', $default_font_size - 2);
1421 $pdf->SetXY($this->marge_gauche, $posy);
1422 $titre = $outputlangs->transnoentities("PaymentMode").':';
1423 $pdf->MultiCell(80, 5, $titre, 0, 'L');
1424
1425 $pdf->SetFont('', '', $default_font_size - 2);
1426 $pdf->SetXY($posxval, $posy);
1427 $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);
1428 //#21654: add account number used for the debit
1429 if ($object->mode_reglement_code == "PRE") {
1430 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1431 $bac = new CompanyBankAccount($this->db);
1432 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1433 $bac->fetch(0, '', $object->thirdparty->id);
1434 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1435 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1436 }
1437 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1438
1439 $posy = $pdf->GetY();
1440 }
1441
1442 // Show if Option VAT debit option is on also if transmitter is french
1443 // Decret n°2099-1299 2022-10-07
1444 // French mention : "Option pour le paiement de la taxe d'après les débits"
1445 if ($this->emetteur->country_code == 'FR') {
1446 if (getDolGlobalInt('TAX_MODE') == 1) {
1447 $pdf->SetXY($this->marge_gauche, $posy);
1448 $pdf->writeHTMLCell(80, 5, null, null, $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1449
1450 $posy = $pdf->GetY() + 1;
1451 }
1452 }
1453
1454 // Show online payment link
1455 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1456 $useonlinepayment = 0;
1457 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1458 // Show online payment link
1459 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1460 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1461 $validpaymentmethod = getValidOnlinePaymentMethods('');
1462 $useonlinepayment = count($validpaymentmethod);
1463 }
1464
1465 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1466 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1467 global $langs;
1468
1469 $langs->loadLangs(array('payment', 'stripe'));
1470 $servicename = $langs->transnoentities('Online');
1471
1472 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1473 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1474
1475 $pdf->SetXY($this->marge_gauche, $posy);
1476 $pdf->writeHTMLCell(80, 5, null, null, dol_htmlentitiesbr($linktopay), 0, 1);
1477
1478 $posy = $pdf->GetY() + 1;
1479 }
1480 }
1481
1482 // Show payment mode CHQ
1483 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1484 // If payment mode unregulated or payment mode forced to CHQ
1485 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1486 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1487
1488 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1489 $account = new Account($this->db);
1490 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1491
1492 $pdf->SetXY($this->marge_gauche, $posy);
1493 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1494 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1495 $posy = $pdf->GetY() + 1;
1496
1497 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1498 $pdf->SetXY($this->marge_gauche, $posy);
1499 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1500 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1501 $posy = $pdf->GetY() + 2;
1502 }
1503 }
1504 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1505 $pdf->SetXY($this->marge_gauche, $posy);
1506 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1507 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1508 $posy = $pdf->GetY() + 1;
1509
1510 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1511 $pdf->SetXY($this->marge_gauche, $posy);
1512 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1513 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1514 $posy = $pdf->GetY() + 2;
1515 }
1516 }
1517 }
1518 }
1519
1520 // If payment mode not forced or forced to VIR, show payment with BAN
1521 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1522 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1523 $bankid = ($object->fk_account <= 0 ? getDolGlobalString('FACTURE_RIB_NUMBER') : $object->fk_account);
1524 if ($object->fk_bank > 0) {
1525 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1526 }
1527 $account = new Account($this->db);
1528 $account->fetch((int) $bankid);
1529
1530 $curx = $this->marge_gauche;
1531 $cury = $posy;
1532
1533 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1534
1535 $posy += 2;
1536
1537 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1538 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1539 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1540
1541 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', false);
1542 }
1543 }
1544 }
1545 }
1546
1547 return $posy;
1548 }
1549
1550
1551 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1552 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1564 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1565 {
1566 // phpcs:enable
1567 global $conf, $mysoc, $hookmanager;
1568
1569 $sign = 1;
1570 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1571 $sign = -1;
1572 }
1573
1574 $default_font_size = pdf_getPDFFontSize($outputlangs);
1575
1576 $outputlangsbis = null;
1577 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1578 $outputlangsbis = new Translate('', $conf);
1579 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1580 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1581 $default_font_size--;
1582 }
1583
1584 $tab2_top = $posy;
1585 $tab2_hl = 4;
1586 $pdf->SetFont('', '', $default_font_size - 1);
1587
1588 // Total table
1589 $col1x = 120;
1590 $col2x = 170;
1591 if ($this->page_largeur < 210) { // To work with US executive format
1592 $col1x -= 15;
1593 $col2x -= 10;
1594 }
1595 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1596
1597 $useborder = 0;
1598 $index = 0;
1599
1600 // Get Total HT
1601 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1602
1603 // Total discount
1604 $total_discount_on_lines = 0;
1605 $multicurrency_total_discount_on_lines = 0;
1606 foreach ($object->lines as $i => $line) {
1607 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1608 $multicurrency_resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2, 1);
1609
1610 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1611 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1612 // If line was a negative line, we do not count the discount as a discount
1613 if ($line->total_ht < 0) {
1614 $total_discount_on_lines += -$line->total_ht;
1615 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1616 }
1617 }
1618
1619 if ($total_discount_on_lines > 0 && !$object->isSituationInvoice()) { // This is false on situation invoice
1620 // Show total NET before discount
1621 $pdf->SetFillColor(255, 255, 255);
1622 $pdf->SetXY($col1x, $tab2_top);
1623 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', true);
1624 $pdf->SetXY($col2x, $tab2_top);
1625
1626 $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));
1627 $pdf->MultiCell($largcol2, $tab2_hl, price($total_before_discount_to_show, 0, $outputlangs), 0, 'R', true);
1628
1629 $index++;
1630
1631 $pdf->SetFillColor(255, 255, 255);
1632 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1633 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', true);
1634 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1635
1636 $total_discount_to_show = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1637 $pdf->MultiCell($largcol2, $tab2_hl, price($total_discount_to_show, 0, $outputlangs), 0, 'R', true);
1638
1639 $index++;
1640 }
1641
1642 // Total HT
1643 $pdf->SetFillColor(255, 255, 255);
1644 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1645 $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);
1646
1647 $total_ht = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1648 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1649 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ht, 0, $outputlangs), 0, 'R', true);
1650
1651 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1652 $index++;
1653 $pdf->SetFillColor(255, 255, 255);
1654 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', true);
1656
1657 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1658 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', true);
1659 }
1660
1661 // Show VAT by rates and total
1662 $pdf->SetFillColor(248, 248, 248);
1663
1664 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1665
1666 $this->atleastoneratenotnull = 0;
1667 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1668 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1669 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1670 // Nothing to do
1671 } else {
1672 //Local tax 1 before VAT
1673 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1674 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1675 continue;
1676 }
1677
1678 foreach ($localtax_rate as $tvakey => $tvaval) {
1679 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1680 //$this->atleastoneratenotnull++;
1681
1682 $index++;
1683 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1684
1685 $tvacompl = '';
1686 if (preg_match('/\*/', (string) $tvakey)) {
1687 $tvakey = str_replace('*', '', (string) $tvakey);
1688 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1689 }
1690
1691 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1692 $totalvat .= ' ';
1693
1694 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1695 $totalvat .= $tvacompl;
1696 } else {
1697 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1698 }
1699
1700 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1701
1702 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1703
1704 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1705 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1706 }
1707 }
1708 }
1709
1710 //Local tax 2 before VAT
1711 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1712 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1713 continue;
1714 }
1715
1716 foreach ($localtax_rate as $tvakey => $tvaval) {
1717 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1718 //$this->atleastoneratenotnull++;
1719
1720 $index++;
1721 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1722
1723 $tvacompl = '';
1724 if (preg_match('/\*/', (string) $tvakey)) {
1725 $tvakey = str_replace('*', '', (string) $tvakey);
1726 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1727 }
1728 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1729 $totalvat .= ' ';
1730
1731 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1732 $totalvat .= $tvacompl;
1733 } else {
1734 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1735 }
1736
1737 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1738
1739 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1740
1741 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1742 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1743 }
1744 }
1745 }
1746
1747 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1748 // VAT
1749 foreach ($this->tva_array as $tvakey => $tvaval) {
1750 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_VAT_LINE_IF_ZERO')) {
1751 $this->atleastoneratenotnull++;
1752
1753 $index++;
1754 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1755
1756 $tvacompl = '';
1757 if (preg_match('/\*/', $tvakey)) {
1758 $tvakey = str_replace('*', '', $tvakey);
1759 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1760 }
1761 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1762 $totalvat .= ' ';
1763 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1764 $totalvat .= vatrate((string) $tvaval['vatrate'], true).$tvacompl;
1765 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1766 $totalvat .= $tvaval['vatcode'].$tvacompl;
1767 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1768 $totalvat .= $tvacompl;
1769 } else {
1770 $totalvat .= vatrate((string) $tvaval['vatrate'], true).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1771 }
1772 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1773 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1774 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', true);
1775 }
1776 }
1777 }
1778
1779 //Local tax 1 after VAT
1780 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1781 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1782 continue;
1783 }
1784
1785 foreach ($localtax_rate as $tvakey => $tvaval) {
1786 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1787 //$this->atleastoneratenotnull++;
1788
1789 $index++;
1790 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1791
1792 $tvacompl = '';
1793 if (preg_match('/\*/', (string) $tvakey)) {
1794 $tvakey = str_replace('*', '', (string) $tvakey);
1795 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1796 }
1797 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1798
1799 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1800 $totalvat .= $tvacompl;
1801 } else {
1802 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1803 }
1804
1805 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1806
1807 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1808
1809 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1810 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1811 }
1812 }
1813 }
1814
1815 //Local tax 2 after VAT
1816 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1817 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1818 continue;
1819 }
1820
1821 foreach ($localtax_rate as $tvakey => $tvaval) {
1822 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1823 //$this->atleastoneratenotnull++;
1824
1825 $index++;
1826 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1827
1828 $tvacompl = '';
1829 if (preg_match('/\*/', (string) $tvakey)) {
1830 $tvakey = str_replace('*', '', (string) $tvakey);
1831 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1832 }
1833 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1834
1835 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1836 $totalvat .= $tvacompl;
1837 } else {
1838 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1839 }
1840
1841 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1842
1843 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1844
1845 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1846 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1847 }
1848 }
1849 }
1850
1851 // Revenue stamp
1852 if (price2num($object->revenuestamp, 'MT') != 0) {
1853 $index++;
1854 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1855 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', true);
1856
1857 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1858 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', true);
1859 }
1860
1861 // Total TTC
1862 $index++;
1863 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1864 $pdf->SetTextColor(0, 0, 60);
1865 $pdf->SetFillColor(224, 224, 224);
1866 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', true);
1867
1868 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1869 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
1870
1871 // Retained warranty
1872 if ($object->displayRetainedWarranty()) {
1873 $pdf->SetTextColor(40, 40, 40);
1874 $pdf->SetFillColor(255, 255, 255);
1875
1876 $retainedWarranty = $object->getRetainedWarrantyAmount();
1877 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1878
1879 // Billed - retained warranty
1880 $index++;
1881 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1882 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', true);
1883
1884 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1885 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', true);
1886
1887 // retained warranty
1888 $index++;
1889 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1890
1891 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
1892 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1893
1894 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', true);
1895 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1896 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', true);
1897 }
1898 }
1899 }
1900
1901 $pdf->SetTextColor(0, 0, 0);
1902 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1903 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1904 //print "x".$creditnoteamount."-".$depositsamount;exit;
1905 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1906 if (!empty($object->paye)) {
1907 $resteapayer = 0;
1908 }
1909
1910 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1911 // Already paid + Deposits
1912 $index++;
1913 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1914 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', false);
1915 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1916 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
1917
1918 // Credit note
1919 if ($creditnoteamount) {
1920 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1921 $index++;
1922 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1923 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', false);
1924 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1925 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', false);
1926 }
1927
1928 // Escompte
1929 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1930 $index++;
1931 $pdf->SetFillColor(255, 255, 255);
1932
1933 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1934 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', true);
1935 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1936 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', true);
1937
1938 $resteapayer = 0;
1939 }
1940
1941 $index++;
1942 $pdf->SetTextColor(0, 0, 60);
1943 $pdf->SetFillColor(224, 224, 224);
1944 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1945 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', true);
1946 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1947 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
1948
1949 $pdf->SetFont('', '', $default_font_size - 1);
1950 $pdf->SetTextColor(0, 0, 0);
1951 }
1952
1953 $index++;
1954
1955 if (getDolGlobalString("BILL_TEXT_TOTAL_FOOTER")) {
1956 $index++;
1957 $index++;
1958 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1959 $pdf->MultiCell($col2x - $col1x, $tab2_hl, getDolGlobalString('BILL_TEXT_TOTAL_FOOTER'), 0, 'L', false);
1960 }
1961
1962 return ($tab2_top + ($tab2_hl * $index));
1963 }
1964
1965 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1979 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1980 {
1981 global $conf;
1982
1983 // Force to disable hidetop and hidebottom
1984 $hidebottom = 0;
1985 if ($hidetop) {
1986 $hidetop = -1;
1987 }
1988
1989 $currency = !empty($currency) ? $currency : $conf->currency;
1990 $default_font_size = pdf_getPDFFontSize($outputlangs);
1991
1992 // Amount in (at tab_top - 1)
1993 $pdf->SetTextColor(0, 0, 0);
1994 $pdf->SetFont('', '', $default_font_size - 2);
1995
1996 if (empty($hidetop)) {
1997 // Show category of operations
1998 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1999 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2000 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2001 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2002 }
2003
2004 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2005 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2006 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2007
2008 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2009 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2010 }
2011 }
2012
2013 $pdf->SetDrawColor(128, 128, 128);
2014 $pdf->SetFont('', '', $default_font_size - 1);
2015
2016 // Output Rect
2017 $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
2018
2019 if (empty($hidetop)) {
2020 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
2021
2022 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
2023 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
2024 }
2025
2026 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
2027 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
2028 //if (empty($hidetop)) {
2029 //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
2030 //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
2031 //}
2032 }
2033
2034 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2035 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
2036 if (empty($hidetop)) {
2037 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
2038 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
2039 }
2040 }
2041
2042 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
2043 if (empty($hidetop)) {
2044 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
2045 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
2046 }
2047
2048 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
2049 if (empty($hidetop)) {
2050 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
2051 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
2052 }
2053
2054 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2055 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
2056 if (empty($hidetop)) {
2057 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
2058 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
2059 }
2060 }
2061
2062 if ($this->atleastonediscount) {
2063 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
2064 if (empty($hidetop)) {
2065 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
2066 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
2067 }
2068 }
2069
2070 if ($this->situationinvoice) {
2071 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
2072 if (empty($hidetop)) {
2073 $pdf->SetXY($this->posxprogress, $tab_top + 1);
2074 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("ProgressShort"), '', 'C');
2075 }
2076 }
2077
2078 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
2079 if (empty($hidetop)) {
2080 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
2081 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
2082 }
2083 }
2084
2085 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2096 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2097 {
2098 // phpcs:enable
2099 global $conf, $langs;
2100
2101 $ltrdirection = 'L';
2102 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2103 $ltrdirection = 'R';
2104 }
2105
2106 // Load traductions files required by page
2107 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2108
2109 $default_font_size = pdf_getPDFFontSize($outputlangs);
2110
2111 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2112
2113 $pdf->SetTextColor(0, 0, 60);
2114 $pdf->SetFont('', 'B', $default_font_size + 3);
2115
2116 $w = 110;
2117
2118 $posy = $this->marge_haute;
2119 $posx = $this->page_largeur - $this->marge_droite - $w;
2120
2121 $pdf->SetXY($this->marge_gauche, $posy);
2122
2123 // Logo
2124 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2125 if ($this->emetteur->logo) {
2126 $logodir = $conf->mycompany->dir_output;
2127 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
2128 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
2129 }
2130 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2131 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2132 } else {
2133 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2134 }
2135 if (is_readable($logo)) {
2136 $height = pdf_getHeightForLogo($logo);
2137 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2138 } else {
2139 $pdf->SetTextColor(200, 0, 0);
2140 $pdf->SetFont('', 'B', $default_font_size - 2);
2141 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2142 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2143 }
2144 } else {
2145 $text = $this->emetteur->name;
2146 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2147 }
2148 }
2149
2150 $pdf->SetFont('', 'B', $default_font_size + 3);
2151 $pdf->SetXY($posx, $posy);
2152 $pdf->SetTextColor(0, 0, 60);
2153 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2154 if ($object->type == 1) {
2155 $title = $outputlangs->transnoentities("InvoiceReplacement");
2156 }
2157 if ($object->type == 2) {
2158 $title = $outputlangs->transnoentities("InvoiceAvoir");
2159 }
2160 if ($object->type == 3) {
2161 $title = $outputlangs->transnoentities("InvoiceDeposit");
2162 }
2163 if ($object->type == 4) {
2164 $title = $outputlangs->transnoentities("InvoiceProForma");
2165 }
2166 if ($this->situationinvoice) {
2167 $outputlangs->loadLangs(array("other"));
2168 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2169 }
2170 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2171 $title .= ' - ';
2172 if ($object->type == 0) {
2173 if ($this->situationinvoice) {
2174 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2175 }
2176 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2177 } elseif ($object->type == 1) {
2178 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2179 } elseif ($object->type == 2) {
2180 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2181 } elseif ($object->type == 3) {
2182 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2183 } elseif ($object->type == 4) {
2184 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2185 }
2186 }
2187 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2188 if ($object->status == $object::STATUS_DRAFT) {
2189 $pdf->SetTextColor(128, 0, 0);
2190 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2191 }
2192
2193 $pdf->MultiCell($w, 3, $title, '', 'R');
2194
2195 $pdf->SetFont('', '', $default_font_size - 2);
2196
2197 pdfWriteBlockedLogSignature($pdf, $outputlangs, $this->page_hauteur, $object, $w, $posx, $posy);
2198
2199 /*
2200 $posy += 5;
2201 $pdf->SetXY($posx, $posy);
2202 $pdf->SetFont('', 'B', $default_font_size);
2203 $pdf->SetTextColor(0, 0, 60);
2204 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2205 if ($object->status == $object::STATUS_DRAFT) {
2206 $pdf->SetTextColor(128, 0, 0);
2207 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2208 }
2209 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2210
2211 $posy += 3;
2212 $pdf->SetFont('', '', $default_font_size - 2);
2213
2214 if ($object->ref_customer) {
2215 $posy += 4;
2216 $pdf->SetXY($posx, $posy);
2217 $pdf->SetTextColor(0, 0, 60);
2218 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_customer), '', 'R');
2219 }
2220
2221 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2222 $object->fetchProject();
2223 if (!empty($object->project->ref)) {
2224 $posy += 3;
2225 $pdf->SetXY($posx, $posy);
2226 $pdf->SetTextColor(0, 0, 60);
2227 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2228 }
2229 }
2230
2231 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2232 $object->fetchProject();
2233 if (!empty($object->project->ref)) {
2234 $outputlangs->load("projects");
2235 $posy += 3;
2236 $pdf->SetXY($posx, $posy);
2237 $pdf->SetTextColor(0, 0, 60);
2238 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2239 }
2240 }
2241
2242 $objectidnext = $object->getIdReplacingInvoice('validated');
2243 if ($object->type == 0 && $objectidnext) {
2244 $objectreplacing = new Facture($this->db);
2245 $objectreplacing->fetch($objectidnext);
2246
2247 $posy += 3;
2248 $pdf->SetXY($posx, $posy);
2249 $pdf->SetTextColor(0, 0, 60);
2250 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2251 }
2252 if ($object->type == 1) {
2253 $objectreplaced = new Facture($this->db);
2254 $objectreplaced->fetch($object->fk_facture_source);
2255
2256 $posy += 4;
2257 $pdf->SetXY($posx, $posy);
2258 $pdf->SetTextColor(0, 0, 60);
2259 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2260 }
2261 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2262 $objectreplaced = new Facture($this->db);
2263 $objectreplaced->fetch($object->fk_facture_source);
2264
2265 $posy += 3;
2266 $pdf->SetXY($posx, $posy);
2267 $pdf->SetTextColor(0, 0, 60);
2268 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2269 }
2270
2271 $posy += 4;
2272 $pdf->SetXY($posx, $posy);
2273 $pdf->SetTextColor(0, 0, 60);
2274 $title = $outputlangs->transnoentities("DateInvoice");
2275 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2276 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2277 }
2278 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2279
2280 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2281 $posy += 4;
2282 $pdf->SetXY($posx, $posy);
2283 $pdf->SetTextColor(0, 0, 60);
2284 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2285 }
2286
2287 if ($object->type != 2) {
2288 $posy += 3;
2289 $pdf->SetXY($posx, $posy);
2290 $pdf->SetTextColor(0, 0, 60);
2291 $title = $outputlangs->transnoentities("DateDue");
2292 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2293 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2294 }
2295 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2296 }
2297
2298 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2299 $posy += 3;
2300 $pdf->SetXY($posx, $posy);
2301 $pdf->SetTextColor(0, 0, 60);
2302 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2303 }
2304
2305 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2306 $posy += 3;
2307 $pdf->SetXY($posx, $posy);
2308 $pdf->SetTextColor(0, 0, 60);
2309 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
2310 }
2311
2312 // Get contact
2313 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2314 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2315 if (count($arrayidcontact) > 0) {
2316 $usertmp = new User($this->db);
2317 $usertmp->fetch($arrayidcontact[0]);
2318 $posy += 4;
2319 $pdf->SetXY($posx, $posy);
2320 $pdf->SetTextColor(0, 0, 60);
2321 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2322 }
2323 }
2324
2325 $posy += 1;
2326
2327 $top_shift = 0;
2328 // Show list of linked objects
2329 if (!getDolGlobalString('INVOICE_HIDE_LINKED_OBJECT')) {
2330 $current_y = $pdf->getY();
2331 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2332 if ($current_y < $pdf->getY()) {
2333 $top_shift = $pdf->getY() - $current_y;
2334 }
2335 }
2336
2337 if ($showaddress) {
2338 // Sender properties
2339 $carac_emetteur = '';
2340 // Add internal contact of object if defined
2341 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2342 if (count($arrayidcontact) > 0) {
2343 $object->fetch_user($arrayidcontact[0]);
2344 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2345 $carac_emetteur .= $labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2346 $carac_emetteur .= "\n";
2347 }
2348
2349 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2350
2351 // Show sender
2352 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2353 $posy += $top_shift;
2354 $posx = $this->marge_gauche;
2355 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2356 $posx = $this->page_largeur - $this->marge_droite - 80;
2357 }
2358
2359 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2360 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2361
2362
2363 // Show sender frame
2364 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2365 $pdf->SetTextColor(0, 0, 0);
2366 $pdf->SetFont('', '', $default_font_size - 2);
2367 $pdf->SetXY($posx, $posy - 5);
2368 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2369 $pdf->SetXY($posx, $posy);
2370 $pdf->SetFillColor(230, 230, 230);
2371 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2372 $pdf->SetTextColor(0, 0, 60);
2373 }
2374
2375 // Show sender name
2376 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2377 $pdf->SetXY($posx + 2, $posy + 3);
2378 $pdf->SetFont('', 'B', $default_font_size);
2379 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2380 $posy = $pdf->getY();
2381 }
2382
2383 // Show sender information
2384 $pdf->SetXY($posx + 2, $posy);
2385 $pdf->SetFont('', '', $default_font_size - 1);
2386 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2387
2388
2389 // If BILLING contact defined on invoice, we use it
2390 $usecontact = false;
2391 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2392 if (count($arrayidcontact) > 0) {
2393 $usecontact = true;
2394 $result = $object->fetch_contact($arrayidcontact[0]);
2395 }
2396
2397 // Recipient name
2398 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2399 $thirdparty = $object->contact;
2400 } else {
2401 $thirdparty = $object->thirdparty;
2402 }
2403
2404 $carac_client_name = is_object($thirdparty) ? pdfBuildThirdpartyName($thirdparty, $outputlangs) : '';
2405
2406 $mode = 'target';
2407 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2408
2409 // Show recipient
2410 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2411 if ($this->page_largeur < 210) {
2412 $widthrecbox = 84; // To work with US executive format
2413 }
2414 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2415 $posy += $top_shift;
2416 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2417 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2418 $posx = $this->marge_gauche;
2419 }
2420
2421 // Show recipient frame
2422 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2423 $pdf->SetTextColor(0, 0, 0);
2424 $pdf->SetFont('', '', $default_font_size - 2);
2425 $pdf->SetXY($posx + 2, $posy - 5);
2426 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2427 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2428 }
2429
2430 // Show recipient name
2431 $pdf->SetXY($posx + 2, $posy + 3);
2432 $pdf->SetFont('', 'B', $default_font_size);
2433 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2434 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2435
2436 $posy = $pdf->getY();
2437
2438 // Show recipient information
2439 $pdf->SetFont('', '', $default_font_size - 1);
2440 $pdf->SetXY($posx + 2, $posy);
2441 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2442 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2443
2444 // Show shipping/delivery address
2445 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2446 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2447
2448 if (!empty($idaddressshipping)) {
2449 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2450 $companystatic = new Societe($this->db);
2451 $companystatic->fetch($object->contact->fk_soc);
2452 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2453 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
2454 } else {
2455 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2456 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2457 }
2458 if (!empty($carac_client_shipping)) {
2459 $posy += $hautcadre;
2460
2461 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2462
2463 // Show shipping frame
2464 $pdf->SetXY($posx + 2, $posy - 5);
2465 $pdf->SetFont('', '', $default_font_size - 2);
2466 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', false);
2467 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2468
2469 // Show shipping name
2470 $pdf->SetXY($posx + 2, $posy + 3);
2471 $pdf->SetFont('', 'B', $default_font_size);
2472 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2473
2474 $posy = $pdf->getY();
2475
2476 // Show shipping information
2477 $pdf->SetXY($posx + 2, $posy);
2478 $pdf->SetFont('', '', $default_font_size - 1);
2479 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2480
2481 $top_shift += $hautcadre + 10;
2482 }
2483 }
2484 }
2485
2486 $pdf->SetTextColor(0, 0, 0);
2487
2488 return $top_shift;
2489 }
2490
2491 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2502 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2503 {
2504 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2505
2506 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);
2507 }
2508}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage bank accounts.
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
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 generate the customer invoice PDF with template Crabe.
__construct($db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
_tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0, $heightforqrinvoice=0)
Show footer of page.
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
Function _tableau_versements_header.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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_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...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
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:2849
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1535
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2550
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:2881
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdfCertifMention(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal certificate mention.
Definition pdf.lib.php:908
pdfWriteBlockedLogSignature(&$pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Show header of page for PDF generation.
Definition pdf.lib.php:780
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:312
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:1110
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2153
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2484
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2091
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:1497
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:928
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:268
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:433
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2398
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2441
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2238
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:824
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:388
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128