dolibarr 20.0.0
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->statut == $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 = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->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') ? '' : $conf->global->CERTIFICATE_CRT;
382 }
383 if (!$certprivate) {
384 $certprivate = !getDolGlobalString('CERTIFICATE_CRT_PRIVATE') ? '' : $conf->global->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 global $conf;
1086
1087 $sign = 1;
1088 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1089 $sign = -1;
1090 }
1091
1092 $tab3_posx = 120;
1093 $tab3_top = $posy + 8;
1094 $tab3_width = 80;
1095 $tab3_height = 4;
1096 if ($this->page_largeur < 210) { // To work with US executive format
1097 $tab3_posx -= 15;
1098 }
1099
1100 $default_font_size = pdf_getPDFFontSize($outputlangs);
1101
1102 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1103 if ($object->type == 2) {
1104 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1105 }
1106
1107 $pdf->SetFont('', '', $default_font_size - 3);
1108 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1109 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1110
1111 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1112
1113 $pdf->SetFont('', '', $default_font_size - 4);
1114 $pdf->SetXY($tab3_posx, $tab3_top);
1115 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1116 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1117 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1118 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1119 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1120 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1121 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1122
1123 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1124
1125 $y = 0;
1126
1127 $pdf->SetFont('', '', $default_font_size - 4);
1128
1129
1130 // Loop on each discount available (deposits and credit notes and excess of payment included)
1131 $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,";
1132 $sql .= " re.description, re.fk_facture_source,";
1133 $sql .= " f.type, f.datef";
1134 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1135 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1136 $resql = $this->db->query($sql);
1137 if ($resql) {
1138 $num = $this->db->num_rows($resql);
1139 $i = 0;
1140 $invoice = new Facture($this->db);
1141 while ($i < $num) {
1142 $y += 3;
1143 $obj = $this->db->fetch_object($resql);
1144
1145 if ($obj->type == 2) {
1146 $text = $outputlangs->transnoentities("CreditNote");
1147 } elseif ($obj->type == 3) {
1148 $text = $outputlangs->transnoentities("Deposit");
1149 } elseif ($obj->type == 0) {
1150 $text = $outputlangs->transnoentities("ExcessReceived");
1151 } else {
1152 $text = $outputlangs->transnoentities("UnknownType");
1153 }
1154
1155 $invoice->fetch($obj->fk_facture_source);
1156
1157 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1158 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1159 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1160 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1161 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1162 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1163 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1164 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1165
1166 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1167
1168 $i++;
1169 }
1170 } else {
1171 $this->error = $this->db->lasterror();
1172 return -1;
1173 }
1174
1175 // Loop on each payment
1176 // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
1177 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1178 $sql .= " cp.code";
1179 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1180 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1181 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1182 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1183 $sql .= " ORDER BY p.datep";
1184
1185 $resql = $this->db->query($sql);
1186 if ($resql) {
1187 $num = $this->db->num_rows($resql);
1188 $i = 0;
1189 $y += 3;
1190 $maxY = $y;
1191 while ($i < $num) {
1192 $row = $this->db->fetch_object($resql);
1193 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1194 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1195 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1196 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1197 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1198 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1199
1200 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1201 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1202 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1203 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1204 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1205 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1206 $y += 3;
1207 $i++;
1208 }
1209
1210 return $tab3_top + $y + 3;
1211 } else {
1212 $this->error = $this->db->lasterror();
1213 return -1;
1214 }
1215 }
1216
1217
1228 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1229 {
1230 global $conf, $mysoc, $hookmanager;
1231
1232 $default_font_size = pdf_getPDFFontSize($outputlangs);
1233
1234 $pdf->SetFont('', '', $default_font_size - 1);
1235
1236 // If France, show VAT mention if not applicable
1237 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1238 $pdf->SetFont('', '', $default_font_size - 2);
1239 $pdf->SetXY($this->marge_gauche, $posy);
1240 if ($mysoc->forme_juridique_code == 92) {
1241 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1242 } else {
1243 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1244 }
1245
1246 $posy = $pdf->GetY() + 4;
1247 }
1248
1249 $posxval = 52; // Position of values of properties shown on left side
1250 $posxend = 110; // End of x for text on left side
1251 if ($this->page_largeur < 210) { // To work with US executive format
1252 $posxend -= 10;
1253 }
1254
1255 // Show payments conditions
1256 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1257 $pdf->SetFont('', '', $default_font_size - 2);
1258 $pdf->SetXY($this->marge_gauche, $posy);
1259 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1260 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1261
1262 $pdf->SetFont('', '', $default_font_size - 2);
1263 $pdf->SetXY($posxval, $posy);
1264 $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);
1265 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1266 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1267
1268 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1269 }
1270
1271 // Show category of operations
1272 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1273 $pdf->SetFont('', '', $default_font_size - 2);
1274 $pdf->SetXY($this->marge_gauche, $posy);
1275 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1276 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1277
1278 $pdf->SetFont('', '', $default_font_size - 2);
1279 $pdf->SetXY($posxval, $posy);
1280 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1281 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1282
1283 $posy = $pdf->GetY() + 3; // for 2 lines
1284 }
1285
1286 if ($object->type != 2) {
1287 // Check a payment mode is defined
1288 if (empty($object->mode_reglement_code)
1289 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1290 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1291 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1292 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1293 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1294 // Avoid having any valid PDF with setup that is not complete
1295 $outputlangs->load("errors");
1296
1297 $pdf->SetXY($this->marge_gauche, $posy);
1298 $pdf->SetTextColor(200, 0, 0);
1299 $pdf->SetFont('', '', $default_font_size - 2);
1300 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1301 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
1302 $pdf->SetTextColor(0, 0, 0);
1303
1304 $posy = $pdf->GetY() + 1;
1305 }
1306
1307 // Show payment mode
1308 if (!empty($object->mode_reglement_code)
1309 && $object->mode_reglement_code != 'CHQ'
1310 && $object->mode_reglement_code != 'VIR') {
1311 $pdf->SetFont('', '', $default_font_size - 2);
1312 $pdf->SetXY($this->marge_gauche, $posy);
1313 $titre = $outputlangs->transnoentities("PaymentMode").':';
1314 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1315
1316 $pdf->SetFont('', '', $default_font_size - 2);
1317 $pdf->SetXY($posxval, $posy);
1318 $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);
1319
1320 //#21654: add account number used for the debit
1321 if ($object->mode_reglement_code == "PRE") {
1322 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1323 $bac = new CompanyBankAccount($this->db);
1324 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1325 $bac->fetch(0, '', $object->thirdparty->id);
1326 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1327 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1328 }
1329
1330 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1331
1332 $posy = $pdf->GetY();
1333 }
1334
1335 // Show if Option VAT debit option is on also if transmitter is french
1336 // Decret n°2099-1299 2022-10-07
1337 // French mention : "Option pour le paiement de la taxe d'après les débits"
1338 if ($this->emetteur->country_code == 'FR') {
1339 if (getDolGlobalInt('TAX_MODE') == 1) {
1340 $pdf->SetXY($this->marge_gauche, $posy);
1341 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1342
1343 $posy = $pdf->GetY() + 1;
1344 }
1345 }
1346
1347 // Show online payment link
1348 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1349 $useonlinepayment = 0;
1350 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1351 // Show online payment link
1352 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1353 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1354 $validpaymentmethod = getValidOnlinePaymentMethods('');
1355 $useonlinepayment = count($validpaymentmethod);
1356 }
1357
1358
1359 if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
1360 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1361 global $langs;
1362
1363 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1364 $servicename = $langs->transnoentities('Online');
1365 $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
1366 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1367
1368 $pdf->SetXY($this->marge_gauche, $posy);
1369 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1370
1371 $posy = $pdf->GetY() + 1;
1372 }
1373 }
1374
1375 // Show payment mode CHQ
1376 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1377 // If payment mode unregulated or payment mode forced to CHQ
1378 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1379 $diffsizetitle = (!getDolGlobalString('PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1380
1381 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1382 $account = new Account($this->db);
1383 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1384
1385 $pdf->SetXY($this->marge_gauche, $posy);
1386 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1387 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
1388 $posy = $pdf->GetY() + 1;
1389
1390 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1391 $pdf->SetXY($this->marge_gauche, $posy);
1392 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1393 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1394 $posy = $pdf->GetY() + 2;
1395 }
1396 }
1397 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1398 $pdf->SetXY($this->marge_gauche, $posy);
1399 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1400 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1401 $posy = $pdf->GetY() + 1;
1402
1403 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1404 $pdf->SetXY($this->marge_gauche, $posy);
1405 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1406 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1407 $posy = $pdf->GetY() + 2;
1408 }
1409 }
1410 }
1411 }
1412
1413 // If payment mode not forced or forced to VIR, show payment with BAN
1414 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1415 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1416 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1417 if ($object->fk_bank > 0) {
1418 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1419 }
1420 $account = new Account($this->db);
1421 $account->fetch($bankid);
1422
1423 $curx = $this->marge_gauche;
1424 $cury = $posy;
1425
1426 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1427
1428 $posy += 2;
1429
1430 // SHOW EPC QR CODE
1431 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == 'bottom') {
1432 $qrPosX = 120;
1433 $qrPosY = $posy;
1434 $qrCodeColor = array('25', '25', '25');
1435 $styleQr = array(
1436 'border' => false,
1437 'padding' => 0,
1438 'fgcolor' => $qrCodeColor,
1439 'bgcolor' => false, //array(255,255,255)
1440 'module_width' => 1, // width of a single module in points
1441 'module_height' => 1 // height of a single module in points
1442 );
1443
1444 $EPCQrCodeString = $object->buildEPCQrCodeString();
1445 $pdf->write2DBarcode($EPCQrCodeString, 'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr, 'N');
1446
1447 $pdf->SetXY($qrPosX + 5, $posy);
1448 $pdf->SetFont('', '', $default_font_size - 5);
1449 $pdf->MultiCell(30, 3, $langs->trans("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0);
1450 $posy = $pdf->GetY() + 2;
1451 }
1452 }
1453 }
1454 }
1455
1456 return $posy;
1457 }
1458
1459
1471 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1472 {
1473 global $conf, $mysoc, $hookmanager;
1474
1475 $sign = 1;
1476 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1477 $sign = -1;
1478 }
1479
1480 $default_font_size = pdf_getPDFFontSize($outputlangs);
1481
1482 $tab2_top = $posy;
1483 $tab2_hl = 4;
1484 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1485 $pdf->SetFont('', '', $default_font_size - 2);
1486 } else {
1487 $pdf->SetFont('', '', $default_font_size - 1);
1488 }
1489
1490 // Total table
1491 $col1x = 120;
1492 $col2x = 170;
1493 if ($this->page_largeur < 210) { // To work with US executive format
1494 $col1x -= 15;
1495 $col2x -= 10;
1496 }
1497 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1498
1499 $useborder = 0;
1500 $index = 0;
1501
1502 // Add trigger to allow to edit $object
1503 $parameters = array(
1504 'object' => &$object,
1505 'outputlangs' => $outputlangs,
1506 );
1507 $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1508
1509 // overall percentage of advancement
1510 $percent = 0;
1511 $i = 0;
1512 foreach ($object->lines as $line) {
1513 if ($line->product_type != 9) {
1514 $percent += $line->situation_percent;
1515 $i++;
1516 }
1517 }
1518
1519 if (!empty($i)) {
1520 $avancementGlobal = $percent / $i;
1521 } else {
1522 $avancementGlobal = 0;
1523 }
1524
1525 $object->fetchPreviousNextSituationInvoice();
1526 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1527
1528 $total_a_payer = 0;
1529 $total_a_payer_ttc = 0;
1530 foreach ($TPreviousIncoice as &$fac) {
1531 $total_a_payer += $fac->total_ht;
1532 $total_a_payer_ttc += $fac->total_ttc;
1533 }
1534 $total_a_payer += $object->total_ht;
1535 $total_a_payer_ttc += $object->total_ttc;
1536
1537 if (!empty($avancementGlobal)) {
1538 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1539 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1540 } else {
1541 $total_a_payer = 0;
1542 $total_a_payer_ttc = 0;
1543 }
1544
1545 $i = 1;
1546 if (!empty($TPreviousIncoice)) {
1547 $pdf->setY($tab2_top);
1548 $posy = $pdf->GetY();
1549
1550 foreach ($TPreviousIncoice as &$fac) {
1551 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1552 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1553 $pdf->addPage();
1554 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1555 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1556 $pdf->setY($this->tab_top_newpage);
1557 } else {
1558 $pdf->setY($this->marge_haute);
1559 }
1560 $posy = $pdf->GetY();
1561 }
1562
1563 // Cumulate preceding VAT
1564 $index++;
1565 $pdf->SetFillColor(255, 255, 255);
1566 $pdf->SetXY($col1x, $posy);
1567 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1568
1569 $pdf->SetXY($col2x, $posy);
1570
1571 $facSign = '';
1572 if ($i > 1) {
1573 $facSign = $fac->total_ht >= 0 ? '+' : '';
1574 }
1575
1576 $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1577
1578 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1579
1580 $i++;
1581 $posy += $tab2_hl;
1582
1583 $pdf->setY($posy);
1584 }
1585
1586 // Display current total
1587 $pdf->SetFillColor(255, 255, 255);
1588 $pdf->SetXY($col1x, $posy);
1589 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1590
1591 $pdf->SetXY($col2x, $posy);
1592 $facSign = '';
1593 if ($i > 1) {
1594 $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1595 }
1596
1597 if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1598 $facSign = '-'; // les avoirs
1599 }
1600
1601
1602 $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1603 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1604
1605 $posy += $tab2_hl;
1606
1607 // Display all total
1608 $pdf->SetFont('', '', $default_font_size - 1);
1609 $pdf->SetFillColor(255, 255, 255);
1610 $pdf->SetXY($col1x, $posy);
1611 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", $avancementGlobal), 0, 'L', 1);
1612
1613 $pdf->SetXY($col2x, $posy);
1614 $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', 1);
1615 $pdf->SetFont('', '', $default_font_size - 2);
1616
1617 $posy += $tab2_hl;
1618
1619 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1620 $pdf->addPage();
1621 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1622 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1623 $pdf->setY($this->tab_top_newpage);
1624 } else {
1625 $pdf->setY($this->marge_haute);
1626 }
1627
1628 $posy = $pdf->GetY();
1629 }
1630
1631 $tab2_top = $posy;
1632 $index = 0;
1633
1634 $tab2_top += 3;
1635 }
1636
1637
1638 // Get Total HT
1639 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1640
1641 // Total remise
1642 $total_line_remise = 0;
1643 foreach ($object->lines as $i => $line) {
1644 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1645 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1646 // Gestion remise sous forme de ligne négative
1647 if ($line->total_ht < 0) {
1648 $total_line_remise += -$line->total_ht;
1649 }
1650 }
1651 if ($total_line_remise > 0) {
1652 if (getDolGlobalString('MAIN_SHOW_AMOUNT_DISCOUNT')) {
1653 $pdf->SetFillColor(255, 255, 255);
1654 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
1656 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1657 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1);
1658
1659 $index++;
1660 }
1661 // Show total NET before discount
1662 if (getDolGlobalString('MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT')) {
1663 $pdf->SetFillColor(255, 255, 255);
1664 $pdf->SetXY($col1x, $tab2_top);
1665 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
1666 $pdf->SetXY($col2x, $tab2_top);
1667 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1);
1668
1669 $index++;
1670 }
1671 }
1672
1673 // Total HT
1674 $pdf->SetFillColor(255, 255, 255);
1675 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1676 $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);
1677
1678 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1679 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1680 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1681
1682 // Show VAT by rates and total
1683 $pdf->SetFillColor(248, 248, 248);
1684
1685 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1686
1687 $this->atleastoneratenotnull = 0;
1688 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1689 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1690 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1691 // Nothing to do
1692 } else {
1693 //Local tax 1 before VAT
1694 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1695 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1696 continue;
1697 }
1698
1699 foreach ($localtax_rate as $tvakey => $tvaval) {
1700 if ($tvakey != 0) { // On affiche pas taux 0
1701 //$this->atleastoneratenotnull++;
1702
1703 $index++;
1704 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1705
1706 $tvacompl = '';
1707 if (preg_match('/\*/', (string) $tvakey)) {
1708 $tvakey = str_replace('*', '', (string) $tvakey);
1709 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1710 }
1711
1712 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1713 $totalvat .= ' ';
1714
1715 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1716 $totalvat .= $tvacompl;
1717 } else {
1718 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1719 }
1720
1721 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1722
1723 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1724
1725 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1726 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1727 }
1728 }
1729 }
1730
1731 //Local tax 2 before VAT
1732 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1733 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1734 continue;
1735 }
1736
1737 foreach ($localtax_rate as $tvakey => $tvaval) {
1738 if ($tvakey != 0) { // On affiche pas taux 0
1739 //$this->atleastoneratenotnull++;
1740
1741 $index++;
1742 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1743
1744 $tvacompl = '';
1745 if (preg_match('/\*/', (string) $tvakey)) {
1746 $tvakey = str_replace('*', '', (string) $tvakey);
1747 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1748 }
1749 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1750 $totalvat .= ' ';
1751
1752 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1753 $totalvat .= $tvacompl;
1754 } else {
1755 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1756 }
1757
1758 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1759
1760 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1761
1762 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1763 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1764 }
1765 }
1766 }
1767
1768 // Situations totals might be wrong on huge amounts with old mode 1
1769 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1770 $sum_pdf_tva = 0;
1771 foreach ($this->tva as $tvakey => $tvaval) {
1772 $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1773 }
1774
1775 if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1776 if (!empty($sum_pdf_tva)) {
1777 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1778 } else {
1779 $coef_fix_tva = 1;
1780 }
1781
1782
1783 foreach ($this->tva as $tvakey => $tvaval) {
1784 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1785 }
1786 foreach ($this->tva_array as $tvakey => $tvaval) {
1787 $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
1788 }
1789 }
1790 }
1791
1792 // VAT
1793 foreach ($this->tva_array as $tvakey => $tvaval) {
1794 if ($tvakey != 0) { // On affiche pas taux 0
1795 $this->atleastoneratenotnull++;
1796
1797 $index++;
1798 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1799
1800 $tvacompl = '';
1801 if (preg_match('/\*/', $tvakey)) {
1802 $tvakey = str_replace('*', '', $tvakey);
1803 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1804 }
1805 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1806 $totalvat .= ' ';
1807 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1808 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1809 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1810 $totalvat .= $tvaval['vatcode'].$tvacompl;
1811 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1812 $totalvat .= $tvacompl;
1813 } else {
1814 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1815 }
1816 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1817
1818 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1819 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1820 }
1821 }
1822
1823 //Local tax 1 after VAT
1824 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1825 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1826 continue;
1827 }
1828
1829 foreach ($localtax_rate as $tvakey => $tvaval) {
1830 if ($tvakey != 0) { // On affiche pas taux 0
1831 //$this->atleastoneratenotnull++;
1832
1833 $index++;
1834 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1835
1836 $tvacompl = '';
1837 if (preg_match('/\*/', (string) $tvakey)) {
1838 $tvakey = str_replace('*', '', (string) $tvakey);
1839 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1840 }
1841 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1842 $totalvat .= ' ';
1843
1844 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1845 $totalvat .= $tvacompl;
1846 } else {
1847 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1848 }
1849
1850 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1851
1852 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1853
1854 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1855 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1856 }
1857 }
1858 }
1859
1860 //Local tax 2 after VAT
1861 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1862 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1863 continue;
1864 }
1865
1866 foreach ($localtax_rate as $tvakey => $tvaval) {
1867 // retrieve global local tax
1868 if ($tvakey != 0) { // On affiche pas taux 0
1869 //$this->atleastoneratenotnull++;
1870
1871 $index++;
1872 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1873
1874 $tvacompl = '';
1875 if (preg_match('/\*/', (string) $tvakey)) {
1876 $tvakey = str_replace('*', '', (string) $tvakey);
1877 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1878 }
1879 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1880 $totalvat .= ' ';
1881
1882 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1883 $totalvat .= $tvacompl;
1884 } else {
1885 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1886 }
1887
1888 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1889
1890 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1891
1892 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1893 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1894 }
1895 }
1896 }
1897
1898 // Revenue stamp
1899 if (price2num($object->revenuestamp, 'MT') != 0) {
1900 $index++;
1901 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1902 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
1903
1904 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1905 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1906 }
1907
1908 // Total TTC
1909 $index++;
1910 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1911 $pdf->SetTextColor(0, 0, 60);
1912 $pdf->SetFillColor(224, 224, 224);
1913 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
1914
1915 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1916 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1917
1918
1919 // Retained warranty
1920 if ($object->displayRetainedWarranty()) {
1921 $pdf->SetTextColor(40, 40, 40);
1922 $pdf->SetFillColor(255, 255, 255);
1923
1924 $retainedWarranty = $object->getRetainedWarrantyAmount();
1925 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1926
1927 // Billed - retained warranty
1928 $index++;
1929 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1930 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1931
1932 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1933 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1934
1935 // retained warranty
1936 $index++;
1937 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1938
1939 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
1940 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1941
1942 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1943 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1944 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1945 }
1946 }
1947 }
1948
1949 $pdf->SetTextColor(0, 0, 0);
1950
1951 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1952 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1953
1954 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1955 if (!empty($object->paye)) {
1956 $resteapayer = 0;
1957 }
1958
1959 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1960 // Already paid + Deposits
1961 $index++;
1962 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1963 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
1964 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1965 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1966
1967 // Credit note
1968 if ($creditnoteamount) {
1969 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1970 $labeltouse .= (is_object($outputlangsbis) ? (' / '.(($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes"))) : '');
1971 $index++;
1972 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1973 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1974 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1975 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1976 }
1977
1978 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1979 $index++;
1980 $pdf->SetFillColor(255, 255, 255);
1981
1982 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1983 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
1984 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1985 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'), 0, $outputlangs), $useborder, 'R', 1);
1986
1987 $resteapayer = 0;
1988 }
1989
1990 $index++;
1991 $pdf->SetTextColor(0, 0, 60);
1992 $pdf->SetFillColor(224, 224, 224);
1993 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1994 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
1995 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1996 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1997
1998 $pdf->SetFont('', '', $default_font_size - 1);
1999 $pdf->SetTextColor(0, 0, 0);
2000 }
2001
2002 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2003
2004 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2005 if ($reshook < 0) {
2006 $this->error = $hookmanager->error;
2007 $this->errors = $hookmanager->errors;
2008 }
2009
2010 $index++;
2011 return ($tab2_top + ($tab2_hl * $index));
2012 }
2013
2014 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2022 public static function liste_modeles($db, $maxfilenamelength = 0)
2023 {
2024 // phpcs:enable
2025 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2026 }
2027
2028 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2043 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2044 {
2045 global $conf;
2046
2047 // Force to disable hidetop and hidebottom
2048 $hidebottom = 0;
2049 if ($hidetop) {
2050 $hidetop = -1;
2051 }
2052
2053 $currency = !empty($currency) ? $currency : $conf->currency;
2054 $default_font_size = pdf_getPDFFontSize($outputlangs);
2055
2056 // Amount in (at tab_top - 1)
2057 $pdf->SetTextColor(0, 0, 0);
2058 $pdf->SetFont('', '', $default_font_size - 2);
2059
2060 if (empty($hidetop)) {
2061 // Show category of operations
2062 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2063 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2064 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2065 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2066 }
2067
2068 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2069 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2070 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2071 }
2072
2073 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2074 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2075
2076 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2077 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2078 $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')));
2079 }
2080 }
2081
2082 $pdf->SetDrawColor(128, 128, 128);
2083 $pdf->SetFont('', '', $default_font_size - 1);
2084
2085 // Output Rect
2086 $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
2087
2088
2089 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2090
2091 if (empty($hidetop)) {
2092 $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
2093 }
2094 }
2095
2096 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2107 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2108 {
2109 // phpcs:enable
2110 global $conf, $langs;
2111
2112 $ltrdirection = 'L';
2113 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2114 $ltrdirection = 'R';
2115 }
2116
2117 // Load traductions files required by page
2118 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2119
2120 $default_font_size = pdf_getPDFFontSize($outputlangs);
2121
2122 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2123
2124 $pdf->SetTextColor(0, 0, 60);
2125 $pdf->SetFont('', 'B', $default_font_size + 3);
2126
2127 $w = 110;
2128
2129 $posy = $this->marge_haute;
2130 $posx = $this->page_largeur - $this->marge_droite - $w;
2131
2132 $pdf->SetXY($this->marge_gauche, $posy);
2133
2134 // Logo
2135 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2136 if ($this->emetteur->logo) {
2137 $logodir = $conf->mycompany->dir_output;
2138 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2139 $logodir = $conf->mycompany->multidir_output[$object->entity];
2140 }
2141 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2142 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2143 } else {
2144 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2145 }
2146 if (is_readable($logo)) {
2147 $height = pdf_getHeightForLogo($logo);
2148 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2149 } else {
2150 $pdf->SetTextColor(200, 0, 0);
2151 $pdf->SetFont('', 'B', $default_font_size - 2);
2152 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2153 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2154 }
2155 } else {
2156 $text = $this->emetteur->name;
2157 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2158 }
2159 }
2160
2161 $pdf->SetFont('', 'B', $default_font_size + 3);
2162 $pdf->SetXY($posx, $posy);
2163 $pdf->SetTextColor(0, 0, 60);
2164 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2165 if ($object->type == 1) {
2166 $title = $outputlangs->transnoentities("InvoiceReplacement");
2167 }
2168 if ($object->type == 2) {
2169 $title = $outputlangs->transnoentities("InvoiceAvoir");
2170 }
2171 if ($object->type == 3) {
2172 $title = $outputlangs->transnoentities("InvoiceDeposit");
2173 }
2174 if ($object->type == 4) {
2175 $title = $outputlangs->transnoentities("InvoiceProForma");
2176 }
2177 if ($this->situationinvoice) {
2178 $langs->loadLangs(array("other"));
2179 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2180 }
2181 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2182 $title .= ' - ';
2183 if ($object->type == 0) {
2184 if ($this->situationinvoice) {
2185 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2186 }
2187 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2188 } elseif ($object->type == 1) {
2189 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2190 } elseif ($object->type == 2) {
2191 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2192 } elseif ($object->type == 3) {
2193 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2194 } elseif ($object->type == 4) {
2195 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2196 }
2197 }
2198 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2199 if ($object->statut == $object::STATUS_DRAFT) {
2200 $pdf->SetTextColor(128, 0, 0);
2201 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2202 }
2203
2204 $pdf->MultiCell($w, 3, $title, '', 'R');
2205
2206 $pdf->SetFont('', 'B', $default_font_size);
2207
2208 /*
2209 $posy += 5;
2210 $pdf->SetXY($posx, $posy);
2211 $pdf->SetTextColor(0, 0, 60);
2212 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2213 if ($object->statut == $object::STATUS_DRAFT) {
2214 $pdf->SetTextColor(128, 0, 0);
2215 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2216 }
2217 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2218
2219 $posy += 3;
2220 $pdf->SetFont('', '', $default_font_size - 2);
2221
2222 if ($object->ref_customer) {
2223 $posy += 4;
2224 $pdf->SetXY($posx, $posy);
2225 $pdf->SetTextColor(0, 0, 60);
2226 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2227 }
2228
2229 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2230 $object->fetch_projet();
2231 if (!empty($object->project->ref)) {
2232 $posy += 3;
2233 $pdf->SetXY($posx, $posy);
2234 $pdf->SetTextColor(0, 0, 60);
2235 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2236 }
2237 }
2238
2239 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2240 $object->fetch_projet();
2241 if (!empty($object->project->ref)) {
2242 $outputlangs->load("projects");
2243 $posy += 3;
2244 $pdf->SetXY($posx, $posy);
2245 $pdf->SetTextColor(0, 0, 60);
2246 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2247 }
2248 }
2249
2250 $objectidnext = $object->getIdReplacingInvoice('validated');
2251 if ($object->type == 0 && $objectidnext) {
2252 $objectreplacing = new Facture($this->db);
2253 $objectreplacing->fetch($objectidnext);
2254
2255 $posy += 3;
2256 $pdf->SetXY($posx, $posy);
2257 $pdf->SetTextColor(0, 0, 60);
2258 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2259 }
2260 if ($object->type == 1) {
2261 $objectreplaced = new Facture($this->db);
2262 $objectreplaced->fetch($object->fk_facture_source);
2263
2264 $posy += 4;
2265 $pdf->SetXY($posx, $posy);
2266 $pdf->SetTextColor(0, 0, 60);
2267 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2268 }
2269 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2270 $objectreplaced = new Facture($this->db);
2271 $objectreplaced->fetch($object->fk_facture_source);
2272
2273 $posy += 3;
2274 $pdf->SetXY($posx, $posy);
2275 $pdf->SetTextColor(0, 0, 60);
2276 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2277 }
2278
2279 $posy += 4;
2280 $pdf->SetXY($posx, $posy);
2281 $pdf->SetTextColor(0, 0, 60);
2282
2283 $title = $outputlangs->transnoentities("DateInvoice");
2284 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2285 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2286 }
2287 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2288
2289 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2290 $posy += 4;
2291 $pdf->SetXY($posx, $posy);
2292 $pdf->SetTextColor(0, 0, 60);
2293 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2294 }
2295
2296 if ($object->type != 2) {
2297 $posy += 3;
2298 $pdf->SetXY($posx, $posy);
2299 $pdf->SetTextColor(0, 0, 60);
2300 $title = $outputlangs->transnoentities("DateDue");
2301 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2302 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2303 }
2304 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2305 }
2306
2307 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2308 $posy += 3;
2309 $pdf->SetXY($posx, $posy);
2310 $pdf->SetTextColor(0, 0, 60);
2311 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2312 }
2313
2314 // Get contact
2315 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2316 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2317 if (count($arrayidcontact) > 0) {
2318 $usertmp = new User($this->db);
2319 $usertmp->fetch($arrayidcontact[0]);
2320 $posy += 4;
2321 $pdf->SetXY($posx, $posy);
2322 $pdf->SetTextColor(0, 0, 60);
2323 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2324 }
2325 }
2326
2327 $posy += 1;
2328
2329 $top_shift = 0;
2330 $shipp_shift = 0;
2331 // Show list of linked objects
2332 $current_y = $pdf->getY();
2333 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2334 if ($current_y < $pdf->getY()) {
2335 $top_shift = $pdf->getY() - $current_y;
2336 }
2337
2338 if ($showaddress) {
2339 // Sender properties
2340 $carac_emetteur = '';
2341 // Add internal contact of object if defined
2342 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2343 if (count($arrayidcontact) > 0) {
2344 $object->fetch_user($arrayidcontact[0]);
2345 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2346 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2347 $carac_emetteur .= "\n";
2348 }
2349
2350 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2351
2352 // Show sender
2353 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2354 $posy += $top_shift;
2355 $posx = $this->marge_gauche;
2356 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2357 $posx = $this->page_largeur - $this->marge_droite - 80;
2358 }
2359
2360 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2361 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2362
2363 // Show sender frame
2364 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2365 $pdf->SetTextColor(0, 0, 0);
2366 $pdf->SetFont('', '', $default_font_size - 2);
2367 $pdf->SetXY($posx, $posy - 5);
2368 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2369 $pdf->SetXY($posx, $posy);
2370 $pdf->SetFillColor(230, 230, 230);
2371 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2372 $pdf->SetTextColor(0, 0, 60);
2373 }
2374
2375 // Show sender name
2376 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2377 $pdf->SetXY($posx + 2, $posy + 3);
2378 $pdf->SetFont('', 'B', $default_font_size);
2379 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2380 $posy = $pdf->getY();
2381 }
2382
2383 // Show sender information
2384 $pdf->SetXY($posx + 2, $posy);
2385 $pdf->SetFont('', '', $default_font_size - 1);
2386 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2387
2388 // If BILLING contact defined on invoice, we use it
2389 $usecontact = false;
2390 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2391 if (count($arrayidcontact) > 0) {
2392 $usecontact = true;
2393 $result = $object->fetch_contact($arrayidcontact[0]);
2394 }
2395
2396 // Recipient name
2397 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2398 $thirdparty = $object->contact;
2399 } else {
2400 $thirdparty = $object->thirdparty;
2401 }
2402
2403 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2404
2405 $mode = 'target';
2406 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2407
2408 // Show recipient
2409 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2410 if ($this->page_largeur < 210) {
2411 $widthrecbox = 84; // To work with US executive format
2412 }
2413 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2414 $posy += $top_shift;
2415 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2416 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2417 $posx = $this->marge_gauche;
2418 }
2419
2420 // Show recipient frame
2421 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2422 $pdf->SetTextColor(0, 0, 0);
2423 $pdf->SetFont('', '', $default_font_size - 2);
2424 $pdf->SetXY($posx + 2, $posy - 5);
2425 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2426 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2427 }
2428
2429 // Show recipient name
2430 $pdf->SetXY($posx + 2, $posy + 3);
2431 $pdf->SetFont('', 'B', $default_font_size);
2432 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2433 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2434
2435 $posy = $pdf->getY();
2436
2437 // Show recipient information
2438 $pdf->SetFont('', '', $default_font_size - 1);
2439 $pdf->SetXY($posx + 2, $posy);
2440 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2441 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2442
2443 // Show shipping address
2444 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2445 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2446
2447 if (!empty($idaddressshipping)) {
2448 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2449 $companystatic = new Societe($this->db);
2450 $companystatic->fetch($object->contact->fk_soc);
2451 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2452 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2453 } else {
2454 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2455 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2456 }
2457 if (!empty($carac_client_shipping)) {
2458 $posy += $hautcadre;
2459
2460 $hautcadre = $hautcadre - 10; // Height for the shipping address does not need to be as high as main box
2461
2462 // Show shipping frame
2463 $pdf->SetXY($posx + 2, $posy - 5);
2464 $pdf->SetFont('', '', $default_font_size - 2);
2465 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2466 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2467
2468 // Show shipping name
2469 $pdf->SetXY($posx + 2, $posy + 3);
2470 $pdf->SetFont('', 'B', $default_font_size);
2471 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2472
2473 $posy = $pdf->getY();
2474
2475 // Show shipping information
2476 $pdf->SetXY($posx + 2, $posy);
2477 $pdf->SetFont('', '', $default_font_size - 1);
2478 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2479
2480 $shipp_shift += $hautcadre + 10;
2481 }
2482 }
2483 }
2484
2485 $pdf->SetTextColor(0, 0, 0);
2486
2487 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2488
2489 return $pagehead;
2490 }
2491
2492 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2503 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2504 {
2505 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2506 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);
2507 }
2508
2519 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2520 {
2521 global $hookmanager;
2522
2523 // Default field style for content
2524 $this->defaultContentsFieldsStyle = array(
2525 'align' => 'R', // R,C,L
2526 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2527 );
2528
2529 // Default field style for content
2530 $this->defaultTitlesFieldsStyle = array(
2531 'align' => 'C', // R,C,L
2532 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2533 );
2534
2535 /*
2536 * For example
2537 $this->cols['theColKey'] = array(
2538 'rank' => $rank, // int : use for ordering columns
2539 'width' => 20, // the column width in mm
2540 'title' => array(
2541 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2542 'label' => ' ', // the final label : used fore final generated text
2543 'align' => 'L', // text alignment : R,C,L
2544 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2545 ),
2546 'content' => array(
2547 'align' => 'L', // text alignment : R,C,L
2548 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2549 ),
2550 );
2551 */
2552
2553 $rank = 0; // do not use negative rank
2554 $this->cols['position'] = array(
2555 'rank' => $rank,
2556 'width' => 10,
2557 'status' => getDolGlobalInt('PDF_SPONGE_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2558 'title' => array(
2559 'textkey' => '#', // use lang key is useful in somme case with module
2560 'align' => 'C',
2561 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2562 // 'label' => ' ', // the final label
2563 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2564 ),
2565 'content' => array(
2566 'align' => 'C',
2567 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2568 ),
2569 );
2570
2571 $rank = 5; // do not use negative rank
2572 $this->cols['desc'] = array(
2573 'rank' => $rank,
2574 'width' => false, // only for desc
2575 'status' => true,
2576 'title' => array(
2577 'textkey' => 'Designation', // use lang key is useful in somme case with module
2578 'align' => 'L',
2579 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2580 // 'label' => ' ', // the final label
2581 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2582 ),
2583 'content' => array(
2584 'align' => 'L',
2585 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2586 ),
2587 );
2588
2589 // Image of product
2590 $rank = $rank + 10;
2591 $this->cols['photo'] = array(
2592 'rank' => $rank,
2593 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2594 'status' => false,
2595 'title' => array(
2596 'textkey' => 'Photo',
2597 'label' => ' '
2598 ),
2599 'content' => array(
2600 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2601 ),
2602 'border-left' => false, // remove left line separator
2603 );
2604
2605 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2606 $this->cols['photo']['status'] = true;
2607 }
2608
2609
2610 $rank = $rank + 10;
2611 $this->cols['vat'] = array(
2612 'rank' => $rank,
2613 'status' => false,
2614 'width' => 16, // in mm
2615 'title' => array(
2616 'textkey' => 'VAT'
2617 ),
2618 'border-left' => true, // add left line separator
2619 );
2620
2621 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2622 $this->cols['vat']['status'] = true;
2623 }
2624
2625 $rank = $rank + 10;
2626 $this->cols['subprice'] = array(
2627 'rank' => $rank,
2628 'width' => 19, // in mm
2629 'status' => true,
2630 'title' => array(
2631 'textkey' => 'PriceUHT'
2632 ),
2633 'border-left' => true, // add left line separator
2634 );
2635
2636 // Adapt dynamically the width of subprice, if text is too long.
2637 $tmpwidth = 0;
2638 $nblines = count($object->lines);
2639 for ($i = 0; $i < $nblines; $i++) {
2640 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2641 $tmpwidth = max($tmpwidth, $tmpwidth2);
2642 }
2643 if ($tmpwidth > 10) {
2644 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2645 }
2646
2647 $rank = $rank + 10;
2648 $this->cols['qty'] = array(
2649 'rank' => $rank,
2650 'width' => 16, // in mm
2651 'status' => true,
2652 'title' => array(
2653 'textkey' => 'Qty'
2654 ),
2655 'border-left' => true, // add left line separator
2656 );
2657
2658 $rank = $rank + 10;
2659 $this->cols['progress'] = array(
2660 'rank' => $rank,
2661 'width' => 19, // in mm
2662 'status' => false,
2663 'title' => array(
2664 'textkey' => 'ProgressShort'
2665 ),
2666 'border-left' => true, // add left line separator
2667 );
2668
2669 if ($this->situationinvoice) {
2670 $this->cols['progress']['status'] = true;
2671 }
2672
2673 $rank = $rank + 10;
2674 $this->cols['unit'] = array(
2675 'rank' => $rank,
2676 'width' => 11, // in mm
2677 'status' => false,
2678 'title' => array(
2679 'textkey' => 'Unit'
2680 ),
2681 'border-left' => true, // add left line separator
2682 );
2683 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2684 $this->cols['unit']['status'] = true;
2685 }
2686
2687 $rank = $rank + 10;
2688 $this->cols['discount'] = array(
2689 'rank' => $rank,
2690 'width' => 13, // in mm
2691 'status' => false,
2692 'title' => array(
2693 'textkey' => 'ReductionShort'
2694 ),
2695 'border-left' => true, // add left line separator
2696 );
2697 if ($this->atleastonediscount) {
2698 $this->cols['discount']['status'] = true;
2699 }
2700
2701 $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2702 $this->cols['totalexcltax'] = array(
2703 'rank' => $rank,
2704 'width' => 26, // in mm
2705 'status' => !getDolGlobalString('PDF_PROPAL_HIDE_PRICE_EXCL_TAX') ? true : false,
2706 'title' => array(
2707 'textkey' => 'TotalHTShort'
2708 ),
2709 'border-left' => true, // add left line separator
2710 );
2711
2712 $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2713 $this->cols['totalincltax'] = array(
2714 'rank' => $rank,
2715 'width' => 26, // in mm
2716 'status' => !getDolGlobalString('PDF_PROPAL_SHOW_PRICE_INCL_TAX') ? false : true,
2717 'title' => array(
2718 'textkey' => 'TotalTTCShort'
2719 ),
2720 'border-left' => true, // add left line separator
2721 );
2722
2723 // Add extrafields cols
2724 if (!empty($object->lines)) {
2725 $line = reset($object->lines);
2726 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2727 }
2728
2729 $parameters = array(
2730 'object' => $object,
2731 'outputlangs' => $outputlangs,
2732 'hidedetails' => $hidedetails,
2733 'hidedesc' => $hidedesc,
2734 'hideref' => $hideref
2735 );
2736
2737 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2738 if ($reshook < 0) {
2739 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2740 } elseif (empty($reshook)) {
2741 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2742 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2743 } else {
2744 $this->cols = $hookmanager->resArray;
2745 }
2746 }
2747}
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:2620
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:2651
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:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140