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