dolibarr 22.0.5
pdf_octopus.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 Garcia <marcosgdf@gmail.com>
10 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
13 * Copyright (C) 2022-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
14 * Copyright (C) 2022-2024 Eric Seigne <eric.seigne@cap-rel.fr>
15 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2024 Nick Fragoulis
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 * or see https://www.gnu.org/
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
40require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
45
46
51{
55 public $db;
56
60 public $name;
61
65 public $description;
66
70 public $update_main_doc_field;
71
75 public $type;
76
81 public $version = 'disabled'; // Disabled by default. Enabled in constructor if option INVOICE_USE_SITUATION is 2.
82
86 public $heightforinfotot;
87
91 public $heightforfreetext;
92
96 public $heightforfooter;
97
101 public $tab_top;
102
106 public $tab_top_newpage;
107
112 public $emetteur;
113
117 public $situationinvoice;
118
119
123 public $cols;
124
128 public $categoryOfOperation = -1; // unknown by default
129
135 public $TDataSituation;
136
140 public $posx_cumul_anterieur;
141
145 public $posx_new_cumul;
146
150 public $posx_current;
151
155 public $tabTitleHeight;
156
160 public $is_rg;
161
165 public $franchise;
166
170 public $tplidx;
171
177 public function __construct($db)
178 {
179 global $conf, $langs, $mysoc, $object;
180
181 // for retro compatibility
182 if (getDolGlobalString('INVOICE_USE_SITUATION_RETAINED_WARRANTY') && !getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY')) {
183 // before it was only for final situation invoice
184 $conf->global->INVOICE_USE_RETAINED_WARRANTY = getDolGlobalString('INVOICE_USE_SITUATION_RETAINED_WARRANTY');
185 $conf->global->USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL = 1;
186 }
187
188 // If hidden option INVOICE_USE_SITUATION is set to 2, we can show the invoice situation template
189 if (getDolGlobalString('INVOICE_USE_SITUATION') == 2) {
190 $this->version = 'dolibarr';
191 }
192
193 // Translations
194 $langs->loadLangs(array("main", "bills"));
195
196 $this->db = $db;
197 $this->name = "octopus";
198 $this->description = $langs->trans('PDFOctopusDescription');
199 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
200
201 // Dimension page
202 $this->type = 'pdf';
203 $formatarray = pdf_getFormat();
204 $this->page_largeur = $formatarray['width'];
205 $this->page_hauteur = $formatarray['height'];
206 $this->format = array($this->page_largeur, $this->page_hauteur);
207 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
208 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
209 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
210 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
211 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
212 $this->posx_cumul_anterieur = 94;
213 $this->posx_new_cumul = 130;
214 $this->posx_current = 166;
215
216 $this->option_logo = 1; // Display logo
217 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
218 $this->option_modereg = 1; // Display payment mode
219 $this->option_condreg = 1; // Display payment terms
220 $this->option_multilang = 1; // Available in several languages
221 $this->option_escompte = 1; // Displays if there has been a discount
222 $this->option_credit_note = 1; // Support credit notes
223 $this->option_freetext = 1; // Support add of a personalised text
224 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
225 $this->watermark = '';
226 $this->franchise = !$mysoc->tva_assuj; // not used ?
227
228 // Define position of columns
229 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
230
231
232 $this->tabTitleHeight = 8; // default height (2 lines due to overtitle)
233
234 // Use new system for position of columns, view $this->defineColumnField()
235
236 $this->tva = array();
237 $this->tva_array = array();
238 $this->localtax1 = array();
239 $this->localtax2 = array();
240 $this->atleastoneratenotnull = 0;
241 $this->atleastonediscount = 0;
242 $this->situationinvoice = true;
243 if (!empty($object)) {
244 '@phan-var-force Facture $object'; // Supposing $object is Facture;
245 $this->TDataSituation = $this->getDataSituation($object);
246 } else {
247 dol_syslog("object is empty, do not call getDataSituation...");
248 }
249
250 if ($mysoc === null) {
251 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
252 return;
253 }
254
255 // Get source company
256 $this->emetteur = $mysoc;
257 if (empty($this->emetteur->country_code)) {
258 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
259 }
260 }
261
262
263 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
275 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
276 {
277 // phpcs:enable
278 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
279
280 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
281
282 if (!is_object($outputlangs)) {
283 $outputlangs = $langs;
284 }
285 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
286 if (getDolGlobalString('MAIN_USE_FPDF')) {
287 $outputlangs->charset_output = 'ISO-8859-1';
288 }
289
290 // Load translation files required by the page
291 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
292
293 global $outputlangsbis;
294 $outputlangsbis = null;
295 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
296 $outputlangsbis = new Translate('', $conf);
297 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
298 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
299 }
300
301 if (empty($object) || ($object->type != Facture::TYPE_SITUATION && ($object->type != Facture::TYPE_CREDIT_NOTE && !empty($object->situation_cycle_ref)))) {
302 setEventMessage($langs->trans('WarningsObjectIsNotASituation'), 'warnings');
303 return 1;
304 }
305 // Show Draft Watermark
306 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
307 $this->watermark = getDolGlobalString('FACTURE_DRAFT_WATERMARK');
308 }
309
310 $nblines = count($object->lines);
311
312 $hidetop = 0;
313 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
314 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
315 }
316
317 // Loop on each lines to detect if there is at least one image to show
318 $realpatharray = array();
319 $this->atleastonephoto = false;
320 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
321 $objphoto = new Product($this->db);
322
323 for ($i = 0; $i < $nblines; $i++) {
324 if (empty($object->lines[$i]->fk_product)) {
325 continue;
326 }
327
328 $objphoto->fetch($object->lines[$i]->fk_product);
329 //var_dump($objphoto->ref);exit;
330 $pdir = array();
331 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
332 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
333 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
334 } else {
335 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
336 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
337 }
338
339 $arephoto = false;
340 $realpath = false;
341 foreach ($pdir as $midir) {
342 if (!$arephoto) {
343 if ($conf->entity != $objphoto->entity) {
344 $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
345 } else {
346 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
347 }
348
349 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
350 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
351 if ($obj['photo_vignette']) {
352 $filename = $obj['photo_vignette'];
353 } else {
354 $filename = $obj['photo'];
355 }
356 } else {
357 $filename = $obj['photo'];
358 }
359
360 $realpath = $dir.$filename;
361 $arephoto = true;
362 $this->atleastonephoto = true;
363 }
364 }
365 }
366
367 if ($realpath && $arephoto) {
368 $realpatharray[$i] = $realpath;
369 }
370 }
371 }
372
373 //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
374
375 if ($conf->facture->multidir_output[$conf->entity]) {
376 $object->fetch_thirdparty();
377
378 $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
379 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
380 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
381
382 // Definition of $dir and $file
383 if ($object->specimen) {
384 $dir = $conf->facture->multidir_output[$conf->entity];
385 $file = $dir."/SPECIMEN.pdf";
386 } else {
387 $objectref = dol_sanitizeFileName($object->ref);
388 $dir = $conf->facture->multidir_output[$object->entity]."/".$objectref;
389 $file = $dir."/".$objectref.".pdf";
390 }
391 if (!file_exists($dir)) {
392 if (dol_mkdir($dir) < 0) {
393 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
394 return 0;
395 }
396 }
397
398 if (file_exists($dir)) {
399 // Add pdfgeneration hook
400 if (!is_object($hookmanager)) {
401 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
402 $hookmanager = new HookManager($this->db);
403 }
404 $hookmanager->initHooks(array('pdfgeneration'));
405 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
406 global $action;
407 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
408
409 // Set nblines with the new facture lines content after hook
410 $nblines = count($object->lines);
411 $nbpayments = count($object->getListOfPayments());
412 $nbprevsituation = is_array($object->tab_previous_situation_invoice) ? count($object->tab_previous_situation_invoice) : 0;
413
414 // Create pdf instance
415 $pdf = pdf_getInstance($this->format);
416 //$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
417 $default_font_size = 9;
418 $pdf->setAutoPageBreak(true, 0);
419
420 // compute height for situation invoices
421 $this->heightforinfotot = 45; // Height reserved to output the info and total part and payment part
422 if (!getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS') && $nbpayments > 0) {
423 $this->heightforinfotot += 4 * ($nbpayments + 3);
424 }
425 if ($nbprevsituation > 0) {
426 $this->heightforinfotot += 4 * ($nbprevsituation + 3);
427 }
428 $this->heightforfreetext = (getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5)); // Height reserved to output the free text on last page
429 $this->heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
430
431 if (class_exists('TCPDF')) {
432 $pdf->setPrintHeader(false);
433 $pdf->setPrintFooter(false);
434 }
435 $pdf->SetFont(pdf_getPDFFont($outputlangs));
436
437 // Set path to the background PDF File
438 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
439 $logodir = $conf->mycompany->dir_output;
440 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
441 $logodir = $conf->mycompany->multidir_output[$object->entity];
442 }
443 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
444 $this->tplidx = $pdf->importPage(1);
445 }
446
447 $pdf->Open();
448 $pagenb = 0;
449 $pdf->SetDrawColor(128, 128, 128);
450
451 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
452 $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceSituationTitle"));
453 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
454 $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
455 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
456 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
457 $pdf->SetCompression(false);
458 }
459
460 // Set certificate
461 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
462 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
463 // If user has no certificate, we try to take the company one
464 if (!$cert) {
465 $cert = getDolGlobalString('CERTIFICATE_CRT', '');
466 }
467 if (!$certprivate) {
468 $certprivate = getDolGlobalString('CERTIFICATE_CRT_PRIVATE', '');
469 }
470 // If a certificate is found
471 if ($cert) {
472 $info = array(
473 'Name' => $this->emetteur->name,
474 'Location' => getCountry($this->emetteur->country_code, ''),
475 'Reason' => 'INVOICE',
476 'ContactInfo' => $this->emetteur->email
477 );
478 $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
479 }
480
481 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
482 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
483
484 // Set $this->atleastonediscount if you have at least one discount
485 // and determine category of operation
486 $categoryOfOperation = 0;
487 $nbProduct = 0;
488 $nbService = 0;
489 for ($i = 0; $i < $nblines; $i++) {
490 if ($object->lines[$i]->remise_percent) {
491 $this->atleastonediscount++;
492 }
493
494 // determine category of operation
495 if ($categoryOfOperation < 2) {
496 $lineProductType = $object->lines[$i]->product_type;
497 if ($lineProductType == Product::TYPE_PRODUCT) {
498 $nbProduct++;
499 } elseif ($lineProductType == Product::TYPE_SERVICE) {
500 $nbService++;
501 }
502 if ($nbProduct > 0 && $nbService > 0) {
503 // mixed products and services
504 $categoryOfOperation = 2;
505 }
506 }
507 }
508 // determine category of operation
509 if ($categoryOfOperation <= 0) {
510 // only services
511 if ($nbProduct == 0 && $nbService > 0) {
512 $categoryOfOperation = 1;
513 }
514 }
515 $this->categoryOfOperation = $categoryOfOperation;
516
517 // New page
518 $pdf->AddPage();
519 if (!empty($this->tplidx)) {
520 $pdf->useTemplate($this->tplidx);
521 }
522 $pagenb++;
523
524 // Output header (logo, ref and address blocks). This is first call for first page.
525 $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
526 $top_shift = $pagehead['top_shift'];
527 $shipp_shift = $pagehead['shipp_shift'];
528 $pdf->SetFont('', '', $default_font_size - 1);
529 $pdf->MultiCell(0, 3, ''); // Set interline to 3
530 $pdf->SetTextColor(0, 0, 0);
531
532 // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher
533
534 // $this->tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
535 $this->tab_top = 90 + $top_shift + $shipp_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
536 $this->tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
537
538 // You can add more thing under header here, if you increase $extra_under_address_shift too.
539 $extra_under_address_shift = 0;
540 $qrcodestring = '';
541 if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) {
542 $qrcodestring = $object->buildZATCAQRString();
543 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
544 $qrcodestring = $object->buildSwitzerlandQRString();
545 }
546 if ($qrcodestring) {
547 $qrcodecolor = array('25', '25', '25');
548 // set style for QR-code
549 $styleQr = array(
550 'border' => false,
551 'padding' => 0,
552 'fgcolor' => $qrcodecolor,
553 'bgcolor' => false, //array(255,255,255)
554 'module_width' => 1, // width of a single module in points
555 'module_height' => 1 // height of a single module in points
556 );
557 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr, 'N');
558 $extra_under_address_shift += 25;
559 }
560
561 // Call hook printUnderHeaderPDFline
562 $parameters = array(
563 'object' => $object,
564 'i' => $i,
565 'pdf' => &$pdf,
566 'outputlangs' => $outputlangs,
567 'hidedetails' => $hidedetails
568 );
569 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
570 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
571 $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift'];
572 }
573
574 $this->tab_top += $extra_under_address_shift;
575 $this->tab_top_newpage += 0;
576
577
578 // Define height of table for lines (for first page)
579 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->getHeightForQRInvoice(1, $object, $langs);
580
581 $nexY = $this->tab_top - 1;
582
583 // Specific stuff for situations invoices first page
584 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
585 $tab_top = 130;
586 } else {
587 $tab_top = 90;
588 }
589
590 $tab_height = 130;
591 $tab_height_newpage = 150;
592
593 $this->_tableFirstPage($pdf, $tab_top, $this->page_hauteur - 100 - $this->heightforfreetext - $this->heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
594
595 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
596
597 $this->_pagefoot($pdf, $object, $outputlangs, 1);
598
599 $pdf->AddPage();
600 $pdf->setPage(2);
601 $pagenb++;
602 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
603 $pdf->setTopMargin($this->tab_top_newpage);
604
605 // Incoterm
606 $height_incoterms = 0;
607 if (isModEnabled('incoterm')) {
608 $desc_incoterms = $object->getIncotermsForPDF();
609 if ($desc_incoterms) {
610 $this->tab_top -= 2;
611
612 $pdf->SetFont('', '', $default_font_size - 1);
613 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
614 $nexY = max($pdf->GetY(), $nexY);
615 $height_incoterms = $nexY - $this->tab_top;
616
617 // Rect takes a length in 3rd parameter
618 $pdf->SetDrawColor(192, 192, 192);
619 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
620
621 $this->tab_top = $nexY + 6;
622 $height_incoterms += 4;
623 }
624 }
625
626 // Displays notes. Here we are still on code eecuted only for the first page.
627 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
628 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
629 // Get first sale rep
630 if (is_object($object->thirdparty)) {
631 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
632 $salerepobj = new User($this->db);
633 $salerepobj->fetch($salereparray[0]['id']);
634 if (!empty($salerepobj->signature)) {
635 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
636 }
637 }
638 }
639
640 // Extrafields in note
641 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
642 if (!empty($extranote)) {
643 $notetoshow = dol_concatdesc((string) $notetoshow, $extranote);
644 }
645
646 $pagenb = $pdf->getPage();
647 if ($notetoshow) {
648 $this->tab_top -= 2;
649
650 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
651 $pageposbeforenote = $pagenb;
652
653 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
654 complete_substitutions_array($substitutionarray, $outputlangs, $object);
655 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
656 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
657
658 $pdf->startTransaction();
659
660 $pdf->SetFont('', '', $default_font_size - 1);
661 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
662 // Description
663 $pageposafternote = $pdf->getPage();
664 $posyafter = $pdf->GetY();
665
666 if ($pageposafternote > $pageposbeforenote) {
667 $pdf->rollbackTransaction(true);
668
669 // prepare pages to receive notes
670 while ($pagenb < $pageposafternote) {
671 $pdf->AddPage();
672 $pagenb++;
673 if (!empty($this->tplidx)) {
674 $pdf->useTemplate($this->tplidx);
675 }
676 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
677 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
678 }
679 $pdf->setTopMargin($this->tab_top_newpage);
680 // The only function to edit the bottom margin of current page to set it.
681 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext);
682 }
683
684 // back to start
685 $pdf->setPage($pageposbeforenote);
686 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext);
687 $pdf->SetFont('', '', $default_font_size - 1);
688 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
689 $pageposafternote = $pdf->getPage();
690
691 $posyafter = $pdf->GetY();
692
693 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) { // There is no space left for total+free text
694 $pdf->AddPage('', '', true);
695 $pagenb++;
696 $pageposafternote++;
697 $pdf->setPage($pageposafternote);
698 $pdf->setTopMargin($this->tab_top_newpage);
699 // The only function to edit the bottom margin of current page to set it.
700 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext);
701 //$posyafter = $this->tab_top_newpage;
702 }
703
704
705 // apply note frame to previous pages
706 $i = $pageposbeforenote;
707 while ($i < $pageposafternote) {
708 $pdf->setPage($i);
709
710
711 $pdf->SetDrawColor(128, 128, 128);
712 // Draw note frame
713 if ($i > $pageposbeforenote) {
714 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
715 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
716 } else {
717 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
718 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
719 }
720
721 // Add footer
722 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
723 $this->_pagefoot($pdf, $object, $outputlangs, 1);
724
725 $i++;
726 }
727
728 // apply note frame to last page
729 $pdf->setPage($pageposafternote);
730 if (!empty($this->tplidx)) {
731 $pdf->useTemplate($this->tplidx);
732 }
733 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
734 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
735 }
736 $height_note = $posyafter - $this->tab_top_newpage;
737 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
738 } else {
739 // No pagebreak
740 $pdf->commitTransaction();
741 $posyafter = $pdf->GetY();
742 $height_note = $posyafter - $this->tab_top;
743 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
744
745
746 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
747 // not enough space, need to add page
748 $pdf->AddPage('', '', true);
749 $pagenb++;
750 $pageposafternote++;
751 $pdf->setPage($pageposafternote);
752 if (!empty($this->tplidx)) {
753 $pdf->useTemplate($this->tplidx);
754 }
755 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
756 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
757 }
758
759 $posyafter = $this->tab_top_newpage;
760 }
761 }
762
763 $tab_height -= $height_note;
764 $this->tab_top = $posyafter + 6;
765 } else {
766 $height_note = 0;
767 }
768
769 // Use new auto column system
770 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
771
772 // Table simulation to know the height of the title line (this set this->tableTitleHeight)
773 // don't need it in situation invoices
774 // $pdf->startTransaction();
775 // $this->pdfTabTitles($pdf, $this->tab_top_newpage + ($this->tabTitleHeight/2), $tab_height, $outputlangs, $hidetop);
776 // $pdf->rollbackTransaction(true);
777
778 $nexY = $this->tab_top_newpage + $this->tabTitleHeight;
779
780 // Loop on each lines
781 $pageposbeforeprintlines = $pdf->getPage();
782 $pagenb = $pageposbeforeprintlines;
783 for ($i = 0; $i < $nblines; $i++) {
784 $posy = $nexY;
785 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
786 $pdf->SetTextColor(0, 0, 0);
787
788 // Define size of image if we need it
789 $imglinesize = array();
790 if (!empty($realpatharray[$i])) {
791 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
792 }
793
794 $pdf->setTopMargin($this->tab_top_newpage);
795 $pdf->setPageOrientation('', true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot); // The only function to edit the bottom margin of current page to set it.
796 $pageposbefore = $pdf->getPage();
797
798 $showpricebeforepagebreak = 1;
799 $posYAfterImage = 0;
800 $posYAfterDescription = 0;
801
802 if ($this->getColumnStatus('photo')) {
803 // We start with Photo of product line
804 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($posy + $imglinesize['height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) { // If photo too high, we moved completely on new page
805 $pdf->AddPage('', '', true);
806 if (!empty($this->tplidx)) {
807 $pdf->useTemplate($this->tplidx);
808 }
809 $pdf->setPage($pageposbefore + 1);
810
811 $posy = $this->tab_top_newpage;
812
813 // Allows data in the first page if description is long enough to break in multiples pages
814 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
815 $showpricebeforepagebreak = 1;
816 } else {
817 $showpricebeforepagebreak = 0;
818 }
819 }
820
822 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
823 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $posy + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
824 // $pdf->Image does not increase value return by getY, so we save it manually
825 $posYAfterImage = $posy + $imglinesize['height'];
826 }
827 }
828
829 // Description of product line
830 if ($this->getColumnStatus('desc')) {
831 $pdf->startTransaction();
832
833 $this->printColDescContent($pdf, $posy, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
834 $pageposafter = $pdf->getPage();
835
836 if ($pageposafter > $pageposbefore) { // There is a pagebreak
837 $pdf->rollbackTransaction(true);
838 $pageposafter = $pageposbefore;
839 $pdf->setPageOrientation('', true, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
840
841 $this->printColDescContent($pdf, $posy, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
842
843 $pageposafter = $pdf->getPage();
844 $posyafter = $pdf->GetY();
845 //var_dump($posyafter); var_dump(($this->page_hauteur - ($this->heightforfooter+$this->heightforfreetext+$this->heightforinfotot))); exit;
846 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) { // There is no space left for total+free text
847 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
848 $pdf->AddPage('', '', true);
849 if (!empty($this->tplidx)) {
850 $pdf->useTemplate($this->tplidx);
851 }
852 $pdf->setPage($pageposafter + 1);
853 }
854 } else {
855 // We found a page break
856 // Allows data in the first page if description is long enough to break in multiples pages
857 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
858 $showpricebeforepagebreak = 1;
859 } else {
860 $showpricebeforepagebreak = 0;
861 }
862 }
863 } else { // No pagebreak
864 $pdf->commitTransaction();
865 }
866 $posYAfterDescription = $pdf->GetY();
867 }
868
869 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
870
871 $pageposafter = $pdf->getPage();
872 $pdf->setPage($pageposbefore);
873 $pdf->setTopMargin($this->marge_haute);
874 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
875
876 // We suppose that a too long description or photo were moved completely on next page
877 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
878 $pdf->setPage($pageposafter);
879 $posy = $this->tab_top_newpage;
880 }
881
882 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
883
884 // VAT Rate
885 if ($this->getColumnStatus('vat')) {
886 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
887 $this->printStdColumnContent($pdf, $posy, 'vat', $vat_rate);
888 $nexY = max($pdf->GetY(), $nexY);
889 }
890
891 // Unit price before discount
892 if ($this->getColumnStatus('subprice')) {
893 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
894 $this->printStdColumnContent($pdf, $posy, 'subprice', $up_excl_tax);
895 $nexY = max($pdf->GetY(), $nexY);
896 }
897
898 // Quantity
899 // Enough for 6 chars
900 if ($this->getColumnStatus('qty')) {
901 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
902 $this->printStdColumnContent($pdf, $posy, 'qty', $qty);
903 $nexY = max($pdf->GetY(), $nexY);
904 }
905
906 // Situation progress
907 if ($this->getColumnStatus('progress')) {
908 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
909 $this->printStdColumnContent($pdf, $posy, 'progress', $progress);
910 $nexY = max($pdf->GetY(), $nexY);
911 }
912
913 // Unit
914 if ($this->getColumnStatus('unit')) {
915 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
916 $this->printStdColumnContent($pdf, $posy, 'unit', $unit);
917 $nexY = max($pdf->GetY(), $nexY);
918 }
919
920 // Discount on line
921 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
922 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
923 $this->printStdColumnContent($pdf, $posy, 'discount', $remise_percent);
924 $nexY = max($pdf->GetY(), $nexY);
925 }
926
927 // Total excl tax line (HT)
928 if ($this->getColumnStatus('totalexcltax')) {
929 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
930 $this->printStdColumnContent($pdf, $posy, 'totalexcltax', $total_excl_tax);
931 $nexY = max($pdf->GetY(), $nexY);
932 }
933
934 // Retrieving information from the previous line
935 $TInfosLigneSituationPrecedente = $this->getInfosLineLastSituation($object, $object->lines[$i]);
936
937 // Sum
938 $columkey = 'btpsomme';
939 if ($this->getColumnStatus($columkey)) {
940 $printval = price($TInfosLigneSituationPrecedente['total_ht_without_progress'], 0, '', 1, -1, 2);
941 $this->printStdColumnContent($pdf, $posy, $columkey, $printval);
942 $nexY = max($pdf->GetY(), $nexY);
943 }
944
945 // Current progress
946 $columkey = 'progress_amount';
947 if ($this->getColumnStatus($columkey)) {
948 $printval = price($object->lines[$i]->total_ht, 0, '', 1, -1, 2);
949 $this->printStdColumnContent($pdf, $posy, $columkey, $printval);
950 $nexY = max($pdf->GetY(), $nexY);
951 }
952 // Previous progress line
953 $columkey = 'prev_progress';
954 if ($this->getColumnStatus($columkey)) {
955 $printval = $TInfosLigneSituationPrecedente['progress_prec'].'%';
956 $this->printStdColumnContent($pdf, $posy, $columkey, $printval);
957 $nexY = max($pdf->GetY(), $nexY);
958 }
959 // Previous progress amount
960 $columkey = 'prev_progress_amount';
961 if ($this->getColumnStatus($columkey)) {
962 $printval = price($TInfosLigneSituationPrecedente['total_ht'], 0, '', 1, -1, 2);
963 $this->printStdColumnContent($pdf, $posy, $columkey, $printval);
964 $nexY = max($pdf->GetY(), $nexY);
965 }
966
967 $parameters = array(
968 'object' => $object,
969 'i' => $i,
970 'pdf' => & $pdf,
971 'curY' => & $posy,
972 'nexY' => & $nexY,
973 'outputlangs' => $outputlangs,
974 'hidedetails' => $hidedetails
975 );
976 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
977
978
979 $sign = 1;
980 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
981 $sign = -1;
982 }
983 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
984 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
985 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
986 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
987 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
988 } else {
989 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
990 }
991 } else {
992 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
993 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
994 } else {
995 $tvaligne = $sign * $object->lines[$i]->total_tva;
996 }
997 }
998
999 $localtax1ligne = $object->lines[$i]->total_localtax1;
1000 $localtax2ligne = $object->lines[$i]->total_localtax2;
1001 $localtax1_rate = $object->lines[$i]->localtax1_tx;
1002 $localtax2_rate = $object->lines[$i]->localtax2_tx;
1003 $localtax1_type = $object->lines[$i]->localtax1_type;
1004 $localtax2_type = $object->lines[$i]->localtax2_type;
1005
1006 $vatrate = (string) $object->lines[$i]->tva_tx;
1007
1008 // Retrieve type from database for backward compatibility with old records
1009 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
1010 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
1011 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
1012 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
1013 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
1014 }
1015
1016 // retrieve global local tax
1017 if ($localtax1_type && $localtax1ligne != 0) {
1018 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
1019 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
1020 } else {
1021 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
1022 }
1023 }
1024 if ($localtax2_type && $localtax2ligne != 0) {
1025 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
1026 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
1027 } else {
1028 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1029 }
1030 }
1031
1032 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
1033 $vatrate .= '*';
1034 }
1035
1036 // Fill $this->tva and $this->tva_array
1037 if (!isset($this->tva[$vatrate])) {
1038 $this->tva[$vatrate] = 0;
1039 }
1040 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
1041 $vatcode = $object->lines[$i]->vat_src_code;
1042 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1043 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
1044 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
1045 }
1046 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne, 'tot_ht' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'] + $object->lines[$i]->total_ht);
1047 } else {
1048 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
1049 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
1050 }
1051 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
1052 }
1053
1054 $nexY = max($nexY, $posYAfterImage);
1055
1056 // Add line
1057 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
1058 $pdf->setPage($pageposafter);
1059 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
1060 //$pdf->SetDrawColor(190,190,200);
1061 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1062 $pdf->SetLineStyle(array('dash' => 0));
1063 }
1064
1065 // Detect if some page were added automatically and output _tableau for past pages
1066 while ($pagenb < $pageposafter) {
1067 $pdf->setPage($pagenb);
1068 $tabtop = $this->tab_top;
1069 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1070 if ($pagenb != $pageposbeforeprintlines) {
1071 $tabtop = $this->tab_top_newpage;
1072 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1073 $hidetop = 1;
1074 }
1075 $this->_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1076
1077 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1078 $pagenb++;
1079 $pdf->setPage($pagenb);
1080 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
1081 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1082 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1083 }
1084 if (!empty($this->tplidx)) {
1085 $pdf->useTemplate($this->tplidx);
1086 }
1087 }
1088
1089 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
1090 $tabtop = $this->tab_top;
1091 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1092 if ($pagenb != $pageposbeforeprintlines) {
1093 $tabtop = $this->tab_top_newpage;
1094 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1095 $hidetop = 1;
1096 }
1097 $this->_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1098
1099 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1100 // New page
1101 $pdf->AddPage();
1102 if (!empty($this->tplidx)) {
1103 $pdf->useTemplate($this->tplidx);
1104 }
1105 $pagenb++;
1106 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1107 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1108 }
1109 }
1110 }
1111
1112 // Show square
1113 // special for situation invoices
1114 $tabtop = $this->tab_top_newpage;
1115 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1116 $tabTitleHeight = 0;
1117 $this->_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1118
1119 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1120
1121 // Display infos area
1122 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1123
1124 // Display total zone
1125 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1126
1127 // Display payment area
1128 $listofpayments = $object->getListOfPayments('', 0, 1);
1129 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1130 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1131 }
1132
1133 // Pagefoot
1134 $this->_pagefoot($pdf, $object, $outputlangs);
1135 if (method_exists($pdf, 'AliasNbPages')) {
1136 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1137 }
1138
1139 $this->resumeLastPage($pdf, $object, 0, $tab_top, $outputlangs, $outputlangsbis);
1140 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1141 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1142
1143 // Add terms to sale
1144 $termsofsalefilename = getDolGlobalString('MAIN_INFO_INVOICE_TERMSOFSALE');
1145 if (getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1146 $termsofsale = $conf->invoice->dir_output.'/'.$termsofsalefilename;
1147 if (!empty($conf->invoice->multidir_output[$object->entity ?? $conf->entity])) {
1148 $termsofsale = $conf->invoice->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
1149 }
1150 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1151 $pagecount = $pdf->setSourceFile($termsofsale);
1152 for ($i = 1; $i <= $pagecount; $i++) {
1153 $tplIdx = $pdf->importPage($i);
1154 if ($tplIdx !== false) {
1155 $s = $pdf->getTemplatesize($tplIdx);
1156 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1157 $pdf->useTemplate($tplIdx);
1158 } else {
1159 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
1160 }
1161 }
1162 }
1163 }
1164
1165 $pdf->Close();
1166
1167 $pdf->Output($file, 'F');
1168
1169 // Add pdfgeneration hook
1170 $hookmanager->initHooks(array('pdfgeneration'));
1171 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1172 global $action;
1173 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1174 if ($reshook < 0) {
1175 $this->error = $hookmanager->error;
1176 $this->errors = $hookmanager->errors;
1177 }
1178
1179 dolChmod($file);
1180
1181 $this->result = array('fullpath' => $file);
1182
1183 return 1; // No error
1184 } else {
1185 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1186 return 0;
1187 }
1188 } else {
1189 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1190 return 0;
1191 }
1192 }
1193
1194
1204 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1205 {
1206 global $conf;
1207
1208 $sign = 1;
1209 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1210 $sign = -1;
1211 }
1212
1213 $tab3_posx = 120;
1214 $tab3_top = $posy + 8;
1215 $tab3_width = 80;
1216 $tab3_height = 4;
1217 if ($this->page_largeur < 210) { // To work with US executive format
1218 $tab3_posx -= 15;
1219 }
1220
1221 $default_font_size = pdf_getPDFFontSize($outputlangs);
1222
1223 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1224 if ($object->type == 2) {
1225 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1226 }
1227
1228 $pdf->SetFont('', '', $default_font_size - 3);
1229 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1230 $pdf->MultiCell(60, 3, $title, 0, 'L', false);
1231
1232 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1233
1234 $pdf->SetFont('', '', $default_font_size - 4);
1235 $pdf->SetXY($tab3_posx, $tab3_top);
1236 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
1237 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1238 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
1239 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1240 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
1241 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1242 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
1243
1244 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1245
1246 $y = 0;
1247
1248 $pdf->SetFont('', '', $default_font_size - 4);
1249
1250
1251 // Loop on each discount available (deposits and credit notes and excess of payment included)
1252 $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,";
1253 $sql .= " re.description, re.fk_facture_source,";
1254 $sql .= " f.type, f.datef";
1255 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1256 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1257 $resql = $this->db->query($sql);
1258 if ($resql) {
1259 $num = $this->db->num_rows($resql);
1260 $i = 0;
1261 $invoice = new Facture($this->db);
1262 while ($i < $num) {
1263 $y += 3;
1264 $obj = $this->db->fetch_object($resql);
1265
1266 if ($obj->type == 2) {
1267 $text = $outputlangs->transnoentities("CreditNote");
1268 } elseif ($obj->type == 3) {
1269 $text = $outputlangs->transnoentities("Deposit");
1270 } elseif ($obj->type == 0) {
1271 $text = $outputlangs->transnoentities("ExcessReceived");
1272 } else {
1273 $text = $outputlangs->transnoentities("UnknownType");
1274 }
1275
1276 $invoice->fetch($obj->fk_facture_source);
1277
1278 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1279 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', false);
1280 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1281 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', false);
1282 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1283 $pdf->MultiCell(20, 3, $text, 0, 'L', false);
1284 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1285 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', false);
1286
1287 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1288
1289 $i++;
1290 }
1291 } else {
1292 $this->error = $this->db->lasterror();
1293 return -1;
1294 }
1295
1296 // Loop on each payment
1297 // TODO Call getListOfPayments instead of hard coded sql
1298 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1299 $sql .= " cp.code";
1300 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1301 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1302 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1303 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1304 $sql .= " ORDER BY p.datep";
1305
1306 $resql = $this->db->query($sql);
1307 if ($resql) {
1308 $num = $this->db->num_rows($resql);
1309 $i = 0;
1310 $y += 3;
1311 $maxY = $y;
1312 while ($i < $num) {
1313 $row = $this->db->fetch_object($resql);
1314 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1315 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1316 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1317 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', false);
1318 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1319 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1320
1321 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1322 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1323 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1324 $pdf->MultiCell(30, 3, $row->num, 0, 'L', false);
1325 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1326 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1327 $y += 3;
1328 $i++;
1329 }
1330
1331 return $tab3_top + $y + 3;
1332 } else {
1333 $this->error = $this->db->lasterror();
1334 return -1;
1335 }
1336 }
1337
1338
1349 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1350 {
1351 global $mysoc, $hookmanager;
1352
1353 $default_font_size = pdf_getPDFFontSize($outputlangs);
1354
1355 $pdf->SetFont('', '', $default_font_size - 1);
1356
1357 krsort($this->tva_array);
1358
1359 // Clean data type
1360 $object->total_tva = (float) $object->total_tva;
1361
1362 // Show VAT details
1363 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1364 $pdf->SetFillColor(224, 224, 224);
1365
1366 $pdf->SetFont('', '', $default_font_size - 2);
1367 $pdf->SetXY($this->marge_gauche, $posy);
1368 $titre = $outputlangs->transnoentities("VAT");
1369 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1370
1371 $pdf->SetFont('', '', $default_font_size - 2);
1372 $pdf->SetXY($this->marge_gauche + 25, $posy);
1373 $titre = $outputlangs->transnoentities("NetTotal");
1374 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1375
1376 $pdf->SetFont('', '', $default_font_size - 2);
1377 $pdf->SetXY($this->marge_gauche + 50, $posy);
1378 $titre = $outputlangs->transnoentities("VATAmount");
1379 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1380
1381 $pdf->SetFont('', '', $default_font_size - 2);
1382 $pdf->SetXY($this->marge_gauche + 75, $posy);
1383 $titre = $outputlangs->transnoentities("AmountTotal");
1384 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1385
1386 $posy = $pdf->GetY();
1387 $tot_ht = 0;
1388 $tot_tva = 0;
1389 $tot_ttc = 0;
1390
1391 foreach ($this->tva_array as $tvakey => $tvaval) {
1392 $pdf->SetFont('', '', $default_font_size - 2);
1393 $pdf->SetXY($this->marge_gauche, $posy);
1394 $titre = round((float) $tvakey, 2) . "%";
1395 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1396
1397 $pdf->SetFont('', '', $default_font_size - 2);
1398 $pdf->SetXY($this->marge_gauche + 25, $posy);
1399 $titre = price($tvaval['tot_ht']);
1400 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1401 $tot_ht += $tvaval['tot_ht'];
1402
1403 $pdf->SetFont('', '', $default_font_size - 2);
1404 $pdf->SetXY($this->marge_gauche + 50, $posy);
1405 $titre = price($tvaval['amount']);
1406 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1407 $tot_tva += $tvaval['amount'];
1408
1409 $pdf->SetFont('', '', $default_font_size - 2);
1410 $pdf->SetXY($this->marge_gauche + 75, $posy);
1411 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1412 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1413 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1414
1415 $posy = $pdf->GetY();
1416 }
1417 }
1418
1419 // If France, show VAT mention if applicable
1420 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1421 $pdf->SetFont('', '', $default_font_size - 2);
1422 $pdf->SetXY($this->marge_gauche, $posy);
1423 if (empty($mysoc->tva_assuj)) {
1424 if ($mysoc->forme_juridique_code == 92) {
1425 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', false);
1426 } else {
1427 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
1428 }
1429 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1430 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', false);
1431 }
1432 $posy = $pdf->GetY() + 4;
1433 }
1434
1435 $posxval = 52; // Position of values of properties shown on left side
1436 $posxend = 110; // End of x for text on left side
1437 if ($this->page_largeur < 210) { // To work with US executive format
1438 $posxend -= 10;
1439 }
1440
1441 // Show payments conditions
1442 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1443 $pdf->SetFont('', 'B', $default_font_size - 2);
1444 $pdf->SetXY($this->marge_gauche, $posy);
1445 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1446 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1447
1448 $pdf->SetFont('', '', $default_font_size - 2);
1449 $pdf->SetXY($posxval, $posy);
1450 $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);
1451 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1452 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1453
1454 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1455 }
1456
1457 // Show category of operations
1458 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1459 $pdf->SetFont('', 'B', $default_font_size - 2);
1460 $pdf->SetXY($this->marge_gauche, $posy);
1461 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1462 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1463
1464 $pdf->SetFont('', '', $default_font_size - 2);
1465 $pdf->SetXY($posxval, $posy);
1466 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1467 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1468
1469 $posy = $pdf->GetY() + 3; // for 2 lines
1470 }
1471
1472 if ($object->type != 2) {
1473 // Check a payment mode is defined
1474 if (empty($object->mode_reglement_code)
1475 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1476 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1477 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1478 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1479 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1480 // Avoid having any valid PDF with setup that is not complete
1481 $outputlangs->load("errors");
1482
1483 $pdf->SetXY($this->marge_gauche, $posy);
1484 $pdf->SetTextColor(200, 0, 0);
1485 $pdf->SetFont('', 'B', $default_font_size - 2);
1486 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1487 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', false);
1488 $pdf->SetTextColor(0, 0, 0);
1489
1490 $posy = $pdf->GetY() + 1;
1491 }
1492
1493 // Show payment mode
1494 if (!empty($object->mode_reglement_code)
1495 && $object->mode_reglement_code != 'CHQ'
1496 && $object->mode_reglement_code != 'VIR') {
1497 $pdf->SetFont('', 'B', $default_font_size - 2);
1498 $pdf->SetXY($this->marge_gauche, $posy);
1499 $titre = $outputlangs->transnoentities("PaymentMode").':';
1500 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1501
1502 $pdf->SetFont('', '', $default_font_size - 2);
1503 $pdf->SetXY($posxval, $posy);
1504 $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);
1505
1506 //#21654: add account number used for the debit
1507 if ($object->mode_reglement_code == "PRE") {
1508 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1509 $bac = new CompanyBankAccount($this->db);
1510 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1511 $bac->fetch(0, (string) $object->thirdparty->id);
1512 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1513 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1514 }
1515
1516 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1517
1518 $posy = $pdf->GetY();
1519 }
1520
1521 // Show if Option VAT debit option is on also if transmitter is french
1522 // Decret n°2099-1299 2022-10-07
1523 // French mention : "Option pour le paiement de la taxe d'après les débits"
1524 if ($this->emetteur->country_code == 'FR') {
1525 if (getDolGlobalInt('TAX_MODE') == 1) {
1526 $pdf->SetXY($this->marge_gauche, $posy);
1527 $pdf->writeHTMLCell(80, 5, null, null, $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1528
1529 $posy = $pdf->GetY() + 1;
1530 }
1531 }
1532
1533 // Show online payment link
1534 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1535 $useonlinepayment = 0;
1536 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1537 if (isModEnabled('paypal')) {
1538 $useonlinepayment++;
1539 }
1540 if (isModEnabled('stripe')) {
1541 $useonlinepayment++;
1542 }
1543 if (isModEnabled('paybox')) {
1544 $useonlinepayment++;
1545 }
1546 $parameters = array();
1547 $action = '';
1548 $reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1549 if ($reshook > 0) {
1550 if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
1551 $useonlinepayment += $hookmanager->resArray['showonlinepaymenturl'];
1552 }
1553 }
1554 }
1555
1556
1557 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1558 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1559 global $langs;
1560
1561 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1562 $servicename = $langs->transnoentities('Online');
1563 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1564 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1565
1566 $pdf->SetXY($this->marge_gauche, $posy);
1567 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, null, null, dol_htmlentitiesbr($linktopay), 0, 1);
1568
1569 $posy = $pdf->GetY() + 1;
1570 }
1571 }
1572
1573 // Show payment mode CHQ
1574 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1575 // If payment mode unregulated or payment mode forced to CHQ
1576 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1577 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1578
1579 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1580 $account = new Account($this->db);
1581 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1582
1583 $pdf->SetXY($this->marge_gauche, $posy);
1584 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1585 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', false);
1586 $posy = $pdf->GetY() + 1;
1587
1588 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1589 $pdf->SetXY($this->marge_gauche, $posy);
1590 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1591 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', false);
1592 $posy = $pdf->GetY() + 2;
1593 }
1594 }
1595 if (getDolGlobalString('FACTURE_CHQ_NUMBER') == -1) {
1596 $pdf->SetXY($this->marge_gauche, $posy);
1597 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1598 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', false);
1599 $posy = $pdf->GetY() + 1;
1600
1601 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1602 $pdf->SetXY($this->marge_gauche, $posy);
1603 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1604 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', false);
1605 $posy = $pdf->GetY() + 2;
1606 }
1607 }
1608 }
1609 }
1610
1611 // If payment mode not forced or forced to VIR, show payment with BAN
1612 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1613 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1614 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1615 if ($object->fk_bank > 0) {
1616 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1617 }
1618 $account = new Account($this->db);
1619 $account->fetch($bankid);
1620
1621 $curx = $this->marge_gauche;
1622 $cury = $posy;
1623
1624 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1625
1626 $posy += 2;
1627
1628 // Show structured communication
1629 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1630 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1631 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1632
1633 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', false);
1634 }
1635 }
1636 }
1637 }
1638
1639 return $posy;
1640 }
1641
1642
1654 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1655 {
1656 global $conf, $mysoc, $hookmanager;
1657
1658 $sign = 1;
1659 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1660 $sign = -1;
1661 }
1662
1663 $default_font_size = pdf_getPDFFontSize($outputlangs);
1664
1665 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1666 $outputlangsbis = new Translate('', $conf);
1667 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1668 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1669 $default_font_size--;
1670 }
1671
1672 $tab2_top = $posy - 4;
1673 $tab2_hl = 4;
1674 $pdf->SetFont('', '', $default_font_size - 1);
1675
1676 // Total table
1677 $col1x = 120;
1678 $col2x = 170;
1679 if ($this->page_largeur < 210) { // To work with US executive format
1680 $col2x -= 20;
1681 }
1682 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1683
1684 $useborder = 0;
1685 $index = 0;
1686
1687 // Total HT
1688 $pdf->SetFillColor(255, 255, 255);
1689 $pdf->SetXY($col1x, $tab2_top + 0);
1690 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', true);
1691
1692 $total_ht = ((isModEnabled('multicurrency') && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1693 $pdf->SetXY($col2x, $tab2_top + 0);
1694 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht, 0, $outputlangs), 0, 'R', true);
1695
1696 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1697 $index++;
1698 $pdf->SetFillColor(255, 255, 255);
1699 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1700 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', true);
1701
1702 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1703 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', true);
1704 }
1705
1706 // Show VAT by rates and total
1707 $pdf->SetFillColor(248, 248, 248);
1708
1709 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1710
1711 $this->atleastoneratenotnull = 0;
1712 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1713 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1714 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1715 // Nothing to do
1716 } else {
1717 //Local tax 1 before VAT
1718 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1719 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1720 continue;
1721 }
1722
1723 foreach ($localtax_rate as $tvakey => $tvaval) {
1724 if ($tvakey != 0) { // On affiche pas taux 0
1725 //$this->atleastoneratenotnull++;
1726
1727 $index++;
1728 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1729
1730 $tvacompl = '';
1731 if (preg_match('/\*/', $tvakey)) {
1732 $tvakey = str_replace('*', '', $tvakey);
1733 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1734 }
1735
1736 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1737 $totalvat .= ' ';
1738
1739 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1740 $totalvat .= $tvacompl;
1741 } else {
1742 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1743 }
1744
1745 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1746
1747 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1748
1749 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1750 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1751 }
1752 }
1753 }
1754
1755 //Local tax 2 before VAT
1756 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1757 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1758 continue;
1759 }
1760
1761 foreach ($localtax_rate as $tvakey => $tvaval) {
1762 if ($tvakey != 0) { // On affiche pas taux 0
1763 //$this->atleastoneratenotnull++;
1764
1765 $index++;
1766 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1767
1768 $tvacompl = '';
1769 if (preg_match('/\*/', $tvakey)) {
1770 $tvakey = str_replace('*', '', $tvakey);
1771 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1772 }
1773 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1774 $totalvat .= ' ';
1775
1776 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1777 $totalvat .= $tvacompl;
1778 } else {
1779 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1780 }
1781
1782 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1783
1784 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1785
1786 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1787 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1788 }
1789 }
1790 }
1791 //}
1792
1793 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1794 // VAT
1795 $tvas = array();
1796 $nblines = count($object->lines);
1797 for ($i = 0; $i < $nblines; $i++) {
1798 $tvaligne = $object->lines[$i]->total_tva;
1799 $vatrate = (string) $object->lines[$i]->tva_tx;
1800
1801 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
1802 $vatrate .= '*';
1803 }
1804 if (! isset($tvas[$vatrate])) {
1805 $tvas[$vatrate] = 0;
1806 }
1807 $tvas[$vatrate] += $tvaligne;
1808 }
1809
1810 foreach ($tvas as $tvakey => $tvaval) {
1811 if ($tvakey != 0) { // On affiche pas taux 0
1812 $this->atleastoneratenotnull++;
1813
1814 $index++;
1815 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1816
1817 $tvacompl = '';
1818 if (preg_match('/\*/', $tvakey)) {
1819 $tvakey = str_replace('*', '', $tvakey);
1820 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1821 }
1822 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1823 $totalvat .= ' ';
1824 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1825 $totalvat .= vatrate($tvaval['vatrate'], true).$tvacompl;
1826 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1827 $totalvat .= $tvaval['vatcode'].$tvacompl;
1828 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1829 $totalvat .= $tvacompl;
1830 } else {
1831 $totalvat .= vatrate($tvaval['vatrate'], true).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1832 }
1833 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1834
1835 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1836 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', true);
1837 }
1838 }
1839 }
1840
1841 //Local tax 1 after VAT
1842 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1843 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1844 continue;
1845 }
1846
1847 foreach ($localtax_rate as $tvakey => $tvaval) {
1848 if ($tvakey != 0) { // On affiche pas taux 0
1849 //$this->atleastoneratenotnull++;
1850
1851 $index++;
1852 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1853
1854 $tvacompl = '';
1855 if (preg_match('/\*/', $tvakey)) {
1856 $tvakey = str_replace('*', '', $tvakey);
1857 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1858 }
1859 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1860 $totalvat .= ' ';
1861
1862 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1863 $totalvat .= $tvacompl;
1864 } else {
1865 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1866 }
1867
1868 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1869
1870 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1871
1872 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1873 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1874 }
1875 }
1876 }
1877
1878 //Local tax 2 after VAT
1879 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1880 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1881 continue;
1882 }
1883
1884 foreach ($localtax_rate as $tvakey => $tvaval) {
1885 // retrieve global local tax
1886 if ($tvakey != 0) { // On affiche pas taux 0
1887 //$this->atleastoneratenotnull++;
1888
1889 $index++;
1890 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1891
1892 $tvacompl = '';
1893 if (preg_match('/\*/', $tvakey)) {
1894 $tvakey = str_replace('*', '', $tvakey);
1895 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1896 }
1897 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1898 $totalvat .= ' ';
1899
1900 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1901 $totalvat .= $tvacompl;
1902 } else {
1903 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1904 }
1905
1906 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1907
1908 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1909
1910 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1911 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1912 }
1913 }
1914 }
1915
1916
1917 // Revenue stamp
1918 if (price2num($object->revenuestamp, 'MT') != 0) {
1919 $index++;
1920 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1921 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', true);
1922
1923 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1924 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', true);
1925 }
1926
1927 // Total TTC
1928 $index++;
1929 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1930 $pdf->SetTextColor(0, 0, 60);
1931 $pdf->SetFillColor(224, 224, 224);
1932 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', true);
1933
1934 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1935 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
1936
1937
1938 // Retained warranty
1939 if ($object->displayRetainedWarranty()) {
1940 $pdf->SetTextColor(40, 40, 40);
1941 $pdf->SetFillColor(255, 255, 255);
1942
1943 $retainedWarranty = $object->getRetainedWarrantyAmount();
1944 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1945
1946 // Billed - retained warranty
1947 $index++;
1948 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1949 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', true);
1950
1951 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1952 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', true);
1953
1954 // retained warranty
1955 $index++;
1956 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1957
1958 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
1959 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1960
1961 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', true);
1962 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1963 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', true);
1964 }
1965 }
1966 }
1967
1968 $pdf->SetTextColor(0, 0, 0);
1969
1970 $resteapayer = 0;
1971 /*
1972 $resteapayer = $object->total_ttc - $deja_regle;
1973 if (! empty($object->paye)) $resteapayer=0;
1974 */
1975
1976 if ($deja_regle > 0) {
1977 // Already paid + Deposits
1978 $index++;
1979
1980 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1981 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', false);
1982
1983 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1984 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', false);
1985
1986 /*
1987 if ($object->close_code == 'discount_vat')
1988 {
1989 $index++;
1990 $pdf->SetFillColor(255,255,255);
1991
1992 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1993 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1994
1995 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1996 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1997
1998 $resteapayer=0;
1999 }
2000 */
2001
2002 $index++;
2003 $pdf->SetTextColor(0, 0, 60);
2004 $pdf->SetFillColor(224, 224, 224);
2005 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2006 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', true);
2007 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2008 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
2009
2010 $pdf->SetFont('', '', $default_font_size - 1);
2011 $pdf->SetTextColor(0, 0, 0);
2012 }
2013
2014 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2015
2016 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2017 if ($reshook < 0) {
2018 $this->error = $hookmanager->error;
2019 $this->errors = $hookmanager->errors;
2020 }
2021
2022 $index++;
2023 return ($tab2_top + ($tab2_hl * $index));
2024 }
2025
2026 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2034 public static function liste_modeles($db, $maxfilenamelength = 0)
2035 {
2036 // phpcs:enable
2037 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2038 }
2039
2040 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2055 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2056 {
2057 global $conf;
2058
2059 // Force to disable hidetop and hidebottom
2060 $hidebottom = 0;
2061 $hidetop = 0;
2062
2063 $currency = !empty($currency) ? $currency : $conf->currency;
2064 $default_font_size = pdf_getPDFFontSize($outputlangs);
2065
2066 // Amount in (at tab_top - 1)
2067 $pdf->SetTextColor(0, 0, 0);
2068 $pdf->SetFont('', '', $default_font_size - 2);
2069
2070 if (empty($hidetop)) {
2071 // Show category of operations
2072 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2073 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2074 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2075 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2076 }
2077
2078 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2079 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2080 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2081
2082 // MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2083 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2084 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2085 }
2086 $tab_top += 4;
2087 }
2088
2089 $pdf->SetDrawColor(128, 128, 128);
2090 $pdf->SetFont('', '', $default_font_size - 1);
2091
2092 // Output Rect
2093 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect prend une longueur en 3eme param et 4eme param
2094
2095 // situation invoice
2096 $pdf->SetFont('', '', $default_font_size - 2);
2097
2098 foreach ($this->cols as $colKey => $colDef) {
2099 if (!$this->getColumnStatus($colKey)) {
2100 continue;
2101 }
2102 $xstartpos = (int) ($colDef['xStartPos'] ?? 0);
2103 //is there any overtitle ?
2104 if (!empty($colDef['overtitle']) && is_array($colDef['overtitle'])) {
2105 $overtitle_top = $tab_top - 4;
2106 $overtitle = $colDef['overtitle']['textkey'] ?? '';
2107 $textWidth = $colDef['overtitle']['width'] ?? 0;
2108 $pdf->SetXY($xstartpos + $colDef['overtitle']['padding'][3], $overtitle_top);
2109 $pdf->MultiCell($textWidth, 2, $overtitle, '', $colDef['overtitle']['align']);
2110 $pdf->line($xstartpos, $overtitle_top, $xstartpos, $overtitle_top + 4); //left
2111 $pdf->line($xstartpos, $overtitle_top, $xstartpos + $textWidth, $overtitle_top); //top
2112 $pdf->line($xstartpos + $textWidth, $overtitle_top, $xstartpos + $textWidth, $overtitle_top + 4); //right
2113 }
2114
2115 // get title label
2116 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
2117
2118 // Add column separator
2119 if (!empty($colDef['border-left'])) {
2120 $pdf->line($xstartpos, $tab_top, $xstartpos, $tab_top + $tab_height);
2121 }
2122
2123 if (empty($hidetop)) {
2124 $pdf->SetXY($xstartpos + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
2125
2126 $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
2127 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
2128 }
2129 }
2130 $pdf->SetFont('', '', $default_font_size - 1);
2131
2132 if (empty($hidetop)) {
2133 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line prend une position y en 2eme param et 4eme param
2134 }
2135 }
2136
2137 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2148 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2149 {
2150 // phpcs:enable
2151 global $conf, $langs;
2152
2153 $ltrdirection = 'L';
2154 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2155 $ltrdirection = 'R';
2156 }
2157
2158 // Load traductions files required by page
2159 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2160
2161 $default_font_size = pdf_getPDFFontSize($outputlangs);
2162
2163 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2164
2165 $pdf->SetTextColor(0, 0, 60);
2166 $pdf->SetFont('', 'B', $default_font_size + 3);
2167
2168 $w = 110;
2169
2170 $posy = $this->marge_haute;
2171 $posx = $this->page_largeur - $this->marge_droite - $w;
2172
2173 $pdf->SetXY($this->marge_gauche, $posy);
2174
2175 // Logo
2176 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2177 if ($this->emetteur->logo) {
2178 $logodir = $conf->mycompany->dir_output;
2179 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2180 $logodir = $conf->mycompany->multidir_output[$object->entity];
2181 }
2182 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2183 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2184 } else {
2185 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2186 }
2187 if (is_readable($logo)) {
2188 $height = pdf_getHeightForLogo($logo);
2189 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2190 } else {
2191 $pdf->SetTextColor(200, 0, 0);
2192 $pdf->SetFont('', 'B', $default_font_size - 2);
2193 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2194 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2195 }
2196 } else {
2197 $text = $this->emetteur->name;
2198 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2199 }
2200 }
2201
2202 $pdf->SetFont('', 'B', $default_font_size + 3);
2203 $pdf->SetXY($posx, $posy);
2204 $pdf->SetTextColor(0, 0, 60);
2205 $subtitle = "";
2206 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2207 if ($object->type == 1) {
2208 $title = $outputlangs->transnoentities("InvoiceReplacement");
2209 }
2210 if ($object->type == 2) {
2211 $title = $outputlangs->transnoentities("InvoiceAvoir");
2212 }
2213 if ($object->type == 3) {
2214 $title = $outputlangs->transnoentities("InvoiceDeposit");
2215 }
2216 if ($object->type == 4) {
2217 $title = $outputlangs->transnoentities("InvoiceProForma");
2218 }
2219 if ($this->situationinvoice) {
2220 $title = $outputlangs->transnoentities("PDFInvoiceSituation");
2221 $subtitle = $outputlangs->transnoentities("PDFSituationTitle", (string) $object->situation_counter);
2222 }
2223 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2224 $title .= ' - ';
2225 if ($object->type == 0) {
2226 if ($this->situationinvoice) {
2227 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2228 }
2229 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2230 } elseif ($object->type == 1) {
2231 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2232 } elseif ($object->type == 2) {
2233 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2234 } elseif ($object->type == 3) {
2235 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2236 } elseif ($object->type == 4) {
2237 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2238 }
2239 }
2240 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2241 // if ($object->status == $object::STATUS_DRAFT) {
2242 // $pdf->SetTextColor(128, 0, 0);
2243 // $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2244 // }
2245
2246 $pdf->MultiCell($w, 3, $title, '', 'R');
2247 if (!empty($subtitle)) {
2248 $pdf->SetFont('', 'B', $default_font_size);
2249 $pdf->SetXY($posx, $posy + 5);
2250 $pdf->MultiCell($w, 6, $subtitle, '', 'R');
2251 $posy += 2;
2252 }
2253
2254 $pdf->SetFont('', 'B', $default_font_size);
2255
2256 /*
2257 $posy += 5;
2258 $pdf->SetXY($posx, $posy);
2259 $pdf->SetTextColor(0, 0, 60);
2260 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2261 if ($object->status == $object::STATUS_DRAFT) {
2262 $pdf->SetTextColor(128, 0, 0);
2263 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2264 }
2265 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2266
2267 $posy += 3;
2268 $pdf->SetFont('', '', $default_font_size - 2);
2269
2270 if ($object->ref_customer) {
2271 $posy += 4;
2272 $pdf->SetXY($posx, $posy);
2273 $pdf->SetTextColor(0, 0, 60);
2274 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2275 }
2276
2277 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2278 $object->fetchProject();
2279 if (!empty($object->project->ref)) {
2280 $posy += 3;
2281 $pdf->SetXY($posx, $posy);
2282 $pdf->SetTextColor(0, 0, 60);
2283 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2284 }
2285 }
2286
2287 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2288 $object->fetchProject();
2289 if (!empty($object->project->ref)) {
2290 $outputlangs->load("projects");
2291 $posy += 3;
2292 $pdf->SetXY($posx, $posy);
2293 $pdf->SetTextColor(0, 0, 60);
2294 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2295 }
2296 }
2297
2298 $objectidnext = $object->getIdReplacingInvoice('validated');
2299 if ($object->type == 0 && $objectidnext) {
2300 $objectreplacing = new Facture($this->db);
2301 $objectreplacing->fetch($objectidnext);
2302
2303 $posy += 3;
2304 $pdf->SetXY($posx, $posy);
2305 $pdf->SetTextColor(0, 0, 60);
2306 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2307 }
2308 if ($object->type == 1) {
2309 $objectreplaced = new Facture($this->db);
2310 $objectreplaced->fetch($object->fk_facture_source);
2311
2312 $posy += 4;
2313 $pdf->SetXY($posx, $posy);
2314 $pdf->SetTextColor(0, 0, 60);
2315 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2316 }
2317 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2318 $objectreplaced = new Facture($this->db);
2319 $objectreplaced->fetch($object->fk_facture_source);
2320
2321 $posy += 3;
2322 $pdf->SetXY($posx, $posy);
2323 $pdf->SetTextColor(0, 0, 60);
2324 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2325 }
2326
2327 $posy += 4;
2328 $pdf->SetXY($posx, $posy);
2329 $pdf->SetTextColor(0, 0, 60);
2330
2331 $title = $outputlangs->transnoentities("DateInvoice");
2332 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2333 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2334 }
2335 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2336
2337 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2338 $posy += 4;
2339 $pdf->SetXY($posx, $posy);
2340 $pdf->SetTextColor(0, 0, 60);
2341 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2342 }
2343
2344 if ($object->type != 2) {
2345 $posy += 3;
2346 $pdf->SetXY($posx, $posy);
2347 $pdf->SetTextColor(0, 0, 60);
2348 $title = $outputlangs->transnoentities("DateDue");
2349 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2350 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2351 }
2352 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2353 }
2354
2355 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2356 $posy += 3;
2357 $pdf->SetXY($posx, $posy);
2358 $pdf->SetTextColor(0, 0, 60);
2359 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2360 }
2361
2362 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2363 $posy += 3;
2364 $pdf->SetXY($posx, $posy);
2365 $pdf->SetTextColor(0, 0, 60);
2366 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
2367 }
2368
2369 // Get contact
2370 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2371 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2372 if (count($arrayidcontact) > 0) {
2373 $usertmp = new User($this->db);
2374 $usertmp->fetch($arrayidcontact[0]);
2375 $posy += 4;
2376 $pdf->SetXY($posx, $posy);
2377 $pdf->SetTextColor(0, 0, 60);
2378 $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2379 }
2380 }
2381
2382 $posy += 1;
2383
2384 $top_shift = 0;
2385 $shipp_shift = 0;
2386 // Show list of linked objects
2387 if (!getDolGlobalString('INVOICE_HIDE_LINKED_OBJECT')) {
2388 $current_y = $pdf->getY();
2389 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2390 if ($current_y < $pdf->getY()) {
2391 $top_shift = $pdf->getY() - $current_y;
2392 }
2393 }
2394
2395 if ($showaddress) {
2396 // Sender properties
2397 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2398
2399 // Show sender
2400 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2401 $posy += $top_shift;
2402 $posx = $this->marge_gauche;
2403 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2404 $posx = $this->page_largeur - $this->marge_droite - 80;
2405 }
2406
2407 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2408 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2409
2410 // Show sender frame
2411 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2412 $pdf->SetTextColor(0, 0, 0);
2413 $pdf->SetFont('', '', $default_font_size - 2);
2414 $pdf->SetXY($posx, $posy - 5);
2415 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2416 $pdf->SetXY($posx, $posy);
2417 $pdf->SetFillColor(230, 230, 230);
2418 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2419 $pdf->SetTextColor(0, 0, 60);
2420 }
2421
2422 // Show sender name
2423 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2424 $pdf->SetXY($posx + 2, $posy + 3);
2425 $pdf->SetFont('', 'B', $default_font_size);
2426 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2427 $posy = $pdf->getY();
2428 }
2429
2430 // Show sender information
2431 $pdf->SetXY($posx + 2, $posy);
2432 $pdf->SetFont('', '', $default_font_size - 1);
2433 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2434
2435 // If BILLING contact defined on invoice, we use it
2436 $usecontact = false;
2437 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2438 if (count($arrayidcontact) > 0) {
2439 $usecontact = true;
2440 $result = $object->fetch_contact($arrayidcontact[0]);
2441 }
2442
2443 // Recipient name
2444 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2445 $thirdparty = $object->contact;
2446 } else {
2447 $thirdparty = $object->thirdparty;
2448 }
2449
2450 $carac_client_name = is_object($thirdparty) ? pdfBuildThirdpartyName($thirdparty, $outputlangs) : 0;
2451
2452 $mode = 'target';
2453 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2454
2455 // Show recipient
2456 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2457 if ($this->page_largeur < 210) {
2458 $widthrecbox = 84; // To work with US executive format
2459 }
2460 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2461 $posy += $top_shift;
2462 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2463 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2464 $posx = $this->marge_gauche;
2465 }
2466
2467 // Show recipient frame
2468 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2469 $pdf->SetTextColor(0, 0, 0);
2470 $pdf->SetFont('', '', $default_font_size - 2);
2471 $pdf->SetXY($posx + 2, $posy - 5);
2472 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2473 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2474 }
2475
2476 // Show recipient name
2477 $pdf->SetXY($posx + 2, $posy + 3);
2478 $pdf->SetFont('', 'B', $default_font_size);
2479 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2480 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2481
2482 $posy = $pdf->getY();
2483
2484 // Show recipient information
2485 $pdf->SetFont('', '', $default_font_size - 1);
2486 $pdf->SetXY($posx + 2, $posy);
2487 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2488 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2489
2490 // Show shipping/delivery address
2491 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2492 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2493
2494 if (!empty($idaddressshipping)) {
2495 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2496 $companystatic = new Societe($this->db);
2497 $companystatic->fetch($object->contact->fk_soc);
2498 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2499 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
2500 } else {
2501 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2502 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2503 }
2504 if (!empty($carac_client_shipping)) {
2505 $posy += $hautcadre;
2506
2507 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2508
2509 // Show shipping frame
2510 $pdf->SetXY($posx + 2, $posy - 5);
2511 $pdf->SetFont('', '', $default_font_size - 2);
2512 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', false);
2513 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2514
2515 // Show shipping name
2516 $pdf->SetXY($posx + 2, $posy + 3);
2517 $pdf->SetFont('', 'B', $default_font_size);
2518 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2519
2520 $posy = $pdf->getY();
2521
2522 // Show shipping information
2523 $pdf->SetXY($posx + 2, $posy);
2524 $pdf->SetFont('', '', $default_font_size - 1);
2525 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2526 $shipp_shift += $hautcadre;
2527 }
2528 }
2529 }
2530
2531 $pdf->SetTextColor(0, 0, 0);
2532
2533 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2534
2535 return $pagehead;
2536 }
2537
2538 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2548 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2549 {
2550 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2551 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2552 }
2553
2564 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2565 {
2566 global $hookmanager;
2567
2568 // Default field style for content
2569 $this->defaultContentsFieldsStyle = array(
2570 'align' => 'R', // R,C,L
2571 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2572 );
2573
2574 // Default field style for content
2575 $this->defaultTitlesFieldsStyle = array(
2576 'align' => 'C', // R,C,L
2577 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2578 );
2579
2580 /*
2581 * For example
2582 $this->cols['theColKey'] = array(
2583 'rank' => $rank, // int : use for ordering columns
2584 'width' => 20, // the column width in mm
2585 'title' => array(
2586 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2587 'label' => ' ', // the final label : used fore final generated text
2588 'align' => 'L', // text alignment : R,C,L
2589 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2590 ),
2591 'content' => array(
2592 'align' => 'L', // text alignment : R,C,L
2593 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2594 ),
2595 );
2596 */
2597
2598 $rank = 0; // do not use negative rank
2599 $this->cols['desc'] = array(
2600 'rank' => $rank,
2601 'width' => false, // only for desc
2602 'status' => true,
2603 'title' => array(
2604 'textkey' => 'Designation', // use lang key is useful in somme case with module
2605 'align' => 'L',
2606 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2607 // 'label' => ' ', // the final label
2608 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2609 ),
2610 'content' => array(
2611 'align' => 'L',
2612 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2613 ),
2614 );
2615
2616 // Image of product
2617 $rank += 10;
2618 $this->cols['photo'] = array(
2619 'rank' => $rank,
2620 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2621 'status' => false,
2622 'title' => array(
2623 'textkey' => 'Photo',
2624 'label' => ' '
2625 ),
2626 'content' => array(
2627 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2628 ),
2629 'border-left' => false, // remove left line separator
2630 );
2631
2632 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2633 $this->cols['photo']['status'] = true;
2634 }
2635
2636
2637 $rank += 10;
2638 $this->cols['vat'] = array(
2639 'rank' => $rank,
2640 'status' => false,
2641 'width' => 10, // in mm
2642 'title' => array(
2643 'textkey' => 'VAT'
2644 ),
2645 'border-left' => true, // add left line separator
2646 );
2647
2648 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2649 $this->cols['vat']['status'] = true;
2650 }
2651
2652 $rank += 10;
2653 $this->cols['unit'] = array(
2654 'rank' => $rank,
2655 'width' => 11, // in mm
2656 'status' => false,
2657 'title' => array(
2658 'textkey' => 'Unit'
2659 ),
2660 'border-left' => true, // add left line separator
2661 );
2662 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2663 $this->cols['unit']['status'] = false;
2664 }
2665
2666 $rank += 10;
2667 $this->cols['subprice'] = array(
2668 'rank' => $rank,
2669 'width' => 17, // in mm
2670 'status' => true,
2671 'title' => array(
2672 'textkey' => 'PriceUHT'
2673 ),
2674 'border-left' => true, // add left line separator
2675 );
2676
2677 // Adapt dynamically the width of subprice, if text is too long.
2678 $tmpwidth = 0;
2679 $nblines = count($object->lines);
2680 for ($i = 0; $i < $nblines; $i++) {
2681 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2682 $tmpwidth = max($tmpwidth, $tmpwidth2);
2683 }
2684 if ($tmpwidth > 10) {
2685 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2686 }
2687
2688 $rank += 10;
2689 $this->cols['qty'] = array(
2690 'rank' => $rank,
2691 'width' => 10, // in mm
2692 'status' => true,
2693 'title' => array(
2694 'textkey' => 'Qty'
2695 ),
2696 'border-left' => true, // add left line separator
2697 );
2698 //situation invoices
2699 $this->cols['qty']['status'] = true;
2700
2701 //sum column
2702 $rank += 10;
2703 $this->cols['btpsomme'] = array(
2704 'rank' => $rank,
2705 'width' => 18, // in mm
2706 'status' => false,
2707 'title' => array(
2708 'textkey' => 'Chantier'
2709 ),
2710 'border-left' => true, // add left line separator
2711 'overtitle' => array(
2712 'textkey' => 'Chantier', // use lang key is useful in somme case with module
2713 'align' => 'C',
2714 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2715 'width' => 18
2716 ),
2717 );
2718 if (!empty($this->TDataSituation['date_derniere_situation'])) {
2719 $this->cols['btpsomme']['status'] = true;
2720 }
2721
2722 $derniere_situation = $this->TDataSituation['derniere_situation'];
2723
2724 if (empty($derniere_situation)) {
2725 $derniere_situation = 0;
2726 }
2727
2728 // Column 'Previous progression'
2729 $rank += 10;
2730 $this->cols['prev_progress'] = array(
2731 'rank' => $rank,
2732 'width' => 10, // in mm
2733 'status' => false,
2734 'title' => array(
2735 'textkey' => $outputlangs->transnoentities('ProgressShort')
2736 ),
2737 'border-left' => true, // add left line separator
2738 'overtitle' => array(
2739 'textkey' => 'S'.$derniere_situation->situation_counter . ' - ' . dol_print_date($derniere_situation->date, "%d/%m/%Y"),
2740 'align' => 'C',
2741 'padding' => array(0.5,0.2,0.5,0.2), // Like css 0 => top, 1 => right, 2 => bottom, 3 => left
2742 'width' => 10 + 18 //current width + amount cell width
2743 ),
2744 );
2745 if ($this->situationinvoice && ! empty($this->TDataSituation['date_derniere_situation'])) {
2746 $this->cols['prev_progress']['status'] = true;
2747 }
2748
2749 // Column 'Previous progression'
2750 $rank += 10;
2751 $this->cols['prev_progress_amount'] = array(
2752 'rank' => $rank,
2753 'width' => 18, // in mm
2754 'status' => false,
2755 'title' => array(
2756 'textkey' => $outputlangs->transnoentities('Amount')
2757 ),
2758 'border-left' => true, // add left line separator
2759 );
2760 if ($this->situationinvoice && ! empty($this->TDataSituation['date_derniere_situation'])) {
2761 $this->cols['prev_progress_amount']['status'] = true;
2762 }
2763
2764 // Column 'Current percent progress'
2765 $rank += 10;
2766 $this->cols['progress'] = array(
2767 'rank' => $rank,
2768 'width' => 10, // in mm
2769 'status' => true,
2770 'title' => array(
2771 'textkey' => $outputlangs->transnoentities('ProgressShort')
2772 ),
2773 'border-left' => true, // add left line separator
2774 'overtitle' => array(
2775 'textkey' => 'S'.$object->situation_counter . ' - ' . dol_print_date($object->date, "%d/%m/%Y"),
2776 'align' => 'C',
2777 'padding' => array(0.5,0.2,0.5,0.2), // Like css 0 => top, 1 => right, 2 => bottom, 3 => left
2778 'width' => 10 + 18
2779 ),
2780 );
2781
2782 // Column 'Current progress'
2783 $rank += 10;
2784 $this->cols['progress_amount'] = array(
2785 'rank' => $rank,
2786 'width' => 18, // in mm
2787 'status' => true,
2788 'title' => array(
2789 'textkey' => $outputlangs->transnoentities('Amount')
2790 ),
2791 'border-left' => true, // add left line separator
2792 );
2793 if ($this->situationinvoice) {
2794 $this->cols['progress_amount']['status'] = true;
2795 }
2796
2797 // FIN BTP SITUATION
2798
2799 $rank += 10;
2800 $this->cols['discount'] = array(
2801 'rank' => $rank,
2802 'width' => 10, // in mm
2803 'status' => false,
2804 'title' => array(
2805 'textkey' => 'ReductionShort'
2806 ),
2807 'border-left' => true, // add left line separator
2808 );
2809 if ($this->atleastonediscount) {
2810 $this->cols['discount']['status'] = true;
2811 }
2812 $rank += 10;
2813 $this->cols['totalexcltax'] = array(
2814 'rank' => $rank,
2815 'width' => 18, // in mm
2816 'status' => true,
2817 'title' => array(
2818 'textkey' => $outputlangs->transnoentities('TotalHT')
2819 ),
2820 'border-left' => true, // add left line separator
2821 );
2822
2823 $parameters = array(
2824 'object' => $object,
2825 'outputlangs' => $outputlangs,
2826 'hidedetails' => $hidedetails,
2827 'hidedesc' => $hidedesc,
2828 'hideref' => $hideref
2829 );
2830
2831 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2832 if ($reshook < 0) {
2833 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2834 } elseif (empty($reshook)) {
2835 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2836 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2837 } else {
2838 $this->cols = $hookmanager->resArray;
2839 }
2840 }
2841
2855 public function _tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
2856 {
2857 global $conf, $object, $db;
2858
2859 $form = new Form($db);
2860
2861 $tab_height -= 29; // Réduction de la hauteur global du tableau
2862 $displayWarranty = $this->displayRetainedWarranty($object);
2863 if (!$displayWarranty) {
2864 $tab_height -= 19; // Réduction de la hauteur global du tableau
2865 }
2866
2867
2868 // Force to disable hidetop and hidebottom
2869 $hidebottom = 0;
2870 if ($hidetop) {
2871 $hidetop = -1;
2872 }
2873
2874 $currency = !empty($currency) ? $currency : $conf->currency;
2875 $default_font_size = pdf_getPDFFontSize($outputlangs);
2876
2877 // Amount in (at tab_top - 1)
2878 $pdf->SetTextColor(0, 0, 0);
2879 $pdf->SetFont('', '', $default_font_size - 2);
2880
2881 if (empty($hidetop)) {
2882 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2883 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2884 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2885
2886 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2887
2888 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2889 //$pdf->Rect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2890 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius, '1001', 'F', explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2891 //$pdf->Rect($this->marge_gauche, $tab_top + 92.5, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 5, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2892 $pdf->RoundedRect($this->marge_gauche, $tab_top + 92.5, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2893 }
2894 }
2895
2896 $pdf->SetDrawColor(128, 128, 128);
2897 $pdf->SetFont('', '', $default_font_size - 1);
2898
2899 // Output Rect
2900 // KEEPTHIS => Affiche les bords extérieurs
2901 $this->printRoundedRectBtp($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect prend une longueur en 3eme param et 4eme param
2902
2903 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2904 if (empty($hidetop)) {
2905 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2906 $pdf->MultiCell(35, 2, $outputlangs->transnoentities("SituationInvoiceOldCumulation"), '', 'C');
2907 }
2908
2909 // PRINT COLUMNS TITLES
2910 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2911 if (empty($hidetop)) {
2912 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2913 $pdf->MultiCell(35, 2, $outputlangs->transnoentities("SituationInvoiceNewCumulation"), '', 'C');
2914 }
2915
2916 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2917 if (empty($hidetop)) {
2918 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2919 $pdf->MultiCell(36, 2, $outputlangs->transnoentities("CurrentSituationTotal", (string) $object->situation_counter), '', 'C');
2920 }
2921
2922 // ADD HORIZONTAL LINES
2923 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2924
2925 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2926
2927 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2928
2929 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2930
2931 if ($displayWarranty) {
2932 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2933 }
2934
2935
2936 // ADD TEXT INTO CELL
2937 /********************** Titles ******************************/
2938 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2939 $pdf->MultiCell(60, 2, $outputlangs->transnoentities("SituationInvoiceMainTask"), '', 'L');
2940
2941 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2942 $pdf->MultiCell(60, 2, $outputlangs->transnoentities("SituationInvoiceAdditionalTask"), '', 'L');
2943
2944 $form->load_cache_vatrates("'".$object->thirdparty->country_code."'");
2945
2946 $i = -8;
2947 foreach ($form->cache_vatrates as $TVatInfo) {
2948 $tva_tx_formated = sprintf("%01.3f", (float) $TVatInfo['txtva']);
2949 // print "<p>Un taux de tva ... $tva_tx_formated :: " . json_encode($this->TDataSituation['current'][$tva_tx_formated]) . "</p>";
2950 if (empty($this->TDataSituation['current'][$tva_tx_formated])) {
2951 continue;
2952 }
2953 $i += 8;
2954
2955 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2956 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalHT").' '.$TVatInfo['label'], '', 'L');
2957
2958 if (! empty($this->TDataSituation['current'][$tva_tx_formated]['TVA'])) {
2959 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2960 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("VAT").' '.$TVatInfo['label'], '', 'L');
2961 } else {
2962 $i -= 4;
2963 }
2964 }
2965
2966 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2967 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalTTC"), '', 'L');
2968
2969
2970 $pdf->SetFont('', 'B', $default_font_size - 1);
2971 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2972 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalSituationInvoice"), '', 'L');
2973 $pdf->SetFont('', '', $default_font_size - 2);
2974
2975 if ($displayWarranty) {
2976 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2977 $pdf->MultiCell(80, 2, $outputlangs->trans("TotalSituationInvoiceWithRetainedWarranty", (string) $object->retained_warranty), '', 'L');
2978 $nextY = $tab_top + 93;
2979 } else {
2980 $nextY = $tab_top + 74;
2981 }
2982
2983 $pdf->SetFont('', 'B', $default_font_size - 1);
2984 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2985 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("SituationTotalRayToRest"), '', 'L');
2986 $pdf->SetFont('', '', $default_font_size - 2);
2987 /***********************************************************/
2988
2989 /********************** Data *******************************/
2990 $TToDisplay = array(
2991 'cumul_anterieur',
2992 'nouveau_cumul',
2993 'current'
2994 );
2995
2996 $x = $this->marge_gauche + 85;
2997 // unset($this->TDataSituation['derniere_situation']);
2998 // print json_encode($object->lines);exit;
2999 // print json_encode($this->TDataSituation);exit;
3000 foreach ($TToDisplay as $col) {
3001 // Travaux principaux
3002 $pdf->SetXY($x, $tab_top + 8);
3003 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['HT'], 0, '', 1, -1, 2), '', 'R');
3004
3005 // Travaux supplémentaires
3006 $pdf->SetXY($x, $tab_top + 12);
3007 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['travaux_sup'], 0, '', 1, -1, 2), '', 'R');
3008
3009 $i = -8;
3010 foreach ($form->cache_vatrates as $TVatInfo) {
3011 $tva_tx_formated = sprintf("%01.3f", (float) $TVatInfo['txtva']);
3012 if (empty($this->TDataSituation['current'][$tva_tx_formated])) {
3013 continue;
3014 }
3015 $i += 8;
3016
3017 // Total HT
3018 $pdf->SetXY($x, $tab_top + 24 + $i);
3019 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col][$tva_tx_formated]['HT'], 0, '', 1, -1, 2), '', 'R');
3020
3021 // Total TVA
3022 if (! empty($this->TDataSituation['current'][$tva_tx_formated]['TVA'])) {
3023 $pdf->SetXY($x, $tab_top + 28 + $i);
3024 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col][$tva_tx_formated]['TVA'], 0, '', 1, -1, 2), '', 'R');
3025 } else {
3026 $i -= 4;
3027 }
3028 }
3029
3030 // Total TTC
3031 $pdf->SetXY($x, $tab_top + 33 + $i);
3032 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['TTC'], 0, '', 1, -1, 2), '', 'R');
3033
3034 // Total situation
3035 $pdf->SetFont('', 'B', $default_font_size - 1);
3036 $pdf->SetXY($x, $tab_top + 58);
3037 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['TTC'], 0, '', 1, -1, 2), '', 'R');
3038 $pdf->SetFont('', '', $default_font_size - 2);
3039
3040
3041 if ($displayWarranty) {
3042 // Retained warranty
3043 $pdf->SetXY($x, $tab_top + 74);
3044 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['retenue_garantie'], 0, '', 1, -1, 2), '', 'R');
3045 $nextY = $tab_top + 93;
3046 } else {
3047 $nextY = $tab_top + 74;
3048 }
3049
3050 // Amount payable incl. VAT
3051 $pdf->SetFont('', 'B', $default_font_size - 1);
3052 $pdf->SetXY($x, $nextY);
3053 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['total_a_payer'], 0, '', 1, -1, 2), '', 'R');
3054 $pdf->SetFont('', '', $default_font_size - 2);
3055
3056 $x += 36;
3057 }
3058 /************************************************************/
3059 }
3060
3061
3082 public function getDataSituation(&$object)
3083 {
3084 // Fetch previous and next situations invoices.
3085 // Return all previous and next invoices (both standard and credit notes)
3086 $object->fetchPreviousNextSituationInvoice();
3088 $TPreviousInvoices = $object->tab_previous_situation_invoice;
3089 unset($object->tab_previous_situation_invoice);
3090
3091 // liste de toutes les factures précédentes
3092 // print json_encode($TPreviousInvoices); exit;
3093
3094 $TPreviousInvoices = array_reverse($TPreviousInvoices);
3095 $facDerniereSituation = $TPreviousInvoices[0];
3096
3097 $TDataSituation = array();
3098
3099 if (! empty($facDerniereSituation)) {
3100 $TDataSituation['derniere_situation'] = $facDerniereSituation;
3101 $TDataSituation['date_derniere_situation'] = $facDerniereSituation->date;
3102 }
3103
3104 $retenue_garantie = 0;
3105 $retenue_garantie_anterieure = 0;
3106 // Init tous les champs à 0
3107 $TDataSituation['cumul_anterieur'] = array(
3108 'HT' => 0, //montant HT normal
3109 'TVA' => 0, //montant de la TVA sur le HTnet
3110 'TTC' => 0, //montant TTC (HTnet + TVA)
3111 'retenue_garantie' => 0,
3112 'travaux_sup' => 0,
3113 'HTnet' => 0, //montant HT
3114 'total_a_payer' => 0 //montant "a payer" sur la facture
3115 );
3116
3117 //S'il y a des factures de situations précédentes
3118 if (!empty($TPreviousInvoices)) {
3119 //calcul des cumuls -- plus necessaire ?
3120 foreach ($TPreviousInvoices as $i => $previousInvoice) {
3121 $TDataSituation['cumul_anterieur']['HT'] += $previousInvoice->total_ht;
3122 // $TDataSituation['cumul_anterieur']['TTC'] += $previousInvoice->total_ttc;
3123 $TDataSituation['cumul_anterieur']['TVA'] += $previousInvoice->total_tva;
3124
3125 //lecture de chaque ligne pour
3126 // 1. recalculer le total_ht pour chaque taux de TVA
3127 // 2. recalculer la TVA associée à ce montant HT
3128 // 3. le cas échéant stocker cette information comme travaux_sup si cette ligne n'est pas liée à une ligne de la situation précédente
3129 foreach ($previousInvoice->lines as $k => $l) {
3130 $total_ht = floatval($l->total_ht);
3131 if (empty($total_ht)) {
3132 continue;
3133 }
3134
3135 // Si $prevSituationPercent vaut 0 c'est que la ligne $l est un travail supplémentaire
3136 $prevSituationPercent = 0;
3137 $isFirstSituation = false;
3138 if (!empty($l->fk_prev_id)) {
3139 $prevSituationPercent = $l->get_prev_progress($previousInvoice->id, true);
3140 } elseif (! array_key_exists($i + 1, $TPreviousInvoices)) {
3141 $isFirstSituation = true;
3142 }
3143
3144 $calc_ht = $l->total_ht;
3145 //modification du format de TVA, cas particulier des imports ou autres qui peuvent avoir des 20.0000
3146 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3147
3148 //1ere ligne
3149 $amounttva = $calc_ht * ($ltvatx / 100);
3150 if (! isset($TDataSituation['cumul_anterieur'][$ltvatx])) {
3151 $TDataSituation['cumul_anterieur'][$ltvatx]['HT'] = $calc_ht;
3152 $TDataSituation['cumul_anterieur'][$ltvatx]['TVA'] = $amounttva;
3153 } else {
3154 //lignes suivantes
3155 $TDataSituation['cumul_anterieur'][$ltvatx]['HT'] += ($calc_ht);
3156 $TDataSituation['cumul_anterieur'][$ltvatx]['TVA'] += $amounttva;
3157 }
3158
3159 //le grand total de TVA
3160 // $TDataSituation['cumul_anterieur']['TVA'] += $amounttva;
3161
3162 if (empty($l->fk_prev_id) && ! $isFirstSituation) {
3163 // TODO: à clarifier, mais pour moi, un facture de situation précédente qui a des progressions à 0% c'est pas logique
3164 $TDataSituation['cumul_anterieur']['travaux_sup'] += $calc_ht;
3165 }
3166 }
3167 }
3168
3169 if (! empty($previousInvoice->retained_warranty) && !getDolGlobalString('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL')) {
3170 $retenue_garantie_anterieure += $previousInvoice->getRetainedWarrantyAmount();
3171 }
3172
3173 //les cumuls
3174 $TDataSituation['cumul_anterieur']['HT'] -= $TDataSituation['cumul_anterieur']['travaux_sup'];
3175 $TDataSituation['cumul_anterieur']['retenue_garantie'] = $retenue_garantie_anterieure;
3176 $TDataSituation['cumul_anterieur']['TTC'] = $TDataSituation['cumul_anterieur']['HT'] + $TDataSituation['cumul_anterieur']['TVA'];
3177 $TDataSituation['cumul_anterieur']['total_a_payer'] = $TDataSituation['cumul_anterieur']['TTC'] - $retenue_garantie_anterieure;
3178 }
3179
3180 // print json_encode($facDerniereSituation->lines);exit;
3181 $TDataSituation['current'] = $this->btpGetInvoiceAmounts($object->id);
3182
3183 if (! empty($facDerniereSituation->lines)) {
3184 $TFacLinesKey = array_keys($facDerniereSituation->lines);
3185 $TObjectLinesKey = array_keys($object->lines);
3186 $TDiffKey = array_diff($TObjectLinesKey, $TFacLinesKey);
3187
3188 // print json_encode($TDiffKey);exit;
3189
3190 foreach ($TDiffKey as $i) {
3191 if (empty($object->lines[$i]->fk_prev_id)) {
3192 // Next line is useless because 'nouveau_cumul' is overwritten below
3193 // $TDataSituation['nouveau_cumul']['travaux_sup'] += $object->lines[$i]->total_ht;
3194 $TDataSituation['current']['travaux_sup'] += $object->lines[$i]->total_ht;
3195 }
3196 }
3197 }
3198
3199 //Le nouveau cumul = cumul antérieur + current
3200 $TDataSituation['nouveau_cumul'] = $this->sumSituation($TDataSituation['current'], $TDataSituation['cumul_anterieur']);
3201
3202 return $TDataSituation;
3203 }
3204
3213 public function sumSituation($a, $b)
3214 {
3215 $ret = array();
3216 if (is_array($a)) {
3217 foreach ($a as $k => $v) {
3218 if (is_array($v)) {
3219 $ret[$k] = $this->sumSituation($v, $b[$k]);
3220 } else {
3221 $ret[$k] = $a[$k];
3222 if (isset($b[$k])) {
3223 $ret[$k] += $b[$k];
3224 }
3225 }
3226 }
3227 } else {
3228 dol_syslog("sumSituation first arg is not an array");
3229 }
3230
3231 return $ret;
3232 }
3233
3241 {
3242 if (is_callable(array($object, 'displayRetainedWarranty'))) {
3243 return $object->displayRetainedWarranty();
3244 } else {
3245 // FOR RETROCOMPATIBILITY
3246
3247 // TODO : add a flag on invoices to store this conf USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL
3248
3249 // note : we don't need to test USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION because if $object->retained_warranty is not empty it's because it was set when this conf was active
3250
3251 $displayWarranty = false;
3252 if (!empty($object->retained_warranty)) {
3253 $displayWarranty = true;
3254
3255 if ($object->isSituationInvoice() && getDolGlobalString('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL')) {
3256 // Check if this situation invoice is 100% for real
3257 $displayWarranty = false;
3258 if (!empty($object->situation_final)) {
3259 $displayWarranty = true;
3260 } elseif (!empty($object->lines) && $object->status == Facture::STATUS_DRAFT) {
3261 // $object->situation_final need validation to be done so this test is need for draft
3262 $displayWarranty = true;
3263
3264 foreach ($object->lines as $i => $line) {
3265 if ($line->product_type < 2 && $line->situation_percent < 100) {
3266 $displayWarranty = false;
3267 break;
3268 }
3269 }
3270 }
3271 }
3272 }
3273 return $displayWarranty;
3274 }
3275 }
3276
3284 public function getInfosLineLastSituation(&$object, &$current_line)
3285 {
3286 if (empty($object->situation_cycle_ref) || $object->situation_counter <= 1) {
3287 return;
3288 }
3289
3290 $facDerniereSituation = &$this->TDataSituation['derniere_situation'];
3291
3292 // Find the previous line of the line you are on
3293 foreach ($facDerniereSituation->lines as $l) {
3294 if ($l->rowid == $current_line->fk_prev_id) {
3295 // Recovery of total_ht without taking progress into account (for the "sums" column)
3296 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3297 $tabprice = calcul_price_total($l->qty, $l->subprice, $l->remise_percent, $ltvatx, $l->localtax1_tx, $l->localtax2_tx, 0, 'HT', $l->info_bits, $l->product_type);
3298 $total_ht = $tabprice[0];
3299 $total_tva = $tabprice[1];
3300 $total_ttc = $tabprice[2];
3301 $total_localtax1 = $tabprice[9];
3302 $total_localtax2 = $tabprice[10];
3303 $pu_ht = $tabprice[3];
3304
3305 return array(
3306 'progress_prec' => (float) $l->situation_percent,
3307 'total_ht_without_progress' => (float) $total_ht,
3308 'total_ht' => $l->total_ht,
3309 );
3310 }
3311 }
3312 }
3313
3326 /*
3327 public function printRectBtp(&$pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
3328 {
3329 if (empty($hidetop) || $hidetop == -1) {
3330 $pdf->line($x, $y, $x + $l, $y);
3331 }
3332 $pdf->line($x + $l, $y, $x + $l, $y + $h);
3333 if (empty($hidebottom)) {
3334 $pdf->line($x + $l, $y + $h, $x, $y + $h);
3335 }
3336 $pdf->line($x, $y + $h, $x, $y);
3337 }*/
3338
3353 public function printRoundedRectBtp($pdf, $x, $y, $w, $h, $r, $hidetop = 0, $hidebottom = 0, $style = 'D')
3354 {
3355 // Top line
3356 if (empty($hidetop) || $hidetop == -1) {
3357 $pdf->RoundedRect($x, $y, $w, $h, $r, '1111', $style);
3358 } else {
3359 // Draw rounded rectangle with hidden top side
3360 $pdf->RoundedRect($x, $y, $w, $h, $r, '0111', $style);
3361 }
3362 if (!empty($hidebottom)) {
3363 $pdf->RoundedRect($x, $y, $w, $h, $r, '1101', $style);
3364 }
3365 }
3366
3375 public function btpGetInvoiceAmounts($id, $forceReadFromDB = false)
3376 {
3377 global $user, $langs, $mysoc, $db, $hookmanager, $nblignes;
3378
3379 $object = new Facture($db);
3380 $object->fetch($id);
3381
3382 /* from dolibarr core
3383 * Fetch previous and next situations invoices.
3384 * Return all previous and next invoices (both standard and credit notes).
3385 */
3386 $object->fetchPreviousNextSituationInvoice();
3388 $TPreviousInvoices = $object->tab_previous_situation_invoice;
3389 unset($object->tab_previous_situation_invoice);
3390
3391 $TPreviousInvoices = array_reverse($TPreviousInvoices);
3392 $facDerniereSituation = $TPreviousInvoices[0];
3393
3394 $ret = array(
3395 'HT' => 0, //montant HT normal
3396 'HTnet' => 0, //montant HT
3397 'TVA' => 0, //montant de la TVA sur le HTnet
3398 'TTC' => 0, //montant TTC (HTnet + TVA)
3399 'retenue_garantie' => 0,
3400 'travaux_sup' => 0,
3401 'total_a_payer' => 0 //montant "a payer" sur la facture
3402 );
3403
3404 if (! empty($facDerniereSituation)) {
3405 $ret['derniere_situation'] = $facDerniereSituation;
3406 $ret['date_derniere_situation'] = $facDerniereSituation->date;
3407 }
3408
3409 // Scroll through the lines of the current invoice to retrieve all data
3410 foreach ($object->lines as $k => $l) {
3411 $total_ht = floatval($l->total_ht);
3412 if (empty($total_ht)) {
3413 continue;
3414 }
3415
3416 // Modification of VAT format, special case of imports or others which may have 20.0000
3417 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3418
3419 $ret[$ltvatx]['TVA'] += $l->total_tva;
3420 $ret[$ltvatx]['HT'] += $l->total_ht;
3421 }
3422
3423 // Retained warranty
3424 $retenue_garantie = $object->getRetainedWarrantyAmount();
3425 if ($retenue_garantie == -1) {
3426 $retenue_garantie = 0;
3427 }
3428
3429 //les cumuls
3430 $ret['TTC'] = $object->total_ttc;
3431 $ret['TVA'] = $object->total_tva;
3432 $ret['HT'] = $object->total_ht - $ret['travaux_sup'];
3433 $ret['total_a_payer'] = $ret['TTC'] - $retenue_garantie;
3434 $ret['retenue_garantie'] = $retenue_garantie;
3435
3436 //Clean up before keep in "cache"
3437 if (array_key_exists('derniere_situation', $ret)) {
3438 unset($ret['derniere_situation']->db);
3439 unset($ret['derniere_situation']->fields);
3440 unset($ret['derniere_situation']->lines);
3441 }
3442
3443 // print "<p>Store to cache $id : " . json_encode($_cache_btpProrataGetInvoiceAmounts[$id]) . "</p>";
3444 return $ret;
3445 }
3446
3447
3459 public function resumeLastPage(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
3460 {
3461 global $conf, $mysoc, $hookmanager;
3462 $default_font_size = pdf_getPDFFontSize($outputlangs);
3463
3464 $sign = 1;
3465 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3466 $sign = -1;
3467 }
3468
3469 $pdf->AddPage();
3470 if (!empty($this->tplidx)) {
3471 $pdf->useTemplate($this->tplidx);
3472 }
3473
3474 $pagehead = $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
3475
3476 $tab2_top = $this->tab_top_newpage - 4;
3477 $posy = $tab2_top;
3478 $posx = $this->marge_gauche;
3479 $index = 1;
3480 $outputlangs->load('orders');
3481 $outputlangs->load('propal');
3482 $width = 70;
3483 $width2 = $this->page_largeur - $posx - $width - $this->marge_droite;
3484
3485 $pdf->SetFont('', '', $default_font_size - 1);
3486 $pdf->MultiCell(0, 3, ''); // Set interline to 3
3487 $pdf->SetTextColor(0, 0, 0);
3488 $pdf->setY($tab2_top);
3489
3490 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
3491 $pdf->SetFont('', '', $default_font_size - 2);
3492 } else {
3493 $pdf->SetFont('', '', $default_font_size - 1);
3494 }
3495
3496 if (empty($object->tab_previous_situation_invoice)) {
3497 $object->fetchPreviousNextSituationInvoice();
3498 }
3499
3500 $previousinvoices = count($object->tab_previous_situation_invoice) ? $object->tab_previous_situation_invoice : array();
3501
3502 $remain_to_pay = 0;
3503
3504 // Proposal total
3505 $propals = array();
3506 $orders = array();
3507
3508 if (count($previousinvoices)) {
3509 foreach ($previousinvoices as $invoice) {
3510 if ($invoice->is_first()) {
3511 $invoice->fetchObjectLinked();
3512
3513 $propals = isset($invoice->linkedObjects['propal']) ? $invoice->linkedObjects['propal'] : array();
3514 $orders = isset($invoice->linkedObjects['commande']) ? $invoice->linkedObjects['commande'] : array();
3515 }
3516 }
3517 } else {
3518 if ($object->is_first()) {
3519 $object->fetchObjectLinked();
3520
3521 $propals = isset($object->linkedObjects['propal']) ? $object->linkedObjects['propal'] : array();
3522 $orders = isset($object->linkedObjects['commande']) ? $object->linkedObjects['commande'] : array();
3523 }
3524 }
3525
3526 if (count($propals)) {
3527 $propal = array_pop($propals);
3528
3529 $total_ht = (isModEnabled('multicurrency') && $propal->multicurrency_tx != 1) ? $propal->multicurrency_total_ht : $propal->total_ht;
3530 $remain_to_pay = $total_ht;
3531
3532 $pdf->SetTextColor(0, 0, 60);
3533 $pdf->SetFont('', '', $default_font_size - 1);
3534
3535 $label = $outputlangs->transnoentities("SituationInvoiceTotalProposal");
3536 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $label, 0, 'L', false, 1, $posx, $posy + 1);
3537
3538 $amount = price($sign * ($total_ht + (! empty($propal->remise) ? $propal->remise : 0)));
3539 $pdf->MultiCell($width2, 3, $amount, 0, 'R', false, 1, $posx + $width, $posy + 1);
3540
3541 $pdf->SetFont('', '', $default_font_size - 1);
3542
3543 // Output Rect
3544 $pdf->SetDrawColor(128, 128, 128);
3545 //$this->printRect($pdf, $posx, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 6); // Rect prend une longueur en 3eme param et 4eme param
3546 $this->printRoundedRect($pdf, $posx, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 6, $this->corner_radius, 0, 0, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
3547
3548 $posy += 4;
3549 } elseif (count($orders)) {
3550 $order = array_pop($orders);
3551
3552 $total_ht = (isModEnabled('multicurrency') && $order->multicurrency_tx != 1 ? $order->multicurrency_total_ht : $order->total_ht);
3553 $remain_to_pay = $total_ht;
3554 }
3555
3556 $useborder = 0;
3557 $index = 0;
3558
3559 $height = 4;
3560
3561 $sign = 1;
3562 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3563 $sign = -1;
3564 }
3565 $pdf->SetTextColor(0, 0, 60);
3566 $pdf->SetFont('', 'B', $default_font_size + 3);
3567
3568
3569 $pdf->SetXY($posx, $posy);
3570
3571
3572 $depositsamount = $object->getSumDepositsUsed();
3573 $deja_regle = $object->getSommePaiement();
3574
3575 $tot_deja_regle = ($depositsamount + $deja_regle);
3576
3577 $previousinvoices[] = $object;
3578
3579 $force_to_zero = false;
3580
3581 $idinv = 0;//count($previousinvoices);
3582 while ($idinv < count($previousinvoices)) {
3583 $invoice = $previousinvoices[$idinv];
3584
3585 $posy += 7;
3586 $index = 0;
3587
3588 $pdf->SetTextColor(0, 0, 60);
3589 $pdf->SetFont('', 'B', $default_font_size + 3);
3590
3591 $pageposbefore = $pdf->getPage();
3592 $pdf->startTransaction();
3593
3594 $pdf->SetXY($posx, $posy);
3595
3596 $ref = $outputlangs->transnoentities("InvoiceSituation").$outputlangs->convToOutputCharset(" n°".$invoice->situation_counter);
3597
3598 // TODO Discuss whether to declare a final invoice as a DGD (definitive general statement like 'décompte général définitif') or not.
3599 if (getDolGlobalInt('INVOICE_SITUATION_USE_DGD')) {
3600 if ($invoice->situation_final) {
3601 $ref .= ' - DGD';
3602 $force_to_zero = true;
3603 }
3604 }
3605
3606 $ref .= ' - '. $invoice->ref;
3607 $ref .= ' ('.dol_print_date($invoice->date, "%d/%m/%Y", false, $outputlangs).')';
3608 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $ref, 0, 'L', false);
3609
3610 $pdf->SetFont('', '', $default_font_size - 1);
3611
3612 $sign = 1;
3613 if ($invoice->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3614 $sign = -1;
3615 }
3616
3617 $posy += 7;
3618 // Total HT
3619 $pdf->SetFillColor(255, 255, 255);
3620 $pdf->SetXY($posx, $posy);
3621 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalHT"), 0, 'L', true);
3622
3623 $total_ht = (isModEnabled('multicurrency') && $invoice->multicurrency_tx != 1 ? $invoice->multicurrency_total_ht : $invoice->total_ht);
3624
3625 $pdf->SetXY($posx + $width, $posy);
3626 $pdf->MultiCell($width2, $height, price($sign * ($total_ht + (!empty($invoice->remise) ? $invoice->remise : 0)), 0, $outputlangs), 0, 'R', true);
3627
3628 $tvas = array();
3629 $nblines = count($invoice->lines);
3630 for ($i = 0; $i < $nblines; $i++) {
3631 $tvaligne = $invoice->lines[$i]->total_tva;
3632 $vatrate = (string) $invoice->lines[$i]->tva_tx;
3633
3634 if (($invoice->lines[$i]->info_bits & 0x01) == 0x01) {
3635 $vatrate .= '*';
3636 }
3637 if (! isset($tvas[$vatrate])) {
3638 $tvas[$vatrate] = 0;
3639 }
3640 $tvas[$vatrate] += $tvaligne;
3641 }
3642
3643 // Show VAT by rates and total
3644 $pdf->SetFillColor(248, 248, 248);
3645 foreach ($tvas as $tvakey => $tvaval) {
3646 if ($tvakey != 0) { // On affiche pas taux 0
3647 $index++;
3648 $pdf->SetXY($posx, $posy + $height * $index);
3649
3650 $tvacompl = '';
3651 if (preg_match('/\*/', $tvakey)) {
3652 $tvakey = str_replace('*', '', $tvakey);
3653 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
3654 }
3655 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
3656 $totalvat .= vatrate($tvakey, true).$tvacompl;
3657 $pdf->MultiCell($width, $height, $totalvat, 0, 'L', true);
3658
3659 $pdf->SetXY($posx + $width, $posy + $height * $index);
3660 $pdf->MultiCell($width2, $height, price($tvaval, 0, $outputlangs), 0, 'R', true);
3661 }
3662 }
3663
3664 $index++;
3665
3666 $total_ht = (isModEnabled('multicurrency') && $invoice->multicurrency_tx != 1) ? $invoice->multicurrency_total_ht : $invoice->total_ht;
3667 $total_ttc = (isModEnabled('multicurrency') && $invoice->multicurrency_tx != 1) ? $invoice->multicurrency_total_ttc : $invoice->total_ttc;
3668
3669 // Total TTC
3670 $pdf->SetXY($posx, $posy + $height * $index);
3671 $pdf->SetTextColor(0, 0, 60);
3672 $pdf->SetFillColor(224, 224, 224);
3673 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', true);
3674
3675
3676 $pdf->SetXY($posx + $width, $posy + $height * $index);
3677 $pdf->MultiCell($width2, $height, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
3678
3679 $retainedWarrantyRate = (float) ($object->retained_warranty ? price2num($object->retained_warranty) : price2num(getDolGlobalString('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT', 0)));
3680
3681 $total_ht_rg = 0;
3682 $total_ttc_rg = 0;
3683
3684 if ($this->is_rg) {
3685 $index++;
3686
3687 $pdf->SetXY($posx, $posy + $height * $index);
3688 $pdf->SetTextColor(0, 0, 60);
3689 $pdf->SetFillColor(241, 241, 241);
3690 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("RetainedWarrantyShort", (string) $retainedWarrantyRate), $useborder, 'L', true);
3691
3692 $total_ht_rg = (float) price2num(price($total_ht * $retainedWarrantyRate / 100), 'MT');
3693 $total_ttc_rg = (float) price2num(price($total_ttc * $retainedWarrantyRate / 100), 'MT');
3694
3695 $pdf->SetXY($posx + $width, $posy + $height * $index);
3696 $pdf->MultiCell($width2, $height, price(-$sign * $total_ht_rg, 0, $outputlangs), $useborder, 'R', true);
3697
3698 $total_ht_with_rg = $total_ht - $total_ht_rg;
3699 $total_ttc_with_rg = $total_ttc - $total_ttc_rg;
3700
3701 $index++;
3702
3703 // Total TTC
3704 $pdf->SetXY($posx, $posy + $height * $index);
3705 $pdf->SetTextColor(0, 0, 60);
3706 $pdf->SetFillColor(224, 224, 224);
3707 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalSituationInvoiceWithRetainedWarranty"), $useborder, 'L', true);
3708
3709 $pdf->SetXY($posx + $width, $posy + $height * $index);
3710 $pdf->MultiCell($width2, $height, price($sign * $total_ttc_with_rg, 0, $outputlangs), $useborder, 'R', true);
3711 }
3712
3713
3714
3715 $index++;
3716
3717 $pdf->SetTextColor(0, 0, 0);
3718
3719 $creditnoteamount = $invoice->getSumCreditNotesUsed();
3720 $depositsamount = $invoice->getSumDepositsUsed();
3721 $deja_regle = $invoice->getSommePaiement();
3722
3723 $resteapayer = price2num($invoice->total_ttc - $deja_regle - $total_ttc_rg - $creditnoteamount - $depositsamount, 'MT');
3724 if ($invoice->paye) {
3725 $resteapayer = 0;
3726 }
3727
3728 $y = 0;
3729
3730
3731 // Already paid + Deposits
3732 $tot_deja_regle += $deja_regle + $depositsamount;
3733
3734 $pdf->SetXY($posx, $posy + $height * $index);
3735 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("Paid"), 0, 'L', false);
3736 $pdf->SetXY($posx + $width, $posy + $height * $index);
3737 $pdf->MultiCell($width2, $height, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
3738
3739 // Credit note
3740 if ($creditnoteamount) {
3741 $index++;
3742 $pdf->SetXY($posx, $posy + $height * $index);
3743 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("CreditNotes"), 0, 'L', false);
3744 $pdf->SetXY($posx + $width, $posy + $height * $index);
3745 $pdf->MultiCell($width2, $height, price($creditnoteamount, 0, $outputlangs), 0, 'R', false);
3746 }
3747
3748 // Escompte
3749 if ($invoice->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
3750 $index++;
3751 $pdf->SetFillColor(255, 255, 255);
3752
3753 $pdf->SetXY($posx, $posy + $height * $index);
3754 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', true);
3755 $pdf->SetXY($posx + $width, $posy + $height * $index);
3756 $pdf->MultiCell($width2, $height, price($invoice->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', true);
3757
3758 $resteapayer = 0;
3759 }
3760
3761 $index++;
3762 $pdf->SetTextColor(0, 0, 60);
3763 $pdf->SetFillColor(224, 224, 224);
3764 $pdf->SetXY($posx, $posy + $height * $index);
3765 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', true);
3766 $pdf->SetXY($posx + $width, $posy + $height * $index);
3767 $pdf->MultiCell($width2, $height, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
3768
3769 $pdf->SetFont('', '', $default_font_size - 1);
3770 $pdf->SetTextColor(0, 0, 0);
3771
3772 $index++;
3773
3774 if ($deja_regle > 0) {
3775 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
3776 if ($invoice->type == 2) {
3777 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
3778 }
3779
3780 $pdf->SetFont('', '', $default_font_size - 3);
3781 $pdf->SetXY($posx, $posy + $height * $index);
3782 $pdf->MultiCell($width, $height, $title, 0, 'L', false);
3783
3784 //$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
3785
3786 $index++;
3787
3788 $width4 = ($this->page_largeur - $this->marge_droite - $posx) / 4;
3789
3790 $pdf->SetFont('', '', $default_font_size - 4);
3791 $pdf->SetXY($posx, $posy + $height * $index);
3792 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Payment"), 0, 'L', false);
3793 $pdf->SetXY($posx + $width4, $posy + $height * $index);
3794 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Amount"), 0, 'L', false);
3795 $pdf->SetXY($posx + $width4 * 2, $posy + $height * $index);
3796 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Type"), 0, 'L', false);
3797 $pdf->SetXY($posx + $width4 * 3, $posy + $height * $index);
3798 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Num"), 0, 'L', false);
3799
3800 //$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
3801
3802 $y = $height - 1;
3803
3804 $pdf->SetFont('', '', $default_font_size - 4);
3806 $payments = $invoice->getListOfPayments();
3807
3808 if (count($payments)) {
3809 foreach ($payments as $payment) {
3810 $pdf->SetXY($posx, $posy + $height * $index + $y);
3811 $pdf->MultiCell($width4, $height - 1, dol_print_date($this->db->jdate($payment['date']), 'day', false, $outputlangs, true), 0, 'L', false);
3812 $pdf->SetXY($posx + $width4, $posy + $height * $index + $y);
3813 $pdf->MultiCell($width4, $height - 1, price($sign * $payment['amount'], 0, $outputlangs), 0, 'L', false);
3814 $pdf->SetXY($posx + $width4 * 2, $posy + $height * $index + $y);
3815 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $payment['type']);
3816
3817 $pdf->MultiCell($width4, $height - 1, $oper, 0, 'L', false);
3818 $pdf->SetXY($posx + $width4 * 3, $posy + $height * $index + $y);
3819 $pdf->MultiCell($width4, $height - 1, $payment['num'], 0, 'L', false);
3820
3821 //$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
3822 $y += ($height - 1);
3823 }
3824 }
3825 }
3826
3827 // Output Rect
3828 $pdf->SetDrawColor(128, 128, 128);
3829 //$this->printRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height * $index + $y);
3830 $this->printRoundedRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height * $index + $y, $this->corner_radius, 0, 0, 'D');
3831 $posy += $height * $index + $y;
3832
3833 $pageposafter = $pdf->getPage();
3834 if ($pageposafter > $pageposbefore) { // There is a pagebreak
3835 $pdf->rollbackTransaction(true);
3836
3837 $pageposafter = $pageposbefore;
3838 $pdf->AddPage('', '', true);
3839 if (!empty($this->tplidx)) {
3840 $pdf->useTemplate($this->tplidx);
3841 }
3842 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
3843 $this->_pagehead($pdf, $object, 0, $outputlangs);
3844 }
3845 $pdf->setPage($pageposafter + 1);
3846 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
3847
3848 $posy = $this->tab_top_newpage + 1;
3849 } else {
3850 $idinv++;
3851 $remain_to_pay += ($sign * ($total_ht + (!empty($invoice->remise) ? $invoice->remise : 0)));
3852
3853 $rem = 0;
3854 if (count($invoice->lines)) {
3855 foreach ($invoice->lines as $l) {
3856 if ($l->fk_remise_except > 0) {
3857 $discount = new DiscountAbsolute($this->db);
3858 $result = $discount->fetch($l->fk_remise_except);
3859 if ($result > 0) {
3860 $rem += $discount->amount_ht;
3861 }
3862 }
3863 }
3864 }
3865
3866 $remain_to_pay -= $rem;
3867
3868 $pdf->commitTransaction();
3869 }
3870 }
3871
3872 if ($force_to_zero) {
3873 $remain_to_pay = 0;
3874 }
3875
3876 $posy += 10;
3877
3878 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
3879
3880 $pdf->SetTextColor(0, 0, 60);
3881 $pdf->SetFont('', '', $default_font_size - 1);
3882 $pdf->SetXY($this->marge_gauche, $posy + 1);
3883 $label = $outputlangs->transnoentities("SituationTotalRayToRest");
3884 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $label, 0, 'L', false);
3885
3886 $amount = price($remain_to_pay);
3887 $pdf->MultiCell($width2, 3, $amount, 0, 'R', false, 1, $posx + $width, $posy + 1);
3888
3889 $pdf->SetDrawColor(128, 128, 128);
3890 //$this->printRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 7);
3891 $this->printRoundedRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 7, $this->corner_radius, 0, 0, 'D');
3892 }
3893}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to manage bank accounts.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage bank accounts description of third parties.
Class to manage absolute discounts.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_SITUATION
Situation invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage generation of HTML components Only common components must be here.
Class to manage hooks.
Parent class of invoice document generators.
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 octopus.
displayRetainedWarranty($object)
Display retained Warranty.
_tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
__construct($db)
Constructor.
printRoundedRectBtp($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Rect pdf.
sumSituation($a, $b)
Calculates the sum of two arrays, key by key, taking into account nested arrays.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
getInfosLineLastSituation(&$object, &$current_line)
Get info line of the last situation.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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 '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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...
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a 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)
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:2731
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2462
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
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:1047
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2080
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2411
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2018
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:742
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1425
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:863
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
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:439
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2325
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2368
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2165
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:778
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:391
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:90
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161