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