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