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