dolibarr 21.0.0-beta
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-2024 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 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024 Nick Fragoulis
16 * Copyright (C) 2024 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 $conf, $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->facture->dir_output : $conf->facture->multidir_output[$object->entity];
276 $file = $dir."/SPECIMEN.pdf";
277 } else {
278 $objectref = dol_sanitizeFileName($object->ref);
279 $dir = (empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->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(1, 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])) {
338 $logodir = $conf->mycompany->multidir_output[$object->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') ? '' : $conf->global->CERTIFICATE_CRT;
363 }
364 if (!$certprivate) {
365 $certprivate = !getDolGlobalString('CERTIFICATE_CRT_PRIVATE') ? '' : $conf->global->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 // determine category of operation
392 if ($categoryOfOperation < 2) {
393 $lineProductType = $object->lines[$i]->product_type;
394 if ($lineProductType == Product::TYPE_PRODUCT) {
395 $nbProduct++;
396 } elseif ($lineProductType == Product::TYPE_SERVICE) {
397 $nbService++;
398 }
399 if ($nbProduct > 0 && $nbService > 0) {
400 // mixed products and services
401 $categoryOfOperation = 2;
402 }
403 }
404 }
405 // determine category of operation
406 if ($categoryOfOperation <= 0) {
407 // only services
408 if ($nbProduct == 0 && $nbService > 0) {
409 $categoryOfOperation = 1;
410 }
411 }
412 $this->categoryOfOperation = $categoryOfOperation;
413 if (empty($this->atleastonediscount)) { // retrieve space not used by discount
414 $delta = ($this->posxprogress - $this->posxdiscount);
415 $this->posxpicture += $delta;
416 $this->posxtva += $delta;
417 $this->posxup += $delta;
418 $this->posxqty += $delta;
419 $this->posxunit += $delta;
420 $this->posxdiscount += $delta;
421 // post of fields after are not modified, stay at same position
422 }
423
424 $progress_width = 0;
425 // Situation invoice handling
426 if ($object->situation_cycle_ref && !getDolGlobalString('MAIN_PDF_HIDE_SITUATION')) {
427 $this->situationinvoice = true;
428 $progress_width = 10;
429 $this->posxpicture -= $progress_width;
430 $this->posxtva -= $progress_width;
431 $this->posxup -= $progress_width;
432 $this->posxqty -= $progress_width;
433 $this->posxunit -= $progress_width;
434 $this->posxdiscount -= $progress_width;
435 $this->posxprogress -= $progress_width;
436 }
437
438 // New page
439 $pdf->AddPage();
440 if (!empty($tplidx)) {
441 $pdf->useTemplate($tplidx);
442 }
443 $pagenb++;
444
445 // Output header (logo, ref and address blocks). This is first call for first page.
446 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
447 $pdf->SetFont('', '', $default_font_size - 1);
448 $pdf->MultiCell(0, 3, ''); // Set interline to 3
449 $pdf->SetTextColor(0, 0, 0);
450
451 // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher
452
453 // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
454 $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
455 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
456
457 // You can add more thing under header here, if you increase $extra_under_address_shift too.
458 $extra_under_address_shift = 0;
459 $qrcodestring = '';
460 if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) {
461 $qrcodestring = $object->buildZATCAQRString();
462 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
463 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
464 $qrcodestring = $object->buildSwitzerlandQRString();
465 }
466 } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
467 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
468 $qrcodestring = $object->buildEPCQrCodeString();
469 }
470 }
471
472 if ($qrcodestring) {
473 $qrcodecolor = array('25', '25', '25');
474 // set style for QR-code
475 $styleQr = array(
476 'border' => false,
477 'padding' => 0,
478 'fgcolor' => $qrcodecolor,
479 'bgcolor' => false, //array(255,255,255)
480 'module_width' => 1, // width of a single module in points
481 'module_height' => 1 // height of a single module in points
482 );
483 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
484
485 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
486 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
487 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
488 $pdf->SetFont('', '', $default_font_size - 4);
489 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0);
490 }
491 }
492
493 $extra_under_address_shift += 25;
494 }
495
496 // Call hook printUnderHeaderPDFline
497 $parameters = array(
498 'object' => $object,
499 'i' => $i,
500 'pdf' => &$pdf,
501 'outputlangs' => $outputlangs,
502 'hidedetails' => $hidedetails
503 );
504 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
505 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
506 $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift'];
507 }
508
509 $tab_top += $extra_under_address_shift;
510 $tab_top_newpage += 0;
511
512 // Incoterm
513 $height_incoterms = 0;
514 if (isModEnabled('incoterm')) {
515 $desc_incoterms = $object->getIncotermsForPDF();
516 if ($desc_incoterms) {
517 $tab_top -= 2;
518
519 $pdf->SetFont('', '', $default_font_size - 1);
520 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
521 $nexY = $pdf->GetY();
522 $height_incoterms = $nexY - $tab_top;
523
524 // Rect takes a length in 3rd parameter
525 $pdf->SetDrawColor(192, 192, 192);
526 $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');
527
528 $tab_top = $nexY + 6;
529 }
530 }
531
532 // Display notes
533 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
534 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
535 // Get first sale rep
536 if (is_object($object->thirdparty)) {
537 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
538 $salerepobj = new User($this->db);
539 $salerepobj->fetch($salereparray[0]['id']);
540 if (!empty($salerepobj->signature)) {
541 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
542 }
543 }
544 }
545 // Extrafields in note
546 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
547 if (!empty($extranote)) {
548 $notetoshow = dol_concatdesc($notetoshow, $extranote);
549 }
550 if ($notetoshow) {
551 $tab_top -= 2;
552
553 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
554 complete_substitutions_array($substitutionarray, $outputlangs, $object);
555
556 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
557 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
558
559 $pdf->SetFont('', '', $default_font_size - 1);
560 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
561 $nexY = $pdf->GetY();
562 $height_note = $nexY - $tab_top;
563
564 // Rect takes a length in 3rd parameter
565 $pdf->SetDrawColor(192, 192, 192);
566 $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');
567
568 $tab_top = $nexY + 6;
569 }
570
571 $iniY = $tab_top + 7;
572 $curY = $tab_top + 7;
573 $nexY = $tab_top + 7;
574
575 // Loop on each lines
576 for ($i = 0; $i < $nblines; $i++) {
577 $curY = $nexY;
578 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
579 $pdf->SetTextColor(0, 0, 0);
580
581 // Define size of image if we need it
582 $imglinesize = array();
583 if (!empty($realpatharray[$i])) {
584 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
585 }
586
587 $pdf->setTopMargin($tab_top_newpage);
588 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
589 $pdf->setPageOrientation('', 1, $page_bottom_margin);
590 $pageposbefore = $pdf->getPage();
591
592 $showpricebeforepagebreak = 1;
593 $posYAfterImage = 0;
594 $posYAfterDescription = 0;
595
596 // We start with Photo of product line
597 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
598 $pdf->AddPage('', '', true);
599 if (!empty($tplidx)) {
600 $pdf->useTemplate($tplidx);
601 }
602 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
603 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
604 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
605 }
606 $pdf->setPage($pageposbefore + 1);
607
608 $curY = $tab_top_newpage;
609
610 // Allows data in the first page if description is long enough to break in multiples pages
611 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
612 $showpricebeforepagebreak = 1;
613 } else {
614 $showpricebeforepagebreak = 0;
615 }
616 }
617
618 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
619 $curX = $this->posxpicture - 1;
620 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
621 // $pdf->Image does not increase value return by getY, so we save it manually
622 $posYAfterImage = $curY + $imglinesize['height'];
623 }
624
625 // Description of product line
626 $curX = $this->posxdesc - 1;
627
628 $pdf->startTransaction();
629 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
630 $pageposafter = $pdf->getPage();
631 if ($pageposafter > $pageposbefore) { // There is a pagebreak
632 $pdf->rollbackTransaction(true);
633 $pageposafter = $pageposbefore;
634 //print $pageposafter.'-'.$pageposbefore;exit;
635 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
636 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
637 $pageposafter = $pdf->getPage();
638 $posyafter = $pdf->GetY();
639 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
640 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text
641 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
642 $pdf->AddPage('', '', true);
643 if (!empty($tplidx)) {
644 $pdf->useTemplate($tplidx);
645 }
646 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
647 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
648 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
649 }
650 $pdf->setPage($pageposafter + 1);
651 }
652 } else {
653 // We found a page break
654
655 // Allows data in the first page if description is long enough to break in multiples pages
656 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
657 $showpricebeforepagebreak = 1;
658 } else {
659 $showpricebeforepagebreak = 0;
660 }
661 }
662 } else { // No pagebreak
663 $pdf->commitTransaction();
664 }
665 $posYAfterDescription = $pdf->GetY();
666
667 $nexY = $pdf->GetY();
668 $pageposafter = $pdf->getPage();
669 $pdf->setPage($pageposbefore);
670 $pdf->setTopMargin($this->marge_haute);
671 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
672
673 // We suppose that a too long description or photo were moved completely on next page
674 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
675 $pdf->setPage($pageposafter);
676 $curY = $tab_top_newpage;
677 }
678
679 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
680
681 // VAT Rate
682 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
683 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
684 $pdf->SetXY($this->posxtva - 5, $curY);
685 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
686 }
687
688 // Unit price before discount
689 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
690 $pdf->SetXY($this->posxup, $curY);
691 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
692
693 // Quantity
694 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
695 $pdf->SetXY($this->posxqty, $curY);
696 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
697
698 // Unit
699 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
700 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
701 $pdf->SetXY($this->posxunit, $curY);
702 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
703 }
704
705 // Discount on line
706 if ($object->lines[$i]->remise_percent) {
707 $pdf->SetXY($this->posxdiscount - 2, $curY);
708 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
709 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
710 }
711
712 // Situation progress
713 if ($this->situationinvoice) {
714 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
715 $pdf->SetXY($this->posxprogress, $curY);
716 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R');
717 }
718
719 // Total HT line
720 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
721 $pdf->SetXY($this->postotalht, $curY);
722 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
723
724
725 $sign = 1;
726 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
727 $sign = -1;
728 }
729 // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
730 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
731 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
732 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
733 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
734 } else {
735 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
736 }
737 } else {
738 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
739 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
740 } else {
741 $tvaligne = $sign * $object->lines[$i]->total_tva;
742 }
743 }
744
745 $localtax1ligne = $object->lines[$i]->total_localtax1;
746 $localtax2ligne = $object->lines[$i]->total_localtax2;
747 $localtax1_rate = $object->lines[$i]->localtax1_tx;
748 $localtax2_rate = $object->lines[$i]->localtax2_tx;
749 $localtax1_type = $object->lines[$i]->localtax1_type;
750 $localtax2_type = $object->lines[$i]->localtax2_type;
751
752 // TODO remise_percent is an obsolete field for object parent
753 /*if ($object->remise_percent) {
754 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
755 }
756 if ($object->remise_percent) {
757 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
758 }
759 if ($object->remise_percent) {
760 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
761 }*/
762
763 $vatrate = (string) $object->lines[$i]->tva_tx;
764
765 // Retrieve type from database for backward compatibility with old records
766 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
767 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
768 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
769 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
770 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
771 }
772
773 // retrieve global local tax
774 if ($localtax1_type && $localtax1ligne != 0) {
775 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
776 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
777 } else {
778 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
779 }
780 }
781 if ($localtax2_type && $localtax2ligne != 0) {
782 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
783 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
784 } else {
785 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
786 }
787 }
788
789 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
790 $vatrate .= '*';
791 }
792
793 // Fill $this->tva and $this->tva_array
794 if (!isset($this->tva[$vatrate])) {
795 $this->tva[$vatrate] = 0;
796 }
797 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
798 $vatcode = $object->lines[$i]->vat_src_code;
799 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
800 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
801 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
802 }
803 $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);
804 } else {
805 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
806 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
807 }
808 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
809 }
810
811 if ($posYAfterImage > $posYAfterDescription) {
812 $nexY = $posYAfterImage;
813 }
814
815 // Add line
816 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
817 $pdf->setPage($pageposafter);
818 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
819 //$pdf->SetDrawColor(190,190,200);
820 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
821 $pdf->SetLineStyle(array('dash' => 0));
822 }
823
824 $nexY += 2; // Add space between lines
825
826 // Detect if some page were added automatically and output _tableau for past pages
827 while ($pagenb < $pageposafter) {
828 $pdf->setPage($pagenb);
829 if ($pagenb == 1) {
830 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
831 } else {
832 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
833 }
834 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
835 $pagenb++;
836 $pdf->setPage($pagenb);
837 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
838 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
839 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
840 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
841 }
842 if (!empty($tplidx)) {
843 $pdf->useTemplate($tplidx);
844 }
845 }
846 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
847 if ($pagenb == 1) {
848 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
849 } else {
850 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
851 }
852 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
853 // New page
854 $pdf->AddPage();
855 if (!empty($tplidx)) {
856 $pdf->useTemplate($tplidx);
857 }
858 $pagenb++;
859 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
860 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
861 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
862 }
863 }
864 }
865
866 // Show square
867 if ($pagenb == 1) {
868 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
869 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
870 } else {
871 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
872 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
873 }
874 dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
875
876 // Display info area
877 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
878
879 // Display total area
880 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
881
882 // Display Payments area
883 $listofpayments = $object->getListOfPayments('', 0, 1);
884 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
885 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
886 }
887
888 // Pagefoot
889 $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs));
890 if (method_exists($pdf, 'AliasNbPages')) {
891 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
892 }
893
894 // Add terms to sale
895 if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) {
896 $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale;
897 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
898 $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale;
899 }
900 if (file_exists($termsofsale) && is_readable($termsofsale)) {
901 $pagecount = $pdf->setSourceFile($termsofsale);
902 for ($i = 1; $i <= $pagecount; $i++) {
903 $tplIdx = $pdf->importPage($i);
904 if ($tplIdx!==false) {
905 $s = $pdf->getTemplatesize($tplIdx);
906 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
907 $pdf->useTemplate($tplIdx);
908 } else {
909 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
910 }
911 }
912 }
913 }
914 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
915 $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs);
916 if (!$result) {
917 $pdf->Close();
918 return 0;
919 }
920 }
921 $pdf->Close();
922
923 $pdf->Output($file, 'F');
924
925 // Add pdfgeneration hook
926 $hookmanager->initHooks(array('pdfgeneration'));
927 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
928 global $action;
929 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
930 if ($reshook < 0) {
931 $this->error = $hookmanager->error;
932 $this->errors = $hookmanager->errors;
933 }
934
935 dolChmod($file);
936
937 $this->result = array('fullpath' => $file);
938
939 return 1; // No error
940 } else {
941 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
942 return 0;
943 }
944 } else {
945 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
946 return 0;
947 }
948 }
949
950
951 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
952 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
963 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
964 {
965 // phpcs:enable
966
967 $sign = 1;
968 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
969 $sign = -1;
970 }
971
972 $current_page = $pdf->getPage();
973 $tab3_posx = 120;
974 $tab3_top = $posy + 8;
975 $tab3_width = 80;
976 $tab3_height = 4;
977 if ($this->page_largeur < 210) { // To work with US executive format
978 $tab3_posx -= 15;
979 }
980
981 $default_font_size = pdf_getPDFFontSize($outputlangs);
982
983 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
984
985 $y = 0;
986
987 $pdf->SetFont('', '', $default_font_size - 4);
988
989
990 // Loop on each discount available (deposits and credit notes and excess of payment included)
991 $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,";
992 $sql .= " re.description, re.fk_facture_source,";
993 $sql .= " f.type, f.datef";
994 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
995 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
996 $resql = $this->db->query($sql);
997 if ($resql) {
998 $num = $this->db->num_rows($resql);
999 $i = 0;
1000 $invoice = new Facture($this->db);
1001 while ($i < $num) {
1002 $y += 3;
1003 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1004 $y = 0;
1005 $current_page++;
1006 $pdf->AddPage('', '', true);
1007 /*if (!empty($tplidx)) {
1008 $pdf->useTemplate($tplidx);
1009 }*/
1010 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1011 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1012 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1013 }
1014 $pdf->setPage($current_page);
1015 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1016 }
1017
1018 $obj = $this->db->fetch_object($resql);
1019
1020 if ($obj->type == 2) {
1021 $text = $outputlangs->transnoentities("CreditNote");
1022 } elseif ($obj->type == 3) {
1023 $text = $outputlangs->transnoentities("Deposit");
1024 } elseif ($obj->type == 0) {
1025 $text = $outputlangs->transnoentities("ExcessReceived");
1026 } else {
1027 $text = $outputlangs->transnoentities("UnknownType");
1028 }
1029
1030 $invoice->fetch($obj->fk_facture_source);
1031
1032 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1033 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1034 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1035 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1036 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1037 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1038 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1039 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1040
1041 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1042
1043 $i++;
1044 }
1045 } else {
1046 $this->error = $this->db->lasterror();
1047 return -1;
1048 }
1049
1050 // Loop on each payment
1051 // TODO Call getListOfPayments instead of hard coded sql
1052 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1053 $sql .= " cp.code";
1054 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1055 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1056 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1057 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1058 $sql .= " ORDER BY p.datep";
1059
1060 $resql = $this->db->query($sql);
1061 if ($resql) {
1062 $num = $this->db->num_rows($resql);
1063 $i = 0;
1064 $y += 3;
1065 $maxY = $y;
1066 while ($i < $num) {
1067 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1068 $y = 0;
1069 $current_page++;
1070 $pdf->AddPage('', '', true);
1071 /*if (!empty($tplidx)) {
1072 $pdf->useTemplate($tplidx);
1073 }*/
1074 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1075 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1076 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1077 }
1078 $pdf->setPage($current_page);
1079 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1080 }
1081
1082 $row = $this->db->fetch_object($resql);
1083
1084 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1085 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1086 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1087 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1088 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1089 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1090
1091 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1092 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1093 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1094 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1095 $y = $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1096 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1097 $y += 3;
1098 $i++;
1099 }
1100
1101 return $tab3_top + $y + 3;
1102 } else {
1103 $this->error = $this->db->lasterror();
1104 return -1;
1105 }
1106 }
1107
1108 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1109 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1123 protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
1124 {
1125 // phpcs:enable
1126 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1127 if ($object->type == 2) {
1128 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1129 }
1130
1131 $pdf->SetFont('', '', $default_font_size - 3);
1132 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1133 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1134
1135 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1136
1137 $pdf->SetFont('', '', $default_font_size - 4);
1138 $pdf->SetXY($tab3_posx, $tab3_top);
1139 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1140 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1141 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1142 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1143 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1144 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1145 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1146
1147 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1148 }
1149
1150 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1151 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1162 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1163 {
1164 // phpcs:enable
1165 global $conf, $mysoc, $hookmanager;
1166
1167 $default_font_size = pdf_getPDFFontSize($outputlangs);
1168
1169 $pdf->SetFont('', '', $default_font_size - 1);
1170
1171 krsort($this->tva_array);
1172
1173 // Show VAT details
1174 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1175 $pdf->SetFillColor(224, 224, 224);
1176
1177 $pdf->SetFont('', '', $default_font_size - 2);
1178 $pdf->SetXY($this->marge_gauche, $posy);
1179 $titre = $outputlangs->transnoentities("VAT");
1180 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1181
1182 $pdf->SetFont('', '', $default_font_size - 2);
1183 $pdf->SetXY($this->marge_gauche + 25, $posy);
1184 $titre = $outputlangs->transnoentities("NetTotal");
1185 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1186
1187 $pdf->SetFont('', '', $default_font_size - 2);
1188 $pdf->SetXY($this->marge_gauche + 50, $posy);
1189 $titre = $outputlangs->transnoentities("VATAmount");
1190 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1191
1192 $pdf->SetFont('', '', $default_font_size - 2);
1193 $pdf->SetXY($this->marge_gauche + 75, $posy);
1194 $titre = $outputlangs->transnoentities("AmountTotal");
1195 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1196
1197 $posy = $pdf->GetY();
1198 $tot_ht = 0;
1199 $tot_tva = 0;
1200 $tot_ttc = 0;
1201
1202 foreach ($this->tva_array as $tvakey => $tvaval) {
1203 $pdf->SetFont('', '', $default_font_size - 2);
1204 $pdf->SetXY($this->marge_gauche, $posy);
1205 $titre = round((float) $tvakey, 2) . "%";
1206 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1207
1208 $pdf->SetFont('', '', $default_font_size - 2);
1209 $pdf->SetXY($this->marge_gauche + 25, $posy);
1210 $titre = price($tvaval['tot_ht']);
1211 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1212 $tot_ht += $tvaval['tot_ht'];
1213
1214 $pdf->SetFont('', '', $default_font_size - 2);
1215 $pdf->SetXY($this->marge_gauche + 50, $posy);
1216 $titre = price($tvaval['amount']);
1217 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1218 $tot_tva += $tvaval['amount'];
1219
1220 $pdf->SetFont('', '', $default_font_size - 2);
1221 $pdf->SetXY($this->marge_gauche + 75, $posy);
1222 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1223 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1224 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1225
1226 $posy = $pdf->GetY();
1227 }
1228 }
1229
1230 // If France, show VAT mention if not applicable
1231 if ($this->emetteur->country_code == 'FR' && empty($object->total_tva) && (empty($mysoc->tva_assuj) || ($this->emetteur->isInEEC() && $object->thirdparty->isInEEC()))) {
1232 $pdf->SetFont('', 'B', $default_font_size - 2);
1233 $pdf->SetXY($this->marge_gauche, $posy);
1234 if ($mysoc->forme_juridique_code == 92) {
1235 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1236 } else {
1237 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1238 }
1239
1240 $posy = $pdf->GetY() + 4;
1241 }
1242
1243 $posxval = 52;
1244 $posxend = 110; // End of x for text on left side
1245 if ($this->page_largeur < 210) { // To work with US executive format
1246 $posxend -= 10;
1247 }
1248
1249 // Show payments conditions
1250 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1251 $pdf->SetFont('', 'B', $default_font_size - 2);
1252 $pdf->SetXY($this->marge_gauche, $posy);
1253 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1254 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1255
1256 $pdf->SetFont('', '', $default_font_size - 2);
1257 $pdf->SetXY($posxval, $posy);
1258 $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);
1259 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1260 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1261
1262 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1263 }
1264
1265 // Show category of operations
1266 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1267 $pdf->SetFont('', 'B', $default_font_size - 2);
1268 $pdf->SetXY($this->marge_gauche, $posy);
1269 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1270 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1271
1272 $pdf->SetFont('', '', $default_font_size - 2);
1273 $pdf->SetXY($posxval, $posy);
1274 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1275 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1276
1277 $posy = $pdf->GetY() + 3; // for 2 lines
1278 }
1279
1280 if ($object->type != 2) {
1281 // Check a payment mode is defined
1282 if (empty($object->mode_reglement_code)
1283 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1284 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1285 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1286 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1287 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1288 // Avoid having any valid PDF with setup that is not complete
1289 $outputlangs->load("errors");
1290
1291 $pdf->SetXY($this->marge_gauche, $posy);
1292 $pdf->SetTextColor(200, 0, 0);
1293 $pdf->SetFont('', 'B', $default_font_size - 2);
1294 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1295 $pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
1296 $pdf->SetTextColor(0, 0, 0);
1297
1298 $posy = $pdf->GetY() + 1;
1299 }
1300
1301 // Show payment mode
1302 if (!empty($object->mode_reglement_code)
1303 && $object->mode_reglement_code != 'CHQ'
1304 && $object->mode_reglement_code != 'VIR') {
1305 $pdf->SetFont('', 'B', $default_font_size - 2);
1306 $pdf->SetXY($this->marge_gauche, $posy);
1307 $titre = $outputlangs->transnoentities("PaymentMode").':';
1308 $pdf->MultiCell(80, 5, $titre, 0, 'L');
1309
1310 $pdf->SetFont('', '', $default_font_size - 2);
1311 $pdf->SetXY($posxval, $posy);
1312 $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);
1313 //#21654: add account number used for the debit
1314 if ($object->mode_reglement_code == "PRE") {
1315 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1316 $bac = new CompanyBankAccount($this->db);
1317 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1318 $bac->fetch(0, '', $object->thirdparty->id);
1319 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1320 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1321 }
1322 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1323
1324 $posy = $pdf->GetY();
1325 }
1326
1327 // Show if Option VAT debit option is on also if transmitter is french
1328 // Decret n°2099-1299 2022-10-07
1329 // French mention : "Option pour le paiement de la taxe d'après les débits"
1330 if ($this->emetteur->country_code == 'FR') {
1331 if (getDolGlobalInt('TAX_MODE') == 1) {
1332 $pdf->SetXY($this->marge_gauche, $posy);
1333 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1334
1335 $posy = $pdf->GetY() + 1;
1336 }
1337 }
1338
1339 // Show online payment link
1340 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1341 $useonlinepayment = 0;
1342 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1343 // Show online payment link
1344 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1345 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1346 $validpaymentmethod = getValidOnlinePaymentMethods('');
1347 $useonlinepayment = count($validpaymentmethod);
1348 }
1349
1350 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1351 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1352 global $langs;
1353
1354 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1355 $servicename = $langs->transnoentities('Online');
1356 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1357 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1358
1359 $pdf->SetXY($this->marge_gauche, $posy);
1360 $pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1361
1362 $posy = $pdf->GetY() + 1;
1363 }
1364 }
1365
1366 // Show payment mode CHQ
1367 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1368 // If payment mode unregulated or payment mode forced to CHQ
1369 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1370 $diffsizetitle = (!getDolGlobalString('PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1371
1372 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1373 $account = new Account($this->db);
1374 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1375
1376 $pdf->SetXY($this->marge_gauche, $posy);
1377 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1378 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
1379 $posy = $pdf->GetY() + 1;
1380
1381 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1382 $pdf->SetXY($this->marge_gauche, $posy);
1383 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1384 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1385 $posy = $pdf->GetY() + 2;
1386 }
1387 }
1388 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1389 $pdf->SetXY($this->marge_gauche, $posy);
1390 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1391 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1392 $posy = $pdf->GetY() + 1;
1393
1394 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1395 $pdf->SetXY($this->marge_gauche, $posy);
1396 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1397 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1398 $posy = $pdf->GetY() + 2;
1399 }
1400 }
1401 }
1402 }
1403
1404 // If payment mode not forced or forced to VIR, show payment with BAN
1405 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1406 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1407 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1408 if ($object->fk_bank > 0) {
1409 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1410 }
1411 $account = new Account($this->db);
1412 $account->fetch($bankid);
1413
1414 $curx = $this->marge_gauche;
1415 $cury = $posy;
1416
1417 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1418
1419 $posy += 2;
1420
1421 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1422 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1423 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1424
1425 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', 0);
1426 }
1427 }
1428 }
1429 }
1430
1431 return $posy;
1432 }
1433
1434
1435 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1436 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1448 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1449 {
1450 // phpcs:enable
1451 global $conf, $mysoc, $hookmanager;
1452
1453 $sign = 1;
1454 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1455 $sign = -1;
1456 }
1457
1458 $default_font_size = pdf_getPDFFontSize($outputlangs);
1459
1460 $outputlangsbis = null;
1461 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1462 $outputlangsbis = new Translate('', $conf);
1463 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1464 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1465 $default_font_size--;
1466 }
1467
1468 $tab2_top = $posy;
1469 $tab2_hl = 4;
1470 $pdf->SetFont('', '', $default_font_size - 1);
1471
1472 // Total table
1473 $col1x = 120;
1474 $col2x = 170;
1475 if ($this->page_largeur < 210) { // To work with US executive format
1476 $col1x -= 15;
1477 $col2x -= 10;
1478 }
1479 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1480
1481 $useborder = 0;
1482 $index = 0;
1483
1484 // Get Total HT
1485 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1486
1487 // Total remise
1488 $total_line_remise = 0;
1489 foreach ($object->lines as $i => $line) {
1490 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1491 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1492 // Gestion remise sous forme de ligne négative
1493 if ($line->total_ht < 0) {
1494 $total_line_remise += -$line->total_ht;
1495 }
1496 }
1497 if ($total_line_remise > 0) {
1498 $pdf->SetFillColor(255, 255, 255);
1499 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1500 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
1501 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1502 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1);
1503
1504 $index++;
1505
1506 // Show total NET before discount
1507 $pdf->SetFillColor(255, 255, 255);
1508 $pdf->SetXY($col1x, $tab2_top);
1509 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
1510 $pdf->SetXY($col2x, $tab2_top);
1511 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1);
1512
1513 $index++;
1514 }
1515
1516 // Total HT
1517 $pdf->SetFillColor(255, 255, 255);
1518 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1519 $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', 1);
1520
1521 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1522 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1523 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1524
1525 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1526 $index++;
1527 $pdf->SetFillColor(255, 255, 255);
1528 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1529 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
1530
1531 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1532 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', 1);
1533 }
1534
1535 // Show VAT by rates and total
1536 $pdf->SetFillColor(248, 248, 248);
1537
1538 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1539
1540 $this->atleastoneratenotnull = 0;
1541 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1542 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1543 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1544 // Nothing to do
1545 } else {
1546 //Local tax 1 before VAT
1547 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1548 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1549 continue;
1550 }
1551
1552 foreach ($localtax_rate as $tvakey => $tvaval) {
1553 if ($tvakey != 0) { // On affiche pas taux 0
1554 //$this->atleastoneratenotnull++;
1555
1556 $index++;
1557 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1558
1559 $tvacompl = '';
1560 if (preg_match('/\*/', (string) $tvakey)) {
1561 $tvakey = str_replace('*', '', (string) $tvakey);
1562 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1563 }
1564
1565 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1566 $totalvat .= ' ';
1567
1568 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1569 $totalvat .= $tvacompl;
1570 } else {
1571 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1572 }
1573
1574 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1575
1576 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1577
1578 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1579 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1580 }
1581 }
1582 }
1583
1584 //Local tax 2 before VAT
1585 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1586 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1587 continue;
1588 }
1589
1590 foreach ($localtax_rate as $tvakey => $tvaval) {
1591 if ($tvakey != 0) { // On affiche pas taux 0
1592 //$this->atleastoneratenotnull++;
1593
1594 $index++;
1595 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1596
1597 $tvacompl = '';
1598 if (preg_match('/\*/', (string) $tvakey)) {
1599 $tvakey = str_replace('*', '', (string) $tvakey);
1600 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1601 }
1602 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1603 $totalvat .= ' ';
1604
1605 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1606 $totalvat .= $tvacompl;
1607 } else {
1608 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1609 }
1610
1611 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1612
1613 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1614
1615 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1616 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1617 }
1618 }
1619 }
1620
1621 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1622 // VAT
1623 foreach ($this->tva_array as $tvakey => $tvaval) {
1624 if ($tvakey != 0) { // On affiche pas taux 0
1625 $this->atleastoneratenotnull++;
1626
1627 $index++;
1628 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1629
1630 $tvacompl = '';
1631 if (preg_match('/\*/', $tvakey)) {
1632 $tvakey = str_replace('*', '', $tvakey);
1633 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1634 }
1635 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1636 $totalvat .= ' ';
1637 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1638 $totalvat .= vatrate($tvaval['vatrate'], true).$tvacompl;
1639 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1640 $totalvat .= $tvaval['vatcode'].$tvacompl;
1641 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1642 $totalvat .= $tvacompl;
1643 } else {
1644 $totalvat .= vatrate($tvaval['vatrate'], true).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1645 }
1646 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1647 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1648 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1649 }
1650 }
1651 }
1652
1653 //Local tax 1 after VAT
1654 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1655 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1656 continue;
1657 }
1658
1659 foreach ($localtax_rate as $tvakey => $tvaval) {
1660 if ($tvakey != 0) { // On affiche pas taux 0
1661 //$this->atleastoneratenotnull++;
1662
1663 $index++;
1664 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1665
1666 $tvacompl = '';
1667 if (preg_match('/\*/', (string) $tvakey)) {
1668 $tvakey = str_replace('*', '', (string) $tvakey);
1669 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1670 }
1671 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1672
1673 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1674 $totalvat .= $tvacompl;
1675 } else {
1676 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1677 }
1678
1679 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1680
1681 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1682
1683 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1684 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1685 }
1686 }
1687 }
1688
1689 //Local tax 2 after VAT
1690 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1691 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1692 continue;
1693 }
1694
1695 foreach ($localtax_rate as $tvakey => $tvaval) {
1696 //$this->atleastoneratenotnull++;
1697
1698 $index++;
1699 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1700
1701 $tvacompl = '';
1702 if (preg_match('/\*/', (string) $tvakey)) {
1703 $tvakey = str_replace('*', '', (string) $tvakey);
1704 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1705 }
1706 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1707
1708 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1709 $totalvat .= $tvacompl;
1710 } else {
1711 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1712 }
1713
1714 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1715
1716 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1717
1718 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1719 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1720 }
1721 }
1722
1723 // Revenue stamp
1724 if (price2num($object->revenuestamp, 'MT') != 0) {
1725 $index++;
1726 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1727 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1728
1729 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1730 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1731 }
1732
1733 // Total TTC
1734 $index++;
1735 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1736 $pdf->SetTextColor(0, 0, 60);
1737 $pdf->SetFillColor(224, 224, 224);
1738 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1739
1740 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1741 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1742
1743 // Retained warranty
1744 if ($object->displayRetainedWarranty()) {
1745 $pdf->SetTextColor(40, 40, 40);
1746 $pdf->SetFillColor(255, 255, 255);
1747
1748 $retainedWarranty = $object->getRetainedWarrantyAmount();
1749 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1750
1751 // Billed - retained warranty
1752 $index++;
1753 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1754 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1755
1756 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1757 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1758
1759 // retained warranty
1760 $index++;
1761 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1762
1763 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
1764 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1765
1766 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1767 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1768 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1769 }
1770 }
1771 }
1772
1773 $pdf->SetTextColor(0, 0, 0);
1774 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1775 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1776 //print "x".$creditnoteamount."-".$depositsamount;exit;
1777 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1778 if (!empty($object->paye)) {
1779 $resteapayer = 0;
1780 }
1781
1782 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1783 // Already paid + Deposits
1784 $index++;
1785 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1786 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1787 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1788 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1789
1790 // Credit note
1791 if ($creditnoteamount) {
1792 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1793 $index++;
1794 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1795 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1796 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1797 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1798 }
1799
1800 // Escompte
1801 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1802 $index++;
1803 $pdf->SetFillColor(255, 255, 255);
1804
1805 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1806 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1807 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1808 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1809
1810 $resteapayer = 0;
1811 }
1812
1813 $index++;
1814 $pdf->SetTextColor(0, 0, 60);
1815 $pdf->SetFillColor(224, 224, 224);
1816 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1817 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1818 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1819 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1820
1821 $pdf->SetFont('', '', $default_font_size - 1);
1822 $pdf->SetTextColor(0, 0, 0);
1823 }
1824
1825 $index++;
1826
1827 if (getDolGlobalString("BILL_TEXT_TOTAL_FOOTER")) {
1828 $index++;
1829 $index++;
1830 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1831 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $conf->global->BILL_TEXT_TOTAL_FOOTER, 0, 'L', 0);
1832 }
1833
1834 return ($tab2_top + ($tab2_hl * $index));
1835 }
1836
1837 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1851 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1852 {
1853 global $conf;
1854
1855 // Force to disable hidetop and hidebottom
1856 $hidebottom = 0;
1857 if ($hidetop) {
1858 $hidetop = -1;
1859 }
1860
1861 $currency = !empty($currency) ? $currency : $conf->currency;
1862 $default_font_size = pdf_getPDFFontSize($outputlangs);
1863
1864 // Amount in (at tab_top - 1)
1865 $pdf->SetTextColor(0, 0, 0);
1866 $pdf->SetFont('', '', $default_font_size - 2);
1867
1868 if (empty($hidetop)) {
1869 // Show category of operations
1870 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1871 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1872 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1873 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1874 }
1875
1876 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1877 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1878 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1879
1880 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1881 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1882 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
1883 }
1884 }
1885
1886 $pdf->SetDrawColor(128, 128, 128);
1887 $pdf->SetFont('', '', $default_font_size - 1);
1888
1889 // Output Rect
1890 $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
1891
1892 if (empty($hidetop)) {
1893 $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
1894
1895 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1896 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1897 }
1898
1899 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
1900 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1901 if (empty($hidetop)) {
1902 //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1903 //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1904 }
1905 }
1906
1907 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1908 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1909 if (empty($hidetop)) {
1910 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1911 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1912 }
1913 }
1914
1915 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1916 if (empty($hidetop)) {
1917 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1918 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1919 }
1920
1921 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1922 if (empty($hidetop)) {
1923 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1924 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1925 }
1926
1927 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1928 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1929 if (empty($hidetop)) {
1930 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1931 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1932 }
1933 }
1934
1935 if ($this->atleastonediscount) {
1936 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1937 if (empty($hidetop)) {
1938 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1939 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1940 }
1941 }
1942
1943 if ($this->situationinvoice) {
1944 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1945 if (empty($hidetop)) {
1946 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1947 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("ProgressShort"), '', 'C');
1948 }
1949 }
1950
1951 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1952 if (empty($hidetop)) {
1953 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1954 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1955 }
1956 }
1957
1958 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1969 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
1970 {
1971 // phpcs:enable
1972 global $conf, $langs;
1973
1974 $ltrdirection = 'L';
1975 if ($outputlangs->trans("DIRECTION") == 'rtl') {
1976 $ltrdirection = 'R';
1977 }
1978
1979 // Load traductions files required by page
1980 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1981
1982 $default_font_size = pdf_getPDFFontSize($outputlangs);
1983
1984 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1985
1986 $pdf->SetTextColor(0, 0, 60);
1987 $pdf->SetFont('', 'B', $default_font_size + 3);
1988
1989 $w = 110;
1990
1991 $posy = $this->marge_haute;
1992 $posx = $this->page_largeur - $this->marge_droite - $w;
1993
1994 $pdf->SetXY($this->marge_gauche, $posy);
1995
1996 // Logo
1997 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1998 if ($this->emetteur->logo) {
1999 $logodir = $conf->mycompany->dir_output;
2000 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2001 $logodir = $conf->mycompany->multidir_output[$object->entity];
2002 }
2003 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2004 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2005 } else {
2006 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2007 }
2008 if (is_readable($logo)) {
2009 $height = pdf_getHeightForLogo($logo);
2010 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2011 } else {
2012 $pdf->SetTextColor(200, 0, 0);
2013 $pdf->SetFont('', 'B', $default_font_size - 2);
2014 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2015 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2016 }
2017 } else {
2018 $text = $this->emetteur->name;
2019 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2020 }
2021 }
2022
2023 $pdf->SetFont('', 'B', $default_font_size + 3);
2024 $pdf->SetXY($posx, $posy);
2025 $pdf->SetTextColor(0, 0, 60);
2026 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2027 if ($object->type == 1) {
2028 $title = $outputlangs->transnoentities("InvoiceReplacement");
2029 }
2030 if ($object->type == 2) {
2031 $title = $outputlangs->transnoentities("InvoiceAvoir");
2032 }
2033 if ($object->type == 3) {
2034 $title = $outputlangs->transnoentities("InvoiceDeposit");
2035 }
2036 if ($object->type == 4) {
2037 $title = $outputlangs->transnoentities("InvoiceProForma");
2038 }
2039 if ($this->situationinvoice) {
2040 $langs->loadLangs(array("other"));
2041 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2042 }
2043 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2044 $title .= ' - ';
2045 if ($object->type == 0) {
2046 if ($this->situationinvoice) {
2047 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2048 }
2049 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2050 } elseif ($object->type == 1) {
2051 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2052 } elseif ($object->type == 2) {
2053 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2054 } elseif ($object->type == 3) {
2055 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2056 } elseif ($object->type == 4) {
2057 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2058 }
2059 }
2060 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2061 if ($object->status == $object::STATUS_DRAFT) {
2062 $pdf->SetTextColor(128, 0, 0);
2063 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2064 }
2065
2066 $pdf->MultiCell($w, 3, $title, '', 'R');
2067
2068 $pdf->SetFont('', 'B', $default_font_size);
2069
2070 /*
2071 $posy += 5;
2072 $pdf->SetXY($posx, $posy);
2073 $pdf->SetTextColor(0, 0, 60);
2074 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2075 if ($object->status == $object::STATUS_DRAFT) {
2076 $pdf->SetTextColor(128, 0, 0);
2077 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2078 }
2079 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2080
2081 $posy += 3;
2082 $pdf->SetFont('', '', $default_font_size - 2);
2083
2084 if ($object->ref_customer) {
2085 $posy += 4;
2086 $pdf->SetXY($posx, $posy);
2087 $pdf->SetTextColor(0, 0, 60);
2088 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_customer), '', 'R');
2089 }
2090
2091 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2092 $object->fetchProject();
2093 if (!empty($object->project->ref)) {
2094 $posy += 3;
2095 $pdf->SetXY($posx, $posy);
2096 $pdf->SetTextColor(0, 0, 60);
2097 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2098 }
2099 }
2100
2101 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2102 $object->fetchProject();
2103 if (!empty($object->project->ref)) {
2104 $outputlangs->load("projects");
2105 $posy += 3;
2106 $pdf->SetXY($posx, $posy);
2107 $pdf->SetTextColor(0, 0, 60);
2108 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2109 }
2110 }
2111
2112 $objectidnext = $object->getIdReplacingInvoice('validated');
2113 if ($object->type == 0 && $objectidnext) {
2114 $objectreplacing = new Facture($this->db);
2115 $objectreplacing->fetch($objectidnext);
2116
2117 $posy += 3;
2118 $pdf->SetXY($posx, $posy);
2119 $pdf->SetTextColor(0, 0, 60);
2120 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2121 }
2122 if ($object->type == 1) {
2123 $objectreplaced = new Facture($this->db);
2124 $objectreplaced->fetch($object->fk_facture_source);
2125
2126 $posy += 4;
2127 $pdf->SetXY($posx, $posy);
2128 $pdf->SetTextColor(0, 0, 60);
2129 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2130 }
2131 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2132 $objectreplaced = new Facture($this->db);
2133 $objectreplaced->fetch($object->fk_facture_source);
2134
2135 $posy += 3;
2136 $pdf->SetXY($posx, $posy);
2137 $pdf->SetTextColor(0, 0, 60);
2138 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2139 }
2140
2141 $posy += 4;
2142 $pdf->SetXY($posx, $posy);
2143 $pdf->SetTextColor(0, 0, 60);
2144 $title = $outputlangs->transnoentities("DateInvoice");
2145 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2146 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2147 }
2148 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2149
2150 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2151 $posy += 4;
2152 $pdf->SetXY($posx, $posy);
2153 $pdf->SetTextColor(0, 0, 60);
2154 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2155 }
2156
2157 if ($object->type != 2) {
2158 $posy += 3;
2159 $pdf->SetXY($posx, $posy);
2160 $pdf->SetTextColor(0, 0, 60);
2161 $title = $outputlangs->transnoentities("DateDue");
2162 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2163 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2164 }
2165 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2166 }
2167
2168 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2169 $posy += 3;
2170 $pdf->SetXY($posx, $posy);
2171 $pdf->SetTextColor(0, 0, 60);
2172 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2173 }
2174
2175 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2176 $posy += 3;
2177 $pdf->SetXY($posx, $posy);
2178 $pdf->SetTextColor(0, 0, 60);
2179 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
2180 }
2181
2182 // Get contact
2183 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2184 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2185 if (count($arrayidcontact) > 0) {
2186 $usertmp = new User($this->db);
2187 $usertmp->fetch($arrayidcontact[0]);
2188 $posy += 4;
2189 $pdf->SetXY($posx, $posy);
2190 $pdf->SetTextColor(0, 0, 60);
2191 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2192 }
2193 }
2194
2195 $posy += 1;
2196
2197 $top_shift = 0;
2198 // Show list of linked objects
2199 $current_y = $pdf->getY();
2200 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2201 if ($current_y < $pdf->getY()) {
2202 $top_shift = $pdf->getY() - $current_y;
2203 }
2204
2205 if ($showaddress) {
2206 // Sender properties
2207 $carac_emetteur = '';
2208 // Add internal contact of object if defined
2209 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2210 if (count($arrayidcontact) > 0) {
2211 $object->fetch_user($arrayidcontact[0]);
2212 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2213 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2214 $carac_emetteur .= "\n";
2215 }
2216
2217 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2218
2219 // Show sender
2220 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2221 $posy += $top_shift;
2222 $posx = $this->marge_gauche;
2223 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2224 $posx = $this->page_largeur - $this->marge_droite - 80;
2225 }
2226
2227 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2228 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2229
2230
2231 // Show sender frame
2232 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2233 $pdf->SetTextColor(0, 0, 0);
2234 $pdf->SetFont('', '', $default_font_size - 2);
2235 $pdf->SetXY($posx, $posy - 5);
2236 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2237 $pdf->SetXY($posx, $posy);
2238 $pdf->SetFillColor(230, 230, 230);
2239 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2240 $pdf->SetTextColor(0, 0, 60);
2241 }
2242
2243 // Show sender name
2244 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2245 $pdf->SetXY($posx + 2, $posy + 3);
2246 $pdf->SetFont('', 'B', $default_font_size);
2247 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2248 $posy = $pdf->getY();
2249 }
2250
2251 // Show sender information
2252 $pdf->SetXY($posx + 2, $posy);
2253 $pdf->SetFont('', '', $default_font_size - 1);
2254 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2255
2256
2257 // If BILLING contact defined on invoice, we use it
2258 $usecontact = false;
2259 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2260 if (count($arrayidcontact) > 0) {
2261 $usecontact = true;
2262 $result = $object->fetch_contact($arrayidcontact[0]);
2263 }
2264
2265 // Recipient name
2266 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2267 $thirdparty = $object->contact;
2268 } else {
2269 $thirdparty = $object->thirdparty;
2270 }
2271
2272 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2273
2274 $mode = 'target';
2275 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2276
2277 // Show recipient
2278 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2279 if ($this->page_largeur < 210) {
2280 $widthrecbox = 84; // To work with US executive format
2281 }
2282 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2283 $posy += $top_shift;
2284 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2285 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2286 $posx = $this->marge_gauche;
2287 }
2288
2289 // Show recipient frame
2290 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2291 $pdf->SetTextColor(0, 0, 0);
2292 $pdf->SetFont('', '', $default_font_size - 2);
2293 $pdf->SetXY($posx + 2, $posy - 5);
2294 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2295 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2296 }
2297
2298 // Show recipient name
2299 $pdf->SetXY($posx + 2, $posy + 3);
2300 $pdf->SetFont('', 'B', $default_font_size);
2301 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2302 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2303
2304 $posy = $pdf->getY();
2305
2306 // Show recipient information
2307 $pdf->SetFont('', '', $default_font_size - 1);
2308 $pdf->SetXY($posx + 2, $posy);
2309 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2310 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2311
2312 // Show shipping/delivery address
2313 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2314 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2315
2316 if (!empty($idaddressshipping)) {
2317 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2318 $companystatic = new Societe($this->db);
2319 $companystatic->fetch($object->contact->fk_soc);
2320 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2321 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, ($usecontact ? 1 : 0), 'target', $object);
2322 } else {
2323 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2324 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2325 }
2326 if (!empty($carac_client_shipping)) {
2327 $posy += $hautcadre;
2328
2329 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2330
2331 // Show shipping frame
2332 $pdf->SetXY($posx + 2, $posy - 5);
2333 $pdf->SetFont('', '', $default_font_size - 2);
2334 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2335 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2336
2337 // Show shipping name
2338 $pdf->SetXY($posx + 2, $posy + 3);
2339 $pdf->SetFont('', 'B', $default_font_size);
2340 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2341
2342 $posy = $pdf->getY();
2343
2344 // Show shipping information
2345 $pdf->SetXY($posx + 2, $posy);
2346 $pdf->SetFont('', '', $default_font_size - 1);
2347 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2348
2349 $top_shift += $hautcadre + 10;
2350 }
2351 }
2352 }
2353
2354 $pdf->SetTextColor(0, 0, 0);
2355
2356 return $top_shift;
2357 }
2358
2359 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2370 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2371 {
2372 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2373
2374 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);
2375 }
2376}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:2648
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:1442
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2382
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0)
Return line total amount discount.
Definition pdf.lib.php:2678
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
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:1027
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2000
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2331
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1938
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:729
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1405
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:850
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
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:434
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2245
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2288
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2085
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:765
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:386
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152