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