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