dolibarr 20.0.5
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(0, '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 $usemc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1);
1652 $total_line_remise_print = $total_line_remise;
1653 if ($usemc) {
1654 $ratio = (!empty($object->total_ht) ? (float) $object->multicurrency_total_ht / (float) $object->total_ht : 0);
1655 if (!empty($ratio)) $total_line_remise_print = price2num($total_line_remise * $ratio, 'MT');
1656 }
1657 }
1658 if ($total_line_remise > 0) {
1659 if (getDolGlobalString('MAIN_SHOW_AMOUNT_DISCOUNT')) {
1660 $pdf->SetFillColor(255, 255, 255);
1661 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1662 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
1663 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1664 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise_print, 0, $outputlangs), 0, 'R', 1);
1665 $index++;
1666 }
1667 // Show total NET before discount
1668 if (getDolGlobalString('MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT')) {
1669 $pdf->SetFillColor(255, 255, 255);
1670 $pdf->SetXY($col1x, $tab2_top);
1671 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
1672 $pdf->SetXY($col2x, $tab2_top);
1673 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise_print + $total_ht, 0, $outputlangs), 0, 'R', 1);
1674 $index++;
1675 }
1676 }
1677
1678 // Total HT
1679 $pdf->SetFillColor(255, 255, 255);
1680 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1681 $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);
1682
1683 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1684 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1685 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1686
1687 // Show VAT by rates and total
1688 $pdf->SetFillColor(248, 248, 248);
1689
1690 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1691
1692 $this->atleastoneratenotnull = 0;
1693 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1694 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1695 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1696 // Nothing to do
1697 } else {
1698 //Local tax 1 before VAT
1699 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1700 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1701 continue;
1702 }
1703
1704 foreach ($localtax_rate as $tvakey => $tvaval) {
1705 if ($tvakey != 0) { // On affiche pas taux 0
1706 //$this->atleastoneratenotnull++;
1707
1708 $index++;
1709 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1710
1711 $tvacompl = '';
1712 if (preg_match('/\*/', (string) $tvakey)) {
1713 $tvakey = str_replace('*', '', (string) $tvakey);
1714 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1715 }
1716
1717 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1718 $totalvat .= ' ';
1719
1720 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1721 $totalvat .= $tvacompl;
1722 } else {
1723 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1724 }
1725
1726 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1727
1728 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1729
1730 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1731 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1732 }
1733 }
1734 }
1735
1736 //Local tax 2 before VAT
1737 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1738 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1739 continue;
1740 }
1741
1742 foreach ($localtax_rate as $tvakey => $tvaval) {
1743 if ($tvakey != 0) { // On affiche pas taux 0
1744 //$this->atleastoneratenotnull++;
1745
1746 $index++;
1747 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1748
1749 $tvacompl = '';
1750 if (preg_match('/\*/', (string) $tvakey)) {
1751 $tvakey = str_replace('*', '', (string) $tvakey);
1752 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1753 }
1754 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1755 $totalvat .= ' ';
1756
1757 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1758 $totalvat .= $tvacompl;
1759 } else {
1760 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1761 }
1762
1763 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1764
1765 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1766
1767 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1768 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1769 }
1770 }
1771 }
1772
1773 // Situations totals might be wrong on huge amounts with old mode 1
1774 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1775 $sum_pdf_tva = 0;
1776 foreach ($this->tva as $tvakey => $tvaval) {
1777 $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1778 }
1779
1780 if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1781 if (!empty($sum_pdf_tva)) {
1782 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1783 } else {
1784 $coef_fix_tva = 1;
1785 }
1786
1787
1788 foreach ($this->tva as $tvakey => $tvaval) {
1789 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1790 }
1791 foreach ($this->tva_array as $tvakey => $tvaval) {
1792 $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
1793 }
1794 }
1795 }
1796
1797 // VAT
1798 foreach ($this->tva_array as $tvakey => $tvaval) {
1799 if ($tvakey != 0) { // On affiche pas taux 0
1800 $this->atleastoneratenotnull++;
1801
1802 $index++;
1803 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1804
1805 $tvacompl = '';
1806 if (preg_match('/\*/', $tvakey)) {
1807 $tvakey = str_replace('*', '', $tvakey);
1808 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1809 }
1810 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1811 $totalvat .= ' ';
1812 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1813 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1814 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1815 $totalvat .= $tvaval['vatcode'].$tvacompl;
1816 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1817 $totalvat .= $tvacompl;
1818 } else {
1819 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1820 }
1821 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1822
1823 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1824 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1825 }
1826 }
1827
1828 //Local tax 1 after VAT
1829 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1830 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1831 continue;
1832 }
1833
1834 foreach ($localtax_rate as $tvakey => $tvaval) {
1835 if ($tvakey != 0) { // On affiche pas taux 0
1836 //$this->atleastoneratenotnull++;
1837
1838 $index++;
1839 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1840
1841 $tvacompl = '';
1842 if (preg_match('/\*/', (string) $tvakey)) {
1843 $tvakey = str_replace('*', '', (string) $tvakey);
1844 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1845 }
1846 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1847 $totalvat .= ' ';
1848
1849 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1850 $totalvat .= $tvacompl;
1851 } else {
1852 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1853 }
1854
1855 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1856
1857 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1858
1859 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1860 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1861 }
1862 }
1863 }
1864
1865 //Local tax 2 after VAT
1866 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1867 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1868 continue;
1869 }
1870
1871 foreach ($localtax_rate as $tvakey => $tvaval) {
1872 // retrieve global local tax
1873 if ($tvakey != 0) { // On affiche pas taux 0
1874 //$this->atleastoneratenotnull++;
1875
1876 $index++;
1877 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1878
1879 $tvacompl = '';
1880 if (preg_match('/\*/', (string) $tvakey)) {
1881 $tvakey = str_replace('*', '', (string) $tvakey);
1882 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1883 }
1884 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1885 $totalvat .= ' ';
1886
1887 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1888 $totalvat .= $tvacompl;
1889 } else {
1890 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1891 }
1892
1893 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1894
1895 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1896
1897 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1898 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1899 }
1900 }
1901 }
1902
1903 // Revenue stamp
1904 if (price2num($object->revenuestamp, 'MT') != 0) {
1905 $index++;
1906 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1907 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
1908
1909 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1910 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1911 }
1912
1913 // Total TTC
1914 $index++;
1915 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1916 $pdf->SetTextColor(0, 0, 60);
1917 $pdf->SetFillColor(224, 224, 224);
1918 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
1919
1920 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1921 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1922
1923
1924 // Retained warranty
1925 if ($object->displayRetainedWarranty()) {
1926 $pdf->SetTextColor(40, 40, 40);
1927 $pdf->SetFillColor(255, 255, 255);
1928
1929 $retainedWarranty = $object->getRetainedWarrantyAmount();
1930 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1931
1932 // Billed - retained warranty
1933 $index++;
1934 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1935 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1936
1937 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1938 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1939
1940 // retained warranty
1941 $index++;
1942 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1943
1944 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
1945 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1946
1947 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1948 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1949 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1950 }
1951 }
1952 }
1953
1954 $pdf->SetTextColor(0, 0, 0);
1955
1956 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1957 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1958
1959 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1960 if (!empty($object->paye)) {
1961 $resteapayer = 0;
1962 }
1963
1964 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1965 // Already paid + Deposits
1966 $index++;
1967 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1968 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
1969 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1970 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1971
1972 // Credit note
1973 if ($creditnoteamount) {
1974 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1975 $labeltouse .= (is_object($outputlangsbis) ? (' / '.(($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes"))) : '');
1976 $index++;
1977 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1978 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1979 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1980 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1981 }
1982
1983 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1984 $index++;
1985 $pdf->SetFillColor(255, 255, 255);
1986
1987 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1988 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
1989 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1990 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'), 0, $outputlangs), $useborder, 'R', 1);
1991
1992 $resteapayer = 0;
1993 }
1994
1995 $index++;
1996 $pdf->SetTextColor(0, 0, 60);
1997 $pdf->SetFillColor(224, 224, 224);
1998 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1999 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
2000 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2001 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
2002
2003 $pdf->SetFont('', '', $default_font_size - 1);
2004 $pdf->SetTextColor(0, 0, 0);
2005 }
2006
2007 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2008
2009 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2010 if ($reshook < 0) {
2011 $this->error = $hookmanager->error;
2012 $this->errors = $hookmanager->errors;
2013 }
2014
2015 $index++;
2016 return ($tab2_top + ($tab2_hl * $index));
2017 }
2018
2019 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2027 public static function liste_modeles($db, $maxfilenamelength = 0)
2028 {
2029 // phpcs:enable
2030 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2031 }
2032
2033 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2048 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2049 {
2050 global $conf;
2051
2052 // Force to disable hidetop and hidebottom
2053 $hidebottom = 0;
2054 if ($hidetop) {
2055 $hidetop = -1;
2056 }
2057
2058 $currency = !empty($currency) ? $currency : $conf->currency;
2059 $default_font_size = pdf_getPDFFontSize($outputlangs);
2060
2061 // Amount in (at tab_top - 1)
2062 $pdf->SetTextColor(0, 0, 0);
2063 $pdf->SetFont('', '', $default_font_size - 2);
2064
2065 if (empty($hidetop)) {
2066 // Show category of operations
2067 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2068 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2069 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2070 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2071 }
2072
2073 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2074 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2075 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2076 }
2077
2078 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2079 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2080
2081 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2082 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2083 $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')));
2084 }
2085 }
2086
2087 $pdf->SetDrawColor(128, 128, 128);
2088 $pdf->SetFont('', '', $default_font_size - 1);
2089
2090 // Output Rect
2091 $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
2092
2093
2094 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2095
2096 if (empty($hidetop)) {
2097 $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
2098 }
2099 }
2100
2101 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2112 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2113 {
2114 // phpcs:enable
2115 global $conf, $langs;
2116
2117 $ltrdirection = 'L';
2118 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2119 $ltrdirection = 'R';
2120 }
2121
2122 // Load traductions files required by page
2123 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2124
2125 $default_font_size = pdf_getPDFFontSize($outputlangs);
2126
2127 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2128
2129 $pdf->SetTextColor(0, 0, 60);
2130 $pdf->SetFont('', 'B', $default_font_size + 3);
2131
2132 $w = 110;
2133
2134 $posy = $this->marge_haute;
2135 $posx = $this->page_largeur - $this->marge_droite - $w;
2136
2137 $pdf->SetXY($this->marge_gauche, $posy);
2138
2139 // Logo
2140 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2141 if ($this->emetteur->logo) {
2142 $logodir = $conf->mycompany->dir_output;
2143 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2144 $logodir = $conf->mycompany->multidir_output[$object->entity];
2145 }
2146 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2147 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2148 } else {
2149 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2150 }
2151 if (is_readable($logo)) {
2152 $height = pdf_getHeightForLogo($logo);
2153 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2154 } else {
2155 $pdf->SetTextColor(200, 0, 0);
2156 $pdf->SetFont('', 'B', $default_font_size - 2);
2157 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2158 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2159 }
2160 } else {
2161 $text = $this->emetteur->name;
2162 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2163 }
2164 }
2165
2166 $pdf->SetFont('', 'B', $default_font_size + 3);
2167 $pdf->SetXY($posx, $posy);
2168 $pdf->SetTextColor(0, 0, 60);
2169 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2170 if ($object->type == 1) {
2171 $title = $outputlangs->transnoentities("InvoiceReplacement");
2172 }
2173 if ($object->type == 2) {
2174 $title = $outputlangs->transnoentities("InvoiceAvoir");
2175 }
2176 if ($object->type == 3) {
2177 $title = $outputlangs->transnoentities("InvoiceDeposit");
2178 }
2179 if ($object->type == 4) {
2180 $title = $outputlangs->transnoentities("InvoiceProForma");
2181 }
2182 if ($this->situationinvoice) {
2183 $outputlangs->loadLangs(array("other"));
2184 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2185 }
2186 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2187 $title .= ' - ';
2188 if ($object->type == 0) {
2189 if ($this->situationinvoice) {
2190 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2191 }
2192 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2193 } elseif ($object->type == 1) {
2194 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2195 } elseif ($object->type == 2) {
2196 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2197 } elseif ($object->type == 3) {
2198 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2199 } elseif ($object->type == 4) {
2200 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2201 }
2202 }
2203 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2204 if ($object->statut == $object::STATUS_DRAFT) {
2205 $pdf->SetTextColor(128, 0, 0);
2206 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2207 }
2208
2209 $pdf->MultiCell($w, 3, $title, '', 'R');
2210
2211 $pdf->SetFont('', 'B', $default_font_size);
2212
2213 /*
2214 $posy += 5;
2215 $pdf->SetXY($posx, $posy);
2216 $pdf->SetTextColor(0, 0, 60);
2217 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2218 if ($object->statut == $object::STATUS_DRAFT) {
2219 $pdf->SetTextColor(128, 0, 0);
2220 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2221 }
2222 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2223
2224 $posy += 3;
2225 $pdf->SetFont('', '', $default_font_size - 2);
2226
2227 if ($object->ref_customer) {
2228 $posy += 4;
2229 $pdf->SetXY($posx, $posy);
2230 $pdf->SetTextColor(0, 0, 60);
2231 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2232 }
2233
2234 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2235 $object->fetch_projet();
2236 if (!empty($object->project->ref)) {
2237 $posy += 3;
2238 $pdf->SetXY($posx, $posy);
2239 $pdf->SetTextColor(0, 0, 60);
2240 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2241 }
2242 }
2243
2244 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2245 $object->fetch_projet();
2246 if (!empty($object->project->ref)) {
2247 $outputlangs->load("projects");
2248 $posy += 3;
2249 $pdf->SetXY($posx, $posy);
2250 $pdf->SetTextColor(0, 0, 60);
2251 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2252 }
2253 }
2254
2255 $objectidnext = $object->getIdReplacingInvoice('validated');
2256 if ($object->type == 0 && $objectidnext) {
2257 $objectreplacing = new Facture($this->db);
2258 $objectreplacing->fetch($objectidnext);
2259
2260 $posy += 3;
2261 $pdf->SetXY($posx, $posy);
2262 $pdf->SetTextColor(0, 0, 60);
2263 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2264 }
2265 if ($object->type == 1) {
2266 $objectreplaced = new Facture($this->db);
2267 $objectreplaced->fetch($object->fk_facture_source);
2268
2269 $posy += 4;
2270 $pdf->SetXY($posx, $posy);
2271 $pdf->SetTextColor(0, 0, 60);
2272 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2273 }
2274 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2275 $objectreplaced = new Facture($this->db);
2276 $objectreplaced->fetch($object->fk_facture_source);
2277
2278 $posy += 3;
2279 $pdf->SetXY($posx, $posy);
2280 $pdf->SetTextColor(0, 0, 60);
2281 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2282 }
2283
2284 $posy += 4;
2285 $pdf->SetXY($posx, $posy);
2286 $pdf->SetTextColor(0, 0, 60);
2287
2288 $title = $outputlangs->transnoentities("DateInvoice");
2289 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2290 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2291 }
2292 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2293
2294 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2295 $posy += 4;
2296 $pdf->SetXY($posx, $posy);
2297 $pdf->SetTextColor(0, 0, 60);
2298 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2299 }
2300
2301 if ($object->type != 2) {
2302 $posy += 3;
2303 $pdf->SetXY($posx, $posy);
2304 $pdf->SetTextColor(0, 0, 60);
2305 $title = $outputlangs->transnoentities("DateDue");
2306 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2307 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2308 }
2309 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2310 }
2311
2312 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2313 $posy += 3;
2314 $pdf->SetXY($posx, $posy);
2315 $pdf->SetTextColor(0, 0, 60);
2316 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2317 }
2318
2319 // Get contact
2320 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2321 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2322 if (count($arrayidcontact) > 0) {
2323 $usertmp = new User($this->db);
2324 $usertmp->fetch($arrayidcontact[0]);
2325 $posy += 4;
2326 $pdf->SetXY($posx, $posy);
2327 $pdf->SetTextColor(0, 0, 60);
2328 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2329 }
2330 }
2331
2332 $posy += 1;
2333
2334 $top_shift = 0;
2335 $shipp_shift = 0;
2336 // Show list of linked objects
2337 $current_y = $pdf->getY();
2338 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2339 if ($current_y < $pdf->getY()) {
2340 $top_shift = $pdf->getY() - $current_y;
2341 }
2342
2343 if ($showaddress) {
2344 // Sender properties
2345 $carac_emetteur = '';
2346 // Add internal contact of object if defined
2347 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2348 if (count($arrayidcontact) > 0) {
2349 $object->fetch_user($arrayidcontact[0]);
2350 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2351 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2352 $carac_emetteur .= "\n";
2353 }
2354
2355 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2356
2357 // Show sender
2358 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2359 $posy += $top_shift;
2360 $posx = $this->marge_gauche;
2361 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2362 $posx = $this->page_largeur - $this->marge_droite - 80;
2363 }
2364
2365 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2366 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2367
2368 // Show sender frame
2369 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2370 $pdf->SetTextColor(0, 0, 0);
2371 $pdf->SetFont('', '', $default_font_size - 2);
2372 $pdf->SetXY($posx, $posy - 5);
2373 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2374 $pdf->SetXY($posx, $posy);
2375 $pdf->SetFillColor(230, 230, 230);
2376 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2377 $pdf->SetTextColor(0, 0, 60);
2378 }
2379
2380 // Show sender name
2381 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2382 $pdf->SetXY($posx + 2, $posy + 3);
2383 $pdf->SetFont('', 'B', $default_font_size);
2384 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2385 $posy = $pdf->getY();
2386 }
2387
2388 // Show sender information
2389 $pdf->SetXY($posx + 2, $posy);
2390 $pdf->SetFont('', '', $default_font_size - 1);
2391 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2392
2393 // If BILLING contact defined on invoice, we use it
2394 $usecontact = false;
2395 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2396 if (count($arrayidcontact) > 0) {
2397 $usecontact = true;
2398 $result = $object->fetch_contact($arrayidcontact[0]);
2399 }
2400
2401 // Recipient name
2402 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2403 $thirdparty = $object->contact;
2404 } else {
2405 $thirdparty = $object->thirdparty;
2406 }
2407
2408 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2409
2410 $mode = 'target';
2411 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2412
2413 // Show recipient
2414 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2415 if ($this->page_largeur < 210) {
2416 $widthrecbox = 84; // To work with US executive format
2417 }
2418 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2419 $posy += $top_shift;
2420 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2421 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2422 $posx = $this->marge_gauche;
2423 }
2424
2425 // Show recipient frame
2426 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2427 $pdf->SetTextColor(0, 0, 0);
2428 $pdf->SetFont('', '', $default_font_size - 2);
2429 $pdf->SetXY($posx + 2, $posy - 5);
2430 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2431 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2432 }
2433
2434 // Show recipient name
2435 $pdf->SetXY($posx + 2, $posy + 3);
2436 $pdf->SetFont('', 'B', $default_font_size);
2437 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2438 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2439
2440 $posy = $pdf->getY();
2441
2442 // Show recipient information
2443 $pdf->SetFont('', '', $default_font_size - 1);
2444 $pdf->SetXY($posx + 2, $posy);
2445 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2446 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2447
2448 // Show shipping address
2449 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2450 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2451
2452 if (!empty($idaddressshipping)) {
2453 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2454 $companystatic = new Societe($this->db);
2455 $companystatic->fetch($object->contact->fk_soc);
2456 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2457 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2458 } else {
2459 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2460 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2461 }
2462 if (!empty($carac_client_shipping)) {
2463 $posy += $hautcadre;
2464
2465 $hautcadre = $hautcadre - 10; // Height for the shipping address does not need to be as high as main box
2466
2467 // Show shipping frame
2468 $pdf->SetXY($posx + 2, $posy - 5);
2469 $pdf->SetFont('', '', $default_font_size - 2);
2470 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2471 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2472
2473 // Show shipping name
2474 $pdf->SetXY($posx + 2, $posy + 3);
2475 $pdf->SetFont('', 'B', $default_font_size);
2476 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2477
2478 $posy = $pdf->getY();
2479
2480 // Show shipping information
2481 $pdf->SetXY($posx + 2, $posy);
2482 $pdf->SetFont('', '', $default_font_size - 1);
2483 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2484
2485 $shipp_shift += $hautcadre + 10;
2486 }
2487 }
2488 }
2489
2490 $pdf->SetTextColor(0, 0, 0);
2491
2492 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2493
2494 return $pagehead;
2495 }
2496
2497 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2508 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2509 {
2510 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2511 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);
2512 }
2513
2524 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2525 {
2526 global $hookmanager;
2527
2528 // Default field style for content
2529 $this->defaultContentsFieldsStyle = array(
2530 'align' => 'R', // R,C,L
2531 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2532 );
2533
2534 // Default field style for content
2535 $this->defaultTitlesFieldsStyle = array(
2536 'align' => 'C', // R,C,L
2537 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2538 );
2539
2540 /*
2541 * For example
2542 $this->cols['theColKey'] = array(
2543 'rank' => $rank, // int : use for ordering columns
2544 'width' => 20, // the column width in mm
2545 'title' => array(
2546 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2547 'label' => ' ', // the final label : used fore final generated text
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 'content' => array(
2552 'align' => 'L', // text alignment : R,C,L
2553 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2554 ),
2555 );
2556 */
2557
2558 $rank = 0; // do not use negative rank
2559 $this->cols['position'] = array(
2560 'rank' => $rank,
2561 'width' => 10,
2562 'status' => getDolGlobalInt('PDF_SPONGE_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2563 'title' => array(
2564 'textkey' => '#', // use lang key is useful in somme case with module
2565 'align' => 'C',
2566 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2567 // 'label' => ' ', // the final label
2568 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2569 ),
2570 'content' => array(
2571 'align' => 'C',
2572 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2573 ),
2574 );
2575
2576 $rank = 5; // do not use negative rank
2577 $this->cols['desc'] = array(
2578 'rank' => $rank,
2579 'width' => false, // only for desc
2580 'status' => true,
2581 'title' => array(
2582 'textkey' => 'Designation', // use lang key is useful in somme case with module
2583 'align' => 'L',
2584 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2585 // 'label' => ' ', // the final label
2586 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2587 ),
2588 'content' => array(
2589 'align' => 'L',
2590 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2591 ),
2592 );
2593
2594 // Image of product
2595 $rank = $rank + 10;
2596 $this->cols['photo'] = array(
2597 'rank' => $rank,
2598 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2599 'status' => false,
2600 'title' => array(
2601 'textkey' => 'Photo',
2602 'label' => ' '
2603 ),
2604 'content' => array(
2605 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2606 ),
2607 'border-left' => false, // remove left line separator
2608 );
2609
2610 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2611 $this->cols['photo']['status'] = true;
2612 }
2613
2614
2615 $rank = $rank + 10;
2616 $this->cols['vat'] = array(
2617 'rank' => $rank,
2618 'status' => false,
2619 'width' => 16, // in mm
2620 'title' => array(
2621 'textkey' => 'VAT'
2622 ),
2623 'border-left' => true, // add left line separator
2624 );
2625
2626 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2627 $this->cols['vat']['status'] = true;
2628 }
2629
2630 $rank = $rank + 10;
2631 $this->cols['subprice'] = array(
2632 'rank' => $rank,
2633 'width' => 19, // in mm
2634 'status' => true,
2635 'title' => array(
2636 'textkey' => 'PriceUHT'
2637 ),
2638 'border-left' => true, // add left line separator
2639 );
2640
2641 // Adapt dynamically the width of subprice, if text is too long.
2642 $tmpwidth = 0;
2643 $nblines = count($object->lines);
2644 for ($i = 0; $i < $nblines; $i++) {
2645 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2646 $tmpwidth = max($tmpwidth, $tmpwidth2);
2647 }
2648 if ($tmpwidth > 10) {
2649 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2650 }
2651
2652 $rank = $rank + 10;
2653 $this->cols['qty'] = array(
2654 'rank' => $rank,
2655 'width' => 16, // in mm
2656 'status' => true,
2657 'title' => array(
2658 'textkey' => 'Qty'
2659 ),
2660 'border-left' => true, // add left line separator
2661 );
2662
2663 $rank = $rank + 10;
2664 $this->cols['progress'] = array(
2665 'rank' => $rank,
2666 'width' => 19, // in mm
2667 'status' => false,
2668 'title' => array(
2669 'textkey' => 'ProgressShort'
2670 ),
2671 'border-left' => true, // add left line separator
2672 );
2673
2674 if ($this->situationinvoice) {
2675 $this->cols['progress']['status'] = true;
2676 }
2677
2678 $rank = $rank + 10;
2679 $this->cols['unit'] = array(
2680 'rank' => $rank,
2681 'width' => 11, // in mm
2682 'status' => false,
2683 'title' => array(
2684 'textkey' => 'Unit'
2685 ),
2686 'border-left' => true, // add left line separator
2687 );
2688 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2689 $this->cols['unit']['status'] = true;
2690 }
2691
2692 $rank = $rank + 10;
2693 $this->cols['discount'] = array(
2694 'rank' => $rank,
2695 'width' => 13, // in mm
2696 'status' => false,
2697 'title' => array(
2698 'textkey' => 'ReductionShort'
2699 ),
2700 'border-left' => true, // add left line separator
2701 );
2702 if ($this->atleastonediscount) {
2703 $this->cols['discount']['status'] = true;
2704 }
2705
2706 $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2707 $this->cols['totalexcltax'] = array(
2708 'rank' => $rank,
2709 'width' => 26, // in mm
2710 'status' => !getDolGlobalString('PDF_INVOICE_HIDE_PRICE_EXCL_TAX') ? true : false,
2711 'title' => array(
2712 'textkey' => 'TotalHTShort'
2713 ),
2714 'border-left' => true, // add left line separator
2715 );
2716
2717 $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2718 $this->cols['totalincltax'] = array(
2719 'rank' => $rank,
2720 'width' => 26, // in mm
2721 'status' => !getDolGlobalString('PDF_INVOICE_SHOW_PRICE_INCL_TAX') ? false : true,
2722 'title' => array(
2723 'textkey' => 'TotalTTCShort'
2724 ),
2725 'border-left' => true, // add left line separator
2726 );
2727
2728 // Add extrafields cols
2729 if (!empty($object->lines)) {
2730 $line = reset($object->lines);
2731 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2732 }
2733
2734 $parameters = array(
2735 'object' => $object,
2736 'outputlangs' => $outputlangs,
2737 'hidedetails' => $hidedetails,
2738 'hidedesc' => $hidedesc,
2739 'hideref' => $hideref
2740 );
2741
2742 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2743 if ($reshook < 0) {
2744 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2745 } elseif (empty($reshook)) {
2746 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2747 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2748 } else {
2749 $this->cols = $hookmanager->resArray;
2750 }
2751 }
2752}
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:2686
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2422
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0)
Return line total amount discount.
Definition pdf.lib.php:2717
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:2478
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:2040
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2371
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1978
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:2285
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2328
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2125
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