dolibarr 18.0.6
pdf_crabe.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 García <marcosgdf@gmail.com>
10 * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
12 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 * or see https://www.gnu.org/
27 */
28
35require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
36require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
40
41
46{
50 public $db;
51
55 public $name;
56
60 public $description;
61
65 public $update_main_doc_field;
66
70 public $type;
71
76 public $version = 'dolibarr';
77
81 public $page_largeur;
82
86 public $page_hauteur;
87
91 public $format;
92
96 public $marge_gauche;
97
101 public $marge_droite;
102
106 public $marge_haute;
107
111 public $marge_basse;
112
117 public $emetteur;
118
122 public $situationinvoice;
123
127 public $posxprogress;
128
132 public $categoryOfOperation = -1; // unknown by default
133
134
140 public function __construct($db)
141 {
142 global $conf, $langs, $mysoc;
143
144 // Translations
145 $langs->loadLangs(array("main", "bills"));
146
147 $this->db = $db;
148 $this->name = "crabe";
149 $this->description = $langs->trans('PDFCrabeDescription');
150 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
151
152 // Dimension page
153 $this->type = 'pdf';
154 $formatarray = pdf_getFormat();
155 $this->page_largeur = $formatarray['width'];
156 $this->page_hauteur = $formatarray['height'];
157 $this->format = array($this->page_largeur, $this->page_hauteur);
158 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
159 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
160 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
161 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
162
163 $this->option_logo = 1; // Display logo
164 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
165 $this->option_modereg = 1; // Display payment mode
166 $this->option_condreg = 1; // Display payment terms
167 $this->option_multilang = 1; // Available in several languages
168 $this->option_escompte = 1; // Displays if there has been a discount
169 $this->option_credit_note = 1; // Support credit notes
170 $this->option_freetext = 1; // Support add of a personalised text
171 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
172 $this->watermark = '';
173
174 // Get source company
175 $this->emetteur = $mysoc;
176 if (empty($this->emetteur->country_code)) {
177 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
178 }
179
180 // Define position of columns
181 $this->posxdesc = $this->marge_gauche + 1;
182 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
183 $this->posxtva = 101;
184 $this->posxup = 118;
185 $this->posxqty = 135;
186 $this->posxunit = 151;
187 } else {
188 $this->posxtva = 106;
189 $this->posxup = 122;
190 $this->posxqty = 145;
191 $this->posxunit = 162;
192 }
193 $this->posxprogress = 151; // Only displayed for situation invoices
194 $this->posxdiscount = 162;
195 $this->posxprogress = 174;
196 $this->postotalht = 174;
197 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
198 $this->posxtva = $this->posxup;
199 }
200 $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
201 if ($this->page_largeur < 210) { // To work with US executive format
202 $this->posxpicture -= 20;
203 $this->posxtva -= 20;
204 $this->posxup -= 20;
205 $this->posxqty -= 20;
206 $this->posxunit -= 20;
207 $this->posxdiscount -= 20;
208 $this->posxprogress -= 20;
209 $this->postotalht -= 20;
210 }
211
212 $this->tva = array();
213 $this->tva_array = array();
214 $this->localtax1 = array();
215 $this->localtax2 = array();
216 $this->atleastoneratenotnull = 0;
217 $this->atleastonediscount = 0;
218 $this->situationinvoice = false;
219 }
220
221
222 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
234 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
235 {
236 // phpcs:enable
237 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
238
239 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
240
241 if (!is_object($outputlangs)) {
242 $outputlangs = $langs;
243 }
244 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
245 if (!empty($conf->global->MAIN_USE_FPDF)) {
246 $outputlangs->charset_output = 'ISO-8859-1';
247 }
248
249 // Load translation files required by the page
250 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
251
252 // Show Draft Watermark
253 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
254 $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
255 }
256
257 global $outputlangsbis;
258 $outputlangsbis = null;
259 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
260 $outputlangsbis = new Translate('', $conf);
261 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
262 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
263 }
264
265 $nblines = count($object->lines);
266
267 // Loop on each lines to detect if there is at least one image to show
268 $realpatharray = array();
269 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
270 for ($i = 0; $i < $nblines; $i++) {
271 if (empty($object->lines[$i]->fk_product)) {
272 continue;
273 }
274
275 $objphoto = new Product($this->db);
276 $objphoto->fetch($object->lines[$i]->fk_product);
277
278 $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
279 $dir = $conf->product->dir_output.'/'.$pdir;
280
281 $realpath = '';
282 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
283 $filename = $obj['photo'];
284 //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
285 $realpath = $dir.$filename;
286 break;
287 }
288
289 if ($realpath) {
290 $realpatharray[$i] = $realpath;
291 }
292 }
293 }
294 if (count($realpatharray) == 0) {
295 $this->posxpicture = $this->posxtva;
296 }
297
298 if ($conf->facture->dir_output) {
299 $object->fetch_thirdparty();
300
301 $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
302 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
303 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
304
305 // Definition of $dir and $file
306 if ($object->specimen) {
307 $dir = empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity];
308 $file = $dir."/SPECIMEN.pdf";
309 } else {
310 $objectref = dol_sanitizeFileName($object->ref);
311 $dir = (empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity])."/".$objectref;
312 $file = $dir."/".$objectref.".pdf";
313 }
314 if (!file_exists($dir)) {
315 if (dol_mkdir($dir) < 0) {
316 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
317 return 0;
318 }
319 }
320
321 if (file_exists($dir)) {
322 // Add pdfgeneration hook
323 if (!is_object($hookmanager)) {
324 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
325 $hookmanager = new HookManager($this->db);
326 }
327 $hookmanager->initHooks(array('pdfgeneration'));
328 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
329 global $action;
330 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
331
332 // Set nblines with the new facture lines content after hook
333 $nblines = count($object->lines);
334 $nbpayments = count($object->getListOfPayments());
335
336 // Create pdf instance
337 $pdf = pdf_getInstance($this->format);
338 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
339 $pdf->SetAutoPageBreak(1, 0);
340
341 $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
342 if ($heightforinfotot > 220) {
343 $heightforinfotot = 220;
344 }
345 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
346 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
347 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
348 $heightforfooter += 6;
349 }
350
351 $heightforqrinvoice_firstpage = 0;
352 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
353 $heightforqrinvoice_firstpage = $this->getHeightForQRInvoice(1, $object, $langs);
354 if ($heightforqrinvoice_firstpage > 0) {
355 // Shrink infotot to a base 30
356 $heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
357 }
358 }
359
360 if (class_exists('TCPDF')) {
361 $pdf->setPrintHeader(false);
362 $pdf->setPrintFooter(false);
363 }
364 $pdf->SetFont(pdf_getPDFFont($outputlangs));
365
366 // Set path to the background PDF File
367 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
368 $logodir = $conf->mycompany->dir_output;
369 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
370 $logodir = $conf->mycompany->multidir_output[$object->entity];
371 }
372 $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
373 $tplidx = $pdf->importPage(1);
374 }
375
376 $pdf->Open();
377 $pagenb = 0;
378 $pdf->SetDrawColor(128, 128, 128);
379
380 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
381 $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
382 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
383 $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
384 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
385 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
386 $pdf->SetCompression(false);
387 }
388
389 // Set certificate
390 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
391 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
392 // If user has no certificate, we try to take the company one
393 if (!$cert) {
394 $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
395 }
396 if (!$certprivate) {
397 $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE;
398 }
399 // If a certificate is found
400 if ($cert) {
401 $info = array(
402 'Name' => $this->emetteur->name,
403 'Location' => getCountry($this->emetteur->country_code, 0),
404 'Reason' => 'INVOICE',
405 'ContactInfo' => $this->emetteur->email
406 );
407 $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
408 }
409
410 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
411
412 // Set $this->atleastonediscount if you have at least one discount
413 // and determine category of operation
414 $categoryOfOperation = 0;
415 $nbProduct = 0;
416 $nbService = 0;
417 for ($i = 0; $i < $nblines; $i++) {
418 if ($object->lines[$i]->remise_percent) {
419 $this->atleastonediscount++;
420 }
421
422 // determine category of operation
423 if ($categoryOfOperation < 2) {
424 $lineProductType = $object->lines[$i]->product_type;
425 if ($lineProductType == Product::TYPE_PRODUCT) {
426 $nbProduct++;
427 } elseif ($lineProductType == Product::TYPE_SERVICE) {
428 $nbService++;
429 }
430 if ($nbProduct > 0 && $nbService > 0) {
431 // mixed products and services
432 $categoryOfOperation = 2;
433 }
434 }
435 }
436 // determine category of operation
437 if ($categoryOfOperation <= 0) {
438 // only services
439 if ($nbProduct == 0 && $nbService > 0) {
440 $categoryOfOperation = 1;
441 }
442 }
443 $this->categoryOfOperation = $categoryOfOperation;
444 if (empty($this->atleastonediscount)) { // retrieve space not used by discount
445 $delta = ($this->posxprogress - $this->posxdiscount);
446 $this->posxpicture += $delta;
447 $this->posxtva += $delta;
448 $this->posxup += $delta;
449 $this->posxqty += $delta;
450 $this->posxunit += $delta;
451 $this->posxdiscount += $delta;
452 // post of fields after are not modified, stay at same position
453 }
454
455 $progress_width = 0;
456 // Situation invoice handling
457 if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
458 $this->situationinvoice = true;
459 $progress_width = 10;
460 $this->posxpicture -= $progress_width;
461 $this->posxtva -= $progress_width;
462 $this->posxup -= $progress_width;
463 $this->posxqty -= $progress_width;
464 $this->posxunit -= $progress_width;
465 $this->posxdiscount -= $progress_width;
466 $this->posxprogress -= $progress_width;
467 }
468
469 // New page
470 $pdf->AddPage();
471 if (!empty($tplidx)) {
472 $pdf->useTemplate($tplidx);
473 }
474 $pagenb++;
475
476 // Output header (logo, ref and address blocks). This is first call for first page.
477 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
478 $pdf->SetFont('', '', $default_font_size - 1);
479 $pdf->MultiCell(0, 3, ''); // Set interline to 3
480 $pdf->SetTextColor(0, 0, 0);
481
482 // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
483
484 // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
485 $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
486 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
487
488 // You can add more thing under header here, if you increase $extra_under_address_shift too.
489 $extra_under_address_shift = 0;
490 $qrcodestring = '';
491 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
492 $qrcodestring = $object->buildZATCAQRString();
493 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
494 $qrcodestring = $object->buildSwitzerlandQRString();
495 }
496
497 if ($qrcodestring) {
498 $qrcodecolor = array('25', '25', '25');
499 // set style for QR-code
500 $styleQr = array(
501 'border' => false,
502 'padding' => 0,
503 'fgcolor' => $qrcodecolor,
504 'bgcolor' => false, //array(255,255,255)
505 'module_width' => 1, // width of a single module in points
506 'module_height' => 1 // height of a single module in points
507 );
508 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
509 $extra_under_address_shift += 25;
510 }
511
512 // Call hook printUnderHeaderPDFline
513 $parameters = array(
514 'object' => $object,
515 'i' => $i,
516 'pdf' =>& $pdf,
517 'outputlangs' => $outputlangs,
518 'hidedetails' => $hidedetails
519 );
520 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
521 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
522 $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
523 }
524
525 $tab_top += $extra_under_address_shift;
526 $tab_top_newpage += 0;
527
528 // Incoterm
529 $height_incoterms = 0;
530 if (isModEnabled('incoterm')) {
531 $desc_incoterms = $object->getIncotermsForPDF();
532 if ($desc_incoterms) {
533 $tab_top -= 2;
534
535 $pdf->SetFont('', '', $default_font_size - 1);
536 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
537 $nexY = $pdf->GetY();
538 $height_incoterms = $nexY - $tab_top;
539
540 // Rect takes a length in 3rd parameter
541 $pdf->SetDrawColor(192, 192, 192);
542 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
543
544 $tab_top = $nexY + 6;
545 }
546 }
547
548 // Display notes
549 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
550 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
551 // Get first sale rep
552 if (is_object($object->thirdparty)) {
553 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
554 $salerepobj = new User($this->db);
555 $salerepobj->fetch($salereparray[0]['id']);
556 if (!empty($salerepobj->signature)) {
557 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
558 }
559 }
560 }
561 // Extrafields in note
562 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
563 if (!empty($extranote)) {
564 $notetoshow = dol_concatdesc($notetoshow, $extranote);
565 }
566 if ($notetoshow) {
567 $tab_top -= 2;
568
569 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
570 complete_substitutions_array($substitutionarray, $outputlangs, $object);
571
572 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
573 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
574
575 $pdf->SetFont('', '', $default_font_size - 1);
576 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
577 $nexY = $pdf->GetY();
578 $height_note = $nexY - $tab_top;
579
580 // Rect takes a length in 3rd parameter
581 $pdf->SetDrawColor(192, 192, 192);
582 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
583
584 $tab_top = $nexY + 6;
585 }
586
587 $iniY = $tab_top + 7;
588 $curY = $tab_top + 7;
589 $nexY = $tab_top + 7;
590
591 // Loop on each lines
592 for ($i = 0; $i < $nblines; $i++) {
593 $curY = $nexY;
594 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
595 $pdf->SetTextColor(0, 0, 0);
596
597 // Define size of image if we need it
598 $imglinesize = array();
599 if (!empty($realpatharray[$i])) {
600 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
601 }
602
603 $pdf->setTopMargin($tab_top_newpage);
604 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
605 $pdf->setPageOrientation('', 1, $page_bottom_margin);
606 $pageposbefore = $pdf->getPage();
607
608 $showpricebeforepagebreak = 1;
609 $posYAfterImage = 0;
610 $posYAfterDescription = 0;
611
612 // We start with Photo of product line
613 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - $page_bottom_margin)) { // If photo too high, we moved completely on new page
614 $pdf->AddPage('', '', true);
615 if (!empty($tplidx)) {
616 $pdf->useTemplate($tplidx);
617 }
618 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
619 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
620 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
621 }
622 $pdf->setPage($pageposbefore + 1);
623
624 $curY = $tab_top_newpage;
625
626 // Allows data in the first page if description is long enough to break in multiples pages
627 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
628 $showpricebeforepagebreak = 1;
629 } else {
630 $showpricebeforepagebreak = 0;
631 }
632 }
633
634 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
635 $curX = $this->posxpicture - 1;
636 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
637 // $pdf->Image does not increase value return by getY, so we save it manually
638 $posYAfterImage = $curY + $imglinesize['height'];
639 }
640
641 // Description of product line
642 $curX = $this->posxdesc - 1;
643
644 $pdf->startTransaction();
645 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
646 $pageposafter = $pdf->getPage();
647 if ($pageposafter > $pageposbefore) { // There is a pagebreak
648 $pdf->rollbackTransaction(true);
649 $pageposafter = $pageposbefore;
650 //print $pageposafter.'-'.$pageposbefore;exit;
651 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
652 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
653 $pageposafter = $pdf->getPage();
654 $posyafter = $pdf->GetY();
655 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
656 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text
657 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
658 $pdf->AddPage('', '', true);
659 if (!empty($tplidx)) {
660 $pdf->useTemplate($tplidx);
661 }
662 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
663 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
664 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
665 }
666 $pdf->setPage($pageposafter + 1);
667 }
668 } else {
669 // We found a page break
670
671 // Allows data in the first page if description is long enough to break in multiples pages
672 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
673 $showpricebeforepagebreak = 1;
674 } else {
675 $showpricebeforepagebreak = 0;
676 }
677 }
678 } else // No pagebreak
679 {
680 $pdf->commitTransaction();
681 }
682 $posYAfterDescription = $pdf->GetY();
683
684 $nexY = $pdf->GetY();
685 $pageposafter = $pdf->getPage();
686 $pdf->setPage($pageposbefore);
687 $pdf->setTopMargin($this->marge_haute);
688 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
689
690 // We suppose that a too long description or photo were moved completely on next page
691 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
692 $pdf->setPage($pageposafter);
693 $curY = $tab_top_newpage;
694 }
695
696 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
697
698 // VAT Rate
699 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
700 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
701 $pdf->SetXY($this->posxtva - 5, $curY);
702 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
703 }
704
705 // Unit price before discount
706 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
707 $pdf->SetXY($this->posxup, $curY);
708 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
709
710 // Quantity
711 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
712 $pdf->SetXY($this->posxqty, $curY);
713 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
714
715 // Unit
716 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
717 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
718 $pdf->SetXY($this->posxunit, $curY);
719 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
720 }
721
722 // Discount on line
723 if ($object->lines[$i]->remise_percent) {
724 $pdf->SetXY($this->posxdiscount - 2, $curY);
725 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
726 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
727 }
728
729 // Situation progress
730 if ($this->situationinvoice) {
731 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
732 $pdf->SetXY($this->posxprogress, $curY);
733 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R');
734 }
735
736 // Total HT line
737 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
738 $pdf->SetXY($this->postotalht, $curY);
739 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
740
741
742 $sign = 1;
743 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
744 $sign = -1;
745 }
746 // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
747 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
748 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
749 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
750 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
751 } else {
752 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
753 }
754 } else {
755 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
756 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
757 } else {
758 $tvaligne = $sign * $object->lines[$i]->total_tva;
759 }
760 }
761
762 $localtax1ligne = $object->lines[$i]->total_localtax1;
763 $localtax2ligne = $object->lines[$i]->total_localtax2;
764 $localtax1_rate = $object->lines[$i]->localtax1_tx;
765 $localtax2_rate = $object->lines[$i]->localtax2_tx;
766 $localtax1_type = $object->lines[$i]->localtax1_type;
767 $localtax2_type = $object->lines[$i]->localtax2_type;
768
769 // TODO remise_percent is an obsolete field for object parent
770 /*if ($object->remise_percent) {
771 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
772 }
773 if ($object->remise_percent) {
774 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
775 }
776 if ($object->remise_percent) {
777 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
778 }*/
779
780 $vatrate = (string) $object->lines[$i]->tva_tx;
781
782 // Retrieve type from database for backward compatibility with old records
783 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
784 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
785 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
786 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
787 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
788 }
789
790 // retrieve global local tax
791 if ($localtax1_type && $localtax1ligne != 0) {
792 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
793 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
794 } else {
795 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
796 }
797 }
798 if ($localtax2_type && $localtax2ligne != 0) {
799 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
800 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
801 } else {
802 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
803 }
804 }
805
806 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
807 $vatrate .= '*';
808 }
809
810 // Fill $this->tva and $this->tva_array
811 if (!isset($this->tva[$vatrate])) {
812 $this->tva[$vatrate] = 0;
813 }
814 $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
815 $vatcode = $object->lines[$i]->vat_src_code;
816 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
817 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
818 }
819 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
820
821 if ($posYAfterImage > $posYAfterDescription) {
822 $nexY = $posYAfterImage;
823 }
824
825 // Add line
826 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
827 $pdf->setPage($pageposafter);
828 $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
829 //$pdf->SetDrawColor(190,190,200);
830 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
831 $pdf->SetLineStyle(array('dash'=>0));
832 }
833
834 $nexY += 2; // Add space between lines
835
836 // Detect if some page were added automatically and output _tableau for past pages
837 while ($pagenb < $pageposafter) {
838 $pdf->setPage($pagenb);
839 if ($pagenb == 1) {
840 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
841 } else {
842 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
843 }
844 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
845 $pagenb++;
846 $pdf->setPage($pagenb);
847 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
848 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
849 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
850 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
851 }
852 if (!empty($tplidx)) {
853 $pdf->useTemplate($tplidx);
854 }
855 }
856 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
857 if ($pagenb == 1) {
858 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
859 } else {
860 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
861 }
862 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
863 // New page
864 $pdf->AddPage();
865 if (!empty($tplidx)) {
866 $pdf->useTemplate($tplidx);
867 }
868 $pagenb++;
869 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
870 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
871 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
872 }
873 }
874 }
875
876 // Show square
877 if ($pagenb == 1) {
878 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
879 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
880 } else {
881 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
882 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
883 }
884 dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
885
886 // Display info area
887 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
888
889 // Display total area
890 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
891
892 // Display Payments area
893 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
894 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
895 }
896
897 // Pagefoot
898 $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs));
899 if (method_exists($pdf, 'AliasNbPages')) {
900 $pdf->AliasNbPages();
901 }
902
903 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
904 $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs);
905 if (!$result) {
906 $pdf->Close();
907 return 0;
908 }
909 }
910 $pdf->Close();
911
912 $pdf->Output($file, 'F');
913
914 // Add pdfgeneration hook
915 $hookmanager->initHooks(array('pdfgeneration'));
916 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
917 global $action;
918 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
919 if ($reshook < 0) {
920 $this->error = $hookmanager->error;
921 $this->errors = $hookmanager->errors;
922 }
923
924 dolChmod($file);
925
926 $this->result = array('fullpath'=>$file);
927
928 return 1; // No error
929 } else {
930 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
931 return 0;
932 }
933 } else {
934 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
935 return 0;
936 }
937 }
938
939
940 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
941 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
952 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
953 {
954 // phpcs:enable
955 global $conf;
956
957 $sign = 1;
958 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
959 $sign = -1;
960 }
961
962 $current_page = $pdf->getPage();
963 $tab3_posx = 120;
964 $tab3_top = $posy + 8;
965 $tab3_width = 80;
966 $tab3_height = 4;
967 if ($this->page_largeur < 210) { // To work with US executive format
968 $tab3_posx -= 15;
969 }
970
971 $default_font_size = pdf_getPDFFontSize($outputlangs);
972
973 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
974
975 $y = 0;
976
977 $pdf->SetFont('', '', $default_font_size - 4);
978
979
980 // Loop on each discount available (deposits and credit notes and excess of payment included)
981 $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,";
982 $sql .= " re.description, re.fk_facture_source,";
983 $sql .= " f.type, f.datef";
984 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
985 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
986 $resql = $this->db->query($sql);
987 if ($resql) {
988 $num = $this->db->num_rows($resql);
989 $i = 0;
990 $invoice = new Facture($this->db);
991 while ($i < $num) {
992 $y += 3;
993 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
994 $y = 0;
995 $current_page++;
996 $pdf->AddPage('', '', true);
997 if (!empty($tplidx)) {
998 $pdf->useTemplate($tplidx);
999 }
1000 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1001 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1002 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1003 }
1004 $pdf->setPage($current_page);
1005 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1006 }
1007
1008 $obj = $this->db->fetch_object($resql);
1009
1010 if ($obj->type == 2) {
1011 $text = $outputlangs->transnoentities("CreditNote");
1012 } elseif ($obj->type == 3) {
1013 $text = $outputlangs->transnoentities("Deposit");
1014 } elseif ($obj->type == 0) {
1015 $text = $outputlangs->transnoentities("ExcessReceived");
1016 } else {
1017 $text = $outputlangs->transnoentities("UnknownType");
1018 }
1019
1020 $invoice->fetch($obj->fk_facture_source);
1021
1022 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1023 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1024 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1025 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1026 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1027 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1028 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1029 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1030
1031 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1032
1033 $i++;
1034 }
1035 } else {
1036 $this->error = $this->db->lasterror();
1037 return -1;
1038 }
1039
1040 // Loop on each payment
1041 // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
1042 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1043 $sql .= " cp.code";
1044 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1045 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1046 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1047 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1048 $sql .= " ORDER BY p.datep";
1049
1050 $resql = $this->db->query($sql);
1051 if ($resql) {
1052 $num = $this->db->num_rows($resql);
1053 $i = 0;
1054 while ($i < $num) {
1055 $y += 3;
1056 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1057 $y = 0;
1058 $current_page++;
1059 $pdf->AddPage('', '', true);
1060 if (!empty($tplidx)) {
1061 $pdf->useTemplate($tplidx);
1062 }
1063 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1064 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1065 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1066 }
1067 $pdf->setPage($current_page);
1068 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1069 }
1070
1071 $row = $this->db->fetch_object($resql);
1072
1073 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1074 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1075 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1076 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1077 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1078 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1079
1080 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1081 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1082 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1083
1084 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1085
1086 $i++;
1087 }
1088
1089 return $tab3_top + $y + 3;
1090 } else {
1091 $this->error = $this->db->lasterror();
1092 return -1;
1093 }
1094 }
1095
1096 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1097 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1111 protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
1112 {
1113 // phpcs:enable
1114 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1115 if ($object->type == 2) {
1116 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1117 }
1118
1119 $pdf->SetFont('', '', $default_font_size - 3);
1120 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1121 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1122
1123 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1124
1125 $pdf->SetFont('', '', $default_font_size - 4);
1126 $pdf->SetXY($tab3_posx, $tab3_top);
1127 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1128 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1129 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1130 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1131 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1132 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1133 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1134
1135 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1136 }
1137
1138 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1139 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1150 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1151 {
1152 // phpcs:enable
1153 global $conf, $mysoc;
1154
1155 $default_font_size = pdf_getPDFFontSize($outputlangs);
1156
1157 $pdf->SetFont('', '', $default_font_size - 1);
1158
1159 // If France, show VAT mention if not applicable
1160 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1161 $pdf->SetFont('', 'B', $default_font_size - 2);
1162 $pdf->SetXY($this->marge_gauche, $posy);
1163 if ($mysoc->forme_juridique_code == 92) {
1164 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1165 } else {
1166 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1167 }
1168
1169 $posy = $pdf->GetY() + 4;
1170 }
1171
1172 $posxval = 52;
1173 $posxend = 110; // End of x for text on left side
1174 if ($this->page_largeur < 210) { // To work with US executive format
1175 $posxend -= 10;
1176 }
1177
1178 // Show payments conditions
1179 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1180 $pdf->SetFont('', 'B', $default_font_size - 2);
1181 $pdf->SetXY($this->marge_gauche, $posy);
1182 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1183 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1184
1185 $pdf->SetFont('', '', $default_font_size - 2);
1186 $pdf->SetXY($posxval, $posy);
1187 $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);
1188 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1189 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1190
1191 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1192 }
1193
1194 // Show category of operations
1195 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1196 $pdf->SetFont('', 'B', $default_font_size - 2);
1197 $pdf->SetXY($this->marge_gauche, $posy);
1198 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1199 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1200
1201 $pdf->SetFont('', '', $default_font_size - 2);
1202 $pdf->SetXY($posxval, $posy);
1203 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1204 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1205
1206 $posy = $pdf->GetY() + 3; // for 2 lines
1207 }
1208
1209 if ($object->type != 2) {
1210 // Check a payment mode is defined
1211 if (empty($object->mode_reglement_code)
1212 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1213 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1214 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1215 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1216 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1217 // Avoid having any valid PDF with setup that is not complete
1218 $outputlangs->load("errors");
1219
1220 $pdf->SetXY($this->marge_gauche, $posy);
1221 $pdf->SetTextColor(200, 0, 0);
1222 $pdf->SetFont('', 'B', $default_font_size - 2);
1223 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1224 $pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
1225 $pdf->SetTextColor(0, 0, 0);
1226
1227 $posy = $pdf->GetY() + 1;
1228 }
1229
1230 // Show payment mode
1231 if (!empty($object->mode_reglement_code)
1232 && $object->mode_reglement_code != 'CHQ'
1233 && $object->mode_reglement_code != 'VIR') {
1234 $pdf->SetFont('', 'B', $default_font_size - 2);
1235 $pdf->SetXY($this->marge_gauche, $posy);
1236 $titre = $outputlangs->transnoentities("PaymentMode").':';
1237 $pdf->MultiCell(80, 5, $titre, 0, 'L');
1238
1239 $pdf->SetFont('', '', $default_font_size - 2);
1240 $pdf->SetXY($posxval, $posy);
1241 $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);
1242 //#21654: add account number used for the debit
1243 if ($object->mode_reglement_code == "PRE") {
1244 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1245 $bac = new CompanyBankAccount($this->db);
1246 $bac->fetch(0, $object->thirdparty->id);
1247 $iban= $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1248 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1249 }
1250 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1251
1252 $posy = $pdf->GetY();
1253 }
1254
1255 // Show if Option VAT debit option is on also if transmitter is french
1256 // Decret n°2099-1299 2022-10-07
1257 // French mention : "Option pour le paiement de la taxe d'après les débits"
1258 if ($this->emetteur->country_code == 'FR') {
1259 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1260 $pdf->SetXY($this->marge_gauche, $posy);
1261 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1262
1263 $posy = $pdf->GetY() + 1;
1264 }
1265 }
1266
1267 // Show online payment link
1268 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1269 $useonlinepayment = 0;
1270 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1271 if (isModEnabled('paypal')) {
1272 $useonlinepayment++;
1273 }
1274 if (isModEnabled('stripe')) {
1275 $useonlinepayment++;
1276 }
1277 if (isModEnabled('paybox')) {
1278 $useonlinepayment++;
1279 }
1280 }
1281
1282 if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
1283 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1284 global $langs;
1285
1286 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1287 $servicename = $langs->transnoentities('Online');
1288 $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
1289 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1290
1291 $pdf->SetXY($this->marge_gauche, $posy);
1292 $pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1293
1294 $posy = $pdf->GetY() + 1;
1295 }
1296 }
1297
1298 // Show payment mode CHQ
1299 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1300 // If payment mode unregulated or payment mode forced to CHQ
1301 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1302 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1303
1304 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1305 $account = new Account($this->db);
1306 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1307
1308 $pdf->SetXY($this->marge_gauche, $posy);
1309 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1310 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1311 $posy = $pdf->GetY() + 1;
1312
1313 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1314 $pdf->SetXY($this->marge_gauche, $posy);
1315 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1316 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1317 $posy = $pdf->GetY() + 2;
1318 }
1319 }
1320 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1321 $pdf->SetXY($this->marge_gauche, $posy);
1322 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1323 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1324 $posy = $pdf->GetY() + 1;
1325
1326 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1327 $pdf->SetXY($this->marge_gauche, $posy);
1328 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1329 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1330 $posy = $pdf->GetY() + 2;
1331 }
1332 }
1333 }
1334 }
1335
1336 // If payment mode not forced or forced to VIR, show payment with BAN
1337 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1338 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1339 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1340 if ($object->fk_bank > 0) {
1341 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1342 }
1343 $account = new Account($this->db);
1344 $account->fetch($bankid);
1345
1346 $curx = $this->marge_gauche;
1347 $cury = $posy;
1348
1349 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1350
1351 $posy += 2;
1352 }
1353 }
1354 }
1355
1356 return $posy;
1357 }
1358
1359
1360 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1361 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1373 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1374 {
1375 // phpcs:enable
1376 global $conf, $mysoc, $hookmanager;
1377
1378 $sign = 1;
1379 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1380 $sign = -1;
1381 }
1382
1383 $default_font_size = pdf_getPDFFontSize($outputlangs);
1384
1385 $outputlangsbis = null;
1386 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1387 $outputlangsbis = new Translate('', $conf);
1388 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1389 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1390 $default_font_size--;
1391 }
1392
1393 $tab2_top = $posy;
1394 $tab2_hl = 4;
1395 $pdf->SetFont('', '', $default_font_size - 1);
1396
1397 // Total table
1398 $col1x = 120;
1399 $col2x = 170;
1400 if ($this->page_largeur < 210) { // To work with US executive format
1401 $col1x -= 15;
1402 $col2x -= 10;
1403 }
1404 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1405
1406 $useborder = 0;
1407 $index = 0;
1408
1409 // Total HT
1410 $pdf->SetFillColor(255, 255, 255);
1411 $pdf->SetXY($col1x, $tab2_top);
1412 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total") : ''), 0, 'L', 1);
1413
1414 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1415 $pdf->SetXY($col2x, $tab2_top);
1416 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1417
1418 // Show VAT by rates and total
1419 $pdf->SetFillColor(248, 248, 248);
1420
1421 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1422
1423 $this->atleastoneratenotnull = 0;
1424 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1425 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1426 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1427 // Nothing to do
1428 } else {
1429 //Local tax 1 before VAT
1430 //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1431 //{
1432 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1433 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1434 continue;
1435 }
1436
1437 foreach ($localtax_rate as $tvakey => $tvaval) {
1438 if ($tvakey != 0) { // On affiche pas taux 0
1439 //$this->atleastoneratenotnull++;
1440
1441 $index++;
1442 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1443
1444 $tvacompl = '';
1445 if (preg_match('/\*/', $tvakey)) {
1446 $tvakey = str_replace('*', '', $tvakey);
1447 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1448 }
1449
1450 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1451 $totalvat .= ' ';
1452 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1453 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1454
1455 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1456
1457 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1458 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1459 }
1460 }
1461 }
1462 //}
1463 //Local tax 2 before VAT
1464 //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1465 //{
1466 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1467 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1468 continue;
1469 }
1470
1471 foreach ($localtax_rate as $tvakey => $tvaval) {
1472 if ($tvakey != 0) { // On affiche pas taux 0
1473 //$this->atleastoneratenotnull++;
1474
1475 $index++;
1476 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1477
1478 $tvacompl = '';
1479 if (preg_match('/\*/', $tvakey)) {
1480 $tvakey = str_replace('*', '', $tvakey);
1481 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1482 }
1483 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1484 $totalvat .= ' ';
1485 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1486 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1487
1488 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1489
1490 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1491 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1492 }
1493 }
1494 }
1495
1496 //}
1497
1498 // VAT
1499 foreach ($this->tva_array as $tvakey => $tvaval) {
1500 if ($tvakey != 0) { // On affiche pas taux 0
1501 $this->atleastoneratenotnull++;
1502
1503 $index++;
1504 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1505
1506 $tvacompl = '';
1507 if (preg_match('/\*/', $tvakey)) {
1508 $tvakey = str_replace('*', '', $tvakey);
1509 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1510 }
1511 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1512 $totalvat .= ' ';
1513 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1514 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1515 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1516 $totalvat .= $tvaval['vatcode'].$tvacompl;
1517 } else {
1518 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1519 }
1520 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1521
1522 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1523 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1524 }
1525 }
1526
1527 //Local tax 1 after VAT
1528 //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1529 //{
1530 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1531 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1532 continue;
1533 }
1534
1535 foreach ($localtax_rate as $tvakey => $tvaval) {
1536 if ($tvakey != 0) { // On affiche pas taux 0
1537 //$this->atleastoneratenotnull++;
1538
1539 $index++;
1540 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1541
1542 $tvacompl = '';
1543 if (preg_match('/\*/', $tvakey)) {
1544 $tvakey = str_replace('*', '', $tvakey);
1545 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1546 }
1547 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1548 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1549
1550 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1551
1552 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1553
1554 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1555 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1556 }
1557 }
1558 }
1559 //}
1560 //Local tax 2 after VAT
1561 //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1562 //{
1563 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1564 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1565 continue;
1566 }
1567
1568 foreach ($localtax_rate as $tvakey => $tvaval) {
1569 //$this->atleastoneratenotnull++;
1570
1571 $index++;
1572 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1573
1574 $tvacompl = '';
1575 if (preg_match('/\*/', $tvakey)) {
1576 $tvakey = str_replace('*', '', $tvakey);
1577 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1578 }
1579 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1580
1581 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1582 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1583
1584 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1585
1586 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1587 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1588 }
1589 }
1590 //}
1591
1592 // Revenue stamp
1593 if (price2num($object->revenuestamp) != 0) {
1594 $index++;
1595 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1596 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1597
1598 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1599 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1600 }
1601
1602 // Total TTC
1603 $index++;
1604 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1605 $pdf->SetTextColor(0, 0, 60);
1606 $pdf->SetFillColor(224, 224, 224);
1607 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1608
1609 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1610 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1611
1612 // Retained warranty
1613 if ($object->displayRetainedWarranty()) {
1614 $pdf->SetTextColor(40, 40, 40);
1615 $pdf->SetFillColor(255, 255, 255);
1616
1617 $retainedWarranty = $object->getRetainedWarrantyAmount();
1618 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1619
1620 // Billed - retained warranty
1621 $index++;
1622 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1623 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1624
1625 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1626 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1627
1628 // retained warranty
1629 $index++;
1630 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1631
1632 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
1633 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1634
1635 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1636 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1637 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1638 }
1639 }
1640 }
1641
1642 $pdf->SetTextColor(0, 0, 0);
1643 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1644 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1645 //print "x".$creditnoteamount."-".$depositsamount;exit;
1646 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1647 if (!empty($object->paye)) {
1648 $resteapayer = 0;
1649 }
1650
1651 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1652 // Already paid + Deposits
1653 $index++;
1654 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1656 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1657 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1658
1659 // Credit note
1660 if ($creditnoteamount) {
1661 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1662 $index++;
1663 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1664 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1665 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1666 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1667 }
1668
1669 // Escompte
1670 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1671 $index++;
1672 $pdf->SetFillColor(255, 255, 255);
1673
1674 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1675 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1676 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1677 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1678
1679 $resteapayer = 0;
1680 }
1681
1682 $index++;
1683 $pdf->SetTextColor(0, 0, 60);
1684 $pdf->SetFillColor(224, 224, 224);
1685 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1687 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1688 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1689
1690 $pdf->SetFont('', '', $default_font_size - 1);
1691 $pdf->SetTextColor(0, 0, 0);
1692 }
1693
1694 $index++;
1695 return ($tab2_top + ($tab2_hl * $index));
1696 }
1697
1698 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1712 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1713 {
1714 global $conf;
1715
1716 // Force to disable hidetop and hidebottom
1717 $hidebottom = 0;
1718 if ($hidetop) {
1719 $hidetop = -1;
1720 }
1721
1722 $currency = !empty($currency) ? $currency : $conf->currency;
1723 $default_font_size = pdf_getPDFFontSize($outputlangs);
1724
1725 // Amount in (at tab_top - 1)
1726 $pdf->SetTextColor(0, 0, 0);
1727 $pdf->SetFont('', '', $default_font_size - 2);
1728
1729 if (empty($hidetop)) {
1730 // Show category of operations
1731 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1732 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1733 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1734 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1735 }
1736
1737 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1738 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1739 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1740
1741 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1742 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1743 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1744 }
1745 }
1746
1747 $pdf->SetDrawColor(128, 128, 128);
1748 $pdf->SetFont('', '', $default_font_size - 1);
1749
1750 // Output Rect
1751 $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
1752
1753 if (empty($hidetop)) {
1754 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
1755
1756 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1757 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1758 }
1759
1760 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1761 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1762 if (empty($hidetop)) {
1763 //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1764 //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1765 }
1766 }
1767
1768 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1769 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1770 if (empty($hidetop)) {
1771 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1772 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1773 }
1774 }
1775
1776 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1777 if (empty($hidetop)) {
1778 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1779 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1780 }
1781
1782 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1783 if (empty($hidetop)) {
1784 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1785 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1786 }
1787
1788 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1789 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1790 if (empty($hidetop)) {
1791 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1792 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1793 }
1794 }
1795
1796 if ($this->atleastonediscount) {
1797 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1798 if (empty($hidetop)) {
1799 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1800 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1801 }
1802 }
1803
1804 if ($this->situationinvoice) {
1805 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1806 if (empty($hidetop)) {
1807 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1808 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("ProgressShort"), '', 'C');
1809 }
1810 }
1811
1812 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1813 if (empty($hidetop)) {
1814 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1815 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1816 }
1817 }
1818
1819 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1830 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
1831 {
1832 global $conf, $langs;
1833
1834 $ltrdirection = 'L';
1835 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
1836
1837 // Load traductions files required by page
1838 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1839
1840 $default_font_size = pdf_getPDFFontSize($outputlangs);
1841
1842 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1843
1844 $pdf->SetTextColor(0, 0, 60);
1845 $pdf->SetFont('', 'B', $default_font_size + 3);
1846
1847 $w = 110;
1848
1849 $posy = $this->marge_haute;
1850 $posx = $this->page_largeur - $this->marge_droite - $w;
1851
1852 $pdf->SetXY($this->marge_gauche, $posy);
1853
1854 // Logo
1855 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1856 if ($this->emetteur->logo) {
1857 $logodir = $conf->mycompany->dir_output;
1858 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1859 $logodir = $conf->mycompany->multidir_output[$object->entity];
1860 }
1861 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1862 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1863 } else {
1864 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1865 }
1866 if (is_readable($logo)) {
1867 $height = pdf_getHeightForLogo($logo);
1868 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1869 } else {
1870 $pdf->SetTextColor(200, 0, 0);
1871 $pdf->SetFont('', 'B', $default_font_size - 2);
1872 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1873 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1874 }
1875 } else {
1876 $text = $this->emetteur->name;
1877 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1878 }
1879 }
1880
1881 $pdf->SetFont('', 'B', $default_font_size + 3);
1882 $pdf->SetXY($posx, $posy);
1883 $pdf->SetTextColor(0, 0, 60);
1884 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1885 if ($object->type == 1) {
1886 $title = $outputlangs->transnoentities("InvoiceReplacement");
1887 }
1888 if ($object->type == 2) {
1889 $title = $outputlangs->transnoentities("InvoiceAvoir");
1890 }
1891 if ($object->type == 3) {
1892 $title = $outputlangs->transnoentities("InvoiceDeposit");
1893 }
1894 if ($object->type == 4) {
1895 $title = $outputlangs->transnoentities("InvoiceProForma");
1896 }
1897 if ($this->situationinvoice) {
1898 $langs->loadLangs(array("other"));
1899 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
1900 }
1901 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1902 $title .= ' - ';
1903 if ($object->type == 0) {
1904 if ($this->situationinvoice) {
1905 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
1906 }
1907 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
1908 } elseif ($object->type == 1) {
1909 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
1910 } elseif ($object->type == 2) {
1911 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
1912 } elseif ($object->type == 3) {
1913 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
1914 } elseif ($object->type == 4) {
1915 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
1916 }
1917 }
1918 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1919 if ($object->statut == $object::STATUS_DRAFT) {
1920 $pdf->SetTextColor(128, 0, 0);
1921 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1922 }
1923
1924 $pdf->MultiCell($w, 3, $title, '', 'R');
1925
1926 $pdf->SetFont('', 'B', $default_font_size);
1927
1928 /*
1929 $posy += 5;
1930 $pdf->SetXY($posx, $posy);
1931 $pdf->SetTextColor(0, 0, 60);
1932 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1933 if ($object->statut == $object::STATUS_DRAFT) {
1934 $pdf->SetTextColor(128, 0, 0);
1935 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1936 }
1937 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
1938
1939 $posy += 3;
1940 $pdf->SetFont('', '', $default_font_size - 2);
1941
1942 if ($object->ref_customer) {
1943 $posy += 4;
1944 $pdf->SetXY($posx, $posy);
1945 $pdf->SetTextColor(0, 0, 60);
1946 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_customer), '', 'R');
1947 }
1948
1949 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1950 $object->fetch_projet();
1951 if (!empty($object->project->ref)) {
1952 $posy += 3;
1953 $pdf->SetXY($posx, $posy);
1954 $pdf->SetTextColor(0, 0, 60);
1955 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1956 }
1957 }
1958
1959 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1960 $object->fetch_projet();
1961 if (!empty($object->project->ref)) {
1962 $outputlangs->load("projects");
1963 $posy += 3;
1964 $pdf->SetXY($posx, $posy);
1965 $pdf->SetTextColor(0, 0, 60);
1966 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1967 }
1968 }
1969
1970 $objectidnext = $object->getIdReplacingInvoice('validated');
1971 if ($object->type == 0 && $objectidnext) {
1972 $objectreplacing = new Facture($this->db);
1973 $objectreplacing->fetch($objectidnext);
1974
1975 $posy += 3;
1976 $pdf->SetXY($posx, $posy);
1977 $pdf->SetTextColor(0, 0, 60);
1978 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1979 }
1980 if ($object->type == 1) {
1981 $objectreplaced = new Facture($this->db);
1982 $objectreplaced->fetch($object->fk_facture_source);
1983
1984 $posy += 4;
1985 $pdf->SetXY($posx, $posy);
1986 $pdf->SetTextColor(0, 0, 60);
1987 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1988 }
1989 if ($object->type == 2 && !empty($object->fk_facture_source)) {
1990 $objectreplaced = new Facture($this->db);
1991 $objectreplaced->fetch($object->fk_facture_source);
1992
1993 $posy += 3;
1994 $pdf->SetXY($posx, $posy);
1995 $pdf->SetTextColor(0, 0, 60);
1996 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1997 }
1998
1999 $posy += 4;
2000 $pdf->SetXY($posx, $posy);
2001 $pdf->SetTextColor(0, 0, 60);
2002 $title = $outputlangs->transnoentities("DateInvoice");
2003 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2004 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2005 }
2006 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2007
2008 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2009 $posy += 4;
2010 $pdf->SetXY($posx, $posy);
2011 $pdf->SetTextColor(0, 0, 60);
2012 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2013 }
2014
2015 if ($object->type != 2) {
2016 $posy += 3;
2017 $pdf->SetXY($posx, $posy);
2018 $pdf->SetTextColor(0, 0, 60);
2019 $title = $outputlangs->transnoentities("DateDue");
2020 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2021 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2022 }
2023 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2024 }
2025
2026 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2027 $posy += 3;
2028 $pdf->SetXY($posx, $posy);
2029 $pdf->SetTextColor(0, 0, 60);
2030 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2031 }
2032
2033 // Get contact
2034 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2035 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2036 if (count($arrayidcontact) > 0) {
2037 $usertmp = new User($this->db);
2038 $usertmp->fetch($arrayidcontact[0]);
2039 $posy += 4;
2040 $pdf->SetXY($posx, $posy);
2041 $pdf->SetTextColor(0, 0, 60);
2042 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2043 }
2044 }
2045
2046 $posy += 1;
2047
2048 $top_shift = 0;
2049 // Show list of linked objects
2050 $current_y = $pdf->getY();
2051 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2052 if ($current_y < $pdf->getY()) {
2053 $top_shift = $pdf->getY() - $current_y;
2054 }
2055
2056 if ($showaddress) {
2057 // Sender properties
2058 $carac_emetteur = '';
2059 // Add internal contact of object if defined
2060 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2061 if (count($arrayidcontact) > 0) {
2062 $object->fetch_user($arrayidcontact[0]);
2063 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2064 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2065 $carac_emetteur .= "\n";
2066 }
2067
2068 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2069
2070 // Show sender
2071 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2072 $posy += $top_shift;
2073 $posx = $this->marge_gauche;
2074 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2075 $posx = $this->page_largeur - $this->marge_droite - 80;
2076 }
2077
2078 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2079 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2080
2081
2082 // Show sender frame
2083 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2084 $pdf->SetTextColor(0, 0, 0);
2085 $pdf->SetFont('', '', $default_font_size - 2);
2086 $pdf->SetXY($posx, $posy - 5);
2087 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2088 $pdf->SetXY($posx, $posy);
2089 $pdf->SetFillColor(230, 230, 230);
2090 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2091 $pdf->SetTextColor(0, 0, 60);
2092 }
2093
2094 // Show sender name
2095 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2096 $pdf->SetXY($posx + 2, $posy + 3);
2097 $pdf->SetFont('', 'B', $default_font_size);
2098 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2099 $posy = $pdf->getY();
2100 }
2101
2102 // Show sender information
2103 $pdf->SetXY($posx + 2, $posy);
2104 $pdf->SetFont('', '', $default_font_size - 1);
2105 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2106
2107
2108 // If BILLING contact defined on invoice, we use it
2109 $usecontact = false;
2110 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2111 if (count($arrayidcontact) > 0) {
2112 $usecontact = true;
2113 $result = $object->fetch_contact($arrayidcontact[0]);
2114 }
2115
2116 // Recipient name
2117 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
2118 $thirdparty = $object->contact;
2119 } else {
2120 $thirdparty = $object->thirdparty;
2121 }
2122
2123 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2124
2125 $mode = 'target';
2126 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2127
2128 // Show recipient
2129 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2130 if ($this->page_largeur < 210) {
2131 $widthrecbox = 84; // To work with US executive format
2132 }
2133 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2134 $posy += $top_shift;
2135 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2136 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2137 $posx = $this->marge_gauche;
2138 }
2139
2140 // Show recipient frame
2141 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2142 $pdf->SetTextColor(0, 0, 0);
2143 $pdf->SetFont('', '', $default_font_size - 2);
2144 $pdf->SetXY($posx + 2, $posy - 5);
2145 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2146 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2147 }
2148
2149 // Show recipient name
2150 $pdf->SetXY($posx + 2, $posy + 3);
2151 $pdf->SetFont('', 'B', $default_font_size);
2152 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2153
2154 $posy = $pdf->getY();
2155
2156 // Show recipient information
2157 $pdf->SetFont('', '', $default_font_size - 1);
2158 $pdf->SetXY($posx + 2, $posy);
2159 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2160
2161 // Show shipping address
2162 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2163 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2164
2165 if (!empty($idaddressshipping)) {
2166 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2167 $companystatic = new Societe($this->db);
2168 $companystatic->fetch($object->contact->fk_soc);
2169 $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs);
2170 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2171 } else {
2172 $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2173 $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2174 }
2175 if (!empty($carac_client_shipping)) {
2176 $posy += $hautcadre;
2177
2178 // Show shipping frame
2179 $pdf->SetXY($posx + 2, $posy - 5);
2180 $pdf->SetFont('', '', $default_font_size - 2);
2181 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2182 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2183
2184 // Show shipping name
2185 $pdf->SetXY($posx + 2, $posy + 3);
2186 $pdf->SetFont('', 'B', $default_font_size);
2187 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2188
2189 $posy = $pdf->getY();
2190
2191 // Show shipping information
2192 $pdf->SetXY($posx+2, $posy);
2193 $pdf->SetFont('', '', $default_font_size - 1);
2194 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2195 $top_shift += $hautcadre;
2196 }
2197 }
2198 }
2199
2200 $pdf->SetTextColor(0, 0, 0);
2201 return $top_shift;
2202 }
2203
2204 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2215 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2216 {
2217 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2218 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $heightforqrinvoice + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2219 }
2220}
Class to manage bank accounts.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
Class to manage hooks.
Parent class of invoice document generators.
addBottomQRInvoice(TCPDF $pdf, Facture $object, Translate $langs)
Add SwissQR invoice at bottom of page 1.
getHeightForQRInvoice(int $pagenbr, Facture $object, Translate $langs)
Get the height for bottom-page QR invoice in mm, depending on the page number.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class to generate the customer invoice PDF with template Crabe.
__construct($db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
_tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0, $heightforqrinvoice=0)
Show footer of page.
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
Function _tableau_versements_header.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $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 formated for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_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:2529
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2284
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:85
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition pdf.lib.php:1374
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
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:1010
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:1901
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2233
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1839
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition pdf.lib.php:2147
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:726
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1338
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition pdf.lib.php:833
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition pdf.lib.php:435
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2190
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:1986
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:758
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:387
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123