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