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