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