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