dolibarr 20.0.2
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, 0),
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 = $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 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1119 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1120 }
1121
1122 // Pagefoot
1123 $this->_pagefoot($pdf, $object, $outputlangs);
1124 if (method_exists($pdf, 'AliasNbPages')) {
1125 $pdf->AliasNbPages();
1126 }
1127
1128 $this->resumeLastPage($pdf, $object, 0, $tab_top, $outputlangs, $outputlangsbis);
1129 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1130 $this->_pagefoot($pdf, $object, $outputlangs, 1);
1131
1132 $pdf->Close();
1133
1134 $pdf->Output($file, 'F');
1135
1136 // Add pdfgeneration hook
1137 $hookmanager->initHooks(array('pdfgeneration'));
1138 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1139 global $action;
1140 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1141 if ($reshook < 0) {
1142 $this->error = $hookmanager->error;
1143 $this->errors = $hookmanager->errors;
1144 }
1145
1146 dolChmod($file);
1147
1148 $this->result = array('fullpath' => $file);
1149
1150 return 1; // No error
1151 } else {
1152 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1153 return 0;
1154 }
1155 } else {
1156 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1157 return 0;
1158 }
1159 }
1160
1161
1171 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1172 {
1173 global $conf;
1174
1175 $sign = 1;
1176 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1177 $sign = -1;
1178 }
1179
1180 $tab3_posx = 120;
1181 $tab3_top = $posy + 8;
1182 $tab3_width = 80;
1183 $tab3_height = 4;
1184 if ($this->page_largeur < 210) { // To work with US executive format
1185 $tab3_posx -= 15;
1186 }
1187
1188 $default_font_size = pdf_getPDFFontSize($outputlangs);
1189
1190 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1191 if ($object->type == 2) {
1192 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1193 }
1194
1195 $pdf->SetFont('', '', $default_font_size - 3);
1196 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1197 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1198
1199 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1200
1201 $pdf->SetFont('', '', $default_font_size - 4);
1202 $pdf->SetXY($tab3_posx, $tab3_top);
1203 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1204 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1205 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1206 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1207 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1208 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1209 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1210
1211 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1212
1213 $y = 0;
1214
1215 $pdf->SetFont('', '', $default_font_size - 4);
1216
1217
1218 // Loop on each discount available (deposits and credit notes and excess of payment included)
1219 $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,";
1220 $sql .= " re.description, re.fk_facture_source,";
1221 $sql .= " f.type, f.datef";
1222 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1223 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1224 $resql = $this->db->query($sql);
1225 if ($resql) {
1226 $num = $this->db->num_rows($resql);
1227 $i = 0;
1228 $invoice = new Facture($this->db);
1229 while ($i < $num) {
1230 $y += 3;
1231 $obj = $this->db->fetch_object($resql);
1232
1233 if ($obj->type == 2) {
1234 $text = $outputlangs->transnoentities("CreditNote");
1235 } elseif ($obj->type == 3) {
1236 $text = $outputlangs->transnoentities("Deposit");
1237 } elseif ($obj->type == 0) {
1238 $text = $outputlangs->transnoentities("ExcessReceived");
1239 } else {
1240 $text = $outputlangs->transnoentities("UnknownType");
1241 }
1242
1243 $invoice->fetch($obj->fk_facture_source);
1244
1245 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1246 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1247 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1248 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1249 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1250 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1251 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1252 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1253
1254 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1255
1256 $i++;
1257 }
1258 } else {
1259 $this->error = $this->db->lasterror();
1260 return -1;
1261 }
1262
1263 // Loop on each payment
1264 // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
1265 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1266 $sql .= " cp.code";
1267 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1268 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1269 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1270 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1271 $sql .= " ORDER BY p.datep";
1272
1273 $resql = $this->db->query($sql);
1274 if ($resql) {
1275 $num = $this->db->num_rows($resql);
1276 $i = 0;
1277 $y += 3;
1278 $maxY = $y;
1279 while ($i < $num) {
1280 $row = $this->db->fetch_object($resql);
1281 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1282 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1283 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1284 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1285 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1286 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1287
1288 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1289 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1290 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1291 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1292 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1293 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1294 $y += 3;
1295 $i++;
1296 }
1297
1298 return $tab3_top + $y + 3;
1299 } else {
1300 $this->error = $this->db->lasterror();
1301 return -1;
1302 }
1303 }
1304
1305
1316 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1317 {
1318 global $conf, $mysoc, $hookmanager;
1319
1320 $default_font_size = pdf_getPDFFontSize($outputlangs);
1321
1322 $pdf->SetFont('', '', $default_font_size - 1);
1323
1324 // If France, show VAT mention if not applicable
1325 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1326 $pdf->SetFont('', 'B', $default_font_size - 2);
1327 $pdf->SetXY($this->marge_gauche, $posy);
1328 if ($mysoc->forme_juridique_code == 92) {
1329 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1330 } else {
1331 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1332 }
1333
1334 $posy = $pdf->GetY() + 4;
1335 }
1336
1337 $posxval = 52; // Position of values of properties shown on left side
1338 $posxend = 110; // End of x for text on left side
1339 if ($this->page_largeur < 210) { // To work with US executive format
1340 $posxend -= 10;
1341 }
1342
1343 // Show payments conditions
1344 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1345 $pdf->SetFont('', 'B', $default_font_size - 2);
1346 $pdf->SetXY($this->marge_gauche, $posy);
1347 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1348 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1349
1350 $pdf->SetFont('', '', $default_font_size - 2);
1351 $pdf->SetXY($posxval, $posy);
1352 $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);
1353 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1354 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1355
1356 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1357 }
1358
1359 // Show category of operations
1360 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1361 $pdf->SetFont('', 'B', $default_font_size - 2);
1362 $pdf->SetXY($this->marge_gauche, $posy);
1363 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1364 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1365
1366 $pdf->SetFont('', '', $default_font_size - 2);
1367 $pdf->SetXY($posxval, $posy);
1368 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1369 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1370
1371 $posy = $pdf->GetY() + 3; // for 2 lines
1372 }
1373
1374 if ($object->type != 2) {
1375 // Check a payment mode is defined
1376 if (empty($object->mode_reglement_code)
1377 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1378 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1379 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1380 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1381 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1382 // Avoid having any valid PDF with setup that is not complete
1383 $outputlangs->load("errors");
1384
1385 $pdf->SetXY($this->marge_gauche, $posy);
1386 $pdf->SetTextColor(200, 0, 0);
1387 $pdf->SetFont('', 'B', $default_font_size - 2);
1388 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1389 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
1390 $pdf->SetTextColor(0, 0, 0);
1391
1392 $posy = $pdf->GetY() + 1;
1393 }
1394
1395 // Show payment mode
1396 if (!empty($object->mode_reglement_code)
1397 && $object->mode_reglement_code != 'CHQ'
1398 && $object->mode_reglement_code != 'VIR') {
1399 $pdf->SetFont('', 'B', $default_font_size - 2);
1400 $pdf->SetXY($this->marge_gauche, $posy);
1401 $titre = $outputlangs->transnoentities("PaymentMode").':';
1402 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1403
1404 $pdf->SetFont('', '', $default_font_size - 2);
1405 $pdf->SetXY($posxval, $posy);
1406 $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);
1407
1408 //#21654: add account number used for the debit
1409 if ($object->mode_reglement_code == "PRE") {
1410 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1411 $bac = new CompanyBankAccount($this->db);
1412 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1413 $bac->fetch(0, $object->thirdparty->id);
1414 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1415 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1416 }
1417
1418 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1419
1420 $posy = $pdf->GetY();
1421 }
1422
1423 // Show if Option VAT debit option is on also if transmitter is french
1424 // Decret n°2099-1299 2022-10-07
1425 // French mention : "Option pour le paiement de la taxe d'après les débits"
1426 if ($this->emetteur->country_code == 'FR') {
1427 if (getDolGlobalInt('TAX_MODE') == 1) {
1428 $pdf->SetXY($this->marge_gauche, $posy);
1429 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1430
1431 $posy = $pdf->GetY() + 1;
1432 }
1433 }
1434
1435 // Show online payment link
1436 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1437 $useonlinepayment = 0;
1438 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1439 if (isModEnabled('paypal')) {
1440 $useonlinepayment++;
1441 }
1442 if (isModEnabled('stripe')) {
1443 $useonlinepayment++;
1444 }
1445 if (isModEnabled('paybox')) {
1446 $useonlinepayment++;
1447 }
1448 $parameters = array();
1449 $action = '';
1450 $reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1451 if ($reshook > 0) {
1452 if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
1453 $useonlinepayment += $hookmanager->resArray['showonlinepaymenturl'];
1454 }
1455 }
1456 }
1457
1458
1459 if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
1460 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1461 global $langs;
1462
1463 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1464 $servicename = $langs->transnoentities('Online');
1465 $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
1466 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1467
1468 $pdf->SetXY($this->marge_gauche, $posy);
1469 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1470
1471 $posy = $pdf->GetY() + 1;
1472 }
1473 }
1474
1475 // Show payment mode CHQ
1476 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1477 // If payment mode unregulated or payment mode forced to CHQ
1478 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1479 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1480
1481 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1482 $account = new Account($this->db);
1483 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1484
1485 $pdf->SetXY($this->marge_gauche, $posy);
1486 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1487 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1488 $posy = $pdf->GetY() + 1;
1489
1490 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1491 $pdf->SetXY($this->marge_gauche, $posy);
1492 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1493 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1494 $posy = $pdf->GetY() + 2;
1495 }
1496 }
1497 if (getDolGlobalString('FACTURE_CHQ_NUMBER') == -1) {
1498 $pdf->SetXY($this->marge_gauche, $posy);
1499 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1500 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1501 $posy = $pdf->GetY() + 1;
1502
1503 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1504 $pdf->SetXY($this->marge_gauche, $posy);
1505 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1506 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1507 $posy = $pdf->GetY() + 2;
1508 }
1509 }
1510 }
1511 }
1512
1513 // If payment mode not forced or forced to VIR, show payment with BAN
1514 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1515 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1516 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1517 if ($object->fk_bank > 0) {
1518 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1519 }
1520 $account = new Account($this->db);
1521 $account->fetch($bankid);
1522
1523 $curx = $this->marge_gauche;
1524 $cury = $posy;
1525
1526 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1527
1528 $posy += 2;
1529 }
1530 }
1531 }
1532
1533 return $posy;
1534 }
1535
1536
1548 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1549 {
1550 global $conf, $mysoc, $hookmanager;
1551
1552 $sign = 1;
1553 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1554 $sign = -1;
1555 }
1556
1557 $default_font_size = pdf_getPDFFontSize($outputlangs);
1558
1559 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1560 $outputlangsbis = new Translate('', $conf);
1561 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1562 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1563 $default_font_size--;
1564 }
1565
1566 $tab2_top = $posy - 4;
1567 $tab2_hl = 4;
1568 $pdf->SetFont('', '', $default_font_size - 1);
1569
1570 // Total table
1571 $col1x = 120;
1572 $col2x = 170;
1573 if ($this->page_largeur < 210) { // To work with US executive format
1574 $col2x -= 20;
1575 }
1576 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1577
1578 $useborder = 0;
1579 $index = 0;
1580
1581 // Total HT
1582 $pdf->SetFillColor(255, 255, 255);
1583 $pdf->SetXY($col1x, $tab2_top + 0);
1584 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
1585
1586 $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1587 $pdf->SetXY($col2x, $tab2_top + 0);
1588 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht, 0, $outputlangs), 0, 'R', 1);
1589
1590 $remise = !empty($object->remise) ? $object->remise : 0;
1591 if ($remise > 0) {
1592 $index++;
1593 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1594 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("DiscountHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("DiscountHT") : ''), 0, 'L', 1);
1595 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1596 $pdf->MultiCell($largcol2, $tab2_hl, price($remise, 0, $outputlangs), 0, 'R', 1);
1597
1598 $index++;
1599 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1600 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTWithDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTWithDiscount") : ''), 0, 'L', 1);
1601 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1602 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht - $remise, 0, $outputlangs), 0, 'R', 1);
1603 }
1604
1605 // Show VAT by rates and total
1606 $pdf->SetFillColor(248, 248, 248);
1607
1608 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1609
1610 $this->atleastoneratenotnull = 0;
1611 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1612 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1613 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1614 // Nothing to do
1615 } else {
1616 //Local tax 1 before VAT
1617 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1618 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1619 continue;
1620 }
1621
1622 foreach ($localtax_rate as $tvakey => $tvaval) {
1623 if ($tvakey != 0) { // On affiche pas taux 0
1624 //$this->atleastoneratenotnull++;
1625
1626 $index++;
1627 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1628
1629 $tvacompl = '';
1630 if (preg_match('/\*/', $tvakey)) {
1631 $tvakey = str_replace('*', '', $tvakey);
1632 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1633 }
1634
1635 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1636 $totalvat .= ' ';
1637
1638 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1639 $totalvat .= $tvacompl;
1640 } else {
1641 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1642 }
1643
1644 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1645
1646 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1647
1648 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1649 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1650 }
1651 }
1652 }
1653
1654 //Local tax 2 before VAT
1655 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1656 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1657 continue;
1658 }
1659
1660 foreach ($localtax_rate as $tvakey => $tvaval) {
1661 if ($tvakey != 0) { // On affiche pas taux 0
1662 //$this->atleastoneratenotnull++;
1663
1664 $index++;
1665 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1666
1667 $tvacompl = '';
1668 if (preg_match('/\*/', $tvakey)) {
1669 $tvakey = str_replace('*', '', $tvakey);
1670 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1671 }
1672 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1673 $totalvat .= ' ';
1674
1675 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1676 $totalvat .= $tvacompl;
1677 } else {
1678 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1679 }
1680
1681 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1682
1683 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1684
1685 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1686 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1687 }
1688 }
1689 }
1690 //}
1691
1692 // VAT
1693 $tvas = array();
1694 $nblines = count($object->lines);
1695 for ($i = 0; $i < $nblines; $i++) {
1696 $tvaligne = $object->lines[$i]->total_tva;
1697 $vatrate = (string) $object->lines[$i]->tva_tx;
1698
1699 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
1700 $vatrate .= '*';
1701 }
1702 if (! isset($tvas[$vatrate])) {
1703 $tvas[$vatrate] = 0;
1704 }
1705 $tvas[$vatrate] += $tvaligne;
1706 }
1707
1708 foreach ($tvas as $tvakey => $tvaval) {
1709 if ($tvakey != 0) { // On affiche pas taux 0
1710 $this->atleastoneratenotnull++;
1711
1712 $index++;
1713 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1714
1715 $tvacompl = '';
1716 if (preg_match('/\*/', $tvakey)) {
1717 $tvakey = str_replace('*', '', $tvakey);
1718 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1719 }
1720 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1721 $totalvat .= ' ';
1722 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1723 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1724 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1725 $totalvat .= $tvaval['vatcode'].$tvacompl;
1726 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1727 $totalvat .= $tvacompl;
1728 } else {
1729 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1730 }
1731 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1732
1733 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1734 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1735 }
1736 }
1737
1738 //Local tax 1 after VAT
1739 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1740 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1741 continue;
1742 }
1743
1744 foreach ($localtax_rate as $tvakey => $tvaval) {
1745 if ($tvakey != 0) { // On affiche pas taux 0
1746 //$this->atleastoneratenotnull++;
1747
1748 $index++;
1749 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1750
1751 $tvacompl = '';
1752 if (preg_match('/\*/', $tvakey)) {
1753 $tvakey = str_replace('*', '', $tvakey);
1754 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1755 }
1756 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1757 $totalvat .= ' ';
1758
1759 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1760 $totalvat .= $tvacompl;
1761 } else {
1762 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1763 }
1764
1765 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1766
1767 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1768
1769 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1770 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1771 }
1772 }
1773 }
1774
1775 //Local tax 2 after VAT
1776 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1777 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1778 continue;
1779 }
1780
1781 foreach ($localtax_rate as $tvakey => $tvaval) {
1782 // retrieve global local tax
1783 if ($tvakey != 0) { // On affiche pas taux 0
1784 //$this->atleastoneratenotnull++;
1785
1786 $index++;
1787 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1788
1789 $tvacompl = '';
1790 if (preg_match('/\*/', $tvakey)) {
1791 $tvakey = str_replace('*', '', $tvakey);
1792 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1793 }
1794 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1795 $totalvat .= ' ';
1796
1797 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1798 $totalvat .= $tvacompl;
1799 } else {
1800 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1801 }
1802
1803 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1804
1805 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1806
1807 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1808 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1809 }
1810 }
1811 }
1812
1813
1814 // Revenue stamp
1815 if (price2num($object->revenuestamp, 'MT') != 0) {
1816 $index++;
1817 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1818 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
1819
1820 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1821 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1822 }
1823
1824 // Total TTC
1825 $index++;
1826 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1827 $pdf->SetTextColor(0, 0, 60);
1828 $pdf->SetFillColor(224, 224, 224);
1829 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
1830
1831 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1832 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1833
1834
1835 // Retained warranty
1836 if ($object->displayRetainedWarranty()) {
1837 $pdf->SetTextColor(40, 40, 40);
1838 $pdf->SetFillColor(255, 255, 255);
1839
1840 $retainedWarranty = $object->getRetainedWarrantyAmount();
1841 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1842
1843 // Billed - retained warranty
1844 $index++;
1845 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1846 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1847
1848 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1849 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1850
1851 // retained warranty
1852 $index++;
1853 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1854
1855 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
1856 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1857
1858 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1859 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1860 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1861 }
1862 }
1863 }
1864
1865 $pdf->SetTextColor(0, 0, 0);
1866
1867 $resteapayer = 0;
1868 /*
1869 $resteapayer = $object->total_ttc - $deja_regle;
1870 if (! empty($object->paye)) $resteapayer=0;
1871 */
1872
1873 if ($deja_regle > 0) {
1874 // Already paid + Deposits
1875 $index++;
1876
1877 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1878 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1879
1880 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1881 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1882
1883 /*
1884 if ($object->close_code == 'discount_vat')
1885 {
1886 $index++;
1887 $pdf->SetFillColor(255,255,255);
1888
1889 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1890 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1891
1892 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1893 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1894
1895 $resteapayer=0;
1896 }
1897 */
1898
1899 $index++;
1900 $pdf->SetTextColor(0, 0, 60);
1901 $pdf->SetFillColor(224, 224, 224);
1902 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1903 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
1904 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1905 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1906
1907 $pdf->SetFont('', '', $default_font_size - 1);
1908 $pdf->SetTextColor(0, 0, 0);
1909 }
1910
1911 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
1912
1913 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
1914 if ($reshook < 0) {
1915 $this->error = $hookmanager->error;
1916 $this->errors = $hookmanager->errors;
1917 }
1918
1919 $index++;
1920 return ($tab2_top + ($tab2_hl * $index));
1921 }
1922
1923 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1931 public static function liste_modeles($db, $maxfilenamelength = 0)
1932 {
1933 // phpcs:enable
1934 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
1935 }
1936
1937 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1952 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
1953 {
1954 global $conf;
1955
1956 // Force to disable hidetop and hidebottom
1957 $hidebottom = 0;
1958 $hidetop = 0;
1959
1960 $currency = !empty($currency) ? $currency : $conf->currency;
1961 $default_font_size = pdf_getPDFFontSize($outputlangs);
1962
1963 // Amount in (at tab_top - 1)
1964 $pdf->SetTextColor(0, 0, 0);
1965 $pdf->SetFont('', '', $default_font_size - 2);
1966
1967 if (empty($hidetop)) {
1968 // Show category of operations
1969 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1970 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1971 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1972 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1973 }
1974
1975 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1976 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1977 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1978
1979 // MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1980 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1981 $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')));
1982 }
1983 $tab_top += 4;
1984 }
1985
1986 $pdf->SetDrawColor(128, 128, 128);
1987 $pdf->SetFont('', '', $default_font_size - 1);
1988
1989 // Output Rect
1990 $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
1991
1992 // situation invoice
1993 $pdf->SetFont('', '', $default_font_size - 2);
1994
1995 foreach ($this->cols as $colKey => $colDef) {
1996 if (!$this->getColumnStatus($colKey)) {
1997 continue;
1998 }
1999 $xstartpos = (int) ($colDef['xStartPos'] ?? 0);
2000 //is there any overtitle ?
2001 if (!empty($colDef['overtitle']) && is_array($colDef['overtitle'])) {
2002 $overtitle_top = $tab_top - 4;
2003 $overtitle = $colDef['overtitle']['textkey'] ?? '';
2004 $textWidth = $colDef['overtitle']['width'] ?? 0;
2005 $pdf->SetXY($xstartpos + $colDef['overtitle']['padding'][3], $overtitle_top);
2006 $pdf->MultiCell($textWidth, 2, $overtitle, '', $colDef['overtitle']['align']);
2007 $pdf->line($xstartpos, $overtitle_top, $xstartpos, $overtitle_top + 4); //left
2008 $pdf->line($xstartpos, $overtitle_top, $xstartpos + $textWidth, $overtitle_top); //top
2009 $pdf->line($xstartpos + $textWidth, $overtitle_top, $xstartpos + $textWidth, $overtitle_top + 4); //right
2010 }
2011
2012 // get title label
2013 $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
2014
2015 // Add column separator
2016 if (!empty($colDef['border-left'])) {
2017 $pdf->line($xstartpos, $tab_top, $xstartpos, $tab_top + $tab_height);
2018 }
2019
2020 if (empty($hidetop)) {
2021 $pdf->SetXY($xstartpos + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
2022
2023 $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
2024 $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
2025 }
2026 }
2027 $pdf->SetFont('', '', $default_font_size - 1);
2028
2029 if (empty($hidetop)) {
2030 $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
2031 }
2032 }
2033
2034 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2045 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2046 {
2047 // phpcs:enable
2048 global $conf, $langs;
2049
2050 $ltrdirection = 'L';
2051 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2052 $ltrdirection = 'R';
2053 }
2054
2055 // Load traductions files required by page
2056 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2057
2058 $default_font_size = pdf_getPDFFontSize($outputlangs);
2059
2060 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2061
2062 $pdf->SetTextColor(0, 0, 60);
2063 $pdf->SetFont('', 'B', $default_font_size + 3);
2064
2065 $w = 110;
2066
2067 $posy = $this->marge_haute;
2068 $posx = $this->page_largeur - $this->marge_droite - $w;
2069
2070 $pdf->SetXY($this->marge_gauche, $posy);
2071
2072 // Logo
2073 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2074 if ($this->emetteur->logo) {
2075 $logodir = $conf->mycompany->dir_output;
2076 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2077 $logodir = $conf->mycompany->multidir_output[$object->entity];
2078 }
2079 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2080 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2081 } else {
2082 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2083 }
2084 if (is_readable($logo)) {
2085 $height = pdf_getHeightForLogo($logo);
2086 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2087 } else {
2088 $pdf->SetTextColor(200, 0, 0);
2089 $pdf->SetFont('', 'B', $default_font_size - 2);
2090 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2091 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2092 }
2093 } else {
2094 $text = $this->emetteur->name;
2095 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2096 }
2097 }
2098
2099 $pdf->SetFont('', 'B', $default_font_size + 3);
2100 $pdf->SetXY($posx, $posy);
2101 $pdf->SetTextColor(0, 0, 60);
2102 $subtitle = "";
2103 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2104 if ($object->type == 1) {
2105 $title = $outputlangs->transnoentities("InvoiceReplacement");
2106 }
2107 if ($object->type == 2) {
2108 $title = $outputlangs->transnoentities("InvoiceAvoir");
2109 }
2110 if ($object->type == 3) {
2111 $title = $outputlangs->transnoentities("InvoiceDeposit");
2112 }
2113 if ($object->type == 4) {
2114 $title = $outputlangs->transnoentities("InvoiceProForma");
2115 }
2116 if ($this->situationinvoice) {
2117 $title = $outputlangs->transnoentities("PDFInvoiceSituation");
2118 $subtitle = $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter);
2119 }
2120 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2121 $title .= ' - ';
2122 if ($object->type == 0) {
2123 if ($this->situationinvoice) {
2124 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2125 }
2126 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2127 } elseif ($object->type == 1) {
2128 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2129 } elseif ($object->type == 2) {
2130 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2131 } elseif ($object->type == 3) {
2132 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2133 } elseif ($object->type == 4) {
2134 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2135 }
2136 }
2137 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2138 // if ($object->statut == $object::STATUS_DRAFT) {
2139 // $pdf->SetTextColor(128, 0, 0);
2140 // $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2141 // }
2142
2143 $pdf->MultiCell($w, 3, $title, '', 'R');
2144 if (!empty($subtitle)) {
2145 $pdf->SetFont('', 'B', $default_font_size);
2146 $pdf->SetXY($posx, $posy + 5);
2147 $pdf->MultiCell($w, 6, $subtitle, '', 'R');
2148 $posy += 2;
2149 }
2150
2151 $pdf->SetFont('', 'B', $default_font_size);
2152
2153 /*
2154 $posy += 5;
2155 $pdf->SetXY($posx, $posy);
2156 $pdf->SetTextColor(0, 0, 60);
2157 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2158 if ($object->statut == $object::STATUS_DRAFT) {
2159 $pdf->SetTextColor(128, 0, 0);
2160 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2161 }
2162 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2163
2164 $posy += 3;
2165 $pdf->SetFont('', '', $default_font_size - 2);
2166
2167 if ($object->ref_customer) {
2168 $posy += 4;
2169 $pdf->SetXY($posx, $posy);
2170 $pdf->SetTextColor(0, 0, 60);
2171 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2172 }
2173
2174 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2175 $object->fetch_projet();
2176 if (!empty($object->project->ref)) {
2177 $posy += 3;
2178 $pdf->SetXY($posx, $posy);
2179 $pdf->SetTextColor(0, 0, 60);
2180 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2181 }
2182 }
2183
2184 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2185 $object->fetch_projet();
2186 if (!empty($object->project->ref)) {
2187 $outputlangs->load("projects");
2188 $posy += 3;
2189 $pdf->SetXY($posx, $posy);
2190 $pdf->SetTextColor(0, 0, 60);
2191 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2192 }
2193 }
2194
2195 $objectidnext = $object->getIdReplacingInvoice('validated');
2196 if ($object->type == 0 && $objectidnext) {
2197 $objectreplacing = new Facture($this->db);
2198 $objectreplacing->fetch($objectidnext);
2199
2200 $posy += 3;
2201 $pdf->SetXY($posx, $posy);
2202 $pdf->SetTextColor(0, 0, 60);
2203 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2204 }
2205 if ($object->type == 1) {
2206 $objectreplaced = new Facture($this->db);
2207 $objectreplaced->fetch($object->fk_facture_source);
2208
2209 $posy += 4;
2210 $pdf->SetXY($posx, $posy);
2211 $pdf->SetTextColor(0, 0, 60);
2212 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2213 }
2214 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2215 $objectreplaced = new Facture($this->db);
2216 $objectreplaced->fetch($object->fk_facture_source);
2217
2218 $posy += 3;
2219 $pdf->SetXY($posx, $posy);
2220 $pdf->SetTextColor(0, 0, 60);
2221 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2222 }
2223
2224 $posy += 4;
2225 $pdf->SetXY($posx, $posy);
2226 $pdf->SetTextColor(0, 0, 60);
2227
2228 $title = $outputlangs->transnoentities("DateInvoice");
2229 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2230 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2231 }
2232 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2233
2234 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2235 $posy += 4;
2236 $pdf->SetXY($posx, $posy);
2237 $pdf->SetTextColor(0, 0, 60);
2238 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2239 }
2240
2241 if ($object->type != 2) {
2242 $posy += 3;
2243 $pdf->SetXY($posx, $posy);
2244 $pdf->SetTextColor(0, 0, 60);
2245 $title = $outputlangs->transnoentities("DateDue");
2246 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2247 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2248 }
2249 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2250 }
2251
2252 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2253 $posy += 3;
2254 $pdf->SetXY($posx, $posy);
2255 $pdf->SetTextColor(0, 0, 60);
2256 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2257 }
2258
2259 // Get contact
2260 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2261 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2262 if (count($arrayidcontact) > 0) {
2263 $usertmp = new User($this->db);
2264 $usertmp->fetch($arrayidcontact[0]);
2265 $posy += 4;
2266 $pdf->SetXY($posx, $posy);
2267 $pdf->SetTextColor(0, 0, 60);
2268 $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2269 }
2270 }
2271
2272 $posy += 1;
2273
2274 $top_shift = 0;
2275 $shipp_shift = 0;
2276 // Show list of linked objects
2277 $current_y = $pdf->getY();
2278 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2279 if ($current_y < $pdf->getY()) {
2280 $top_shift = $pdf->getY() - $current_y;
2281 }
2282
2283 if ($showaddress) {
2284 // Sender properties
2285 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2286
2287 // Show sender
2288 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2289 $posy += $top_shift;
2290 $posx = $this->marge_gauche;
2291 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2292 $posx = $this->page_largeur - $this->marge_droite - 80;
2293 }
2294
2295 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2296 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2297
2298 // Show sender frame
2299 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2300 $pdf->SetTextColor(0, 0, 0);
2301 $pdf->SetFont('', '', $default_font_size - 2);
2302 $pdf->SetXY($posx, $posy - 5);
2303 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2304 $pdf->SetXY($posx, $posy);
2305 $pdf->SetFillColor(230, 230, 230);
2306 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2307 $pdf->SetTextColor(0, 0, 60);
2308 }
2309
2310 // Show sender name
2311 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2312 $pdf->SetXY($posx + 2, $posy + 3);
2313 $pdf->SetFont('', 'B', $default_font_size);
2314 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2315 $posy = $pdf->getY();
2316 }
2317
2318 // Show sender information
2319 $pdf->SetXY($posx + 2, $posy);
2320 $pdf->SetFont('', '', $default_font_size - 1);
2321 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2322
2323 // If BILLING contact defined on invoice, we use it
2324 $usecontact = false;
2325 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2326 if (count($arrayidcontact) > 0) {
2327 $usecontact = true;
2328 $result = $object->fetch_contact($arrayidcontact[0]);
2329 }
2330
2331 // Recipient name
2332 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2333 $thirdparty = $object->contact;
2334 } else {
2335 $thirdparty = $object->thirdparty;
2336 }
2337
2338 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2339
2340 $mode = 'target';
2341 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2342
2343 // Show recipient
2344 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2345 if ($this->page_largeur < 210) {
2346 $widthrecbox = 84; // To work with US executive format
2347 }
2348 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2349 $posy += $top_shift;
2350 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2351 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2352 $posx = $this->marge_gauche;
2353 }
2354
2355 // Show recipient frame
2356 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2357 $pdf->SetTextColor(0, 0, 0);
2358 $pdf->SetFont('', '', $default_font_size - 2);
2359 $pdf->SetXY($posx + 2, $posy - 5);
2360 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2361 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2362 }
2363
2364 // Show recipient name
2365 $pdf->SetXY($posx + 2, $posy + 3);
2366 $pdf->SetFont('', 'B', $default_font_size);
2367 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2368 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2369
2370 $posy = $pdf->getY();
2371
2372 // Show recipient information
2373 $pdf->SetFont('', '', $default_font_size - 1);
2374 $pdf->SetXY($posx + 2, $posy);
2375 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2376 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2377
2378 // Show shipping address
2379 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2380 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2381
2382 if (!empty($idaddressshipping)) {
2383 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2384 $companystatic = new Societe($this->db);
2385 $companystatic->fetch($object->contact->fk_soc);
2386 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2387 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2388 } else {
2389 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2390 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2391 }
2392 if (!empty($carac_client_shipping)) {
2393 $posy += $hautcadre;
2394
2395 // Show shipping frame
2396 $pdf->SetXY($posx + 2, $posy - 5);
2397 $pdf->SetFont('', '', $default_font_size - 2);
2398 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2399 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2400
2401 // Show shipping name
2402 $pdf->SetXY($posx + 2, $posy + 3);
2403 $pdf->SetFont('', 'B', $default_font_size);
2404 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2405
2406 $posy = $pdf->getY();
2407
2408 // Show shipping information
2409 $pdf->SetXY($posx + 2, $posy);
2410 $pdf->SetFont('', '', $default_font_size - 1);
2411 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2412 $shipp_shift += $hautcadre;
2413 }
2414 }
2415 }
2416
2417 $pdf->SetTextColor(0, 0, 0);
2418
2419 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2420
2421 return $pagehead;
2422 }
2423
2424 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2434 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2435 {
2436 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2437 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);
2438 }
2439
2450 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2451 {
2452 global $conf, $hookmanager;
2453
2454 // Default field style for content
2455 $this->defaultContentsFieldsStyle = array(
2456 'align' => 'R', // R,C,L
2457 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2458 );
2459
2460 // Default field style for content
2461 $this->defaultTitlesFieldsStyle = array(
2462 'align' => 'C', // R,C,L
2463 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2464 );
2465
2466 /*
2467 * For example
2468 $this->cols['theColKey'] = array(
2469 'rank' => $rank, // int : use for ordering columns
2470 'width' => 20, // the column width in mm
2471 'title' => array(
2472 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2473 'label' => ' ', // the final label : used fore final generated text
2474 'align' => 'L', // text alignment : R,C,L
2475 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2476 ),
2477 'content' => array(
2478 'align' => 'L', // text alignment : R,C,L
2479 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2480 ),
2481 );
2482 */
2483
2484 $rank = 0; // do not use negative rank
2485 $this->cols['desc'] = array(
2486 'rank' => $rank,
2487 'width' => false, // only for desc
2488 'status' => true,
2489 'title' => array(
2490 'textkey' => 'Designation', // use lang key is useful in somme case with module
2491 'align' => 'L',
2492 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2493 // 'label' => ' ', // the final label
2494 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2495 ),
2496 'content' => array(
2497 'align' => 'L',
2498 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2499 ),
2500 );
2501
2502 // Image of product
2503 $rank = $rank + 10;
2504 $this->cols['photo'] = array(
2505 'rank' => $rank,
2506 'width' => getDolGlobalString('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2507 'status' => false,
2508 'title' => array(
2509 'textkey' => 'Photo',
2510 'label' => ' '
2511 ),
2512 'content' => array(
2513 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2514 ),
2515 'border-left' => false, // remove left line separator
2516 );
2517
2518 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2519 $this->cols['photo']['status'] = true;
2520 }
2521
2522
2523 $rank = $rank + 10;
2524 $this->cols['vat'] = array(
2525 'rank' => $rank,
2526 'status' => false,
2527 'width' => 10, // in mm
2528 'title' => array(
2529 'textkey' => 'VAT'
2530 ),
2531 'border-left' => true, // add left line separator
2532 );
2533
2534 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2535 $this->cols['vat']['status'] = true;
2536 }
2537
2538 $rank = $rank + 10;
2539 $this->cols['unit'] = array(
2540 'rank' => $rank,
2541 'width' => 11, // in mm
2542 'status' => false,
2543 'title' => array(
2544 'textkey' => 'Unit'
2545 ),
2546 'border-left' => true, // add left line separator
2547 );
2548 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2549 $this->cols['unit']['status'] = false;
2550 }
2551
2552 $rank = $rank + 10;
2553 $this->cols['subprice'] = array(
2554 'rank' => $rank,
2555 'width' => 17, // in mm
2556 'status' => true,
2557 'title' => array(
2558 'textkey' => 'PriceUHT'
2559 ),
2560 'border-left' => true, // add left line separator
2561 );
2562
2563 // Adapt dynamically the width of subprice, if text is too long.
2564 $tmpwidth = 0;
2565 $nblines = count($object->lines);
2566 for ($i = 0; $i < $nblines; $i++) {
2567 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2568 $tmpwidth = max($tmpwidth, $tmpwidth2);
2569 }
2570 if ($tmpwidth > 10) {
2571 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2572 }
2573
2574 $rank = $rank + 10;
2575 $this->cols['qty'] = array(
2576 'rank' => $rank,
2577 'width' => 10, // in mm
2578 'status' => true,
2579 'title' => array(
2580 'textkey' => 'Qty'
2581 ),
2582 'border-left' => true, // add left line separator
2583 );
2584 //situation invoices
2585 $this->cols['qty']['status'] = true;
2586
2587 //sum column
2588 $rank = $rank + 10;
2589 $this->cols['btpsomme'] = array(
2590 'rank' => $rank,
2591 'width' => 18, // in mm
2592 'status' => false,
2593 'title' => array(
2594 'textkey' => 'Chantier'
2595 ),
2596 'border-left' => true, // add left line separator
2597 'overtitle' => array(
2598 'textkey' => 'Chantier', // use lang key is useful in somme case with module
2599 'align' => 'C',
2600 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2601 'width' => 18
2602 ),
2603 );
2604 if (!empty($this->TDataSituation['date_derniere_situation'])) {
2605 $this->cols['btpsomme']['status'] = true;
2606 }
2607
2608 $derniere_situation = $this->TDataSituation['derniere_situation'];
2609
2610 if (empty($derniere_situation)) {
2611 $derniere_situation = 0;
2612 }
2613
2614 // Column 'Previous progression'
2615 $rank = $rank + 10;
2616 $this->cols['prev_progress'] = array(
2617 'rank' => $rank,
2618 'width' => 10, // in mm
2619 'status' => false,
2620 'title' => array(
2621 'textkey' => $outputlangs->transnoentities('ProgressShort')
2622 ),
2623 'border-left' => true, // add left line separator
2624 'overtitle' => array(
2625 'textkey' => 'S'.$derniere_situation->situation_counter . ' - ' . dol_print_date($derniere_situation->date, "%d/%m/%Y"),
2626 'align' => 'C',
2627 'padding' => array(0.5,0.2,0.5,0.2), // Like css 0 => top, 1 => right, 2 => bottom, 3 => left
2628 'width' => 10 + 15 //current width + amount cell width
2629 ),
2630 );
2631 if ($this->situationinvoice && ! empty($this->TDataSituation['date_derniere_situation'])) {
2632 $this->cols['prev_progress']['status'] = true;
2633 }
2634
2635 // Column 'Previous progression'
2636 $rank = $rank + 10;
2637 $this->cols['prev_progress_amount'] = array(
2638 'rank' => $rank,
2639 'width' => 15, // in mm
2640 'status' => false,
2641 'title' => array(
2642 'textkey' => $outputlangs->transnoentities('Amount')
2643 ),
2644 'border-left' => true, // add left line separator
2645 );
2646 if ($this->situationinvoice && ! empty($this->TDataSituation['date_derniere_situation'])) {
2647 $this->cols['prev_progress_amount']['status'] = true;
2648 }
2649
2650 // Column 'Current percent progress'
2651 $rank = $rank + 10;
2652 $this->cols['progress'] = array(
2653 'rank' => $rank,
2654 'width' => 10, // in mm
2655 'status' => true,
2656 'title' => array(
2657 'textkey' => $outputlangs->transnoentities('ProgressShort')
2658 ),
2659 'border-left' => true, // add left line separator
2660 'overtitle' => array(
2661 'textkey' => 'S'.$object->situation_counter . ' - ' . dol_print_date($object->date, "%d/%m/%Y"),
2662 'align' => 'C',
2663 'padding' => array(0.5,0.2,0.5,0.2), // Like css 0 => top, 1 => right, 2 => bottom, 3 => left
2664 'width' => 10 + 15
2665 ),
2666 );
2667
2668 // Column 'Current progress'
2669 $rank = $rank + 10;
2670 $this->cols['progress_amount'] = array(
2671 'rank' => $rank,
2672 'width' => 15, // in mm
2673 'status' => true,
2674 'title' => array(
2675 'textkey' => $outputlangs->transnoentities('Amount')
2676 ),
2677 'border-left' => true, // add left line separator
2678 );
2679 if ($this->situationinvoice) {
2680 $this->cols['progress_amount']['status'] = true;
2681 }
2682
2683 // FIN BTP SITUATION
2684
2685 $rank = $rank + 10;
2686 $this->cols['discount'] = array(
2687 'rank' => $rank,
2688 'width' => 10, // in mm
2689 'status' => false,
2690 'title' => array(
2691 'textkey' => 'ReductionShort'
2692 ),
2693 'border-left' => true, // add left line separator
2694 );
2695 if ($this->atleastonediscount) {
2696 $this->cols['discount']['status'] = true;
2697 }
2698 $rank = $rank + 10;
2699 $this->cols['totalexcltax'] = array(
2700 'rank' => $rank,
2701 'width' => 18, // in mm
2702 'status' => true,
2703 'title' => array(
2704 'textkey' => $outputlangs->transnoentities('TotalHT')
2705 ),
2706 'border-left' => true, // add left line separator
2707 );
2708
2709 $parameters = array(
2710 'object' => $object,
2711 'outputlangs' => $outputlangs,
2712 'hidedetails' => $hidedetails,
2713 'hidedesc' => $hidedesc,
2714 'hideref' => $hideref
2715 );
2716
2717 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2718 if ($reshook < 0) {
2719 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2720 } elseif (empty($reshook)) {
2721 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2722 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2723 } else {
2724 $this->cols = $hookmanager->resArray;
2725 }
2726 }
2727
2741 public function _tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
2742 {
2743 global $conf, $object, $db;
2744
2745 $form = new Form($db);
2746
2747 $tab_height -= 29; // Réduction de la hauteur global du tableau
2748 $displayWarranty = $this->displayRetainedWarranty($object);
2749 if (!$displayWarranty) {
2750 $tab_height -= 19; // Réduction de la hauteur global du tableau
2751 }
2752
2753
2754 // Force to disable hidetop and hidebottom
2755 $hidebottom = 0;
2756 if ($hidetop) {
2757 $hidetop = -1;
2758 }
2759
2760 $currency = !empty($currency) ? $currency : $conf->currency;
2761 $default_font_size = pdf_getPDFFontSize($outputlangs);
2762
2763 // Amount in (at tab_top - 1)
2764 $pdf->SetTextColor(0, 0, 0);
2765 $pdf->SetFont('', '', $default_font_size - 2);
2766
2767 if (empty($hidetop)) {
2768 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2769 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2770 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2771
2772 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2773
2774 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2775 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2776 $pdf->Rect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2777 $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')));
2778 }
2779 }
2780
2781 $pdf->SetDrawColor(128, 128, 128);
2782 $pdf->SetFont('', '', $default_font_size - 1);
2783
2784 // Output Rect
2785 // KEEPTHIS => Affiche les bords extérieurs
2786 $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
2787
2788 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2789 if (empty($hidetop)) {
2790 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2791 $pdf->MultiCell(35, 2, $outputlangs->transnoentities("SituationInvoiceOldCumulation"), '', 'C');
2792 }
2793
2794 // PRINT COLUMNS TITLES
2795 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2796 if (empty($hidetop)) {
2797 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2798 $pdf->MultiCell(35, 2, $outputlangs->transnoentities("SituationInvoiceNewCumulation"), '', 'C');
2799 }
2800
2801 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2802 if (empty($hidetop)) {
2803 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2804 $pdf->MultiCell(36, 2, $outputlangs->transnoentities("CurrentSituationTotal", $object->situation_counter), '', 'C');
2805 }
2806
2807 // ADD HORIZONTAL LINES
2808 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2809
2810 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2811
2812 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2813
2814 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2815
2816 if ($displayWarranty) {
2817 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2818 }
2819
2820
2821 // ADD TEXT INTO CELL
2822 /********************** Titles ******************************/
2823 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2824 $pdf->MultiCell(60, 2, $outputlangs->transnoentities("SituationInvoiceMainTask"), '', 'L');
2825
2826 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2827 $pdf->MultiCell(60, 2, $outputlangs->transnoentities("SituationInvoiceAdditionalTask"), '', 'L');
2828
2829 $form->load_cache_vatrates("'".$object->thirdparty->country_code."'");
2830
2831 $i = -8;
2832 foreach ($form->cache_vatrates as $TVatInfo) {
2833 $tva_tx_formated = sprintf("%01.3f", (float) $TVatInfo['txtva']);
2834 // print "<p>Un taux de tva ... $tva_tx_formated :: " . json_encode($this->TDataSituation['current'][$tva_tx_formated]) . "</p>";
2835 if (empty($this->TDataSituation['current'][$tva_tx_formated])) {
2836 continue;
2837 }
2838 $i += 8;
2839
2840 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2841 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalHT").' '.$TVatInfo['label'], '', 'L');
2842
2843 if (! empty($this->TDataSituation['current'][$tva_tx_formated]['TVA'])) {
2844 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2845 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("VAT").' '.$TVatInfo['label'], '', 'L');
2846 } else {
2847 $i -= 4;
2848 }
2849 }
2850
2851 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2852 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalTTC"), '', 'L');
2853
2854
2855 $pdf->SetFont('', 'B', $default_font_size - 1);
2856 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2857 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("TotalSituationInvoice"), '', 'L');
2858 $pdf->SetFont('', '', $default_font_size - 2);
2859
2860 if ($displayWarranty) {
2861 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2862 $pdf->MultiCell(80, 2, $outputlangs->trans("TotalSituationInvoiceWithRetainedWarranty", $object->retained_warranty), '', 'L');
2863 $nextY = $tab_top + 93;
2864 } else {
2865 $nextY = $tab_top + 74;
2866 }
2867
2868 $pdf->SetFont('', 'B', $default_font_size - 1);
2869 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2870 $pdf->MultiCell(80, 2, $outputlangs->transnoentities("SituationTotalRayToRest"), '', 'L');
2871 $pdf->SetFont('', '', $default_font_size - 2);
2872 /***********************************************************/
2873
2874 /********************** Data *******************************/
2875 $TToDisplay = array(
2876 'cumul_anterieur',
2877 'nouveau_cumul',
2878 'current'
2879 );
2880
2881 $x = $this->marge_gauche + 85;
2882 // unset($this->TDataSituation['derniere_situation']);
2883 // print json_encode($object->lines);exit;
2884 // print json_encode($this->TDataSituation);exit;
2885 foreach ($TToDisplay as $col) {
2886 // Travaux principaux
2887 $pdf->SetXY($x, $tab_top + 8);
2888 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['HT'], 0, '', 1, -1, 2), '', 'R');
2889
2890 // Travaux supplémentaires
2891 $pdf->SetXY($x, $tab_top + 12);
2892 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['travaux_sup'], 0, '', 1, -1, 2), '', 'R');
2893
2894 $i = -8;
2895 foreach ($form->cache_vatrates as $TVatInfo) {
2896 $tva_tx_formated = sprintf("%01.3f", (float) $TVatInfo['txtva']);
2897 if (empty($this->TDataSituation['current'][$tva_tx_formated])) {
2898 continue;
2899 }
2900 $i += 8;
2901
2902 // Total HT
2903 $pdf->SetXY($x, $tab_top + 24 + $i);
2904 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col][$tva_tx_formated]['HT'], 0, '', 1, -1, 2), '', 'R');
2905
2906 // Total TVA
2907 if (! empty($this->TDataSituation['current'][$tva_tx_formated]['TVA'])) {
2908 $pdf->SetXY($x, $tab_top + 28 + $i);
2909 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col][$tva_tx_formated]['TVA'], 0, '', 1, -1, 2), '', 'R');
2910 } else {
2911 $i -= 4;
2912 }
2913 }
2914
2915 // Total TTC
2916 $pdf->SetXY($x, $tab_top + 33 + $i);
2917 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['TTC'], 0, '', 1, -1, 2), '', 'R');
2918
2919 // Total situation
2920 $pdf->SetFont('', 'B', $default_font_size - 1);
2921 $pdf->SetXY($x, $tab_top + 58);
2922 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['TTC'], 0, '', 1, -1, 2), '', 'R');
2923 $pdf->SetFont('', '', $default_font_size - 2);
2924
2925
2926 if ($displayWarranty) {
2927 // Retained warranty
2928 $pdf->SetXY($x, $tab_top + 74);
2929 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['retenue_garantie'], 0, '', 1, -1, 2), '', 'R');
2930 $nextY = $tab_top + 93;
2931 } else {
2932 $nextY = $tab_top + 74;
2933 }
2934
2935 // Amount payable incl. VAT
2936 $pdf->SetFont('', 'B', $default_font_size - 1);
2937 $pdf->SetXY($x, $nextY);
2938 $pdf->MultiCell(32, 2, price($this->TDataSituation[$col]['total_a_payer'], 0, '', 1, -1, 2), '', 'R');
2939 $pdf->SetFont('', '', $default_font_size - 2);
2940
2941 $x += 36;
2942 }
2943 /************************************************************/
2944 }
2945
2946
2968 public function getDataSituation(&$object)
2969 {
2970 global $conf, $db;
2971
2972 // Fetch previous and next situations invoices.
2973 // Return all previous and next invoices (both standard and credit notes)
2974 $object->fetchPreviousNextSituationInvoice();
2976 $TPreviousInvoices = $object->tab_previous_situation_invoice;
2977 unset($object->tab_previous_situation_invoice);
2978
2979 // liste de toutes les factures précédentes
2980 // print json_encode($TPreviousInvoices); exit;
2981
2982 $TPreviousInvoices = array_reverse($TPreviousInvoices);
2983 $facDerniereSituation = $TPreviousInvoices[0];
2984
2985 $TDataSituation = array();
2986
2987 if (! empty($facDerniereSituation)) {
2988 $TDataSituation['derniere_situation'] = $facDerniereSituation;
2989 $TDataSituation['date_derniere_situation'] = $facDerniereSituation->date;
2990 }
2991
2992 $retenue_garantie = 0;
2993 $retenue_garantie_anterieure = 0;
2994 // Init tous les champs à 0
2995 $TDataSituation['cumul_anterieur'] = array(
2996 'HT' => 0, //montant HT normal
2997 'TVA' => 0, //montant de la TVA sur le HTnet
2998 'TTC' => 0, //montant TTC (HTnet + TVA)
2999 'retenue_garantie' => 0,
3000 'travaux_sup' => 0,
3001 'HTnet' => 0, //montant HT
3002 'total_a_payer' => 0 //montant "a payer" sur la facture
3003 );
3004
3005 //S'il y a des factures de situations précédentes
3006 if (!empty($TPreviousInvoices)) {
3007 //calcul des cumuls -- plus necessaire ?
3008 foreach ($TPreviousInvoices as $i => $previousInvoice) {
3009 $TDataSituation['cumul_anterieur']['HT'] += $previousInvoice->total_ht;
3010 // $TDataSituation['cumul_anterieur']['TTC'] += $previousInvoice->total_ttc;
3011 $TDataSituation['cumul_anterieur']['TVA'] += $previousInvoice->total_tva;
3012
3013 //lecture de chaque ligne pour
3014 // 1. recalculer le total_ht pour chaque taux de TVA
3015 // 2. recalculer la TVA associée à ce montant HT
3016 // 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
3017 foreach ($previousInvoice->lines as $k => $l) {
3018 $total_ht = floatval($l->total_ht);
3019 if (empty($total_ht)) {
3020 continue;
3021 }
3022
3023 // Si $prevSituationPercent vaut 0 c'est que la ligne $l est un travail supplémentaire
3024 $prevSituationPercent = 0;
3025 $isFirstSituation = false;
3026 if (!empty($l->fk_prev_id)) {
3027 $prevSituationPercent = $l->get_prev_progress($previousInvoice->id, true);
3028 } elseif (! array_key_exists($i + 1, $TPreviousInvoices)) {
3029 $isFirstSituation = true;
3030 }
3031
3032 $calc_ht = $l->total_ht;
3033 //modification du format de TVA, cas particulier des imports ou autres qui peuvent avoir des 20.0000
3034 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3035
3036 //1ere ligne
3037 $amounttva = $calc_ht * ($ltvatx / 100);
3038 if (! isset($TDataSituation['cumul_anterieur'][$ltvatx])) {
3039 $TDataSituation['cumul_anterieur'][$ltvatx]['HT'] = $calc_ht;
3040 $TDataSituation['cumul_anterieur'][$ltvatx]['TVA'] = $amounttva;
3041 } else {
3042 //lignes suivantes
3043 $TDataSituation['cumul_anterieur'][$ltvatx]['HT'] += ($calc_ht);
3044 $TDataSituation['cumul_anterieur'][$ltvatx]['TVA'] += $amounttva;
3045 }
3046
3047 //le grand total de TVA
3048 // $TDataSituation['cumul_anterieur']['TVA'] += $amounttva;
3049
3050 if (empty($l->fk_prev_id) && ! $isFirstSituation) {
3051 // TODO: à clarifier, mais pour moi, un facture de situation précédente qui a des progressions à 0% c'est pas logique
3052 $TDataSituation['cumul_anterieur']['travaux_sup'] += $calc_ht;
3053 }
3054 }
3055 }
3056
3057 if (! empty($previousInvoice->retained_warranty) && !getDolGlobalString('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL')) {
3058 $retenue_garantie_anterieure += $previousInvoice->getRetainedWarrantyAmount();
3059 }
3060
3061 //les cumuls
3062 $TDataSituation['cumul_anterieur']['HT'] -= $TDataSituation['cumul_anterieur']['travaux_sup'];
3063 $TDataSituation['cumul_anterieur']['retenue_garantie'] = $retenue_garantie_anterieure;
3064 $TDataSituation['cumul_anterieur']['TTC'] = $TDataSituation['cumul_anterieur']['HT'] + $TDataSituation['cumul_anterieur']['TVA'];
3065 $TDataSituation['cumul_anterieur']['total_a_payer'] = $TDataSituation['cumul_anterieur']['TTC'] - $retenue_garantie_anterieure;
3066 }
3067
3068 // print json_encode($facDerniereSituation->lines);exit;
3069 $TDataSituation['current'] = $this->btpGetInvoiceAmounts($object->id);
3070
3071 if (! empty($facDerniereSituation->lines)) {
3072 $TFacLinesKey = array_keys($facDerniereSituation->lines);
3073 $TObjectLinesKey = array_keys($object->lines);
3074 $TDiffKey = array_diff($TObjectLinesKey, $TFacLinesKey);
3075
3076 // print json_encode($TDiffKey);exit;
3077
3078 foreach ($TDiffKey as $i) {
3079 if (empty($object->lines[$i]->fk_prev_id)) {
3080 $TDataSituation['nouveau_cumul']['travaux_sup'] += $object->lines[$i]->total_ht;
3081 $TDataSituation['current']['travaux_sup'] += $object->lines[$i]->total_ht;
3082 }
3083 }
3084 }
3085
3086 //Le nouveau cumul = cumul antérieur + current
3087 $TDataSituation['nouveau_cumul'] = $this->sumSituation($TDataSituation['current'], $TDataSituation['cumul_anterieur']);
3088
3089 return $TDataSituation;
3090 }
3091
3100 public function sumSituation($a, $b)
3101 {
3102 $ret = array();
3103 if (is_array($a)) {
3104 foreach ($a as $k => $v) {
3105 if (is_array($v)) {
3106 $ret[$k] = $this->sumSituation($v, $b[$k]);
3107 } else {
3108 $ret[$k] = $a[$k];
3109 if (isset($b[$k])) {
3110 $ret[$k] += $b[$k];
3111 }
3112 }
3113 }
3114 } else {
3115 dol_syslog("sumSituation first arg is not an array");
3116 }
3117
3118 return $ret;
3119 }
3120
3128 {
3129 if (is_callable(array($object, 'displayRetainedWarranty'))) {
3130 return $object->displayRetainedWarranty();
3131 } else {
3132 // FOR RETROCOMPATIBILITY
3133 global $conf;
3134
3135 // TODO : add a flag on invoices to store this conf USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL
3136
3137 // 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
3138
3139 $displayWarranty = false;
3140 if (!empty($object->retained_warranty)) {
3141 $displayWarranty = true;
3142
3143 if ($object->type == Facture::TYPE_SITUATION && getDolGlobalString('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL')) {
3144 // Check if this situation invoice is 100% for real
3145 $displayWarranty = false;
3146 if (!empty($object->situation_final)) {
3147 $displayWarranty = true;
3148 } elseif (!empty($object->lines) && $object->status == Facture::STATUS_DRAFT) {
3149 // $object->situation_final need validation to be done so this test is need for draft
3150 $displayWarranty = true;
3151
3152 foreach ($object->lines as $i => $line) {
3153 if ($line->product_type < 2 && $line->situation_percent < 100) {
3154 $displayWarranty = false;
3155 break;
3156 }
3157 }
3158 }
3159 }
3160 }
3161 return $displayWarranty;
3162 }
3163 }
3164
3172 public function getInfosLineLastSituation(&$object, &$current_line)
3173 {
3174 if (empty($object->situation_cycle_ref) || $object->situation_counter <= 1) {
3175 return;
3176 }
3177
3178 $facDerniereSituation = &$this->TDataSituation['derniere_situation'];
3179
3180 // Find the previous line of the line you are on
3181 foreach ($facDerniereSituation->lines as $l) {
3182 if ($l->rowid == $current_line->fk_prev_id) {
3183 // Recovery of total_ht without taking progress into account (for the "sums" column)
3184 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3185 $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);
3186 $total_ht = $tabprice[0];
3187 $total_tva = $tabprice[1];
3188 $total_ttc = $tabprice[2];
3189 $total_localtax1 = $tabprice[9];
3190 $total_localtax2 = $tabprice[10];
3191 $pu_ht = $tabprice[3];
3192
3193 return array(
3194 'progress_prec' => $l->situation_percent,
3195 'total_ht_without_progress' => $total_ht,
3196 'total_ht' => $l->total_ht,
3197 );
3198 }
3199 }
3200 }
3201
3214 public function printRectBtp(&$pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0)
3215 {
3216 if (empty($hidetop) || $hidetop == -1) {
3217 $pdf->line($x, $y, $x + $l, $y);
3218 }
3219 $pdf->line($x + $l, $y, $x + $l, $y + $h);
3220 if (empty($hidebottom)) {
3221 $pdf->line($x + $l, $y + $h, $x, $y + $h);
3222 }
3223 $pdf->line($x, $y + $h, $x, $y);
3224 }
3225
3226
3235 public function btpGetInvoiceAmounts($id, $forceReadFromDB = false)
3236 {
3237 global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
3238
3239 $object = new Facture($db);
3240 $object->fetch($id);
3241
3242 /* from dolibarr core
3243 * Fetch previous and next situations invoices.
3244 * Return all previous and next invoices (both standard and credit notes).
3245 */
3246 $object->fetchPreviousNextSituationInvoice();
3248 $TPreviousInvoices = $object->tab_previous_situation_invoice;
3249 unset($object->tab_previous_situation_invoice);
3250
3251 $TPreviousInvoices = array_reverse($TPreviousInvoices);
3252 $facDerniereSituation = $TPreviousInvoices[0];
3253
3254 $ret = array(
3255 'HT' => 0, //montant HT normal
3256 'HTnet' => 0, //montant HT
3257 'TVA' => 0, //montant de la TVA sur le HTnet
3258 'TTC' => 0, //montant TTC (HTnet + TVA)
3259 'retenue_garantie' => 0,
3260 'travaux_sup' => 0,
3261 'total_a_payer' => 0 //montant "a payer" sur la facture
3262 );
3263
3264 if (! empty($facDerniereSituation)) {
3265 $ret['derniere_situation'] = $facDerniereSituation;
3266 $ret['date_derniere_situation'] = $facDerniereSituation->date;
3267 }
3268
3269 // Scroll through the lines of the current invoice to retrieve all data
3270 foreach ($object->lines as $k => $l) {
3271 $total_ht = floatval($l->total_ht);
3272 if (empty($total_ht)) {
3273 continue;
3274 }
3275
3276 // Modification of VAT format, special case of imports or others which may have 20.0000
3277 $ltvatx = (float) sprintf("%01.3f", $l->tva_tx);
3278
3279 $ret[$ltvatx]['TVA'] += $l->total_tva;
3280 $ret[$ltvatx]['HT'] += $l->total_ht;
3281 }
3282
3283 // Retained warranty
3284 $retenue_garantie = $object->getRetainedWarrantyAmount();
3285 if ($retenue_garantie == -1) {
3286 $retenue_garantie = 0;
3287 }
3288
3289 //les cumuls
3290 $ret['TTC'] = $object->total_ttc;
3291 $ret['TVA'] = $object->total_tva;
3292 $ret['HT'] = $object->total_ht - $ret['travaux_sup'];
3293 $ret['total_a_payer'] = $ret['TTC'] - $retenue_garantie;
3294 $ret['retenue_garantie'] = $retenue_garantie;
3295
3296 //Clean up before keep in "cache"
3297 unset($ret['derniere_situation']->db);
3298 unset($ret['derniere_situation']->fields);
3299 unset($ret['derniere_situation']->lines);
3300
3301 // print "<p>Store to cache $id : " . json_encode($_cache_btpProrataGetInvoiceAmounts[$id]) . "</p>";
3302 return $ret;
3303 }
3304
3305
3317 public function resumeLastPage(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
3318 {
3319 global $conf, $mysoc, $hookmanager;
3320 $default_font_size = pdf_getPDFFontSize($outputlangs);
3321
3322 $sign = 1;
3323 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3324 $sign = -1;
3325 }
3326
3327 $pdf->AddPage();
3328 if (!empty($this->tplidx)) {
3329 $pdf->useTemplate($this->tplidx);
3330 }
3331
3332 $pagehead = $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
3333
3334 $tab2_top = $this->tab_top_newpage - 4;
3335 $posy = $tab2_top;
3336 $posx = $this->marge_gauche;
3337 $index = 1;
3338 $outputlangs->load('orders');
3339 $outputlangs->load('propal');
3340 $width = 70;
3341 $width2 = $this->page_largeur - $posx - $width - $this->marge_droite;
3342
3343 $pdf->SetFont('', '', $default_font_size - 1);
3344 $pdf->MultiCell(0, 3, ''); // Set interline to 3
3345 $pdf->SetTextColor(0, 0, 0);
3346 $pdf->setY($tab2_top);
3347
3348 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
3349 $pdf->SetFont('', '', $default_font_size - 2);
3350 } else {
3351 $pdf->SetFont('', '', $default_font_size - 1);
3352 }
3353
3354 if (empty($object->tab_previous_situation_invoice)) {
3355 $object->fetchPreviousNextSituationInvoice();
3356 }
3357
3358 $previousinvoices = count($object->tab_previous_situation_invoice) ? $object->tab_previous_situation_invoice : array();
3359
3360 $remain_to_pay = 0;
3361
3362 // Proposal total
3363 $propals = array();
3364 $orders = array();
3365
3366 if (count($previousinvoices)) {
3367 foreach ($previousinvoices as $invoice) {
3368 if ($invoice->is_first()) {
3369 $invoice->fetchObjectLinked();
3370
3371 $propals = isset($invoice->linkedObjects['propal']) ? $invoice->linkedObjects['propal'] : array();
3372 $orders = isset($invoice->linkedObjects['commande']) ? $invoice->linkedObjects['commande'] : array();
3373 }
3374 }
3375 } else {
3376 if ($object->is_first()) {
3377 $object->fetchObjectLinked();
3378
3379 $propals = isset($object->linkedObjects['propal']) ? $object->linkedObjects['propal'] : array();
3380 $orders = isset($object->linkedObjects['commande']) ? $object->linkedObjects['commande'] : array();
3381 }
3382 }
3383
3384 if (count($propals)) {
3385 $propal = array_pop($propals);
3386
3387 $total_ht = ($conf->multicurrency->enabled && $propal->multicurrency_tx != 1) ? $propal->multicurrency_total_ht : $propal->total_ht;
3388 $remain_to_pay = $total_ht;
3389
3390 $pdf->SetTextColor(0, 0, 60);
3391 $pdf->SetFont('', '', $default_font_size - 1);
3392
3393 $label = $outputlangs->transnoentities("SituationInvoiceTotalProposal");
3394 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $label, 0, 'L', 0, 1, $posx, $posy + 1);
3395
3396 $amount = price($sign * ($total_ht + (! empty($propal->remise) ? $propal->remise : 0)));
3397 $pdf->MultiCell($width2, 3, $amount, 0, 'R', 0, 1, $posx + $width, $posy + 1);
3398
3399 $pdf->SetFont('', '', $default_font_size - 1);
3400
3401 // Output Rect
3402 $pdf->SetDrawColor(128, 128, 128);
3403 $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
3404
3405 $posy += 4;
3406 } elseif (count($orders)) {
3407 $order = array_pop($orders);
3408
3409 $total_ht = ($conf->multicurrency->enabled && $order->multicurrency_tx != 1 ? $order->multicurrency_total_ht : $order->total_ht);
3410 $remain_to_pay = $total_ht;
3411 }
3412
3413 $useborder = 0;
3414 $index = 0;
3415
3416 $height = 4;
3417
3418 $sign = 1;
3419 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3420 $sign = -1;
3421 }
3422 $pdf->SetTextColor(0, 0, 60);
3423 $pdf->SetFont('', 'B', $default_font_size + 3);
3424
3425
3426 $pdf->SetXY($posx, $posy);
3427
3428
3429 $depositsamount = $object->getSumDepositsUsed();
3430 $deja_regle = $object->getSommePaiement();
3431
3432 $tot_deja_regle = ($depositsamount + $deja_regle);
3433
3434 $previousinvoices[] = $object;
3435
3436 $force_to_zero = false;
3437
3438 $idinv = 0;//count($previousinvoices);
3439 while ($idinv < count($previousinvoices)) {
3440 $invoice = $previousinvoices[$idinv];
3441
3442 $posy += 7;
3443 $index = 0;
3444
3445 $pdf->SetTextColor(0, 0, 60);
3446 $pdf->SetFont('', 'B', $default_font_size + 3);
3447
3448 $pageposbefore = $pdf->getPage();
3449 $pdf->startTransaction();
3450
3451 $pdf->SetXY($posx, $posy);
3452
3453 $ref = $outputlangs->transnoentities("InvoiceSituation").$outputlangs->convToOutputCharset(" n°".$invoice->situation_counter);
3454
3455 if ($invoice->situation_final) {
3456 $ref .= ' - DGD';
3457 $force_to_zero = true;
3458 }
3459
3460 $ref .= ' - '. $invoice->ref;
3461 $ref .= ' ('.dol_print_date($invoice->date, "%d/%m/%Y", false, $outputlangs).')';
3462 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $ref, 0, 'L', 0);
3463
3464 $pdf->SetFont('', '', $default_font_size - 1);
3465
3466 $sign = 1;
3467 if ($invoice->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3468 $sign = -1;
3469 }
3470
3471 $posy += 7;
3472 // Total HT
3473 $pdf->SetFillColor(255, 255, 255);
3474 $pdf->SetXY($posx, $posy);
3475 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
3476
3477 $total_ht = ($conf->multicurrency->enabled && $invoice->multicurrency_tx != 1 ? $invoice->multicurrency_total_ht : $invoice->total_ht);
3478 $pdf->SetXY($posx + $width, $posy);
3479 $pdf->MultiCell($width2, $height, price($sign * ($total_ht + (!empty($invoice->remise) ? $invoice->remise : 0)), 0, $outputlangs), 0, 'R', 1);
3480
3481 $tvas = array();
3482 $nblines = count($invoice->lines);
3483 for ($i = 0; $i < $nblines; $i++) {
3484 $tvaligne = $invoice->lines[$i]->total_tva;
3485 $vatrate = (string) $invoice->lines[$i]->tva_tx;
3486
3487 if (($invoice->lines[$i]->info_bits & 0x01) == 0x01) {
3488 $vatrate .= '*';
3489 }
3490 if (! isset($tvas[$vatrate])) {
3491 $tvas[$vatrate] = 0;
3492 }
3493 $tvas[$vatrate] += $tvaligne;
3494 }
3495
3496 // Show VAT by rates and total
3497 $pdf->SetFillColor(248, 248, 248);
3498 foreach ($tvas as $tvakey => $tvaval) {
3499 if ($tvakey != 0) { // On affiche pas taux 0
3500 $index++;
3501 $pdf->SetXY($posx, $posy + $height * $index);
3502
3503 $tvacompl = '';
3504 if (preg_match('/\*/', $tvakey)) {
3505 $tvakey = str_replace('*', '', $tvakey);
3506 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
3507 }
3508 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
3509 $totalvat .= vatrate($tvakey, 1).$tvacompl;
3510 $pdf->MultiCell($width, $height, $totalvat, 0, 'L', 1);
3511
3512 $pdf->SetXY($posx + $width, $posy + $height * $index);
3513 $pdf->MultiCell($width2, $height, price($tvaval, 0, $outputlangs), 0, 'R', 1);
3514 }
3515 }
3516
3517 $index++;
3518
3519 $total_ht = ($conf->multicurrency->enabled && $invoice->multicurrency_tx != 1) ? $invoice->multicurrency_total_ht : $invoice->total_ht;
3520 $total_ttc = ($conf->multicurrency->enabled && $invoice->multicurrency_tx != 1) ? $invoice->multicurrency_total_ttc : $invoice->total_ttc;
3521
3522 // Total TTC
3523 $pdf->SetXY($posx, $posy + $height * $index);
3524 $pdf->SetTextColor(0, 0, 60);
3525 $pdf->SetFillColor(224, 224, 224);
3526 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
3527
3528
3529 $pdf->SetXY($posx + $width, $posy + $height * $index);
3530 $pdf->MultiCell($width2, $height, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
3531
3532 $retainedWarrantyRate = (float) ($object->retained_warranty ? price2num($object->retained_warranty) : price2num(getDolGlobalString('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT', 0)));
3533
3534 $total_ht_rg = 0;
3535 $total_ttc_rg = 0;
3536
3537 if ($this->is_rg) {
3538 $index++;
3539
3540 $pdf->SetXY($posx, $posy + $height * $index);
3541 $pdf->SetTextColor(0, 0, 60);
3542 $pdf->SetFillColor(241, 241, 241);
3543 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("RetainedWarrantyShort", $retainedWarrantyRate), $useborder, 'L', 1);
3544
3545 $total_ht_rg = (float) price2num(price($total_ht * $retainedWarrantyRate / 100), 'MT');
3546 $total_ttc_rg = (float) price2num(price($total_ttc * $retainedWarrantyRate / 100), 'MT');
3547
3548 $pdf->SetXY($posx + $width, $posy + $height * $index);
3549 $pdf->MultiCell($width2, $height, price(-$sign * $total_ht_rg, 0, $outputlangs), $useborder, 'R', 1);
3550
3551 $total_ht_with_rg = $total_ht - $total_ht_rg;
3552 $total_ttc_with_rg = $total_ttc - $total_ttc_rg;
3553
3554 $index++;
3555
3556 // Total TTC
3557 $pdf->SetXY($posx, $posy + $height * $index);
3558 $pdf->SetTextColor(0, 0, 60);
3559 $pdf->SetFillColor(224, 224, 224);
3560 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("TotalSituationInvoiceWithRetainedWarranty"), $useborder, 'L', 1);
3561
3562 $pdf->SetXY($posx + $width, $posy + $height * $index);
3563 $pdf->MultiCell($width2, $height, price($sign * $total_ttc_with_rg, 0, $outputlangs), $useborder, 'R', 1);
3564 }
3565
3566
3567
3568 $index++;
3569
3570 $pdf->SetTextColor(0, 0, 0);
3571
3572 $creditnoteamount = $invoice->getSumCreditNotesUsed();
3573 $depositsamount = $invoice->getSumDepositsUsed();
3574 $deja_regle = $invoice->getSommePaiement();
3575
3576 $resteapayer = price2num($invoice->total_ttc - $deja_regle - $total_ttc_rg - $creditnoteamount - $depositsamount, 'MT');
3577 if ($invoice->paye) {
3578 $resteapayer = 0;
3579 }
3580
3581 $y = 0;
3582
3583
3584 // Already paid + Deposits
3585 $tot_deja_regle += $deja_regle + $depositsamount;
3586
3587 $pdf->SetXY($posx, $posy + $height * $index);
3588 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
3589 $pdf->SetXY($posx + $width, $posy + $height * $index);
3590 $pdf->MultiCell($width2, $height, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
3591
3592 // Credit note
3593 if ($creditnoteamount) {
3594 $index++;
3595 $pdf->SetXY($posx, $posy + $height * $index);
3596 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
3597 $pdf->SetXY($posx + $width, $posy + $height * $index);
3598 $pdf->MultiCell($width2, $height, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
3599 }
3600
3601 // Escompte
3602 if ($invoice->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
3603 $index++;
3604 $pdf->SetFillColor(255, 255, 255);
3605
3606 $pdf->SetXY($posx, $posy + $height * $index);
3607 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
3608 $pdf->SetXY($posx + $width, $posy + $height * $index);
3609 $pdf->MultiCell($width2, $height, price($invoice->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
3610
3611 $resteapayer = 0;
3612 }
3613
3614 $index++;
3615 $pdf->SetTextColor(0, 0, 60);
3616 $pdf->SetFillColor(224, 224, 224);
3617 $pdf->SetXY($posx, $posy + $height * $index);
3618 $pdf->MultiCell($width, $height, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
3619 $pdf->SetXY($posx + $width, $posy + $height * $index);
3620 $pdf->MultiCell($width2, $height, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
3621
3622 $pdf->SetFont('', '', $default_font_size - 1);
3623 $pdf->SetTextColor(0, 0, 0);
3624
3625 $index++;
3626
3627 if ($deja_regle > 0) {
3628 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
3629 if ($invoice->type == 2) {
3630 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
3631 }
3632
3633 $pdf->SetFont('', '', $default_font_size - 3);
3634 $pdf->SetXY($posx, $posy + $height * $index);
3635 $pdf->MultiCell($width, $height, $title, 0, 'L', 0);
3636
3637 //$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
3638
3639 $index++;
3640
3641 $width4 = ($this->page_largeur - $this->marge_droite - $posx) / 4;
3642
3643 $pdf->SetFont('', '', $default_font_size - 4);
3644 $pdf->SetXY($posx, $posy + $height * $index);
3645 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
3646 $pdf->SetXY($posx + $width4, $posy + $height * $index);
3647 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
3648 $pdf->SetXY($posx + $width4 * 2, $posy + $height * $index);
3649 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Type"), 0, 'L', 0);
3650 $pdf->SetXY($posx + $width4 * 3, $posy + $height * $index);
3651 $pdf->MultiCell($width4, $height - 1, $outputlangs->transnoentities("Num"), 0, 'L', 0);
3652
3653 //$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
3654
3655 $y = $height - 1;
3656
3657 $pdf->SetFont('', '', $default_font_size - 4);
3659 $payments = $invoice->getListOfPayments();
3660
3661 if (count($payments)) {
3662 foreach ($payments as $payment) {
3663 $pdf->SetXY($posx, $posy + $height * $index + $y);
3664 $pdf->MultiCell($width4, $height - 1, dol_print_date($this->db->jdate($payment['date']), 'day', false, $outputlangs, true), 0, 'L', 0);
3665 $pdf->SetXY($posx + $width4, $posy + $height * $index + $y);
3666 $pdf->MultiCell($width4, $height - 1, price($sign * $payment['amount'], 0, $outputlangs), 0, 'L', 0);
3667 $pdf->SetXY($posx + $width4 * 2, $posy + $height * $index + $y);
3668 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $payment['type']);
3669
3670 $pdf->MultiCell($width4, $height - 1, $oper, 0, 'L', 0);
3671 $pdf->SetXY($posx + $width4 * 3, $posy + $height * $index + $y);
3672 $pdf->MultiCell($width4, $height - 1, $payment['num'], 0, 'L', 0);
3673
3674 //$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
3675 $y += ($height - 1);
3676 }
3677 }
3678 }
3679
3680 // Output Rect
3681 $pdf->SetDrawColor(128, 128, 128);
3682 $this->printRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height * $index + $y);
3683 $posy += $height * $index + $y;
3684
3685 $pageposafter = $pdf->getPage();
3686 if ($pageposafter > $pageposbefore) { // There is a pagebreak
3687 $pdf->rollbackTransaction(true);
3688
3689 $pageposafter = $pageposbefore;
3690 $pdf->AddPage('', '', true);
3691 if (!empty($this->tplidx)) {
3692 $pdf->useTemplate($this->tplidx);
3693 }
3694 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
3695 $this->_pagehead($pdf, $object, 0, $outputlangs);
3696 }
3697 $pdf->setPage($pageposafter + 1);
3698 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
3699
3700 $posy = $this->tab_top_newpage + 1;
3701 } else {
3702 $idinv++;
3703 $remain_to_pay -= ($sign * ($total_ht + (!empty($invoice->remise) ? $invoice->remise : 0)));
3704
3705 $rem = 0;
3706 if (count($invoice->lines)) {
3707 foreach ($invoice->lines as $l) {
3708 if ($l->fk_remise_except > 0) {
3709 $discount = new DiscountAbsolute($this->db);
3710 $result = $discount->fetch($l->fk_remise_except);
3711 if ($result > 0) {
3712 $rem += $discount->amount_ht;
3713 }
3714 }
3715 }
3716 }
3717
3718 $remain_to_pay -= $rem;
3719
3720 $pdf->commitTransaction();
3721 }
3722 }
3723
3724 if ($force_to_zero) {
3725 $remain_to_pay = 0;
3726 }
3727
3728 $posy += 10;
3729
3730 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
3731
3732 $pdf->SetTextColor(0, 0, 60);
3733 $pdf->SetFont('', '', $default_font_size - 1);
3734 $pdf->SetXY($this->marge_gauche, $posy + 1);
3735 $label = $outputlangs->transnoentities("SituationTotalRayToRest");
3736 $pdf->MultiCell($this->page_largeur - ($this->marge_droite + $this->marge_gauche), 3, $label, 0, 'L', 0);
3737
3738 $amount = price($remain_to_pay);
3739 $pdf->MultiCell($width2, 3, $amount, 0, 'R', 0, 1, $posx + $width, $posy + 1);
3740
3741 $pdf->SetDrawColor(128, 128, 128);
3742 $this->printRect($pdf, $this->marge_gauche, $posy, $this->page_largeur - $this->marge_gauche - $this->marge_droite, 7);
3743 }
3744}
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...
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)
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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:2637
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2376
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:290
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:315
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:1027
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:1994
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2325
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1932
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1401
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:850
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:267
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:436
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2239
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2282
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2079
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:769
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:388
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