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