dolibarr 18.0.8
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 $is_deposit = false;
424 if (preg_match('/^\‍((.*)\‍)$/', $object->lines[$i]->desc, $reg)) {
425 if ($reg[1] == 'DEPOSIT') {
426 $is_deposit = true;
427 }
428 }
429 // If DEPOSIT, this line is completely ignored for calculations.
430 if ($is_deposit) {
431 continue;
432 }
433
434
435 // determine category of operation
436 if ($categoryOfOperation < 2) {
437 $lineProductType = $object->lines[$i]->product_type;
438 if ($lineProductType == Product::TYPE_PRODUCT) {
439 $nbProduct++;
440 } elseif ($lineProductType == Product::TYPE_SERVICE) {
441 $nbService++;
442 }
443 if ($nbProduct > 0 && $nbService > 0) {
444 // mixed products and services
445 $categoryOfOperation = 2;
446 }
447 }
448 }
449 // determine category of operation
450 if ($categoryOfOperation <= 0) {
451 // only services
452 if ($nbProduct == 0 && $nbService > 0) {
453 $categoryOfOperation = 1;
454 }
455 }
456 $this->categoryOfOperation = $categoryOfOperation;
457 if (empty($this->atleastonediscount)) { // retrieve space not used by discount
458 $delta = ($this->posxprogress - $this->posxdiscount);
459 $this->posxpicture += $delta;
460 $this->posxtva += $delta;
461 $this->posxup += $delta;
462 $this->posxqty += $delta;
463 $this->posxunit += $delta;
464 $this->posxdiscount += $delta;
465 // post of fields after are not modified, stay at same position
466 }
467
468 $progress_width = 0;
469 // Situation invoice handling
470 if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
471 $this->situationinvoice = true;
472 $progress_width = 10;
473 $this->posxpicture -= $progress_width;
474 $this->posxtva -= $progress_width;
475 $this->posxup -= $progress_width;
476 $this->posxqty -= $progress_width;
477 $this->posxunit -= $progress_width;
478 $this->posxdiscount -= $progress_width;
479 $this->posxprogress -= $progress_width;
480 }
481
482 // New page
483 $pdf->AddPage();
484 if (!empty($tplidx)) {
485 $pdf->useTemplate($tplidx);
486 }
487 $pagenb++;
488
489 // Output header (logo, ref and address blocks). This is first call for first page.
490 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
491 $pdf->SetFont('', '', $default_font_size - 1);
492 $pdf->MultiCell(0, 3, ''); // Set interline to 3
493 $pdf->SetTextColor(0, 0, 0);
494
495 // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
496
497 // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
498 $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
499 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
500
501 // You can add more thing under header here, if you increase $extra_under_address_shift too.
502 $extra_under_address_shift = 0;
503 $qrcodestring = '';
504 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
505 $qrcodestring = $object->buildZATCAQRString();
506 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
507 $qrcodestring = $object->buildSwitzerlandQRString();
508 }
509
510 if ($qrcodestring) {
511 $qrcodecolor = array('25', '25', '25');
512 // set style for QR-code
513 $styleQr = array(
514 'border' => false,
515 'padding' => 0,
516 'fgcolor' => $qrcodecolor,
517 'bgcolor' => false, //array(255,255,255)
518 'module_width' => 1, // width of a single module in points
519 'module_height' => 1 // height of a single module in points
520 );
521 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
522 $extra_under_address_shift += 25;
523 }
524
525 // Call hook printUnderHeaderPDFline
526 $parameters = array(
527 'object' => $object,
528 'i' => $i,
529 'pdf' =>& $pdf,
530 'outputlangs' => $outputlangs,
531 'hidedetails' => $hidedetails
532 );
533 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
534 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
535 $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
536 }
537
538 $tab_top += $extra_under_address_shift;
539 $tab_top_newpage += 0;
540
541 // Incoterm
542 $height_incoterms = 0;
543 if (isModEnabled('incoterm')) {
544 $desc_incoterms = $object->getIncotermsForPDF();
545 if ($desc_incoterms) {
546 $tab_top -= 2;
547
548 $pdf->SetFont('', '', $default_font_size - 1);
549 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
550 $nexY = $pdf->GetY();
551 $height_incoterms = $nexY - $tab_top;
552
553 // Rect takes a length in 3rd parameter
554 $pdf->SetDrawColor(192, 192, 192);
555 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
556
557 $tab_top = $nexY + 6;
558 }
559 }
560
561 // Display notes
562 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
563 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
564 // Get first sale rep
565 if (is_object($object->thirdparty)) {
566 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
567 $salerepobj = new User($this->db);
568 $salerepobj->fetch($salereparray[0]['id']);
569 if (!empty($salerepobj->signature)) {
570 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
571 }
572 }
573 }
574 // Extrafields in note
575 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
576 if (!empty($extranote)) {
577 $notetoshow = dol_concatdesc($notetoshow, $extranote);
578 }
579 if ($notetoshow) {
580 $tab_top -= 2;
581
582 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
583 complete_substitutions_array($substitutionarray, $outputlangs, $object);
584
585 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
586 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
587
588 $pdf->SetFont('', '', $default_font_size - 1);
589 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
590 $nexY = $pdf->GetY();
591 $height_note = $nexY - $tab_top;
592
593 // Rect takes a length in 3rd parameter
594 $pdf->SetDrawColor(192, 192, 192);
595 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
596
597 $tab_top = $nexY + 6;
598 }
599
600 $iniY = $tab_top + 7;
601 $curY = $tab_top + 7;
602 $nexY = $tab_top + 7;
603
604 // Loop on each lines
605 for ($i = 0; $i < $nblines; $i++) {
606 $curY = $nexY;
607 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
608 $pdf->SetTextColor(0, 0, 0);
609
610 // Define size of image if we need it
611 $imglinesize = array();
612 if (!empty($realpatharray[$i])) {
613 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
614 }
615
616 $pdf->setTopMargin($tab_top_newpage);
617 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
618 $pdf->setPageOrientation('', 1, $page_bottom_margin);
619 $pageposbefore = $pdf->getPage();
620
621 $showpricebeforepagebreak = 1;
622 $posYAfterImage = 0;
623 $posYAfterDescription = 0;
624
625 // We start with Photo of product line
626 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
627 $pdf->AddPage('', '', true);
628 if (!empty($tplidx)) {
629 $pdf->useTemplate($tplidx);
630 }
631 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
632 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
633 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
634 }
635 $pdf->setPage($pageposbefore + 1);
636
637 $curY = $tab_top_newpage;
638
639 // Allows data in the first page if description is long enough to break in multiples pages
640 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
641 $showpricebeforepagebreak = 1;
642 } else {
643 $showpricebeforepagebreak = 0;
644 }
645 }
646
647 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
648 $curX = $this->posxpicture - 1;
649 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
650 // $pdf->Image does not increase value return by getY, so we save it manually
651 $posYAfterImage = $curY + $imglinesize['height'];
652 }
653
654 // Description of product line
655 $curX = $this->posxdesc - 1;
656
657 $pdf->startTransaction();
658 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
659 $pageposafter = $pdf->getPage();
660 if ($pageposafter > $pageposbefore) { // There is a pagebreak
661 $pdf->rollbackTransaction(true);
662 $pageposafter = $pageposbefore;
663 //print $pageposafter.'-'.$pageposbefore;exit;
664 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
665 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
666 $pageposafter = $pdf->getPage();
667 $posyafter = $pdf->GetY();
668 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
669 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text
670 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
671 $pdf->AddPage('', '', true);
672 if (!empty($tplidx)) {
673 $pdf->useTemplate($tplidx);
674 }
675 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
676 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
677 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
678 }
679 $pdf->setPage($pageposafter + 1);
680 }
681 } else {
682 // We found a page break
683
684 // Allows data in the first page if description is long enough to break in multiples pages
685 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
686 $showpricebeforepagebreak = 1;
687 } else {
688 $showpricebeforepagebreak = 0;
689 }
690 }
691 } else // No pagebreak
692 {
693 $pdf->commitTransaction();
694 }
695 $posYAfterDescription = $pdf->GetY();
696
697 $nexY = $pdf->GetY();
698 $pageposafter = $pdf->getPage();
699 $pdf->setPage($pageposbefore);
700 $pdf->setTopMargin($this->marge_haute);
701 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
702
703 // We suppose that a too long description or photo were moved completely on next page
704 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
705 $pdf->setPage($pageposafter);
706 $curY = $tab_top_newpage;
707 }
708
709 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
710
711 // VAT Rate
712 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
713 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
714 $pdf->SetXY($this->posxtva - 5, $curY);
715 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
716 }
717
718 // Unit price before discount
719 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
720 $pdf->SetXY($this->posxup, $curY);
721 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
722
723 // Quantity
724 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
725 $pdf->SetXY($this->posxqty, $curY);
726 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
727
728 // Unit
729 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
730 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
731 $pdf->SetXY($this->posxunit, $curY);
732 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
733 }
734
735 // Discount on line
736 if ($object->lines[$i]->remise_percent) {
737 $pdf->SetXY($this->posxdiscount - 2, $curY);
738 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
739 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
740 }
741
742 // Situation progress
743 if ($this->situationinvoice) {
744 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
745 $pdf->SetXY($this->posxprogress, $curY);
746 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R');
747 }
748
749 // Total HT line
750 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
751 $pdf->SetXY($this->postotalht, $curY);
752 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
753
754
755 $sign = 1;
756 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
757 $sign = -1;
758 }
759 // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
760 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
761 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
762 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
763 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
764 } else {
765 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
766 }
767 } else {
768 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
769 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
770 } else {
771 $tvaligne = $sign * $object->lines[$i]->total_tva;
772 }
773 }
774
775 $localtax1ligne = $object->lines[$i]->total_localtax1;
776 $localtax2ligne = $object->lines[$i]->total_localtax2;
777 $localtax1_rate = $object->lines[$i]->localtax1_tx;
778 $localtax2_rate = $object->lines[$i]->localtax2_tx;
779 $localtax1_type = $object->lines[$i]->localtax1_type;
780 $localtax2_type = $object->lines[$i]->localtax2_type;
781
782 // TODO remise_percent is an obsolete field for object parent
783 /*if ($object->remise_percent) {
784 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
785 }
786 if ($object->remise_percent) {
787 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
788 }
789 if ($object->remise_percent) {
790 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
791 }*/
792
793 $vatrate = (string) $object->lines[$i]->tva_tx;
794
795 // Retrieve type from database for backward compatibility with old records
796 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
797 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
798 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
799 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
800 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
801 }
802
803 // retrieve global local tax
804 if ($localtax1_type && $localtax1ligne != 0) {
805 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
806 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
807 } else {
808 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
809 }
810 }
811 if ($localtax2_type && $localtax2ligne != 0) {
812 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
813 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
814 } else {
815 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
816 }
817 }
818
819 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
820 $vatrate .= '*';
821 }
822
823 // Fill $this->tva and $this->tva_array
824 if (!isset($this->tva[$vatrate])) {
825 $this->tva[$vatrate] = 0;
826 }
827 $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
828 $vatcode = $object->lines[$i]->vat_src_code;
829 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
830 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
831 }
832 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
833
834 if ($posYAfterImage > $posYAfterDescription) {
835 $nexY = $posYAfterImage;
836 }
837
838 // Add line
839 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
840 $pdf->setPage($pageposafter);
841 $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
842 //$pdf->SetDrawColor(190,190,200);
843 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
844 $pdf->SetLineStyle(array('dash'=>0));
845 }
846
847 $nexY += 2; // Add space between lines
848
849 // Detect if some page were added automatically and output _tableau for past pages
850 while ($pagenb < $pageposafter) {
851 $pdf->setPage($pagenb);
852 if ($pagenb == 1) {
853 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
854 } else {
855 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
856 }
857 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
858 $pagenb++;
859 $pdf->setPage($pagenb);
860 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
861 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
862 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
863 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
864 }
865 if (!empty($tplidx)) {
866 $pdf->useTemplate($tplidx);
867 }
868 }
869 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
870 if ($pagenb == 1) {
871 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
872 } else {
873 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
874 }
875 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
876 // New page
877 $pdf->AddPage();
878 if (!empty($tplidx)) {
879 $pdf->useTemplate($tplidx);
880 }
881 $pagenb++;
882 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
883 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
884 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
885 }
886 }
887 }
888
889 // Show square
890 if ($pagenb == 1) {
891 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
892 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
893 } else {
894 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
895 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
896 }
897 dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
898
899 // Display info area
900 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
901
902 // Display total area
903 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
904
905 // Display Payments area
906 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
907 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
908 }
909
910 // Pagefoot
911 $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs));
912 if (method_exists($pdf, 'AliasNbPages')) {
913 $pdf->AliasNbPages();
914 }
915
916 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
917 $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs);
918 if (!$result) {
919 $pdf->Close();
920 return 0;
921 }
922 }
923 $pdf->Close();
924
925 $pdf->Output($file, 'F');
926
927 // Add pdfgeneration hook
928 $hookmanager->initHooks(array('pdfgeneration'));
929 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
930 global $action;
931 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
932 if ($reshook < 0) {
933 $this->error = $hookmanager->error;
934 $this->errors = $hookmanager->errors;
935 }
936
937 dolChmod($file);
938
939 $this->result = array('fullpath'=>$file);
940
941 return 1; // No error
942 } else {
943 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
944 return 0;
945 }
946 } else {
947 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
948 return 0;
949 }
950 }
951
952
953 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
954 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
965 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
966 {
967 // phpcs:enable
968 global $conf;
969
970 $sign = 1;
971 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
972 $sign = -1;
973 }
974
975 $current_page = $pdf->getPage();
976 $tab3_posx = 120;
977 $tab3_top = $posy + 8;
978 $tab3_width = 80;
979 $tab3_height = 4;
980 if ($this->page_largeur < 210) { // To work with US executive format
981 $tab3_posx -= 15;
982 }
983
984 $default_font_size = pdf_getPDFFontSize($outputlangs);
985
986 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
987
988 $y = 0;
989
990 $pdf->SetFont('', '', $default_font_size - 4);
991
992
993 // Loop on each discount available (deposits and credit notes and excess of payment included)
994 $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,";
995 $sql .= " re.description, re.fk_facture_source,";
996 $sql .= " f.type, f.datef";
997 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
998 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
999 $resql = $this->db->query($sql);
1000 if ($resql) {
1001 $num = $this->db->num_rows($resql);
1002 $i = 0;
1003 $invoice = new Facture($this->db);
1004 while ($i < $num) {
1005 $y += 3;
1006 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1007 $y = 0;
1008 $current_page++;
1009 $pdf->AddPage('', '', true);
1010 if (!empty($tplidx)) {
1011 $pdf->useTemplate($tplidx);
1012 }
1013 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1014 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1015 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1016 }
1017 $pdf->setPage($current_page);
1018 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1019 }
1020
1021 $obj = $this->db->fetch_object($resql);
1022
1023 if ($obj->type == 2) {
1024 $text = $outputlangs->transnoentities("CreditNote");
1025 } elseif ($obj->type == 3) {
1026 $text = $outputlangs->transnoentities("Deposit");
1027 } elseif ($obj->type == 0) {
1028 $text = $outputlangs->transnoentities("ExcessReceived");
1029 } else {
1030 $text = $outputlangs->transnoentities("UnknownType");
1031 }
1032
1033 $invoice->fetch($obj->fk_facture_source);
1034
1035 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1036 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1037 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1038 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1039 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1040 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1041 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1042 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1043
1044 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1045
1046 $i++;
1047 }
1048 } else {
1049 $this->error = $this->db->lasterror();
1050 return -1;
1051 }
1052
1053 // Loop on each payment
1054 // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
1055 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1056 $sql .= " cp.code";
1057 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1058 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1059 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1060 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1061 $sql .= " ORDER BY p.datep";
1062
1063 $resql = $this->db->query($sql);
1064 if ($resql) {
1065 $num = $this->db->num_rows($resql);
1066 $i = 0;
1067 while ($i < $num) {
1068 $y += 3;
1069 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1070 $y = 0;
1071 $current_page++;
1072 $pdf->AddPage('', '', true);
1073 if (!empty($tplidx)) {
1074 $pdf->useTemplate($tplidx);
1075 }
1076 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1077 $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1078 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1079 }
1080 $pdf->setPage($current_page);
1081 $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1082 }
1083
1084 $row = $this->db->fetch_object($resql);
1085
1086 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1087 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1088 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1089 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1090 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1091 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1092
1093 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1094 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1095 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1096
1097 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1098
1099 $i++;
1100 }
1101
1102 return $tab3_top + $y + 3;
1103 } else {
1104 $this->error = $this->db->lasterror();
1105 return -1;
1106 }
1107 }
1108
1109 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1110 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1124 protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
1125 {
1126 // phpcs:enable
1127 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1128 if ($object->type == 2) {
1129 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1130 }
1131
1132 $pdf->SetFont('', '', $default_font_size - 3);
1133 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1134 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1135
1136 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1137
1138 $pdf->SetFont('', '', $default_font_size - 4);
1139 $pdf->SetXY($tab3_posx, $tab3_top);
1140 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1141 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1142 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1143 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1144 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1145 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1146 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1147
1148 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1149 }
1150
1151 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1152 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1163 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1164 {
1165 // phpcs:enable
1166 global $conf, $mysoc;
1167
1168 $default_font_size = pdf_getPDFFontSize($outputlangs);
1169
1170 $pdf->SetFont('', '', $default_font_size - 1);
1171
1172 // If France, show VAT mention if not applicable
1173 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1174 $pdf->SetFont('', 'B', $default_font_size - 2);
1175 $pdf->SetXY($this->marge_gauche, $posy);
1176 if ($mysoc->forme_juridique_code == 92) {
1177 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1178 } else {
1179 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1180 }
1181
1182 $posy = $pdf->GetY() + 4;
1183 }
1184
1185 $posxval = 52;
1186 $posxend = 110; // End of x for text on left side
1187 if ($this->page_largeur < 210) { // To work with US executive format
1188 $posxend -= 10;
1189 }
1190
1191 // Show payments conditions
1192 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1193 $pdf->SetFont('', 'B', $default_font_size - 2);
1194 $pdf->SetXY($this->marge_gauche, $posy);
1195 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1196 $pdf->MultiCell(43, 4, $titre, 0, 'L');
1197
1198 $pdf->SetFont('', '', $default_font_size - 2);
1199 $pdf->SetXY($posxval, $posy);
1200 $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);
1201 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1202 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1203
1204 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1205 }
1206
1207 // Show category of operations
1208 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1209 $pdf->SetFont('', 'B', $default_font_size - 2);
1210 $pdf->SetXY($this->marge_gauche, $posy);
1211 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1212 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1213
1214 $pdf->SetFont('', '', $default_font_size - 2);
1215 $pdf->SetXY($posxval, $posy);
1216 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1217 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1218
1219 $posy = $pdf->GetY() + 3; // for 2 lines
1220 }
1221
1222 if ($object->type != 2) {
1223 // Check a payment mode is defined
1224 if (empty($object->mode_reglement_code)
1225 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1226 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1227 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1228 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1229 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1230 // Avoid having any valid PDF with setup that is not complete
1231 $outputlangs->load("errors");
1232
1233 $pdf->SetXY($this->marge_gauche, $posy);
1234 $pdf->SetTextColor(200, 0, 0);
1235 $pdf->SetFont('', 'B', $default_font_size - 2);
1236 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1237 $pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
1238 $pdf->SetTextColor(0, 0, 0);
1239
1240 $posy = $pdf->GetY() + 1;
1241 }
1242
1243 // Show payment mode
1244 if (!empty($object->mode_reglement_code)
1245 && $object->mode_reglement_code != 'CHQ'
1246 && $object->mode_reglement_code != 'VIR') {
1247 $pdf->SetFont('', 'B', $default_font_size - 2);
1248 $pdf->SetXY($this->marge_gauche, $posy);
1249 $titre = $outputlangs->transnoentities("PaymentMode").':';
1250 $pdf->MultiCell(80, 5, $titre, 0, 'L');
1251
1252 $pdf->SetFont('', '', $default_font_size - 2);
1253 $pdf->SetXY($posxval, $posy);
1254 $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);
1255 //#21654: add account number used for the debit
1256 if ($object->mode_reglement_code == "PRE") {
1257 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1258 $bac = new CompanyBankAccount($this->db);
1259 $bac->fetch(0, $object->thirdparty->id);
1260 $iban= $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1261 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1262 }
1263 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1264
1265 $posy = $pdf->GetY();
1266 }
1267
1268 // Show if Option VAT debit option is on also if transmitter is french
1269 // Decret n°2099-1299 2022-10-07
1270 // French mention : "Option pour le paiement de la taxe d'après les débits"
1271 if ($this->emetteur->country_code == 'FR') {
1272 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1273 $pdf->SetXY($this->marge_gauche, $posy);
1274 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1275
1276 $posy = $pdf->GetY() + 1;
1277 }
1278 }
1279
1280 // Show online payment link
1281 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1282 $useonlinepayment = 0;
1283 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1284 if (isModEnabled('paypal')) {
1285 $useonlinepayment++;
1286 }
1287 if (isModEnabled('stripe')) {
1288 $useonlinepayment++;
1289 }
1290 if (isModEnabled('paybox')) {
1291 $useonlinepayment++;
1292 }
1293 }
1294
1295 if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
1296 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1297 global $langs;
1298
1299 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1300 $servicename = $langs->transnoentities('Online');
1301 $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
1302 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1303
1304 $pdf->SetXY($this->marge_gauche, $posy);
1305 $pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1306
1307 $posy = $pdf->GetY() + 1;
1308 }
1309 }
1310
1311 // Show payment mode CHQ
1312 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1313 // If payment mode unregulated or payment mode forced to CHQ
1314 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1315 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1316
1317 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1318 $account = new Account($this->db);
1319 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1320
1321 $pdf->SetXY($this->marge_gauche, $posy);
1322 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1323 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 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($account->owner_address), 0, 'L', 0);
1330 $posy = $pdf->GetY() + 2;
1331 }
1332 }
1333 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1334 $pdf->SetXY($this->marge_gauche, $posy);
1335 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1336 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1337 $posy = $pdf->GetY() + 1;
1338
1339 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1340 $pdf->SetXY($this->marge_gauche, $posy);
1341 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1342 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1343 $posy = $pdf->GetY() + 2;
1344 }
1345 }
1346 }
1347 }
1348
1349 // If payment mode not forced or forced to VIR, show payment with BAN
1350 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1351 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1352 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1353 if ($object->fk_bank > 0) {
1354 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1355 }
1356 $account = new Account($this->db);
1357 $account->fetch($bankid);
1358
1359 $curx = $this->marge_gauche;
1360 $cury = $posy;
1361
1362 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1363
1364 $posy += 2;
1365 }
1366 }
1367 }
1368
1369 return $posy;
1370 }
1371
1372
1373 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1374 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1386 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1387 {
1388 // phpcs:enable
1389 global $conf, $mysoc, $hookmanager;
1390
1391 $sign = 1;
1392 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1393 $sign = -1;
1394 }
1395
1396 $default_font_size = pdf_getPDFFontSize($outputlangs);
1397
1398 $outputlangsbis = null;
1399 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1400 $outputlangsbis = new Translate('', $conf);
1401 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1402 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1403 $default_font_size--;
1404 }
1405
1406 $tab2_top = $posy;
1407 $tab2_hl = 4;
1408 $pdf->SetFont('', '', $default_font_size - 1);
1409
1410 // Total table
1411 $col1x = 120;
1412 $col2x = 170;
1413 if ($this->page_largeur < 210) { // To work with US executive format
1414 $col1x -= 15;
1415 $col2x -= 10;
1416 }
1417 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1418
1419 $useborder = 0;
1420 $index = 0;
1421
1422 // Total HT
1423 $pdf->SetFillColor(255, 255, 255);
1424 $pdf->SetXY($col1x, $tab2_top);
1425 $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);
1426
1427 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1428 $pdf->SetXY($col2x, $tab2_top);
1429 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1430
1431 // Show VAT by rates and total
1432 $pdf->SetFillColor(248, 248, 248);
1433
1434 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1435
1436 $this->atleastoneratenotnull = 0;
1437 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1438 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1439 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1440 // Nothing to do
1441 } else {
1442 //Local tax 1 before VAT
1443 //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1444 //{
1445 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1446 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1447 continue;
1448 }
1449
1450 foreach ($localtax_rate as $tvakey => $tvaval) {
1451 if ($tvakey != 0) { // On affiche pas taux 0
1452 //$this->atleastoneratenotnull++;
1453
1454 $index++;
1455 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1456
1457 $tvacompl = '';
1458 if (preg_match('/\*/', $tvakey)) {
1459 $tvakey = str_replace('*', '', $tvakey);
1460 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1461 }
1462
1463 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1464 $totalvat .= ' ';
1465 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1466 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1467
1468 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1469
1470 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1471 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1472 }
1473 }
1474 }
1475 //}
1476 //Local tax 2 before VAT
1477 //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1478 //{
1479 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1480 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1481 continue;
1482 }
1483
1484 foreach ($localtax_rate as $tvakey => $tvaval) {
1485 if ($tvakey != 0) { // On affiche pas taux 0
1486 //$this->atleastoneratenotnull++;
1487
1488 $index++;
1489 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1490
1491 $tvacompl = '';
1492 if (preg_match('/\*/', $tvakey)) {
1493 $tvakey = str_replace('*', '', $tvakey);
1494 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1495 }
1496 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1497 $totalvat .= ' ';
1498 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1499 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1500
1501 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1502
1503 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1504 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1505 }
1506 }
1507 }
1508
1509 //}
1510
1511 // VAT
1512 foreach ($this->tva_array as $tvakey => $tvaval) {
1513 if ($tvakey != 0) { // On affiche pas taux 0
1514 $this->atleastoneratenotnull++;
1515
1516 $index++;
1517 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1518
1519 $tvacompl = '';
1520 if (preg_match('/\*/', $tvakey)) {
1521 $tvakey = str_replace('*', '', $tvakey);
1522 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1523 }
1524 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1525 $totalvat .= ' ';
1526 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1527 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1528 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1529 $totalvat .= $tvaval['vatcode'].$tvacompl;
1530 } else {
1531 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1532 }
1533 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1534
1535 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1536 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1537 }
1538 }
1539
1540 //Local tax 1 after VAT
1541 //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1542 //{
1543 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1544 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1545 continue;
1546 }
1547
1548 foreach ($localtax_rate as $tvakey => $tvaval) {
1549 if ($tvakey != 0) { // On affiche pas taux 0
1550 //$this->atleastoneratenotnull++;
1551
1552 $index++;
1553 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1554
1555 $tvacompl = '';
1556 if (preg_match('/\*/', $tvakey)) {
1557 $tvakey = str_replace('*', '', $tvakey);
1558 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1559 }
1560 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1561 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1562
1563 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1564
1565 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1566
1567 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1568 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1569 }
1570 }
1571 }
1572 //}
1573 //Local tax 2 after VAT
1574 //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1575 //{
1576 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1577 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1578 continue;
1579 }
1580
1581 foreach ($localtax_rate as $tvakey => $tvaval) {
1582 //$this->atleastoneratenotnull++;
1583
1584 $index++;
1585 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1586
1587 $tvacompl = '';
1588 if (preg_match('/\*/', $tvakey)) {
1589 $tvakey = str_replace('*', '', $tvakey);
1590 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1591 }
1592 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1593
1594 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1595 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1596
1597 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1598
1599 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1600 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1601 }
1602 }
1603 //}
1604
1605 // Revenue stamp
1606 if (price2num($object->revenuestamp) != 0) {
1607 $index++;
1608 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1609 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1610
1611 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1612 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1613 }
1614
1615 // Total TTC
1616 $index++;
1617 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1618 $pdf->SetTextColor(0, 0, 60);
1619 $pdf->SetFillColor(224, 224, 224);
1620 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1621
1622 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1623 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1624
1625 // Retained warranty
1626 if ($object->displayRetainedWarranty()) {
1627 $pdf->SetTextColor(40, 40, 40);
1628 $pdf->SetFillColor(255, 255, 255);
1629
1630 $retainedWarranty = $object->getRetainedWarrantyAmount();
1631 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1632
1633 // Billed - retained warranty
1634 $index++;
1635 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1636 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1637
1638 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1639 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1640
1641 // retained warranty
1642 $index++;
1643 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1644
1645 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
1646 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1647
1648 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1649 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1650 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1651 }
1652 }
1653 }
1654
1655 $pdf->SetTextColor(0, 0, 0);
1656 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1657 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1658 //print "x".$creditnoteamount."-".$depositsamount;exit;
1659 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1660 if (!empty($object->paye)) {
1661 $resteapayer = 0;
1662 }
1663
1664 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1665 // Already paid + Deposits
1666 $index++;
1667 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1668 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1669 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1670 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1671
1672 // Credit note
1673 if ($creditnoteamount) {
1674 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1675 $index++;
1676 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1677 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1678 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1679 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1680 }
1681
1682 // Escompte
1683 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1684 $index++;
1685 $pdf->SetFillColor(255, 255, 255);
1686
1687 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1688 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1689 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1690 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1691
1692 $resteapayer = 0;
1693 }
1694
1695 $index++;
1696 $pdf->SetTextColor(0, 0, 60);
1697 $pdf->SetFillColor(224, 224, 224);
1698 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1699 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1700 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1701 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1702
1703 $pdf->SetFont('', '', $default_font_size - 1);
1704 $pdf->SetTextColor(0, 0, 0);
1705 }
1706
1707 $index++;
1708 return ($tab2_top + ($tab2_hl * $index));
1709 }
1710
1711 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1725 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1726 {
1727 global $conf;
1728
1729 // Force to disable hidetop and hidebottom
1730 $hidebottom = 0;
1731 if ($hidetop) {
1732 $hidetop = -1;
1733 }
1734
1735 $currency = !empty($currency) ? $currency : $conf->currency;
1736 $default_font_size = pdf_getPDFFontSize($outputlangs);
1737
1738 // Amount in (at tab_top - 1)
1739 $pdf->SetTextColor(0, 0, 0);
1740 $pdf->SetFont('', '', $default_font_size - 2);
1741
1742 if (empty($hidetop)) {
1743 // Show category of operations
1744 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1745 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1746 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1747 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1748 }
1749
1750 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1751 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1752 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1753
1754 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1755 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1756 $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));
1757 }
1758 }
1759
1760 $pdf->SetDrawColor(128, 128, 128);
1761 $pdf->SetFont('', '', $default_font_size - 1);
1762
1763 // Output Rect
1764 $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
1765
1766 if (empty($hidetop)) {
1767 $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
1768
1769 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1770 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1771 }
1772
1773 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1774 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1775 if (empty($hidetop)) {
1776 //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1777 //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1778 }
1779 }
1780
1781 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1782 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1783 if (empty($hidetop)) {
1784 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1785 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1786 }
1787 }
1788
1789 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1790 if (empty($hidetop)) {
1791 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1792 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1793 }
1794
1795 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1796 if (empty($hidetop)) {
1797 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1798 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1799 }
1800
1801 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1802 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1803 if (empty($hidetop)) {
1804 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1805 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1806 }
1807 }
1808
1809 if ($this->atleastonediscount) {
1810 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1811 if (empty($hidetop)) {
1812 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1813 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1814 }
1815 }
1816
1817 if ($this->situationinvoice) {
1818 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1819 if (empty($hidetop)) {
1820 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1821 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("ProgressShort"), '', 'C');
1822 }
1823 }
1824
1825 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1826 if (empty($hidetop)) {
1827 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1828 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1829 }
1830 }
1831
1832 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1843 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
1844 {
1845 global $conf, $langs;
1846
1847 $ltrdirection = 'L';
1848 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
1849
1850 // Load traductions files required by page
1851 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1852
1853 $default_font_size = pdf_getPDFFontSize($outputlangs);
1854
1855 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1856
1857 $pdf->SetTextColor(0, 0, 60);
1858 $pdf->SetFont('', 'B', $default_font_size + 3);
1859
1860 $w = 110;
1861
1862 $posy = $this->marge_haute;
1863 $posx = $this->page_largeur - $this->marge_droite - $w;
1864
1865 $pdf->SetXY($this->marge_gauche, $posy);
1866
1867 // Logo
1868 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1869 if ($this->emetteur->logo) {
1870 $logodir = $conf->mycompany->dir_output;
1871 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1872 $logodir = $conf->mycompany->multidir_output[$object->entity];
1873 }
1874 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1875 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1876 } else {
1877 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1878 }
1879 if (is_readable($logo)) {
1880 $height = pdf_getHeightForLogo($logo);
1881 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1882 } else {
1883 $pdf->SetTextColor(200, 0, 0);
1884 $pdf->SetFont('', 'B', $default_font_size - 2);
1885 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1886 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1887 }
1888 } else {
1889 $text = $this->emetteur->name;
1890 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1891 }
1892 }
1893
1894 $pdf->SetFont('', 'B', $default_font_size + 3);
1895 $pdf->SetXY($posx, $posy);
1896 $pdf->SetTextColor(0, 0, 60);
1897 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1898 if ($object->type == 1) {
1899 $title = $outputlangs->transnoentities("InvoiceReplacement");
1900 }
1901 if ($object->type == 2) {
1902 $title = $outputlangs->transnoentities("InvoiceAvoir");
1903 }
1904 if ($object->type == 3) {
1905 $title = $outputlangs->transnoentities("InvoiceDeposit");
1906 }
1907 if ($object->type == 4) {
1908 $title = $outputlangs->transnoentities("InvoiceProForma");
1909 }
1910 if ($this->situationinvoice) {
1911 $langs->loadLangs(array("other"));
1912 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
1913 }
1914 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1915 $title .= ' - ';
1916 if ($object->type == 0) {
1917 if ($this->situationinvoice) {
1918 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
1919 }
1920 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
1921 } elseif ($object->type == 1) {
1922 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
1923 } elseif ($object->type == 2) {
1924 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
1925 } elseif ($object->type == 3) {
1926 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
1927 } elseif ($object->type == 4) {
1928 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
1929 }
1930 }
1931 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1932 if ($object->statut == $object::STATUS_DRAFT) {
1933 $pdf->SetTextColor(128, 0, 0);
1934 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1935 }
1936
1937 $pdf->MultiCell($w, 3, $title, '', 'R');
1938
1939 $pdf->SetFont('', 'B', $default_font_size);
1940
1941 /*
1942 $posy += 5;
1943 $pdf->SetXY($posx, $posy);
1944 $pdf->SetTextColor(0, 0, 60);
1945 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1946 if ($object->statut == $object::STATUS_DRAFT) {
1947 $pdf->SetTextColor(128, 0, 0);
1948 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1949 }
1950 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
1951
1952 $posy += 3;
1953 $pdf->SetFont('', '', $default_font_size - 2);
1954
1955 if ($object->ref_customer) {
1956 $posy += 4;
1957 $pdf->SetXY($posx, $posy);
1958 $pdf->SetTextColor(0, 0, 60);
1959 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_customer), '', 'R');
1960 }
1961
1962 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1963 $object->fetch_projet();
1964 if (!empty($object->project->ref)) {
1965 $posy += 3;
1966 $pdf->SetXY($posx, $posy);
1967 $pdf->SetTextColor(0, 0, 60);
1968 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1969 }
1970 }
1971
1972 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1973 $object->fetch_projet();
1974 if (!empty($object->project->ref)) {
1975 $outputlangs->load("projects");
1976 $posy += 3;
1977 $pdf->SetXY($posx, $posy);
1978 $pdf->SetTextColor(0, 0, 60);
1979 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1980 }
1981 }
1982
1983 $objectidnext = $object->getIdReplacingInvoice('validated');
1984 if ($object->type == 0 && $objectidnext) {
1985 $objectreplacing = new Facture($this->db);
1986 $objectreplacing->fetch($objectidnext);
1987
1988 $posy += 3;
1989 $pdf->SetXY($posx, $posy);
1990 $pdf->SetTextColor(0, 0, 60);
1991 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1992 }
1993 if ($object->type == 1) {
1994 $objectreplaced = new Facture($this->db);
1995 $objectreplaced->fetch($object->fk_facture_source);
1996
1997 $posy += 4;
1998 $pdf->SetXY($posx, $posy);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2001 }
2002 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2003 $objectreplaced = new Facture($this->db);
2004 $objectreplaced->fetch($object->fk_facture_source);
2005
2006 $posy += 3;
2007 $pdf->SetXY($posx, $posy);
2008 $pdf->SetTextColor(0, 0, 60);
2009 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2010 }
2011
2012 $posy += 4;
2013 $pdf->SetXY($posx, $posy);
2014 $pdf->SetTextColor(0, 0, 60);
2015 $title = $outputlangs->transnoentities("DateInvoice");
2016 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2017 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2018 }
2019 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2020
2021 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2022 $posy += 4;
2023 $pdf->SetXY($posx, $posy);
2024 $pdf->SetTextColor(0, 0, 60);
2025 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2026 }
2027
2028 if ($object->type != 2) {
2029 $posy += 3;
2030 $pdf->SetXY($posx, $posy);
2031 $pdf->SetTextColor(0, 0, 60);
2032 $title = $outputlangs->transnoentities("DateDue");
2033 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2034 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2035 }
2036 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2037 }
2038
2039 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2040 $posy += 3;
2041 $pdf->SetXY($posx, $posy);
2042 $pdf->SetTextColor(0, 0, 60);
2043 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2044 }
2045
2046 // Get contact
2047 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2048 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2049 if (count($arrayidcontact) > 0) {
2050 $usertmp = new User($this->db);
2051 $usertmp->fetch($arrayidcontact[0]);
2052 $posy += 4;
2053 $pdf->SetXY($posx, $posy);
2054 $pdf->SetTextColor(0, 0, 60);
2055 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2056 }
2057 }
2058
2059 $posy += 1;
2060
2061 $top_shift = 0;
2062 // Show list of linked objects
2063 $current_y = $pdf->getY();
2064 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2065 if ($current_y < $pdf->getY()) {
2066 $top_shift = $pdf->getY() - $current_y;
2067 }
2068
2069 if ($showaddress) {
2070 // Sender properties
2071 $carac_emetteur = '';
2072 // Add internal contact of object if defined
2073 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2074 if (count($arrayidcontact) > 0) {
2075 $object->fetch_user($arrayidcontact[0]);
2076 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2077 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2078 $carac_emetteur .= "\n";
2079 }
2080
2081 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2082
2083 // Show sender
2084 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2085 $posy += $top_shift;
2086 $posx = $this->marge_gauche;
2087 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2088 $posx = $this->page_largeur - $this->marge_droite - 80;
2089 }
2090
2091 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2092 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2093
2094
2095 // Show sender frame
2096 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2097 $pdf->SetTextColor(0, 0, 0);
2098 $pdf->SetFont('', '', $default_font_size - 2);
2099 $pdf->SetXY($posx, $posy - 5);
2100 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2101 $pdf->SetXY($posx, $posy);
2102 $pdf->SetFillColor(230, 230, 230);
2103 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2104 $pdf->SetTextColor(0, 0, 60);
2105 }
2106
2107 // Show sender name
2108 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2109 $pdf->SetXY($posx + 2, $posy + 3);
2110 $pdf->SetFont('', 'B', $default_font_size);
2111 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2112 $posy = $pdf->getY();
2113 }
2114
2115 // Show sender information
2116 $pdf->SetXY($posx + 2, $posy);
2117 $pdf->SetFont('', '', $default_font_size - 1);
2118 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2119
2120
2121 // If BILLING contact defined on invoice, we use it
2122 $usecontact = false;
2123 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2124 if (count($arrayidcontact) > 0) {
2125 $usecontact = true;
2126 $result = $object->fetch_contact($arrayidcontact[0]);
2127 }
2128
2129 // Recipient name
2130 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)))) {
2131 $thirdparty = $object->contact;
2132 } else {
2133 $thirdparty = $object->thirdparty;
2134 }
2135
2136 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2137
2138 $mode = 'target';
2139 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2140
2141 // Show recipient
2142 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2143 if ($this->page_largeur < 210) {
2144 $widthrecbox = 84; // To work with US executive format
2145 }
2146 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2147 $posy += $top_shift;
2148 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2149 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2150 $posx = $this->marge_gauche;
2151 }
2152
2153 // Show recipient frame
2154 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2155 $pdf->SetTextColor(0, 0, 0);
2156 $pdf->SetFont('', '', $default_font_size - 2);
2157 $pdf->SetXY($posx + 2, $posy - 5);
2158 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2159 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2160 }
2161
2162 // Show recipient name
2163 $pdf->SetXY($posx + 2, $posy + 3);
2164 $pdf->SetFont('', 'B', $default_font_size);
2165 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2166
2167 $posy = $pdf->getY();
2168
2169 // Show recipient information
2170 $pdf->SetFont('', '', $default_font_size - 1);
2171 $pdf->SetXY($posx + 2, $posy);
2172 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2173
2174 // Show shipping address
2175 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2176 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2177
2178 if (!empty($idaddressshipping)) {
2179 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2180 $companystatic = new Societe($this->db);
2181 $companystatic->fetch($object->contact->fk_soc);
2182 $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs);
2183 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2184 } else {
2185 $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2186 $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2187 }
2188 if (!empty($carac_client_shipping)) {
2189 $posy += $hautcadre;
2190
2191 // Show shipping frame
2192 $pdf->SetXY($posx + 2, $posy - 5);
2193 $pdf->SetFont('', '', $default_font_size - 2);
2194 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2195 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2196
2197 // Show shipping name
2198 $pdf->SetXY($posx + 2, $posy + 3);
2199 $pdf->SetFont('', 'B', $default_font_size);
2200 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2201
2202 $posy = $pdf->getY();
2203
2204 // Show shipping information
2205 $pdf->SetXY($posx+2, $posy);
2206 $pdf->SetFont('', '', $default_font_size - 1);
2207 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2208 $top_shift += $hautcadre;
2209 }
2210 }
2211 }
2212
2213 $pdf->SetTextColor(0, 0, 0);
2214 return $top_shift;
2215 }
2216
2217 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2228 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2229 {
2230 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2231 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);
2232 }
2233}
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:2568
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2323
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:1940
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2272
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1878
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition pdf.lib.php:2186
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:2229
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2025
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