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