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