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