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