dolibarr 21.0.0-beta
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 = getDolGlobalString('INVOICE_USE_SITUATION_RETAINED_WARRANTY');
185 $conf->global->USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL = 1;
186 }
187
188 // If hidden option INVOICE_USE_SITUATION is set to 2, we can show the invoice situation template
189 if (getDolGlobalString('INVOICE_USE_SITUATION') == 2) {
190 $this->version = 'dolibarr';
191 }
192
193 // Translations
194 $langs->loadLangs(array("main", "bills"));
195
196 $this->db = $db;
197 $this->name = "octopus";
198 $this->description = $langs->trans('PDFOctopusDescription');
199 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
200
201 // Dimension page
202 $this->type = 'pdf';
203 $formatarray = pdf_getFormat();
204 $this->page_largeur = $formatarray['width'];
205 $this->page_hauteur = $formatarray['height'];
206 $this->format = array($this->page_largeur, $this->page_hauteur);
207 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
208 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
209 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
210 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
211 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
212 $this->posx_cumul_anterieur = 94;
213 $this->posx_new_cumul = 130;
214 $this->posx_current = 166;
215
216 $this->option_logo = 1; // Display logo
217 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
218 $this->option_modereg = 1; // Display payment mode
219 $this->option_condreg = 1; // Display payment terms
220 $this->option_multilang = 1; // Available in several languages
221 $this->option_escompte = 1; // Displays if there has been a discount
222 $this->option_credit_note = 1; // Support credit notes
223 $this->option_freetext = 1; // Support add of a personalised text
224 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
225 $this->watermark = '';
226 $this->franchise = !$mysoc->tva_assuj; // not used ?
227
228 // Define position of columns
229 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
230
231
232 $this->tabTitleHeight = 8; // default height (2 lines due to overtitle)
233
234 // Use new system for position of columns, view $this->defineColumnField()
235
236 $this->tva = array();
237 $this->tva_array = array();
238 $this->localtax1 = array();
239 $this->localtax2 = array();
240 $this->atleastoneratenotnull = 0;
241 $this->atleastonediscount = 0;
242 $this->situationinvoice = true;
243 if (!empty($object)) {
244 $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 (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1046 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
1047 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
1048 }
1049 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne, 'tot_ht'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'] + $object->lines[$i]->total_ht);
1050 } else {
1051 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
1052 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
1053 }
1054 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
1055 }
1056
1057 $nexY = max($nexY, $posYAfterImage);
1058
1059 // Add line
1060 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
1061 $pdf->setPage($pageposafter);
1062 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
1063 //$pdf->SetDrawColor(190,190,200);
1064 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1065 $pdf->SetLineStyle(array('dash' => 0));
1066 }
1067
1068 // Detect if some page were added automatically and output _tableau for past pages
1069 while ($pagenb < $pageposafter) {
1070 $pdf->setPage($pagenb);
1071 $tabtop = $this->tab_top;
1072 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1073 if ($pagenb != $pageposbeforeprintlines) {
1074 $tabtop = $this->tab_top_newpage;
1075 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1076 $hidetop = 1;
1077 }
1078 $this->_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1079
1080 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1081 $pagenb++;
1082 $pdf->setPage($pagenb);
1083 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
1084 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1085 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1086 }
1087 if (!empty($this->tplidx)) {
1088 $pdf->useTemplate($this->tplidx);
1089 }
1090 }
1091
1092 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
1093 $tabtop = $this->tab_top;
1094 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1095 if ($pagenb != $pageposbeforeprintlines) {
1096 $tabtop = $this->tab_top_newpage;
1097 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1098 $hidetop = 1;
1099 }
1100 $this->_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1101
1102 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1103 // New page
1104 $pdf->AddPage();
1105 if (!empty($this->tplidx)) {
1106 $pdf->useTemplate($this->tplidx);
1107 }
1108 $pagenb++;
1109 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1110 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1111 }
1112 }
1113 }
1114
1115 // Show square
1116 // special for situation invoices
1117 $tabtop = $this->tab_top_newpage;
1118 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1119 $tabTitleHeight = 0;
1120 $this->_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1121
1122 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1123
1124 // Display infos area
1125 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1126
1127 // Display total zone
1128 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1129
1130 // Display payment area
1131 $listofpayments = $object->getListOfPayments('', 0, 1);
1132 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1133 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1134 }
1135
1136 // Pagefoot
1137 $this->_pagefoot($pdf, $object, $outputlangs);
1138 if (method_exists($pdf, 'AliasNbPages')) {
1139 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1140 }
1141
1142 $this->resumeLastPage($pdf, $object, 0, $tab_top, $outputlangs, $outputlangsbis);
1143 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1144 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1145
1146 $pdf->Close();
1147
1148 $pdf->Output($file, 'F');
1149
1150 // Add pdfgeneration hook
1151 $hookmanager->initHooks(array('pdfgeneration'));
1152 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1153 global $action;
1154 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1155 if ($reshook < 0) {
1156 $this->error = $hookmanager->error;
1157 $this->errors = $hookmanager->errors;
1158 }
1159
1160 dolChmod($file);
1161
1162 $this->result = array('fullpath' => $file);
1163
1164 return 1; // No error
1165 } else {
1166 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1167 return 0;
1168 }
1169 } else {
1170 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1171 return 0;
1172 }
1173 }
1174
1175
1185 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1186 {
1187 global $conf;
1188
1189 $sign = 1;
1190 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1191 $sign = -1;
1192 }
1193
1194 $tab3_posx = 120;
1195 $tab3_top = $posy + 8;
1196 $tab3_width = 80;
1197 $tab3_height = 4;
1198 if ($this->page_largeur < 210) { // To work with US executive format
1199 $tab3_posx -= 15;
1200 }
1201
1202 $default_font_size = pdf_getPDFFontSize($outputlangs);
1203
1204 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1205 if ($object->type == 2) {
1206 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1207 }
1208
1209 $pdf->SetFont('', '', $default_font_size - 3);
1210 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1211 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1212
1213 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1214
1215 $pdf->SetFont('', '', $default_font_size - 4);
1216 $pdf->SetXY($tab3_posx, $tab3_top);
1217 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1218 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1219 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1220 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1221 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1222 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1223 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1224
1225 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1226
1227 $y = 0;
1228
1229 $pdf->SetFont('', '', $default_font_size - 4);
1230
1231
1232 // Loop on each discount available (deposits and credit notes and excess of payment included)
1233 $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,";
1234 $sql .= " re.description, re.fk_facture_source,";
1235 $sql .= " f.type, f.datef";
1236 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1237 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1238 $resql = $this->db->query($sql);
1239 if ($resql) {
1240 $num = $this->db->num_rows($resql);
1241 $i = 0;
1242 $invoice = new Facture($this->db);
1243 while ($i < $num) {
1244 $y += 3;
1245 $obj = $this->db->fetch_object($resql);
1246
1247 if ($obj->type == 2) {
1248 $text = $outputlangs->transnoentities("CreditNote");
1249 } elseif ($obj->type == 3) {
1250 $text = $outputlangs->transnoentities("Deposit");
1251 } elseif ($obj->type == 0) {
1252 $text = $outputlangs->transnoentities("ExcessReceived");
1253 } else {
1254 $text = $outputlangs->transnoentities("UnknownType");
1255 }
1256
1257 $invoice->fetch($obj->fk_facture_source);
1258
1259 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1260 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1261 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1262 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1263 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1264 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1265 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1266 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1267
1268 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1269
1270 $i++;
1271 }
1272 } else {
1273 $this->error = $this->db->lasterror();
1274 return -1;
1275 }
1276
1277 // Loop on each payment
1278 // TODO Call getListOfPayments instead of hard coded sql
1279 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1280 $sql .= " cp.code";
1281 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1282 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1283 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1284 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1285 $sql .= " ORDER BY p.datep";
1286
1287 $resql = $this->db->query($sql);
1288 if ($resql) {
1289 $num = $this->db->num_rows($resql);
1290 $i = 0;
1291 $y += 3;
1292 $maxY = $y;
1293 while ($i < $num) {
1294 $row = $this->db->fetch_object($resql);
1295 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1296 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1297 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1298 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1299 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1300 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1301
1302 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1303 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1304 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1305 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1306 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1307 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1308 $y += 3;
1309 $i++;
1310 }
1311
1312 return $tab3_top + $y + 3;
1313 } else {
1314 $this->error = $this->db->lasterror();
1315 return -1;
1316 }
1317 }
1318
1319
1330 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1331 {
1332 global $conf, $mysoc, $hookmanager;
1333
1334 $default_font_size = pdf_getPDFFontSize($outputlangs);
1335
1336 $pdf->SetFont('', '', $default_font_size - 1);
1337
1338 krsort($this->tva_array);
1339
1340 // Show VAT details
1341 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1342 $pdf->SetFillColor(224, 224, 224);
1343
1344 $pdf->SetFont('', '', $default_font_size - 2);
1345 $pdf->SetXY($this->marge_gauche, $posy);
1346 $titre = $outputlangs->transnoentities("VAT");
1347 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1348
1349 $pdf->SetFont('', '', $default_font_size - 2);
1350 $pdf->SetXY($this->marge_gauche + 25, $posy);
1351 $titre = $outputlangs->transnoentities("NetTotal");
1352 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1353
1354 $pdf->SetFont('', '', $default_font_size - 2);
1355 $pdf->SetXY($this->marge_gauche + 50, $posy);
1356 $titre = $outputlangs->transnoentities("VATAmount");
1357 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1358
1359 $pdf->SetFont('', '', $default_font_size - 2);
1360 $pdf->SetXY($this->marge_gauche + 75, $posy);
1361 $titre = $outputlangs->transnoentities("AmountTotal");
1362 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1363
1364 $posy = $pdf->GetY();
1365 $tot_ht = 0;
1366 $tot_tva = 0;
1367 $tot_ttc = 0;
1368
1369 foreach ($this->tva_array as $tvakey => $tvaval) {
1370 $pdf->SetFont('', '', $default_font_size - 2);
1371 $pdf->SetXY($this->marge_gauche, $posy);
1372 $titre = round((float) $tvakey, 2) . "%";
1373 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1374
1375 $pdf->SetFont('', '', $default_font_size - 2);
1376 $pdf->SetXY($this->marge_gauche + 25, $posy);
1377 $titre = price($tvaval['tot_ht']);
1378 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1379 $tot_ht += $tvaval['tot_ht'];
1380
1381 $pdf->SetFont('', '', $default_font_size - 2);
1382 $pdf->SetXY($this->marge_gauche + 50, $posy);
1383 $titre = price($tvaval['amount']);
1384 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1385 $tot_tva += $tvaval['amount'];
1386
1387 $pdf->SetFont('', '', $default_font_size - 2);
1388 $pdf->SetXY($this->marge_gauche + 75, $posy);
1389 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1390 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1391 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1392
1393 $posy = $pdf->GetY();
1394 }
1395 }
1396
1397 // If France, show VAT mention if not applicable
1398 if ($this->emetteur->country_code == 'FR' && empty($object->total_tva) && (empty($mysoc->tva_assuj) || ($this->emetteur->isInEEC() && $object->thirdparty->isInEEC()))) {
1399 $pdf->SetFont('', 'B', $default_font_size - 2);
1400 $pdf->SetXY($this->marge_gauche, $posy);
1401 if ($mysoc->forme_juridique_code == 92) {
1402 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1403 } else {
1404 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1405 }
1406
1407 $posy = $pdf->GetY() + 4;
1408 }
1409
1410 $posxval = 52; // Position of values of properties shown on left side
1411 $posxend = 110; // End of x for text on left side
1412 if ($this->page_largeur < 210) { // To work with US executive format
1413 $posxend -= 10;
1414 }
1415
1416 // Show payments conditions
1417 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1418 $pdf->SetFont('', 'B', $default_font_size - 2);
1419 $pdf->SetXY($this->marge_gauche, $posy);
1420 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1421 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1422
1423 $pdf->SetFont('', '', $default_font_size - 2);
1424 $pdf->SetXY($posxval, $posy);
1425 $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);
1426 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1427 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1428
1429 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1430 }
1431
1432 // Show category of operations
1433 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1434 $pdf->SetFont('', 'B', $default_font_size - 2);
1435 $pdf->SetXY($this->marge_gauche, $posy);
1436 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1437 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1438
1439 $pdf->SetFont('', '', $default_font_size - 2);
1440 $pdf->SetXY($posxval, $posy);
1441 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1442 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1443
1444 $posy = $pdf->GetY() + 3; // for 2 lines
1445 }
1446
1447 if ($object->type != 2) {
1448 // Check a payment mode is defined
1449 if (empty($object->mode_reglement_code)
1450 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1451 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1452 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1453 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1454 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1455 // Avoid having any valid PDF with setup that is not complete
1456 $outputlangs->load("errors");
1457
1458 $pdf->SetXY($this->marge_gauche, $posy);
1459 $pdf->SetTextColor(200, 0, 0);
1460 $pdf->SetFont('', 'B', $default_font_size - 2);
1461 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1462 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
1463 $pdf->SetTextColor(0, 0, 0);
1464
1465 $posy = $pdf->GetY() + 1;
1466 }
1467
1468 // Show payment mode
1469 if (!empty($object->mode_reglement_code)
1470 && $object->mode_reglement_code != 'CHQ'
1471 && $object->mode_reglement_code != 'VIR') {
1472 $pdf->SetFont('', 'B', $default_font_size - 2);
1473 $pdf->SetXY($this->marge_gauche, $posy);
1474 $titre = $outputlangs->transnoentities("PaymentMode").':';
1475 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1476
1477 $pdf->SetFont('', '', $default_font_size - 2);
1478 $pdf->SetXY($posxval, $posy);
1479 $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);
1480
1481 //#21654: add account number used for the debit
1482 if ($object->mode_reglement_code == "PRE") {
1483 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1484 $bac = new CompanyBankAccount($this->db);
1485 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1486 $bac->fetch(0, $object->thirdparty->id);
1487 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1488 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1489 }
1490
1491 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1492
1493 $posy = $pdf->GetY();
1494 }
1495
1496 // Show if Option VAT debit option is on also if transmitter is french
1497 // Decret n°2099-1299 2022-10-07
1498 // French mention : "Option pour le paiement de la taxe d'après les débits"
1499 if ($this->emetteur->country_code == 'FR') {
1500 if (getDolGlobalInt('TAX_MODE') == 1) {
1501 $pdf->SetXY($this->marge_gauche, $posy);
1502 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1503
1504 $posy = $pdf->GetY() + 1;
1505 }
1506 }
1507
1508 // Show online payment link
1509 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1510 $useonlinepayment = 0;
1511 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1512 if (isModEnabled('paypal')) {
1513 $useonlinepayment++;
1514 }
1515 if (isModEnabled('stripe')) {
1516 $useonlinepayment++;
1517 }
1518 if (isModEnabled('paybox')) {
1519 $useonlinepayment++;
1520 }
1521 $parameters = array();
1522 $action = '';
1523 $reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1524 if ($reshook > 0) {
1525 if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
1526 $useonlinepayment += $hookmanager->resArray['showonlinepaymenturl'];
1527 }
1528 }
1529 }
1530
1531
1532 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1533 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1534 global $langs;
1535
1536 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1537 $servicename = $langs->transnoentities('Online');
1538 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1539 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1540
1541 $pdf->SetXY($this->marge_gauche, $posy);
1542 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1543
1544 $posy = $pdf->GetY() + 1;
1545 }
1546 }
1547
1548 // Show payment mode CHQ
1549 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1550 // If payment mode unregulated or payment mode forced to CHQ
1551 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1552 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1553
1554 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1555 $account = new Account($this->db);
1556 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1557
1558 $pdf->SetXY($this->marge_gauche, $posy);
1559 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1560 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
1561 $posy = $pdf->GetY() + 1;
1562
1563 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1564 $pdf->SetXY($this->marge_gauche, $posy);
1565 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1566 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1567 $posy = $pdf->GetY() + 2;
1568 }
1569 }
1570 if (getDolGlobalString('FACTURE_CHQ_NUMBER') == -1) {
1571 $pdf->SetXY($this->marge_gauche, $posy);
1572 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1573 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1574 $posy = $pdf->GetY() + 1;
1575
1576 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1577 $pdf->SetXY($this->marge_gauche, $posy);
1578 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1579 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1580 $posy = $pdf->GetY() + 2;
1581 }
1582 }
1583 }
1584 }
1585
1586 // If payment mode not forced or forced to VIR, show payment with BAN
1587 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1588 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1589 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1590 if ($object->fk_bank > 0) {
1591 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1592 }
1593 $account = new Account($this->db);
1594 $account->fetch($bankid);
1595
1596 $curx = $this->marge_gauche;
1597 $cury = $posy;
1598
1599 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1600
1601 $posy += 2;
1602
1603 // Show structured communication
1604 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1605 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1606 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1607
1608 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', 0);
1609 }
1610 }
1611 }
1612 }
1613
1614 return $posy;
1615 }
1616
1617
1629 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1630 {
1631 global $conf, $mysoc, $hookmanager;
1632
1633 $sign = 1;
1634 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1635 $sign = -1;
1636 }
1637
1638 $default_font_size = pdf_getPDFFontSize($outputlangs);
1639
1640 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1641 $outputlangsbis = new Translate('', $conf);
1642 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1643 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1644 $default_font_size--;
1645 }
1646
1647 $tab2_top = $posy - 4;
1648 $tab2_hl = 4;
1649 $pdf->SetFont('', '', $default_font_size - 1);
1650
1651 // Total table
1652 $col1x = 120;
1653 $col2x = 170;
1654 if ($this->page_largeur < 210) { // To work with US executive format
1655 $col2x -= 20;
1656 }
1657 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1658
1659 $useborder = 0;
1660 $index = 0;
1661
1662 // Total HT
1663 $pdf->SetFillColor(255, 255, 255);
1664 $pdf->SetXY($col1x, $tab2_top + 0);
1665 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
1666
1667 $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1668 $pdf->SetXY($col2x, $tab2_top + 0);
1669 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht, 0, $outputlangs), 0, 'R', 1);
1670
1671 $remise = !empty($object->remise) ? $object->remise : 0;
1672 if ($remise > 0) {
1673 $index++;
1674 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1675 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("DiscountHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("DiscountHT") : ''), 0, 'L', 1);
1676 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1677 $pdf->MultiCell($largcol2, $tab2_hl, price($remise, 0, $outputlangs), 0, 'R', 1);
1678
1679 $index++;
1680 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1681 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTWithDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTWithDiscount") : ''), 0, 'L', 1);
1682 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1683 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht - $remise, 0, $outputlangs), 0, 'R', 1);
1684 }
1685
1686 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1687 $index++;
1688 $pdf->SetFillColor(255, 255, 255);
1689 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1690 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
1691
1692 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1693 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', 1);
1694 }
1695
1696 // Show VAT by rates and total
1697 $pdf->SetFillColor(248, 248, 248);
1698
1699 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1700
1701 $this->atleastoneratenotnull = 0;
1702 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1703 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1704 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1705 // Nothing to do
1706 } else {
1707 //Local tax 1 before VAT
1708 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1709 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1710 continue;
1711 }
1712
1713 foreach ($localtax_rate as $tvakey => $tvaval) {
1714 if ($tvakey != 0) { // On affiche pas taux 0
1715 //$this->atleastoneratenotnull++;
1716
1717 $index++;
1718 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1719
1720 $tvacompl = '';
1721 if (preg_match('/\*/', $tvakey)) {
1722 $tvakey = str_replace('*', '', $tvakey);
1723 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1724 }
1725
1726 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1727 $totalvat .= ' ';
1728
1729 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1730 $totalvat .= $tvacompl;
1731 } else {
1732 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1733 }
1734
1735 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1736
1737 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1738
1739 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1740 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1741 }
1742 }
1743 }
1744
1745 //Local tax 2 before VAT
1746 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1747 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1748 continue;
1749 }
1750
1751 foreach ($localtax_rate as $tvakey => $tvaval) {
1752 if ($tvakey != 0) { // On affiche pas taux 0
1753 //$this->atleastoneratenotnull++;
1754
1755 $index++;
1756 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1757
1758 $tvacompl = '';
1759 if (preg_match('/\*/', $tvakey)) {
1760 $tvakey = str_replace('*', '', $tvakey);
1761 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1762 }
1763 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1764 $totalvat .= ' ';
1765
1766 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1767 $totalvat .= $tvacompl;
1768 } else {
1769 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1770 }
1771
1772 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1773
1774 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1775
1776 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1777 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1778 }
1779 }
1780 }
1781 //}
1782
1783 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1784 // VAT
1785 $tvas = array();
1786 $nblines = count($object->lines);
1787 for ($i = 0; $i < $nblines; $i++) {
1788 $tvaligne = $object->lines[$i]->total_tva;
1789 $vatrate = (string) $object->lines[$i]->tva_tx;
1790
1791 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
1792 $vatrate .= '*';
1793 }
1794 if (! isset($tvas[$vatrate])) {
1795 $tvas[$vatrate] = 0;
1796 }
1797 $tvas[$vatrate] += $tvaligne;
1798 }
1799
1800 foreach ($tvas as $tvakey => $tvaval) {
1801 if ($tvakey != 0) { // On affiche pas taux 0
1802 $this->atleastoneratenotnull++;
1803
1804 $index++;
1805 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1806
1807 $tvacompl = '';
1808 if (preg_match('/\*/', $tvakey)) {
1809 $tvakey = str_replace('*', '', $tvakey);
1810 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1811 }
1812 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1813 $totalvat .= ' ';
1814 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1815 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1816 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1817 $totalvat .= $tvaval['vatcode'].$tvacompl;
1818 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1819 $totalvat .= $tvacompl;
1820 } else {
1821 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1822 }
1823 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1824
1825 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1826 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1827 }
1828 }
1829 }
1830
1831 //Local tax 1 after VAT
1832 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1833 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1834 continue;
1835 }
1836
1837 foreach ($localtax_rate as $tvakey => $tvaval) {
1838 if ($tvakey != 0) { // On affiche pas taux 0
1839 //$this->atleastoneratenotnull++;
1840
1841 $index++;
1842 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1843
1844 $tvacompl = '';
1845 if (preg_match('/\*/', $tvakey)) {
1846 $tvakey = str_replace('*', '', $tvakey);
1847 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1848 }
1849 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1850 $totalvat .= ' ';
1851
1852 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1853 $totalvat .= $tvacompl;
1854 } else {
1855 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1856 }
1857
1858 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1859
1860 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1861
1862 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1863 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1864 }
1865 }
1866 }
1867
1868 //Local tax 2 after VAT
1869 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1870 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1871 continue;
1872 }
1873
1874 foreach ($localtax_rate as $tvakey => $tvaval) {
1875 // retrieve global local tax
1876 if ($tvakey != 0) { // On affiche pas taux 0
1877 //$this->atleastoneratenotnull++;
1878
1879 $index++;
1880 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1881
1882 $tvacompl = '';
1883 if (preg_match('/\*/', $tvakey)) {
1884 $tvakey = str_replace('*', '', $tvakey);
1885 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1886 }
1887 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1888 $totalvat .= ' ';
1889
1890 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1891 $totalvat .= $tvacompl;
1892 } else {
1893 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1894 }
1895
1896 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1897
1898 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1899
1900 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1901 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1902 }
1903 }
1904 }
1905
1906
1907 // Revenue stamp
1908 if (price2num($object->revenuestamp, 'MT') != 0) {
1909 $index++;
1910 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1911 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
1912
1913 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1914 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1915 }
1916
1917 // Total TTC
1918 $index++;
1919 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1920 $pdf->SetTextColor(0, 0, 60);
1921 $pdf->SetFillColor(224, 224, 224);
1922 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
1923
1924 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1925 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1926
1927
1928 // Retained warranty
1929 if ($object->displayRetainedWarranty()) {
1930 $pdf->SetTextColor(40, 40, 40);
1931 $pdf->SetFillColor(255, 255, 255);
1932
1933 $retainedWarranty = $object->getRetainedWarrantyAmount();
1934 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1935
1936 // Billed - retained warranty
1937 $index++;
1938 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1939 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1940
1941 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1942 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1943
1944 // retained warranty
1945 $index++;
1946 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1947
1948 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
1949 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1950
1951 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1952 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1953 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1954 }
1955 }
1956 }
1957
1958 $pdf->SetTextColor(0, 0, 0);
1959
1960 $resteapayer = 0;
1961 /*
1962 $resteapayer = $object->total_ttc - $deja_regle;
1963 if (! empty($object->paye)) $resteapayer=0;
1964 */
1965
1966 if ($deja_regle > 0) {
1967 // Already paid + Deposits
1968 $index++;
1969
1970 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1971 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1972
1973 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1974 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1975
1976 /*
1977 if ($object->close_code == 'discount_vat')
1978 {
1979 $index++;
1980 $pdf->SetFillColor(255,255,255);
1981
1982 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1983 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1984
1985 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1986 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1987
1988 $resteapayer=0;
1989 }
1990 */
1991
1992 $index++;
1993 $pdf->SetTextColor(0, 0, 60);
1994 $pdf->SetFillColor(224, 224, 224);
1995 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1996 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
1997 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1998 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1999
2000 $pdf->SetFont('', '', $default_font_size - 1);
2001 $pdf->SetTextColor(0, 0, 0);
2002 }
2003
2004 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2005
2006 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2007 if ($reshook < 0) {
2008 $this->error = $hookmanager->error;
2009 $this->errors = $hookmanager->errors;
2010 }
2011
2012 $index++;
2013 return ($tab2_top + ($tab2_hl * $index));
2014 }
2015
2016 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2024 public static function liste_modeles($db, $maxfilenamelength = 0)
2025 {
2026 // phpcs:enable
2027 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2028 }
2029
2030 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2045 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2046 {
2047 global $conf;
2048
2049 // Force to disable hidetop and hidebottom
2050 $hidebottom = 0;
2051 $hidetop = 0;
2052
2053 $currency = !empty($currency) ? $currency : $conf->currency;
2054 $default_font_size = pdf_getPDFFontSize($outputlangs);
2055
2056 // Amount in (at tab_top - 1)
2057 $pdf->SetTextColor(0, 0, 0);
2058 $pdf->SetFont('', '', $default_font_size - 2);
2059
2060 if (empty($hidetop)) {
2061 // Show category of operations
2062 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2063 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2064 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2065 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2066 }
2067
2068 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2069 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2070 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2071
2072 // MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2073 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2074 $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')));
2075 }
2076 $tab_top += 4;
2077 }
2078
2079 $pdf->SetDrawColor(128, 128, 128);
2080 $pdf->SetFont('', '', $default_font_size - 1);
2081
2082 // Output Rect
2083 $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
2084
2085 // situation invoice
2086 $pdf->SetFont('', '', $default_font_size - 2);
2087
2088 foreach ($this->cols as $colKey => $colDef) {
2089 if (!$this->getColumnStatus($colKey)) {
2090 continue;
2091 }
2092 $xstartpos = (int) ($colDef['xStartPos'] ?? 0);
2093 //is there any overtitle ?
2094 if (!empty($colDef['overtitle']) && is_array($colDef['overtitle'])) {
2095 $overtitle_top = $tab_top - 4;
2096 $overtitle = $colDef['overtitle']['textkey'] ?? '';
2097 $textWidth = $colDef['overtitle']['width'] ?? 0;
2098 $pdf->SetXY($xstartpos + $colDef['overtitle']['padding'][3], $overtitle_top);
2099 $pdf->MultiCell($textWidth, 2, $overtitle, '', $colDef['overtitle']['align']);
2100 $pdf->line($xstartpos, $overtitle_top, $xstartpos, $overtitle_top + 4); //left
2101 $pdf->line($xstartpos, $overtitle_top, $xstartpos + $textWidth, $overtitle_top); //top
2102 $pdf->line($xstartpos + $textWidth, $overtitle_top, $xstartpos + $textWidth, $overtitle_top + 4); //right
2103 }
2104
2105 // get title label
2106 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
2107
2108 // Add column separator
2109 if (!empty($colDef['border-left'])) {
2110 $pdf->line($xstartpos, $tab_top, $xstartpos, $tab_top + $tab_height);
2111 }
2112
2113 if (empty($hidetop)) {
2114 $pdf->SetXY($xstartpos + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
2115
2116 $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
2117 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
2118 }
2119 }
2120 $pdf->SetFont('', '', $default_font_size - 1);
2121
2122 if (empty($hidetop)) {
2123 $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
2124 }
2125 }
2126
2127 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2138 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2139 {
2140 // phpcs:enable
2141 global $conf, $langs;
2142
2143 $ltrdirection = 'L';
2144 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2145 $ltrdirection = 'R';
2146 }
2147
2148 // Load traductions files required by page
2149 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2150
2151 $default_font_size = pdf_getPDFFontSize($outputlangs);
2152
2153 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2154
2155 $pdf->SetTextColor(0, 0, 60);
2156 $pdf->SetFont('', 'B', $default_font_size + 3);
2157
2158 $w = 110;
2159
2160 $posy = $this->marge_haute;
2161 $posx = $this->page_largeur - $this->marge_droite - $w;
2162
2163 $pdf->SetXY($this->marge_gauche, $posy);
2164
2165 // Logo
2166 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2167 if ($this->emetteur->logo) {
2168 $logodir = $conf->mycompany->dir_output;
2169 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2170 $logodir = $conf->mycompany->multidir_output[$object->entity];
2171 }
2172 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2173 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2174 } else {
2175 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2176 }
2177 if (is_readable($logo)) {
2178 $height = pdf_getHeightForLogo($logo);
2179 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2180 } else {
2181 $pdf->SetTextColor(200, 0, 0);
2182 $pdf->SetFont('', 'B', $default_font_size - 2);
2183 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2184 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2185 }
2186 } else {
2187 $text = $this->emetteur->name;
2188 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2189 }
2190 }
2191
2192 $pdf->SetFont('', 'B', $default_font_size + 3);
2193 $pdf->SetXY($posx, $posy);
2194 $pdf->SetTextColor(0, 0, 60);
2195 $subtitle = "";
2196 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2197 if ($object->type == 1) {
2198 $title = $outputlangs->transnoentities("InvoiceReplacement");
2199 }
2200 if ($object->type == 2) {
2201 $title = $outputlangs->transnoentities("InvoiceAvoir");
2202 }
2203 if ($object->type == 3) {
2204 $title = $outputlangs->transnoentities("InvoiceDeposit");
2205 }
2206 if ($object->type == 4) {
2207 $title = $outputlangs->transnoentities("InvoiceProForma");
2208 }
2209 if ($this->situationinvoice) {
2210 $title = $outputlangs->transnoentities("PDFInvoiceSituation");
2211 $subtitle = $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter);
2212 }
2213 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2214 $title .= ' - ';
2215 if ($object->type == 0) {
2216 if ($this->situationinvoice) {
2217 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2218 }
2219 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2220 } elseif ($object->type == 1) {
2221 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2222 } elseif ($object->type == 2) {
2223 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2224 } elseif ($object->type == 3) {
2225 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2226 } elseif ($object->type == 4) {
2227 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2228 }
2229 }
2230 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2231 // if ($object->status == $object::STATUS_DRAFT) {
2232 // $pdf->SetTextColor(128, 0, 0);
2233 // $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2234 // }
2235
2236 $pdf->MultiCell($w, 3, $title, '', 'R');
2237 if (!empty($subtitle)) {
2238 $pdf->SetFont('', 'B', $default_font_size);
2239 $pdf->SetXY($posx, $posy + 5);
2240 $pdf->MultiCell($w, 6, $subtitle, '', 'R');
2241 $posy += 2;
2242 }
2243
2244 $pdf->SetFont('', 'B', $default_font_size);
2245
2246 /*
2247 $posy += 5;
2248 $pdf->SetXY($posx, $posy);
2249 $pdf->SetTextColor(0, 0, 60);
2250 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2251 if ($object->status == $object::STATUS_DRAFT) {
2252 $pdf->SetTextColor(128, 0, 0);
2253 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2254 }
2255 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2256
2257 $posy += 3;
2258 $pdf->SetFont('', '', $default_font_size - 2);
2259
2260 if ($object->ref_customer) {
2261 $posy += 4;
2262 $pdf->SetXY($posx, $posy);
2263 $pdf->SetTextColor(0, 0, 60);
2264 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2265 }
2266
2267 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2268 $object->fetchProject();
2269 if (!empty($object->project->ref)) {
2270 $posy += 3;
2271 $pdf->SetXY($posx, $posy);
2272 $pdf->SetTextColor(0, 0, 60);
2273 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2274 }
2275 }
2276
2277 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2278 $object->fetchProject();
2279 if (!empty($object->project->ref)) {
2280 $outputlangs->load("projects");
2281 $posy += 3;
2282 $pdf->SetXY($posx, $posy);
2283 $pdf->SetTextColor(0, 0, 60);
2284 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2285 }
2286 }
2287
2288 $objectidnext = $object->getIdReplacingInvoice('validated');
2289 if ($object->type == 0 && $objectidnext) {
2290 $objectreplacing = new Facture($this->db);
2291 $objectreplacing->fetch($objectidnext);
2292
2293 $posy += 3;
2294 $pdf->SetXY($posx, $posy);
2295 $pdf->SetTextColor(0, 0, 60);
2296 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2297 }
2298 if ($object->type == 1) {
2299 $objectreplaced = new Facture($this->db);
2300 $objectreplaced->fetch($object->fk_facture_source);
2301
2302 $posy += 4;
2303 $pdf->SetXY($posx, $posy);
2304 $pdf->SetTextColor(0, 0, 60);
2305 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2306 }
2307 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2308 $objectreplaced = new Facture($this->db);
2309 $objectreplaced->fetch($object->fk_facture_source);
2310
2311 $posy += 3;
2312 $pdf->SetXY($posx, $posy);
2313 $pdf->SetTextColor(0, 0, 60);
2314 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2315 }
2316
2317 $posy += 4;
2318 $pdf->SetXY($posx, $posy);
2319 $pdf->SetTextColor(0, 0, 60);
2320
2321 $title = $outputlangs->transnoentities("DateInvoice");
2322 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2323 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2324 }
2325 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2326
2327 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2328 $posy += 4;
2329 $pdf->SetXY($posx, $posy);
2330 $pdf->SetTextColor(0, 0, 60);
2331 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2332 }
2333
2334 if ($object->type != 2) {
2335 $posy += 3;
2336 $pdf->SetXY($posx, $posy);
2337 $pdf->SetTextColor(0, 0, 60);
2338 $title = $outputlangs->transnoentities("DateDue");
2339 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2340 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2341 }
2342 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2343 }
2344
2345 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2346 $posy += 3;
2347 $pdf->SetXY($posx, $posy);
2348 $pdf->SetTextColor(0, 0, 60);
2349 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2350 }
2351
2352 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2353 $posy += 3;
2354 $pdf->SetXY($posx, $posy);
2355 $pdf->SetTextColor(0, 0, 60);
2356 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
2357 }
2358
2359 // Get contact
2360 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2361 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2362 if (count($arrayidcontact) > 0) {
2363 $usertmp = new User($this->db);
2364 $usertmp->fetch($arrayidcontact[0]);
2365 $posy += 4;
2366 $pdf->SetXY($posx, $posy);
2367 $pdf->SetTextColor(0, 0, 60);
2368 $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2369 }
2370 }
2371
2372 $posy += 1;
2373
2374 $top_shift = 0;
2375 $shipp_shift = 0;
2376 // Show list of linked objects
2377 $current_y = $pdf->getY();
2378 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2379 if ($current_y < $pdf->getY()) {
2380 $top_shift = $pdf->getY() - $current_y;
2381 }
2382
2383 if ($showaddress) {
2384 // Sender properties
2385 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2386
2387 // Show sender
2388 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2389 $posy += $top_shift;
2390 $posx = $this->marge_gauche;
2391 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2392 $posx = $this->page_largeur - $this->marge_droite - 80;
2393 }
2394
2395 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2396 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2397
2398 // Show sender frame
2399 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2400 $pdf->SetTextColor(0, 0, 0);
2401 $pdf->SetFont('', '', $default_font_size - 2);
2402 $pdf->SetXY($posx, $posy - 5);
2403 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2404 $pdf->SetXY($posx, $posy);
2405 $pdf->SetFillColor(230, 230, 230);
2406 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2407 $pdf->SetTextColor(0, 0, 60);
2408 }
2409
2410 // Show sender name
2411 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2412 $pdf->SetXY($posx + 2, $posy + 3);
2413 $pdf->SetFont('', 'B', $default_font_size);
2414 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2415 $posy = $pdf->getY();
2416 }
2417
2418 // Show sender information
2419 $pdf->SetXY($posx + 2, $posy);
2420 $pdf->SetFont('', '', $default_font_size - 1);
2421 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2422
2423 // If BILLING contact defined on invoice, we use it
2424 $usecontact = false;
2425 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2426 if (count($arrayidcontact) > 0) {
2427 $usecontact = true;
2428 $result = $object->fetch_contact($arrayidcontact[0]);
2429 }
2430
2431 // Recipient name
2432 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2433 $thirdparty = $object->contact;
2434 } else {
2435 $thirdparty = $object->thirdparty;
2436 }
2437
2438 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2439
2440 $mode = 'target';
2441 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2442
2443 // Show recipient
2444 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2445 if ($this->page_largeur < 210) {
2446 $widthrecbox = 84; // To work with US executive format
2447 }
2448 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2449 $posy += $top_shift;
2450 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2451 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2452 $posx = $this->marge_gauche;
2453 }
2454
2455 // Show recipient frame
2456 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2457 $pdf->SetTextColor(0, 0, 0);
2458 $pdf->SetFont('', '', $default_font_size - 2);
2459 $pdf->SetXY($posx + 2, $posy - 5);
2460 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2461 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2462 }
2463
2464 // Show recipient name
2465 $pdf->SetXY($posx + 2, $posy + 3);
2466 $pdf->SetFont('', 'B', $default_font_size);
2467 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2468 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2469
2470 $posy = $pdf->getY();
2471
2472 // Show recipient information
2473 $pdf->SetFont('', '', $default_font_size - 1);
2474 $pdf->SetXY($posx + 2, $posy);
2475 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2476 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2477
2478 // Show shipping/delivery address
2479 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2480 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2481
2482 if (!empty($idaddressshipping)) {
2483 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2484 $companystatic = new Societe($this->db);
2485 $companystatic->fetch($object->contact->fk_soc);
2486 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2487 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, ($usecontact ? 1 : 0), 'target', $object);
2488 } else {
2489 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2490 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2491 }
2492 if (!empty($carac_client_shipping)) {
2493 $posy += $hautcadre;
2494
2495 // Show shipping frame
2496 $pdf->SetXY($posx + 2, $posy - 5);
2497 $pdf->SetFont('', '', $default_font_size - 2);
2498 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2499 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2500
2501 // Show shipping name
2502 $pdf->SetXY($posx + 2, $posy + 3);
2503 $pdf->SetFont('', 'B', $default_font_size);
2504 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2505
2506 $posy = $pdf->getY();
2507
2508 // Show shipping information
2509 $pdf->SetXY($posx + 2, $posy);
2510 $pdf->SetFont('', '', $default_font_size - 1);
2511 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2512 $shipp_shift += $hautcadre;
2513 }
2514 }
2515 }
2516
2517 $pdf->SetTextColor(0, 0, 0);
2518
2519 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2520
2521 return $pagehead;
2522 }
2523
2524 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2534 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2535 {
2536 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2537 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);
2538 }
2539
2550 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2551 {
2552 global $conf, $hookmanager;
2553
2554 // Default field style for content
2555 $this->defaultContentsFieldsStyle = array(
2556 'align' => 'R', // R,C,L
2557 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2558 );
2559
2560 // Default field style for content
2561 $this->defaultTitlesFieldsStyle = array(
2562 'align' => 'C', // R,C,L
2563 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2564 );
2565
2566 /*
2567 * For example
2568 $this->cols['theColKey'] = array(
2569 'rank' => $rank, // int : use for ordering columns
2570 'width' => 20, // the column width in mm
2571 'title' => array(
2572 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2573 'label' => ' ', // the final label : used fore final generated text
2574 'align' => 'L', // text alignment : R,C,L
2575 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2576 ),
2577 'content' => array(
2578 'align' => 'L', // text alignment : R,C,L
2579 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2580 ),
2581 );
2582 */
2583
2584 $rank = 0; // do not use negative rank
2585 $this->cols['desc'] = array(
2586 'rank' => $rank,
2587 'width' => false, // only for desc
2588 'status' => true,
2589 'title' => array(
2590 'textkey' => 'Designation', // use lang key is useful in somme case with module
2591 'align' => 'L',
2592 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2593 // 'label' => ' ', // the final label
2594 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2595 ),
2596 'content' => array(
2597 'align' => 'L',
2598 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2599 ),
2600 );
2601
2602 // Image of product
2603 $rank += 10;
2604 $this->cols['photo'] = array(
2605 'rank' => $rank,
2606 'width' => getDolGlobalString('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2607 'status' => false,
2608 'title' => array(
2609 'textkey' => 'Photo',
2610 'label' => ' '
2611 ),
2612 'content' => array(
2613 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2614 ),
2615 'border-left' => false, // remove left line separator
2616 );
2617
2618 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2619 $this->cols['photo']['status'] = true;
2620 }
2621
2622
2623 $rank += 10;
2624 $this->cols['vat'] = array(
2625 'rank' => $rank,
2626 'status' => false,
2627 'width' => 10, // in mm
2628 'title' => array(
2629 'textkey' => 'VAT'
2630 ),
2631 'border-left' => true, // add left line separator
2632 );
2633
2634 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2635 $this->cols['vat']['status'] = true;
2636 }
2637
2638 $rank += 10;
2639 $this->cols['unit'] = array(
2640 'rank' => $rank,
2641 'width' => 11, // in mm
2642 'status' => false,
2643 'title' => array(
2644 'textkey' => 'Unit'
2645 ),
2646 'border-left' => true, // add left line separator
2647 );
2648 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2649 $this->cols['unit']['status'] = false;
2650 }
2651
2652 $rank += 10;
2653 $this->cols['subprice'] = array(
2654 'rank' => $rank,
2655 'width' => 17, // in mm
2656 'status' => true,
2657 'title' => array(
2658 'textkey' => 'PriceUHT'
2659 ),
2660 'border-left' => true, // add left line separator
2661 );
2662
2663 // Adapt dynamically the width of subprice, if text is too long.
2664 $tmpwidth = 0;
2665 $nblines = count($object->lines);
2666 for ($i = 0; $i < $nblines; $i++) {
2667 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2668 $tmpwidth = max($tmpwidth, $tmpwidth2);
2669 }
2670 if ($tmpwidth > 10) {
2671 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2672 }
2673
2674 $rank += 10;
2675 $this->cols['qty'] = array(
2676 'rank' => $rank,
2677 'width' => 10, // in mm
2678 'status' => true,
2679 'title' => array(
2680 'textkey' => 'Qty'
2681 ),
2682 'border-left' => true, // add left line separator
2683 );
2684 //situation invoices
2685 $this->cols['qty']['status'] = true;
2686
2687 //sum column
2688 $rank += 10;
2689 $this->cols['btpsomme'] = array(
2690 'rank' => $rank,
2691 'width' => 18, // in mm
2692 'status' => false,
2693 'title' => array(
2694 'textkey' => 'Chantier'
2695 ),
2696 'border-left' => true, // add left line separator
2697 'overtitle' => array(
2698 'textkey' => 'Chantier', // use lang key is useful in somme case with module
2699 'align' => 'C',
2700 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2701 'width' => 18
2702 ),
2703 );
2704 if (!empty($this->TDataSituation['date_derniere_situation'])) {
2705 $this->cols['btpsomme']['status'] = true;
2706 }
2707
2708 $derniere_situation = $this->TDataSituation['derniere_situation'];
2709
2710 if (empty($derniere_situation)) {
2711 $derniere_situation = 0;
2712 }
2713
2714 // Column 'Previous progression'
2715 $rank += 10;
2716 $this->cols['prev_progress'] = array(
2717 'rank' => $rank,
2718 'width' => 10, // in mm
2719 'status' => false,
2720 'title' => array(
2721 'textkey' => $outputlangs->transnoentities('ProgressShort')
2722 ),
2723 'border-left' => true, // add left line separator
2724 'overtitle' => array(
2725 'textkey' => 'S'.$derniere_situation->situation_counter . ' - ' . dol_print_date($derniere_situation->date, "%d/%m/%Y"),
2726 'align' => 'C',
2727 'padding' => array(0.5,0.2,0.5,0.2), // Like css 0 => top, 1 => right, 2 => bottom, 3 => left
2728 'width' => 10 + 15 //current width + amount cell width
2729 ),
2730 );
2731 if ($this->situationinvoice && ! empty($this->TDataSituation['date_derniere_situation'])) {
2732 $this->cols['prev_progress']['status'] = true;
2733 }
2734
2735 // Column 'Previous progression'
2736 $rank += 10;
2737 $this->cols['prev_progress_amount'] = array(
2738 'rank' => $rank,
2739 'width' => 15, // in mm
2740 'status' => false,
2741 'title' => array(
2742 'textkey' => $outputlangs->transnoentities('Amount')
2743 ),
2744 'border-left' => true, // add left line separator
2745 );
2746 if ($this->situationinvoice && ! empty($this->TDataSituation['date_derniere_situation'])) {
2747 $this->cols['prev_progress_amount']['status'] = true;
2748 }
2749
2750 // Column 'Current percent progress'
2751 $rank += 10;
2752 $this->cols['progress'] = array(
2753 'rank' => $rank,
2754 'width' => 10, // in mm
2755 'status' => true,
2756 'title' => array(
2757 'textkey' => $outputlangs->transnoentities('ProgressShort')
2758 ),
2759 'border-left' => true, // add left line separator
2760 'overtitle' => array(
2761 'textkey' => 'S'.$object->situation_counter . ' - ' . dol_print_date($object->date, "%d/%m/%Y"),
2762 'align' => 'C',
2763 'padding' => array(0.5,0.2,0.5,0.2), // Like css 0 => top, 1 => right, 2 => bottom, 3 => left
2764 'width' => 10 + 15
2765 ),
2766 );
2767
2768 // Column 'Current progress'
2769 $rank += 10;
2770 $this->cols['progress_amount'] = array(
2771 'rank' => $rank,
2772 'width' => 15, // in mm
2773 'status' => true,
2774 'title' => array(
2775 'textkey' => $outputlangs->transnoentities('Amount')
2776 ),
2777 'border-left' => true, // add left line separator
2778 );
2779 if ($this->situationinvoice) {
2780 $this->cols['progress_amount']['status'] = true;
2781 }
2782
2783 // FIN BTP SITUATION
2784
2785 $rank += 10;
2786 $this->cols['discount'] = array(
2787 'rank' => $rank,
2788 'width' => 10, // in mm
2789 'status' => false,
2790 'title' => array(
2791 'textkey' => 'ReductionShort'
2792 ),
2793 'border-left' => true, // add left line separator
2794 );
2795 if ($this->atleastonediscount) {
2796 $this->cols['discount']['status'] = true;
2797 }
2798 $rank += 10;
2799 $this->cols['totalexcltax'] = array(
2800 'rank' => $rank,
2801 'width' => 18, // in mm
2802 'status' => true,
2803 'title' => array(
2804 'textkey' => $outputlangs->transnoentities('TotalHT')
2805 ),
2806 'border-left' => true, // add left line separator
2807 );
2808
2809 $parameters = array(
2810 'object' => $object,
2811 'outputlangs' => $outputlangs,
2812 'hidedetails' => $hidedetails,
2813 'hidedesc' => $hidedesc,
2814 'hideref' => $hideref
2815 );
2816
2817 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2818 if ($reshook < 0) {
2819 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2820 } elseif (empty($reshook)) {
2821 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2822 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2823 } else {
2824 $this->cols = $hookmanager->resArray;
2825 }
2826 }
2827
2841 public function _tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
2842 {
2843 global $conf, $object, $db;
2844
2845 $form = new Form($db);
2846
2847 $tab_height -= 29; // Réduction de la hauteur global du tableau
2848 $displayWarranty = $this->displayRetainedWarranty($object);
2849 if (!$displayWarranty) {
2850 $tab_height -= 19; // Réduction de la hauteur global du tableau
2851 }
2852
2853
2854 // Force to disable hidetop and hidebottom
2855 $hidebottom = 0;
2856 if ($hidetop) {
2857 $hidetop = -1;
2858 }
2859
2860 $currency = !empty($currency) ? $currency : $conf->currency;
2861 $default_font_size = pdf_getPDFFontSize($outputlangs);
2862
2863 // Amount in (at tab_top - 1)
2864 $pdf->SetTextColor(0, 0, 0);
2865 $pdf->SetFont('', '', $default_font_size - 2);
2866
2867 if (empty($hidetop)) {
2868 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2869 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2870 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2871
2872 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2873
2874 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2875 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2876 //$pdf->Rect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2877 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius, '1001', 'F', explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2878 //$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')));
2879 $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')));
2880 }
2881 }
2882
2883 $pdf->SetDrawColor(128, 128, 128);
2884 $pdf->SetFont('', '', $default_font_size - 1);
2885
2886 // Output Rect
2887 // KEEPTHIS => Affiche les bords extérieurs
2888 $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
2889
2890 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2891 if (empty($hidetop)) {
2892 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2893 $pdf->MultiCell(35, 2, $outputlangs->transnoentities("SituationInvoiceOldCumulation"), '', 'C');
2894 }
2895
2896 // PRINT COLUMNS TITLES
2897 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2898 if (empty($hidetop)) {
2899 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2900 $pdf->MultiCell(35, 2, $outputlangs->transnoentities("SituationInvoiceNewCumulation"), '', 'C');
2901 }
2902
2903 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2904 if (empty($hidetop)) {
2905 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2906 $pdf->MultiCell(36, 2, $outputlangs->transnoentities("CurrentSituationTotal", $object->situation_counter), '', 'C');
2907 }
2908
2909 // ADD HORIZONTAL LINES
2910 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2911
2912 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2913
2914 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2915
2916 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2917
2918 if ($displayWarranty) {
2919 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2920 }
2921
2922
2923 // ADD TEXT INTO CELL
2924 /********************** Titles ******************************/
2925 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2926 $pdf->MultiCell(60, 2, $outputlangs->transnoentities("SituationInvoiceMainTask"), '', 'L');
2927
2928 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2929 $pdf->MultiCell(60, 2, $outputlangs->transnoentities("SituationInvoiceAdditionalTask"), '', 'L');
2930
2931 $form->load_cache_vatrates("'".$object->thirdparty->country_code."'");
2932
2933 $i = -8;
2934 foreach ($form->cache_vatrates as $TVatInfo) {
2935 $tva_tx_formated = sprintf("%01.3f", (float) $TVatInfo['txtva']);
2936 // print "<p>Un taux de tva ... $tva_tx_formated :: " . json_encode($this->TDataSituation['current'][$tva_tx_formated]) . "</p>";
2937 if (empty($this->TDataSituation['current'][$tva_tx_formated])) {
2938 continue;
2939 }
2940 $i += 8;
2941
2942 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2943 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalHT").' '.$TVatInfo['label'], '', 'L');
2944
2945 if (! empty($this->TDataSituation['current'][$tva_tx_formated]['TVA'])) {
2946 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2947 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("VAT").' '.$TVatInfo['label'], '', 'L');
2948 } else {
2949 $i -= 4;
2950 }
2951 }
2952
2953 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2954 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalTTC"), '', 'L');
2955
2956
2957 $pdf->SetFont('', 'B', $default_font_size - 1);
2958 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2959 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalSituationInvoice"), '', 'L');
2960 $pdf->SetFont('', '', $default_font_size - 2);
2961
2962 if ($displayWarranty) {
2963 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2964 $pdf->MultiCell(80, 2, $outputlangs->trans("TotalSituationInvoiceWithRetainedWarranty", $object->retained_warranty), '', 'L');
2965 $nextY = $tab_top + 93;
2966 } else {
2967 $nextY = $tab_top + 74;
2968 }
2969
2970 $pdf->SetFont('', 'B', $default_font_size - 1);
2971 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2972 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("SituationTotalRayToRest"), '', 'L');
2973 $pdf->SetFont('', '', $default_font_size - 2);
2974 /***********************************************************/
2975
2976 /********************** Data *******************************/
2977 $TToDisplay = array(
2978 'cumul_anterieur',
2979 'nouveau_cumul',
2980 'current'
2981 );
2982
2983 $x = $this->marge_gauche + 85;
2984 // unset($this->TDataSituation['derniere_situation']);
2985 // print json_encode($object->lines);exit;
2986 // print json_encode($this->TDataSituation);exit;
2987 foreach ($TToDisplay as $col) {
2988 // Travaux principaux
2989 $pdf->SetXY($x, $tab_top + 8);
2990 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['HT'], 0, '', 1, -1, 2), '', 'R');
2991
2992 // Travaux supplémentaires
2993 $pdf->SetXY($x, $tab_top + 12);
2994 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['travaux_sup'], 0, '', 1, -1, 2), '', 'R');
2995
2996 $i = -8;
2997 foreach ($form->cache_vatrates as $TVatInfo) {
2998 $tva_tx_formated = sprintf("%01.3f", (float) $TVatInfo['txtva']);
2999 if (empty($this->TDataSituation['current'][$tva_tx_formated])) {
3000 continue;
3001 }
3002 $i += 8;
3003
3004 // Total HT
3005 $pdf->SetXY($x, $tab_top + 24 + $i);
3006 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col][$tva_tx_formated]['HT'], 0, '', 1, -1, 2), '', 'R');
3007
3008 // Total TVA
3009 if (! empty($this->TDataSituation['current'][$tva_tx_formated]['TVA'])) {
3010 $pdf->SetXY($x, $tab_top + 28 + $i);
3011 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col][$tva_tx_formated]['TVA'], 0, '', 1, -1, 2), '', 'R');
3012 } else {
3013 $i -= 4;
3014 }
3015 }
3016
3017 // Total TTC
3018 $pdf->SetXY($x, $tab_top + 33 + $i);
3019 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['TTC'], 0, '', 1, -1, 2), '', 'R');
3020
3021 // Total situation
3022 $pdf->SetFont('', 'B', $default_font_size - 1);
3023 $pdf->SetXY($x, $tab_top + 58);
3024 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['TTC'], 0, '', 1, -1, 2), '', 'R');
3025 $pdf->SetFont('', '', $default_font_size - 2);
3026
3027
3028 if ($displayWarranty) {
3029 // Retained warranty
3030 $pdf->SetXY($x, $tab_top + 74);
3031 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['retenue_garantie'], 0, '', 1, -1, 2), '', 'R');
3032 $nextY = $tab_top + 93;
3033 } else {
3034 $nextY = $tab_top + 74;
3035 }
3036
3037 // Amount payable incl. VAT
3038 $pdf->SetFont('', 'B', $default_font_size - 1);
3039 $pdf->SetXY($x, $nextY);
3040 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['total_a_payer'], 0, '', 1, -1, 2), '', 'R');
3041 $pdf->SetFont('', '', $default_font_size - 2);
3042
3043 $x += 36;
3044 }
3045 /************************************************************/
3046 }
3047
3048
3070 public function getDataSituation(&$object)
3071 {
3072 global $conf, $db;
3073
3074 // Fetch previous and next situations invoices.
3075 // Return all previous and next invoices (both standard and credit notes)
3076 $object->fetchPreviousNextSituationInvoice();
3078 $TPreviousInvoices = $object->tab_previous_situation_invoice;
3079 unset($object->tab_previous_situation_invoice);
3080
3081 // liste de toutes les factures précédentes
3082 // print json_encode($TPreviousInvoices); exit;
3083
3084 $TPreviousInvoices = array_reverse($TPreviousInvoices);
3085 $facDerniereSituation = $TPreviousInvoices[0];
3086
3087 $TDataSituation = array();
3088
3089 if (! empty($facDerniereSituation)) {
3090 $TDataSituation['derniere_situation'] = $facDerniereSituation;
3091 $TDataSituation['date_derniere_situation'] = $facDerniereSituation->date;
3092 }
3093
3094 $retenue_garantie = 0;
3095 $retenue_garantie_anterieure = 0;
3096 // Init tous les champs à 0
3097 $TDataSituation['cumul_anterieur'] = array(
3098 'HT' => 0, //montant HT normal
3099 'TVA' => 0, //montant de la TVA sur le HTnet
3100 'TTC' => 0, //montant TTC (HTnet + TVA)
3101 'retenue_garantie' => 0,
3102 'travaux_sup' => 0,
3103 'HTnet' => 0, //montant HT
3104 'total_a_payer' => 0 //montant "a payer" sur la facture
3105 );
3106
3107 //S'il y a des factures de situations précédentes
3108 if (!empty($TPreviousInvoices)) {
3109 //calcul des cumuls -- plus necessaire ?
3110 foreach ($TPreviousInvoices as $i => $previousInvoice) {
3111 $TDataSituation['cumul_anterieur']['HT'] += $previousInvoice->total_ht;
3112 // $TDataSituation['cumul_anterieur']['TTC'] += $previousInvoice->total_ttc;
3113 $TDataSituation['cumul_anterieur']['TVA'] += $previousInvoice->total_tva;
3114
3115 //lecture de chaque ligne pour
3116 // 1. recalculer le total_ht pour chaque taux de TVA
3117 // 2. recalculer la TVA associée à ce montant HT
3118 // 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
3119 foreach ($previousInvoice->lines as $k => $l) {
3120 $total_ht = floatval($l->total_ht);
3121 if (empty($total_ht)) {
3122 continue;
3123 }
3124
3125 // Si $prevSituationPercent vaut 0 c'est que la ligne $l est un travail supplémentaire
3126 $prevSituationPercent = 0;
3127 $isFirstSituation = false;
3128 if (!empty($l->fk_prev_id)) {
3129 $prevSituationPercent = $l->get_prev_progress($previousInvoice->id, true);
3130 } elseif (! array_key_exists($i + 1, $TPreviousInvoices)) {
3131 $isFirstSituation = true;
3132 }
3133
3134 $calc_ht = $l->total_ht;
3135 //modification du format de TVA, cas particulier des imports ou autres qui peuvent avoir des 20.0000
3136 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3137
3138 //1ere ligne
3139 $amounttva = $calc_ht * ($ltvatx / 100);
3140 if (! isset($TDataSituation['cumul_anterieur'][$ltvatx])) {
3141 $TDataSituation['cumul_anterieur'][$ltvatx]['HT'] = $calc_ht;
3142 $TDataSituation['cumul_anterieur'][$ltvatx]['TVA'] = $amounttva;
3143 } else {
3144 //lignes suivantes
3145 $TDataSituation['cumul_anterieur'][$ltvatx]['HT'] += ($calc_ht);
3146 $TDataSituation['cumul_anterieur'][$ltvatx]['TVA'] += $amounttva;
3147 }
3148
3149 //le grand total de TVA
3150 // $TDataSituation['cumul_anterieur']['TVA'] += $amounttva;
3151
3152 if (empty($l->fk_prev_id) && ! $isFirstSituation) {
3153 // TODO: à clarifier, mais pour moi, un facture de situation précédente qui a des progressions à 0% c'est pas logique
3154 $TDataSituation['cumul_anterieur']['travaux_sup'] += $calc_ht;
3155 }
3156 }
3157 }
3158
3159 if (! empty($previousInvoice->retained_warranty) && !getDolGlobalString('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL')) {
3160 $retenue_garantie_anterieure += $previousInvoice->getRetainedWarrantyAmount();
3161 }
3162
3163 //les cumuls
3164 $TDataSituation['cumul_anterieur']['HT'] -= $TDataSituation['cumul_anterieur']['travaux_sup'];
3165 $TDataSituation['cumul_anterieur']['retenue_garantie'] = $retenue_garantie_anterieure;
3166 $TDataSituation['cumul_anterieur']['TTC'] = $TDataSituation['cumul_anterieur']['HT'] + $TDataSituation['cumul_anterieur']['TVA'];
3167 $TDataSituation['cumul_anterieur']['total_a_payer'] = $TDataSituation['cumul_anterieur']['TTC'] - $retenue_garantie_anterieure;
3168 }
3169
3170 // print json_encode($facDerniereSituation->lines);exit;
3171 $TDataSituation['current'] = $this->btpGetInvoiceAmounts($object->id);
3172
3173 if (! empty($facDerniereSituation->lines)) {
3174 $TFacLinesKey = array_keys($facDerniereSituation->lines);
3175 $TObjectLinesKey = array_keys($object->lines);
3176 $TDiffKey = array_diff($TObjectLinesKey, $TFacLinesKey);
3177
3178 // print json_encode($TDiffKey);exit;
3179
3180 foreach ($TDiffKey as $i) {
3181 if (empty($object->lines[$i]->fk_prev_id)) {
3182 // Next line is useless because 'nouveau_cumul' is overwritten below
3183 // $TDataSituation['nouveau_cumul']['travaux_sup'] += $object->lines[$i]->total_ht;
3184 $TDataSituation['current']['travaux_sup'] += $object->lines[$i]->total_ht;
3185 }
3186 }
3187 }
3188
3189 //Le nouveau cumul = cumul antérieur + current
3190 $TDataSituation['nouveau_cumul'] = $this->sumSituation($TDataSituation['current'], $TDataSituation['cumul_anterieur']);
3191
3192 return $TDataSituation;
3193 }
3194
3203 public function sumSituation($a, $b)
3204 {
3205 $ret = array();
3206 if (is_array($a)) {
3207 foreach ($a as $k => $v) {
3208 if (is_array($v)) {
3209 $ret[$k] = $this->sumSituation($v, $b[$k]);
3210 } else {
3211 $ret[$k] = $a[$k];
3212 if (isset($b[$k])) {
3213 $ret[$k] += $b[$k];
3214 }
3215 }
3216 }
3217 } else {
3218 dol_syslog("sumSituation first arg is not an array");
3219 }
3220
3221 return $ret;
3222 }
3223
3231 {
3232 if (is_callable(array($object, 'displayRetainedWarranty'))) {
3233 return $object->displayRetainedWarranty();
3234 } else {
3235 // FOR RETROCOMPATIBILITY
3236 global $conf;
3237
3238 // TODO : add a flag on invoices to store this conf USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL
3239
3240 // 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
3241
3242 $displayWarranty = false;
3243 if (!empty($object->retained_warranty)) {
3244 $displayWarranty = true;
3245
3246 if ($object->type == Facture::TYPE_SITUATION && getDolGlobalString('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL')) {
3247 // Check if this situation invoice is 100% for real
3248 $displayWarranty = false;
3249 if (!empty($object->situation_final)) {
3250 $displayWarranty = true;
3251 } elseif (!empty($object->lines) && $object->status == Facture::STATUS_DRAFT) {
3252 // $object->situation_final need validation to be done so this test is need for draft
3253 $displayWarranty = true;
3254
3255 foreach ($object->lines as $i => $line) {
3256 if ($line->product_type < 2 && $line->situation_percent < 100) {
3257 $displayWarranty = false;
3258 break;
3259 }
3260 }
3261 }
3262 }
3263 }
3264 return $displayWarranty;
3265 }
3266 }
3267
3275 public function getInfosLineLastSituation(&$object, &$current_line)
3276 {
3277 if (empty($object->situation_cycle_ref) || $object->situation_counter <= 1) {
3278 return;
3279 }
3280
3281 $facDerniereSituation = &$this->TDataSituation['derniere_situation'];
3282
3283 // Find the previous line of the line you are on
3284 foreach ($facDerniereSituation->lines as $l) {
3285 if ($l->rowid == $current_line->fk_prev_id) {
3286 // Recovery of total_ht without taking progress into account (for the "sums" column)
3287 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3288 $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);
3289 $total_ht = $tabprice[0];
3290 $total_tva = $tabprice[1];
3291 $total_ttc = $tabprice[2];
3292 $total_localtax1 = $tabprice[9];
3293 $total_localtax2 = $tabprice[10];
3294 $pu_ht = $tabprice[3];
3295
3296 return array(
3297 'progress_prec' => (float) $l->situation_percent,
3298 'total_ht_without_progress' => (float) $total_ht,
3299 'total_ht' => $l->total_ht,
3300 );
3301 }
3302 }
3303 }
3304
3317 /*
3318 public function printRectBtp(&$pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
3319 {
3320 if (empty($hidetop) || $hidetop == -1) {
3321 $pdf->line($x, $y, $x + $l, $y);
3322 }
3323 $pdf->line($x + $l, $y, $x + $l, $y + $h);
3324 if (empty($hidebottom)) {
3325 $pdf->line($x + $l, $y + $h, $x, $y + $h);
3326 }
3327 $pdf->line($x, $y + $h, $x, $y);
3328 }*/
3329
3344 public function printRoundedRectBtp($pdf, $x, $y, $w, $h, $r, $hidetop = 0, $hidebottom = 0, $style = 'D')
3345 {
3346 // Top line
3347 if (empty($hidetop) || $hidetop == -1) {
3348 $pdf->RoundedRect($x, $y, $w, $h, $r, '1111', $style);
3349 } else {
3350 // Draw rounded rectangle with hidden top side
3351 $pdf->RoundedRect($x, $y, $w, $h, $r, '0111', $style);
3352 }
3353 if (!empty($hidebottom)) {
3354 $pdf->RoundedRect($x, $y, $w, $h, $r, '1101', $style);
3355 }
3356 }
3357
3366 public function btpGetInvoiceAmounts($id, $forceReadFromDB = false)
3367 {
3368 global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
3369
3370 $object = new Facture($db);
3371 $object->fetch($id);
3372
3373 /* from dolibarr core
3374 * Fetch previous and next situations invoices.
3375 * Return all previous and next invoices (both standard and credit notes).
3376 */
3377 $object->fetchPreviousNextSituationInvoice();
3379 $TPreviousInvoices = $object->tab_previous_situation_invoice;
3380 unset($object->tab_previous_situation_invoice);
3381
3382 $TPreviousInvoices = array_reverse($TPreviousInvoices);
3383 $facDerniereSituation = $TPreviousInvoices[0];
3384
3385 $ret = array(
3386 'HT' => 0, //montant HT normal
3387 'HTnet' => 0, //montant HT
3388 'TVA' => 0, //montant de la TVA sur le HTnet
3389 'TTC' => 0, //montant TTC (HTnet + TVA)
3390 'retenue_garantie' => 0,
3391 'travaux_sup' => 0,
3392 'total_a_payer' => 0 //montant "a payer" sur la facture
3393 );
3394
3395 if (! empty($facDerniereSituation)) {
3396 $ret['derniere_situation'] = $facDerniereSituation;
3397 $ret['date_derniere_situation'] = $facDerniereSituation->date;
3398 }
3399
3400 // Scroll through the lines of the current invoice to retrieve all data
3401 foreach ($object->lines as $k => $l) {
3402 $total_ht = floatval($l->total_ht);
3403 if (empty($total_ht)) {
3404 continue;
3405 }
3406
3407 // Modification of VAT format, special case of imports or others which may have 20.0000
3408 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3409
3410 $ret[$ltvatx]['TVA'] += $l->total_tva;
3411 $ret[$ltvatx]['HT'] += $l->total_ht;
3412 }
3413
3414 // Retained warranty
3415 $retenue_garantie = $object->getRetainedWarrantyAmount();
3416 if ($retenue_garantie == -1) {
3417 $retenue_garantie = 0;
3418 }
3419
3420 //les cumuls
3421 $ret['TTC'] = $object->total_ttc;
3422 $ret['TVA'] = $object->total_tva;
3423 $ret['HT'] = $object->total_ht - $ret['travaux_sup'];
3424 $ret['total_a_payer'] = $ret['TTC'] - $retenue_garantie;
3425 $ret['retenue_garantie'] = $retenue_garantie;
3426
3427 //Clean up before keep in "cache"
3428 if (array_key_exists('derniere_situation', $ret)) {
3429 unset($ret['derniere_situation']->db);
3430 unset($ret['derniere_situation']->fields);
3431 unset($ret['derniere_situation']->lines);
3432 }
3433
3434 // print "<p>Store to cache $id : " . json_encode($_cache_btpProrataGetInvoiceAmounts[$id]) . "</p>";
3435 return $ret;
3436 }
3437
3438
3450 public function resumeLastPage(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
3451 {
3452 global $conf, $mysoc, $hookmanager;
3453 $default_font_size = pdf_getPDFFontSize($outputlangs);
3454
3455 $sign = 1;
3456 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3457 $sign = -1;
3458 }
3459
3460 $pdf->AddPage();
3461 if (!empty($this->tplidx)) {
3462 $pdf->useTemplate($this->tplidx);
3463 }
3464
3465 $pagehead = $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
3466
3467 $tab2_top = $this->tab_top_newpage - 4;
3468 $posy = $tab2_top;
3469 $posx = $this->marge_gauche;
3470 $index = 1;
3471 $outputlangs->load('orders');
3472 $outputlangs->load('propal');
3473 $width = 70;
3474 $width2 = $this->page_largeur - $posx - $width - $this->marge_droite;
3475
3476 $pdf->SetFont('', '', $default_font_size - 1);
3477 $pdf->MultiCell(0, 3, ''); // Set interline to 3
3478 $pdf->SetTextColor(0, 0, 0);
3479 $pdf->setY($tab2_top);
3480
3481 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
3482 $pdf->SetFont('', '', $default_font_size - 2);
3483 } else {
3484 $pdf->SetFont('', '', $default_font_size - 1);
3485 }
3486
3487 if (empty($object->tab_previous_situation_invoice)) {
3488 $object->fetchPreviousNextSituationInvoice();
3489 }
3490
3491 $previousinvoices = count($object->tab_previous_situation_invoice) ? $object->tab_previous_situation_invoice : array();
3492
3493 $remain_to_pay = 0;
3494
3495 // Proposal total
3496 $propals = array();
3497 $orders = array();
3498
3499 if (count($previousinvoices)) {
3500 foreach ($previousinvoices as $invoice) {
3501 if ($invoice->is_first()) {
3502 $invoice->fetchObjectLinked();
3503
3504 $propals = isset($invoice->linkedObjects['propal']) ? $invoice->linkedObjects['propal'] : array();
3505 $orders = isset($invoice->linkedObjects['commande']) ? $invoice->linkedObjects['commande'] : array();
3506 }
3507 }
3508 } else {
3509 if ($object->is_first()) {
3510 $object->fetchObjectLinked();
3511
3512 $propals = isset($object->linkedObjects['propal']) ? $object->linkedObjects['propal'] : array();
3513 $orders = isset($object->linkedObjects['commande']) ? $object->linkedObjects['commande'] : array();
3514 }
3515 }
3516
3517 if (count($propals)) {
3518 $propal = array_pop($propals);
3519
3520 $total_ht = ($conf->multicurrency->enabled && $propal->multicurrency_tx != 1) ? $propal->multicurrency_total_ht : $propal->total_ht;
3521 $remain_to_pay = $total_ht;
3522
3523 $pdf->SetTextColor(0, 0, 60);
3524 $pdf->SetFont('', '', $default_font_size - 1);
3525
3526 $label = $outputlangs->transnoentities("SituationInvoiceTotalProposal");
3527 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $label, 0, 'L', 0, 1, $posx, $posy + 1);
3528
3529 $amount = price($sign * ($total_ht + (! empty($propal->remise) ? $propal->remise : 0)));
3530 $pdf->MultiCell($width2, 3, $amount, 0, 'R', 0, 1, $posx + $width, $posy + 1);
3531
3532 $pdf->SetFont('', '', $default_font_size - 1);
3533
3534 // Output Rect
3535 $pdf->SetDrawColor(128, 128, 128);
3536 //$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
3537 $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
3538
3539 $posy += 4;
3540 } elseif (count($orders)) {
3541 $order = array_pop($orders);
3542
3543 $total_ht = ($conf->multicurrency->enabled && $order->multicurrency_tx != 1 ? $order->multicurrency_total_ht : $order->total_ht);
3544 $remain_to_pay = $total_ht;
3545 }
3546
3547 $useborder = 0;
3548 $index = 0;
3549
3550 $height = 4;
3551
3552 $sign = 1;
3553 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3554 $sign = -1;
3555 }
3556 $pdf->SetTextColor(0, 0, 60);
3557 $pdf->SetFont('', 'B', $default_font_size + 3);
3558
3559
3560 $pdf->SetXY($posx, $posy);
3561
3562
3563 $depositsamount = $object->getSumDepositsUsed();
3564 $deja_regle = $object->getSommePaiement();
3565
3566 $tot_deja_regle = ($depositsamount + $deja_regle);
3567
3568 $previousinvoices[] = $object;
3569
3570 $force_to_zero = false;
3571
3572 $idinv = 0;//count($previousinvoices);
3573 while ($idinv < count($previousinvoices)) {
3574 $invoice = $previousinvoices[$idinv];
3575
3576 $posy += 7;
3577 $index = 0;
3578
3579 $pdf->SetTextColor(0, 0, 60);
3580 $pdf->SetFont('', 'B', $default_font_size + 3);
3581
3582 $pageposbefore = $pdf->getPage();
3583 $pdf->startTransaction();
3584
3585 $pdf->SetXY($posx, $posy);
3586
3587 $ref = $outputlangs->transnoentities("InvoiceSituation").$outputlangs->convToOutputCharset(" n°".$invoice->situation_counter);
3588
3589 if ($invoice->situation_final) {
3590 $ref .= ' - DGD';
3591 $force_to_zero = true;
3592 }
3593
3594 $ref .= ' - '. $invoice->ref;
3595 $ref .= ' ('.dol_print_date($invoice->date, "%d/%m/%Y", false, $outputlangs).')';
3596 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $ref, 0, 'L', 0);
3597
3598 $pdf->SetFont('', '', $default_font_size - 1);
3599
3600 $sign = 1;
3601 if ($invoice->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3602 $sign = -1;
3603 }
3604
3605 $posy += 7;
3606 // Total HT
3607 $pdf->SetFillColor(255, 255, 255);
3608 $pdf->SetXY($posx, $posy);
3609 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
3610
3611 $total_ht = ($conf->multicurrency->enabled && $invoice->multicurrency_tx != 1 ? $invoice->multicurrency_total_ht : $invoice->total_ht);
3612
3613 $pdf->SetXY($posx + $width, $posy);
3614 $pdf->MultiCell($width2, $height, price($sign * ($total_ht + (!empty($invoice->remise) ? $invoice->remise : 0)), 0, $outputlangs), 0, 'R', 1);
3615
3616 $tvas = array();
3617 $nblines = count($invoice->lines);
3618 for ($i = 0; $i < $nblines; $i++) {
3619 $tvaligne = $invoice->lines[$i]->total_tva;
3620 $vatrate = (string) $invoice->lines[$i]->tva_tx;
3621
3622 if (($invoice->lines[$i]->info_bits & 0x01) == 0x01) {
3623 $vatrate .= '*';
3624 }
3625 if (! isset($tvas[$vatrate])) {
3626 $tvas[$vatrate] = 0;
3627 }
3628 $tvas[$vatrate] += $tvaligne;
3629 }
3630
3631 // Show VAT by rates and total
3632 $pdf->SetFillColor(248, 248, 248);
3633 foreach ($tvas as $tvakey => $tvaval) {
3634 if ($tvakey != 0) { // On affiche pas taux 0
3635 $index++;
3636 $pdf->SetXY($posx, $posy + $height * $index);
3637
3638 $tvacompl = '';
3639 if (preg_match('/\*/', $tvakey)) {
3640 $tvakey = str_replace('*', '', $tvakey);
3641 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
3642 }
3643 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
3644 $totalvat .= vatrate($tvakey, 1).$tvacompl;
3645 $pdf->MultiCell($width, $height, $totalvat, 0, 'L', 1);
3646
3647 $pdf->SetXY($posx + $width, $posy + $height * $index);
3648 $pdf->MultiCell($width2, $height, price($tvaval, 0, $outputlangs), 0, 'R', 1);
3649 }
3650 }
3651
3652 $index++;
3653
3654 $total_ht = ($conf->multicurrency->enabled && $invoice->multicurrency_tx != 1) ? $invoice->multicurrency_total_ht : $invoice->total_ht;
3655 $total_ttc = ($conf->multicurrency->enabled && $invoice->multicurrency_tx != 1) ? $invoice->multicurrency_total_ttc : $invoice->total_ttc;
3656
3657 // Total TTC
3658 $pdf->SetXY($posx, $posy + $height * $index);
3659 $pdf->SetTextColor(0, 0, 60);
3660 $pdf->SetFillColor(224, 224, 224);
3661 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
3662
3663
3664 $pdf->SetXY($posx + $width, $posy + $height * $index);
3665 $pdf->MultiCell($width2, $height, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
3666
3667 $retainedWarrantyRate = (float) ($object->retained_warranty ? price2num($object->retained_warranty) : price2num(getDolGlobalString('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT', 0)));
3668
3669 $total_ht_rg = 0;
3670 $total_ttc_rg = 0;
3671
3672 if ($this->is_rg) {
3673 $index++;
3674
3675 $pdf->SetXY($posx, $posy + $height * $index);
3676 $pdf->SetTextColor(0, 0, 60);
3677 $pdf->SetFillColor(241, 241, 241);
3678 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("RetainedWarrantyShort", $retainedWarrantyRate), $useborder, 'L', 1);
3679
3680 $total_ht_rg = (float) price2num(price($total_ht * $retainedWarrantyRate / 100), 'MT');
3681 $total_ttc_rg = (float) price2num(price($total_ttc * $retainedWarrantyRate / 100), 'MT');
3682
3683 $pdf->SetXY($posx + $width, $posy + $height * $index);
3684 $pdf->MultiCell($width2, $height, price(-$sign * $total_ht_rg, 0, $outputlangs), $useborder, 'R', 1);
3685
3686 $total_ht_with_rg = $total_ht - $total_ht_rg;
3687 $total_ttc_with_rg = $total_ttc - $total_ttc_rg;
3688
3689 $index++;
3690
3691 // Total TTC
3692 $pdf->SetXY($posx, $posy + $height * $index);
3693 $pdf->SetTextColor(0, 0, 60);
3694 $pdf->SetFillColor(224, 224, 224);
3695 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalSituationInvoiceWithRetainedWarranty"), $useborder, 'L', 1);
3696
3697 $pdf->SetXY($posx + $width, $posy + $height * $index);
3698 $pdf->MultiCell($width2, $height, price($sign * $total_ttc_with_rg, 0, $outputlangs), $useborder, 'R', 1);
3699 }
3700
3701
3702
3703 $index++;
3704
3705 $pdf->SetTextColor(0, 0, 0);
3706
3707 $creditnoteamount = $invoice->getSumCreditNotesUsed();
3708 $depositsamount = $invoice->getSumDepositsUsed();
3709 $deja_regle = $invoice->getSommePaiement();
3710
3711 $resteapayer = price2num($invoice->total_ttc - $deja_regle - $total_ttc_rg - $creditnoteamount - $depositsamount, 'MT');
3712 if ($invoice->paye) {
3713 $resteapayer = 0;
3714 }
3715
3716 $y = 0;
3717
3718
3719 // Already paid + Deposits
3720 $tot_deja_regle += $deja_regle + $depositsamount;
3721
3722 $pdf->SetXY($posx, $posy + $height * $index);
3723 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
3724 $pdf->SetXY($posx + $width, $posy + $height * $index);
3725 $pdf->MultiCell($width2, $height, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
3726
3727 // Credit note
3728 if ($creditnoteamount) {
3729 $index++;
3730 $pdf->SetXY($posx, $posy + $height * $index);
3731 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
3732 $pdf->SetXY($posx + $width, $posy + $height * $index);
3733 $pdf->MultiCell($width2, $height, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
3734 }
3735
3736 // Escompte
3737 if ($invoice->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
3738 $index++;
3739 $pdf->SetFillColor(255, 255, 255);
3740
3741 $pdf->SetXY($posx, $posy + $height * $index);
3742 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
3743 $pdf->SetXY($posx + $width, $posy + $height * $index);
3744 $pdf->MultiCell($width2, $height, price($invoice->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
3745
3746 $resteapayer = 0;
3747 }
3748
3749 $index++;
3750 $pdf->SetTextColor(0, 0, 60);
3751 $pdf->SetFillColor(224, 224, 224);
3752 $pdf->SetXY($posx, $posy + $height * $index);
3753 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
3754 $pdf->SetXY($posx + $width, $posy + $height * $index);
3755 $pdf->MultiCell($width2, $height, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
3756
3757 $pdf->SetFont('', '', $default_font_size - 1);
3758 $pdf->SetTextColor(0, 0, 0);
3759
3760 $index++;
3761
3762 if ($deja_regle > 0) {
3763 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
3764 if ($invoice->type == 2) {
3765 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
3766 }
3767
3768 $pdf->SetFont('', '', $default_font_size - 3);
3769 $pdf->SetXY($posx, $posy + $height * $index);
3770 $pdf->MultiCell($width, $height, $title, 0, 'L', 0);
3771
3772 //$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
3773
3774 $index++;
3775
3776 $width4 = ($this->page_largeur - $this->marge_droite - $posx) / 4;
3777
3778 $pdf->SetFont('', '', $default_font_size - 4);
3779 $pdf->SetXY($posx, $posy + $height * $index);
3780 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
3781 $pdf->SetXY($posx + $width4, $posy + $height * $index);
3782 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
3783 $pdf->SetXY($posx + $width4 * 2, $posy + $height * $index);
3784 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Type"), 0, 'L', 0);
3785 $pdf->SetXY($posx + $width4 * 3, $posy + $height * $index);
3786 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Num"), 0, 'L', 0);
3787
3788 //$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
3789
3790 $y = $height - 1;
3791
3792 $pdf->SetFont('', '', $default_font_size - 4);
3794 $payments = $invoice->getListOfPayments();
3795
3796 if (count($payments)) {
3797 foreach ($payments as $payment) {
3798 $pdf->SetXY($posx, $posy + $height * $index + $y);
3799 $pdf->MultiCell($width4, $height - 1, dol_print_date($this->db->jdate($payment['date']), 'day', false, $outputlangs, true), 0, 'L', 0);
3800 $pdf->SetXY($posx + $width4, $posy + $height * $index + $y);
3801 $pdf->MultiCell($width4, $height - 1, price($sign * $payment['amount'], 0, $outputlangs), 0, 'L', 0);
3802 $pdf->SetXY($posx + $width4 * 2, $posy + $height * $index + $y);
3803 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $payment['type']);
3804
3805 $pdf->MultiCell($width4, $height - 1, $oper, 0, 'L', 0);
3806 $pdf->SetXY($posx + $width4 * 3, $posy + $height * $index + $y);
3807 $pdf->MultiCell($width4, $height - 1, $payment['num'], 0, 'L', 0);
3808
3809 //$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
3810 $y += ($height - 1);
3811 }
3812 }
3813 }
3814
3815 // Output Rect
3816 $pdf->SetDrawColor(128, 128, 128);
3817 //$this->printRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height * $index + $y);
3818 $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');
3819 $posy += $height * $index + $y;
3820
3821 $pageposafter = $pdf->getPage();
3822 if ($pageposafter > $pageposbefore) { // There is a pagebreak
3823 $pdf->rollbackTransaction(true);
3824
3825 $pageposafter = $pageposbefore;
3826 $pdf->AddPage('', '', true);
3827 if (!empty($this->tplidx)) {
3828 $pdf->useTemplate($this->tplidx);
3829 }
3830 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
3831 $this->_pagehead($pdf, $object, 0, $outputlangs);
3832 }
3833 $pdf->setPage($pageposafter + 1);
3834 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
3835
3836 $posy = $this->tab_top_newpage + 1;
3837 } else {
3838 $idinv++;
3839 $remain_to_pay -= ($sign * ($total_ht + (!empty($invoice->remise) ? $invoice->remise : 0)));
3840
3841 $rem = 0;
3842 if (count($invoice->lines)) {
3843 foreach ($invoice->lines as $l) {
3844 if ($l->fk_remise_except > 0) {
3845 $discount = new DiscountAbsolute($this->db);
3846 $result = $discount->fetch($l->fk_remise_except);
3847 if ($result > 0) {
3848 $rem += $discount->amount_ht;
3849 }
3850 }
3851 }
3852 }
3853
3854 $remain_to_pay -= $rem;
3855
3856 $pdf->commitTransaction();
3857 }
3858 }
3859
3860 if ($force_to_zero) {
3861 $remain_to_pay = 0;
3862 }
3863
3864 $posy += 10;
3865
3866 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
3867
3868 $pdf->SetTextColor(0, 0, 60);
3869 $pdf->SetFont('', '', $default_font_size - 1);
3870 $pdf->SetXY($this->marge_gauche, $posy + 1);
3871 $label = $outputlangs->transnoentities("SituationTotalRayToRest");
3872 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $label, 0, 'L', 0);
3873
3874 $amount = price($remain_to_pay);
3875 $pdf->MultiCell($width2, 3, $amount, 0, 'R', 0, 1, $posx + $width, $posy + 1);
3876
3877 $pdf->SetDrawColor(128, 128, 128);
3878 //$this->printRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 7);
3879 $this->printRoundedRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 7, $this->corner_radius, 0, 0, 'D');
3880 }
3881}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php: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:90
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152