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