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