dolibarr 21.0.4
pdf_sponge.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2024 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 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2018-2024 Anthony Berton <anthony.berton@bb2a.fr>
13 * Copyright (C) 2022-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
14 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024 Nick Fragoulis
16 * Copyright (C) 2024 Franck Moreau
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 * or see https://www.gnu.org/
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
40require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
44
45
50{
54 public $db;
55
59 public $name;
60
64 public $description;
65
69 public $update_main_doc_field;
70
74 public $type;
75
80 public $version = 'dolibarr';
81
85 public $heightforinfotot;
86
90 public $heightforfreetext;
91
95 public $heightforfooter;
96
100 public $tab_top;
101
105 public $tab_top_newpage;
106
110 public $situationinvoice;
111
112
116 public $cols;
117
121 public $categoryOfOperation = -1; // unknown by default
122
123
129 public function __construct($db)
130 {
131 global $langs, $mysoc;
132
133 // Translations
134 $langs->loadLangs(array("main", "bills"));
135
136 $this->db = $db;
137 $this->name = "sponge";
138 $this->description = $langs->trans('PDFSpongeDescription');
139 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
140
141 // Dimension page
142 $this->type = 'pdf';
143 $formatarray = pdf_getFormat();
144 $this->page_largeur = $formatarray['width'];
145 $this->page_hauteur = $formatarray['height'];
146 $this->format = array($this->page_largeur, $this->page_hauteur);
147 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
148 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
149 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
150 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
151 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
152 $this->option_logo = 1; // Display logo
153 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
154 $this->option_modereg = 1; // Display payment mode
155 $this->option_condreg = 1; // Display payment terms
156 $this->option_multilang = 1; // Available in several languages
157 $this->option_escompte = 1; // Displays if there has been a discount
158 $this->option_credit_note = 1; // Support credit notes
159 $this->option_freetext = 1; // Support add of a personalised text
160 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
161 $this->watermark = '';
162
163 if ($mysoc === null) {
164 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
165 return;
166 }
167
168 // Get source company
169 $this->emetteur = $mysoc;
170 if (empty($this->emetteur->country_code)) {
171 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
172 }
173
174 // Define position of columns
175 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
176
177
178 $this->tabTitleHeight = 5; // default height
179
180 // Use new system for position of columns, view $this->defineColumnField()
181
182 $this->tva = array();
183 $this->tva_array = array();
184 $this->localtax1 = array();
185 $this->localtax2 = array();
186 $this->atleastoneratenotnull = 0;
187 $this->atleastonediscount = 0;
188 $this->situationinvoice = false;
189 }
190
191
192 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
204 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
205 {
206 // phpcs:enable
207 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
208
209 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
210
211 if (!is_object($outputlangs)) {
212 $outputlangs = $langs;
213 }
214 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
215 if (getDolGlobalString('MAIN_USE_FPDF')) {
216 $outputlangs->charset_output = 'ISO-8859-1';
217 }
218
219 // Load translation files required by the page
220 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
221
222 global $outputlangsbis;
223 $outputlangsbis = null;
224 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
225 $outputlangsbis = new Translate('', $conf);
226 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
227 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies", "compta"));
228 }
229
230 // Show Draft Watermark
231 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
232 $this->watermark = getDolGlobalString('FACTURE_DRAFT_WATERMARK');
233 }
234
235 $nblines = count($object->lines);
236
237 $hidetop = 0;
238 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
239 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
240 }
241
242 // Loop on each lines to detect if there is at least one image to show
243 $realpatharray = array();
244 $this->atleastonephoto = false;
245 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
246 $objphoto = new Product($this->db);
247
248 for ($i = 0; $i < $nblines; $i++) {
249 if (empty($object->lines[$i]->fk_product)) {
250 continue;
251 }
252
253 $objphoto->fetch($object->lines[$i]->fk_product);
254 //var_dump($objphoto->ref);exit;
255 $pdir = array();
256 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
257 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
258 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
259 } else {
260 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
261 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
262 }
263
264 $arephoto = false;
265 foreach ($pdir as $midir) {
266 if (!$arephoto) {
267 if ($conf->entity != $objphoto->entity) {
268 $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
269 } else {
270 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
271 }
272
273 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
274 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
275 if ($obj['photo_vignette']) {
276 $filename = $obj['photo_vignette'];
277 } else {
278 $filename = $obj['photo'];
279 }
280 } else {
281 $filename = $obj['photo'];
282 }
283
284 $realpath = $dir.$filename;
285 $arephoto = true;
286 $this->atleastonephoto = true;
287 }
288 }
289 }
290
291 if ($realpath && $arephoto) {
292 $realpatharray[$i] = $realpath;
293 }
294 }
295 }
296
297 //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
298
299 if ($conf->facture->multidir_output[$conf->entity]) {
300 $object->fetch_thirdparty();
301
302 $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
303 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
304 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
305
306 // Definition of $dir and $file
307 if ($object->specimen) {
308 $dir = $conf->facture->multidir_output[$conf->entity];
309 $file = $dir."/SPECIMEN.pdf";
310 } else {
311 $objectref = dol_sanitizeFileName($object->ref);
312 $dir = $conf->facture->multidir_output[$object->entity]."/".$objectref;
313 $file = $dir."/".$objectref.".pdf";
314 }
315 if (!file_exists($dir)) {
316 if (dol_mkdir($dir) < 0) {
317 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
318 return 0;
319 }
320 }
321
322 if (file_exists($dir)) {
323 // Add pdfgeneration hook
324 if (!is_object($hookmanager)) {
325 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
326 $hookmanager = new HookManager($this->db);
327 }
328 $hookmanager->initHooks(array('pdfgeneration'));
329 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
330 global $action;
331 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
332
333 // Set nblines with the new facture lines content after hook
334 $nblines = count($object->lines);
335 $nbpayments = count($object->getListOfPayments());
336
337 // Create pdf instance
338 $pdf = pdf_getInstance($this->format);
339 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
340 $pdf->SetAutoPageBreak(1, 0);
341
342 $this->heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
343 $this->heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
344 $this->heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
345
346 $heightforqrinvoice = 0;
347 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
348 if ($this->getHeightForQRInvoice(1, $object, $langs) > 0) {
349 // Shrink infotot to a base 30
350 $this->heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
351 }
352 }
353
354 if (class_exists('TCPDF')) {
355 $pdf->setPrintHeader(false);
356 $pdf->setPrintFooter(false);
357 }
358 $pdf->SetFont(pdf_getPDFFont($outputlangs));
359
360 // Set path to the background PDF File
361 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
362 $logodir = $conf->mycompany->dir_output;
363 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
364 $logodir = $conf->mycompany->multidir_output[$object->entity];
365 }
366 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
367 $tplidx = $pdf->importPage(1);
368 }
369
370 $pdf->Open();
371 $pagenb = 0;
372 $pdf->SetDrawColor(128, 128, 128);
373
374 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
375 $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
376 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
377 $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
378 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
379 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
380 $pdf->SetCompression(false);
381 }
382
383 // Set certificate
384 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
385 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
386 // If user has no certificate, we try to take the company one
387 if (!$cert) {
388 $cert = getDolGlobalString('CERTIFICATE_CRT');
389 }
390 if (!$certprivate) {
391 $certprivate = getDolGlobalString('CERTIFICATE_CRT_PRIVATE');
392 }
393 // If a certificate is found
394 if ($cert) {
395 $info = array(
396 'Name' => $this->emetteur->name,
397 'Location' => getCountry($this->emetteur->country_code, ''),
398 'Reason' => 'INVOICE',
399 'ContactInfo' => $this->emetteur->email
400 );
401 $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
402 }
403
404 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
405 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
406
407 // Set $this->atleastonediscount if you have at least one discount
408 // and determine category of operation
409 $categoryOfOperation = 0;
410 $nbProduct = 0;
411 $nbService = 0;
412 for ($i = 0; $i < $nblines; $i++) {
413 if ($object->lines[$i]->remise_percent) {
414 $this->atleastonediscount++;
415 }
416
417 // determine category of operation
418 if ($categoryOfOperation < 2) {
419 $lineProductType = $object->lines[$i]->product_type;
420 if ($lineProductType == Product::TYPE_PRODUCT) {
421 $nbProduct++;
422 } elseif ($lineProductType == Product::TYPE_SERVICE) {
423 $nbService++;
424 }
425 if ($nbProduct > 0 && $nbService > 0) {
426 // mixed products and services
427 $categoryOfOperation = 2;
428 }
429 }
430 }
431 // determine category of operation
432 if ($categoryOfOperation <= 0) {
433 // only services
434 if ($nbProduct == 0 && $nbService > 0) {
435 $categoryOfOperation = 1;
436 }
437 }
438 $this->categoryOfOperation = $categoryOfOperation;
439
440 // Situation invoice handling
441 if ($object->situation_cycle_ref) {
442 $this->situationinvoice = true;
443 }
444
445 // New page
446 $pdf->AddPage();
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
449 }
450 $pagenb++;
451
452 // Output header (logo, ref and address blocks). This is first call for first page.
453 $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
454 $top_shift = $pagehead['top_shift'];
455 $shipp_shift = $pagehead['shipp_shift'];
456 $pdf->SetFont('', '', $default_font_size - 1);
457 $pdf->MultiCell(0, 3, ''); // Set interline to 3
458 $pdf->SetTextColor(0, 0, 0);
459
460 // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher
461
462 // $this->tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
463 $this->tab_top = 90 + $top_shift + $shipp_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
464 $this->tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
465
466 // You can add more thing under header here, if you increase $extra_under_address_shift too.
467 $extra_under_address_shift = 0;
468 $qrcodestring = '';
469 if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) {
470 $qrcodestring = $object->buildZATCAQRString();
471 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
472 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
473 $qrcodestring = $object->buildSwitzerlandQRString();
474 }
475 } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
476 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
477 $qrcodestring = $object->buildEPCQrCodeString();
478 }
479 }
480
481 if ($qrcodestring) {
482 $qrcodecolor = array('25', '25', '25');
483 // set style for QR-code
484 $styleQr = array(
485 'border' => false,
486 'padding' => 0,
487 'fgcolor' => $qrcodecolor,
488 'bgcolor' => false, //array(255,255,255)
489 'module_width' => 1, // width of a single module in points
490 'module_height' => 1 // height of a single module in points
491 );
492 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr, 'N');
493
494 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
495 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
496 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
497 $pdf->SetFont('', '', $default_font_size - 4);
498 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0);
499 }
500 }
501
502 $extra_under_address_shift += 25;
503 }
504
505 // Call hook printUnderHeaderPDFline
506 $parameters = array(
507 'object' => $object,
508 'i' => $i,
509 'pdf' => &$pdf,
510 'outputlangs' => $outputlangs,
511 'hidedetails' => $hidedetails
512 );
513 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
514 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
515 $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift'];
516 }
517
518 $this->tab_top += $extra_under_address_shift;
519 $this->tab_top_newpage += 0;
520
521
522 // Define height of table for lines (for first page)
523 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->getHeightForQRInvoice(1, $object, $langs);
524
525 $nexY = $this->tab_top - 1;
526
527 // Incoterm
528 $height_incoterms = 0;
529 if (isModEnabled('incoterm')) {
530 $desc_incoterms = $object->getIncotermsForPDF();
531 if ($desc_incoterms) {
532 $this->tab_top -= 2;
533
534 $pdf->SetFont('', '', $default_font_size - 1);
535 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
536 $nexY = max($pdf->GetY(), $nexY);
537 $height_incoterms = $nexY - $this->tab_top;
538
539 // Rect takes a length in 3rd parameter
540 $pdf->SetDrawColor(192, 192, 192);
541 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
542
543 $this->tab_top = $nexY + 6;
544 $height_incoterms += 4;
545 }
546 }
547
548 // Displays notes. Here we are still on code executed only for the first page.
549 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
550 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
551 // Get first sale rep
552 if (is_object($object->thirdparty)) {
553 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
554 $salerepobj = new User($this->db);
555 $salerepobj->fetch($salereparray[0]['id']);
556 if (!empty($salerepobj->signature)) {
557 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
558 }
559 }
560 }
561
562 // Extrafields in note
563 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
564 if (!empty($extranote)) {
565 $notetoshow = dol_concatdesc($notetoshow, $extranote);
566 }
567
568 $pagenb = $pdf->getPage();
569 if ($notetoshow) {
570 $this->tab_top -= 2;
571
572 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
573 $pageposbeforenote = $pagenb;
574
575 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
576 complete_substitutions_array($substitutionarray, $outputlangs, $object);
577 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
578 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
579
580 $pdf->startTransaction();
581
582 $pdf->SetFont('', '', $default_font_size - 1);
583 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
584 // Description
585 $pageposafternote = $pdf->getPage();
586 $posyafter = $pdf->GetY();
587
588 if ($pageposafternote > $pageposbeforenote) {
589 $pdf->rollbackTransaction(true);
590
591 // prepare pages to receive notes
592 while ($pagenb < $pageposafternote) {
593 $pdf->AddPage();
594 $pagenb++;
595 if (!empty($tplidx)) {
596 $pdf->useTemplate($tplidx);
597 }
598 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
599 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
600 }
601 $pdf->setTopMargin($this->tab_top_newpage);
602 // The only function to edit the bottom margin of current page to set it.
603 $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
604 }
605
606 // back to start
607 $pdf->setPage($pageposbeforenote);
608 $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
609 $pdf->SetFont('', '', $default_font_size - 1);
610 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
611 $pageposafternote = $pdf->getPage();
612
613 $posyafter = $pdf->GetY();
614
615 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) { // There is no space left for total+free text
616 $pdf->AddPage('', '', true);
617 $pagenb++;
618 $pageposafternote++;
619 $pdf->setPage($pageposafternote);
620 $pdf->setTopMargin($this->tab_top_newpage);
621 // The only function to edit the bottom margin of current page to set it.
622 $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
623 //$posyafter = $this->tab_top_newpage;
624 }
625
626
627 // apply note frame to previous pages
628 $i = $pageposbeforenote;
629 while ($i < $pageposafternote) {
630 $pdf->setPage($i);
631
632
633 $pdf->SetDrawColor(128, 128, 128);
634 // Draw note frame
635 if ($i > $pageposbeforenote) {
636 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
637 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
638 } else {
639 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
640 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
641 }
642
643 // Add footer
644 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
645 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($i, $object, $outputlangs));
646
647 $i++;
648 }
649
650 // apply note frame to last page
651 $pdf->setPage($pageposafternote);
652 if (!empty($tplidx)) {
653 $pdf->useTemplate($tplidx);
654 }
655 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
656 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
657 }
658 $height_note = $posyafter - $this->tab_top_newpage;
659 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
660 } else {
661 // No pagebreak
662 $pdf->commitTransaction();
663 $posyafter = $pdf->GetY();
664 $height_note = $posyafter - $this->tab_top;
665 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
666
667
668 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
669 // not enough space, need to add page
670 $pdf->AddPage('', '', true);
671 $pagenb++;
672 $pageposafternote++;
673 $pdf->setPage($pageposafternote);
674 if (!empty($tplidx)) {
675 $pdf->useTemplate($tplidx);
676 }
677 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
678 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
679 }
680
681 $posyafter = $this->tab_top_newpage;
682 }
683 }
684
685 $tab_height -= $height_note;
686 $this->tab_top = $posyafter + 6;
687 } else {
688 $height_note = 0;
689 }
690
691 // Use new auto column system
692 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
693
694 // Table simulation to know the height of the title line (this set this->tableTitleHeight)
695 $pdf->startTransaction();
696 $this->pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
697 $pdf->rollbackTransaction(true);
698
699 $nexY = $this->tab_top + $this->tabTitleHeight;
700
701 // Loop on each lines
702 $pageposbeforeprintlines = $pdf->getPage();
703 $pagenb = $pageposbeforeprintlines;
704 for ($i = 0; $i < $nblines; $i++) {
705 $linePosition = $i + 1;
706 $curY = $nexY;
707
708 // in First Check line page break and add page if needed
709 if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
710 // New page
711 $pdf->AddPage();
712 if (!empty($tplidx)) {
713 $pdf->useTemplate($tplidx);
714 }
715
716 $pdf->setPage($pdf->getNumPages());
717 $nexY = $this->tab_top_newpage;
718 }
719
720 $this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
721
722 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
723 $pdf->SetTextColor(0, 0, 0);
724
725 // Define size of image if we need it
726 $imglinesize = array();
727 if (!empty($realpatharray[$i])) {
728 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
729 }
730
731 $pdf->setTopMargin($this->tab_top_newpage);
732 $pdf->setPageOrientation('', 1, $this->heightforfooter);
733 $pageposbefore = $pdf->getPage();
734 $curYBefore = $curY;
735
736 // Allows data in the first page if description is long enough to break in multiples pages
737 $showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
738
739 if ($this->getColumnStatus('photo')) {
740 // We start with Photo of product line
741 $imageTopMargin = 1;
742 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imageTopMargin + $imglinesize['height']) > ($this->page_hauteur - $this->heightforfooter)) { // If photo too high, we moved completely on new page
743 $pdf->AddPage('', '', true);
744 if (!empty($tplidx)) {
745 $pdf->useTemplate($tplidx);
746 }
747 $pdf->setPage($pageposbefore + 1);
748 $pdf->setPageOrientation('', 1, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
749 $curY = $this->tab_top_newpage;
750 $showpricebeforepagebreak = 0;
751 }
752
753 $pdf->setPageOrientation('', 0, $this->heightforfooter + $this->heightforfreetext); // The only function to edit the bottom margin of current page to set it.
754 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
755 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
756 // $pdf->Image does not increase value return by getY, so we save it manually
757 $posYAfterImage = $curY + $imglinesize['height'];
758
759 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
760 }
761 }
762
763 // restore Page orientation for text
764 $pdf->setPageOrientation('', 1, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
765
766 // Description of product line
767 if ($this->getColumnStatus('desc')) {
768 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
769 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
770 }
771
772
773 $afterPosData = $this->getMaxAfterColsLinePositionsData();
774 $pdf->setPage($pageposbefore);
775 $pdf->setTopMargin($this->marge_haute);
776 $curY = $curYBefore;
777 $pdf->setPageOrientation('', 0, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
778
779 // We suppose that a too long description or photo were moved completely on next page
780 if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
781 $pdf->setPage($afterPosData['page']);
782 $curY = $this->tab_top_newpage;
783 }
784
785 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
786
787 // Line position
788 if ($this->getColumnStatus('position')) {
789 $this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
790 }
791
792 // VAT Rate
793 if ($this->getColumnStatus('vat')) {
794 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
795 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
796 }
797
798 // Unit price before discount
799 if ($this->getColumnStatus('subprice')) {
800 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
801 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
802 }
803
804 // Quantity
805 // Enough for 6 chars
806 if ($this->getColumnStatus('qty')) {
807 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
808 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
809 }
810
811 // Situation progress
812 if ($this->getColumnStatus('progress')) {
813 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
814 $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
815 }
816
817 // Unit
818 if ($this->getColumnStatus('unit')) {
819 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
820 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
821 }
822
823 // Discount on line
824 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
825 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
826 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
827 }
828
829 // Total excl tax line (HT)
830 if ($this->getColumnStatus('totalexcltax')) {
831 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
832 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
833 }
834
835 // Total with tax line (TTC)
836 if ($this->getColumnStatus('totalincltax')) {
837 $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
838 $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
839 }
840
841 // Extrafields
842 if (!empty($object->lines[$i]->array_options)) {
843 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
844 if ($this->getColumnStatus($extrafieldColKey)) {
845 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
846 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
847
848 $this->setAfterColsLinePositionsData('options_' . $extrafieldColKey, $pdf->GetY(), $pdf->getPage());
849 }
850 }
851 }
852
853 $afterPosData = $this->getMaxAfterColsLinePositionsData();
854 $parameters = array(
855 'object' => $object,
856 'i' => $i,
857 'pdf' => & $pdf,
858 'curY' => & $curY,
859 'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
860 'outputlangs' => $outputlangs,
861 'hidedetails' => $hidedetails
862 );
863 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
864
865
866 $sign = 1;
867 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
868 $sign = -1;
869 }
870 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
871 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
872 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
873 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
874 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
875 } else {
876 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
877 }
878 } else {
879 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
880 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
881 } else {
882 $tvaligne = $sign * $object->lines[$i]->total_tva;
883 }
884 }
885
886 $localtax1ligne = $object->lines[$i]->total_localtax1;
887 $localtax2ligne = $object->lines[$i]->total_localtax2;
888 $localtax1_rate = $object->lines[$i]->localtax1_tx;
889 $localtax2_rate = $object->lines[$i]->localtax2_tx;
890 $localtax1_type = $object->lines[$i]->localtax1_type;
891 $localtax2_type = $object->lines[$i]->localtax2_type;
892
893 // TODO remise_percent is an obsolete field for object parent
894 /*if ($object->remise_percent) {
895 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
896 }
897 if ($object->remise_percent) {
898 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
899 }
900 if ($object->remise_percent) {
901 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
902 }*/
903
904 $vatrate = (string) $object->lines[$i]->tva_tx;
905
906 // Retrieve type from database for backward compatibility with old records
907 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
908 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
909 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
910 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
911 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
912 }
913
914 // retrieve global local tax
915 if ($localtax1_type && $localtax1ligne != 0) {
916 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
917 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
918 } else {
919 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
920 }
921 }
922 if ($localtax2_type && $localtax2ligne != 0) {
923 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
924 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
925 } else {
926 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
927 }
928 }
929
930 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
931 $vatrate .= '*';
932 }
933
934 // Fill $this->tva and $this->tva_array
935 if (!isset($this->tva[$vatrate])) {
936 $this->tva[$vatrate] = 0;
937 }
938 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
939 $vatcode = $object->lines[$i]->vat_src_code;
940 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
941 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
942 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
943 }
944 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne, 'tot_ht'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'] + $object->lines[$i]->total_ht);
945 } else {
946 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
947 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
948 }
949 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
950 }
951
952 $afterPosData = $this->getMaxAfterColsLinePositionsData();
953 $pdf->setPage($afterPosData['page']);
954 $nexY = $afterPosData['y'];
955
956 // Add line
957 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $this->heightforfooter - 5) {
958 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
959 //$pdf->SetDrawColor(190,190,200);
960 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
961 $pdf->SetLineStyle(array('dash' => 0));
962 }
963
964 $nexY += 2; // Add space between lines
965 }
966
967 // Add last page for document footer if there are not enough size left
968 $afterPosData = $this->getMaxAfterColsLinePositionsData();
969 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
970
971 if (isset($afterPosData['y']) && $afterPosData['y'] > $this->page_hauteur - $page_bottom_margin) {
972 $pdf->AddPage();
973 if (!empty($tplidx)) {
974 $pdf->useTemplate($tplidx);
975 }
976 $pagenb++;
977 $pdf->setPage($pagenb);
978 }
979
980 // Draw table frames and columns borders
981 $drawTabNumbPage = $pdf->getNumPages();
982 for ($i=$pageposbeforeprintlines; $i<=$drawTabNumbPage; $i++) {
983 $pdf->setPage($i);
984 // reset page orientation each loop to override it if it was changed
985 $pdf->setPageOrientation('', 0, 0); // The only function to edit the bottom margin of current page to set it.
986
987 $drawTabHideTop = $hidetop;
988 $drawTabTop = $this->tab_top_newpage;
989 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
990 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
991
992 if ($i == $pageposbeforeprintlines) {
993 // first page need to start after notes
994 $drawTabTop = $this->tab_top;
995 } elseif (!$drawTabHideTop) {
996 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
997 $drawTabTop-= $this->tabTitleHeight;
998 } else {
999 $drawTabHideTop = 1;
1000 }
1001 }
1002
1003 // last page need to include document footer
1004 if ($i == $pdf->getNumPages()) {
1005 // remove document footer height to tab bottom position
1006 $drawTabBottom-= $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs);
1007 }
1008
1009 $drawTabHeight = $drawTabBottom - $drawTabTop;
1010 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object->multicurrency_code, $outputlangsbis);
1011
1012 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
1013
1014 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1015
1016 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
1017
1018 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
1019 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
1020
1021 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
1022 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1023 $this->_pagehead($pdf, $object, 0, $outputlangs);
1024 }
1025 if (!empty($tplidx)) {
1026 $pdf->useTemplate($tplidx);
1027 }
1028 }
1029
1030
1031 // reset text color before print footers
1032 $pdf->SetTextColor(0, 0, 0);
1033
1034 $pdf->setPage($pdf->getNumPages());
1035
1036 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1037
1038 // Display infos area
1039 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1040
1041 // Display total zone
1042 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1043
1044 // Display payment area
1045 $listofpayments = $object->getListOfPayments('', 0, 1);
1046 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1047 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1048 }
1049
1050 // Add number of pages in footer
1051 if (method_exists($pdf, 'AliasNbPages')) {
1052 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1053 }
1054 // Add terms to sale
1055 if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) {
1056 $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale;
1057 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1058 $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale;
1059 }
1060 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1061 $pagecount = $pdf->setSourceFile($termsofsale);
1062 for ($i = 1; $i <= $pagecount; $i++) {
1063 $tplIdx = $pdf->importPage($i);
1064 if ($tplIdx!==false) {
1065 $s = $pdf->getTemplatesize($tplIdx);
1066 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1067 $pdf->useTemplate($tplIdx);
1068 } else {
1069 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
1070 }
1071 }
1072 }
1073 }
1074
1075 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
1076 $this->addBottomQRInvoice($pdf, $object, $outputlangs);
1077 }
1078
1079 $pdf->Close();
1080
1081 $pdf->Output($file, 'F');
1082
1083 // Add pdfgeneration hook
1084 $hookmanager->initHooks(array('pdfgeneration'));
1085 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1086 global $action;
1087 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1088 if ($reshook < 0) {
1089 $this->error = $hookmanager->error;
1090 $this->errors = $hookmanager->errors;
1091 }
1092
1093 dolChmod($file);
1094
1095 $this->result = array('fullpath' => $file);
1096
1097 return 1; // No error
1098 } else {
1099 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1100 return 0;
1101 }
1102 } else {
1103 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1104 return 0;
1105 }
1106 }
1107
1108
1118 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1119 {
1120 $sign = 1;
1121 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1122 $sign = -1;
1123 }
1124
1125 $tab3_posx = 120;
1126 $tab3_top = $posy + 8;
1127 $tab3_width = 80;
1128 $tab3_height = 4;
1129 if ($this->page_largeur < 210) { // To work with US executive format
1130 $tab3_posx -= 15;
1131 }
1132
1133 $default_font_size = pdf_getPDFFontSize($outputlangs);
1134
1135 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1136 if ($object->type == 2) {
1137 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1138 }
1139
1140 $pdf->SetFont('', '', $default_font_size - 3);
1141 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1142 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1143
1144 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1145
1146 $pdf->SetFont('', '', $default_font_size - 4);
1147 $pdf->SetXY($tab3_posx, $tab3_top);
1148 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1149 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1150 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1151 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1152 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1153 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1154 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1155
1156 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1157
1158 $y = 0;
1159
1160 $pdf->SetFont('', '', $default_font_size - 4);
1161
1162
1163 // Loop on each discount available (deposits and credit notes and excess of payment included)
1164 $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,";
1165 $sql .= " re.description, re.fk_facture_source,";
1166 $sql .= " f.type, f.datef";
1167 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1168 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1169 $resql = $this->db->query($sql);
1170 if ($resql) {
1171 $num = $this->db->num_rows($resql);
1172 $i = 0;
1173 $invoice = new Facture($this->db);
1174 while ($i < $num) {
1175 $y += 3;
1176 $obj = $this->db->fetch_object($resql);
1177
1178 if ($obj->type == 2) {
1179 $text = $outputlangs->transnoentities("CreditNote");
1180 } elseif ($obj->type == 3) {
1181 $text = $outputlangs->transnoentities("Deposit");
1182 } elseif ($obj->type == 0) {
1183 $text = $outputlangs->transnoentities("ExcessReceived");
1184 } else {
1185 $text = $outputlangs->transnoentities("UnknownType");
1186 }
1187
1188 $invoice->fetch($obj->fk_facture_source);
1189
1190 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1191 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1192 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1193 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1194 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1195 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1196 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1197 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1198
1199 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1200
1201 $i++;
1202 }
1203 } else {
1204 $this->error = $this->db->lasterror();
1205 return -1;
1206 }
1207
1208 // Loop on each payment
1209 // TODO Call getListOfPayments instead of hard coded sql
1210 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1211 $sql .= " cp.code";
1212 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1213 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1214 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1215 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1216 $sql .= " ORDER BY p.datep";
1217
1218 $resql = $this->db->query($sql);
1219 if ($resql) {
1220 $num = $this->db->num_rows($resql);
1221 $i = 0;
1222 $y += 3;
1223 $maxY = $y;
1224 while ($i < $num) {
1225 $row = $this->db->fetch_object($resql);
1226 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1227 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1228 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1229 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1230 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1231 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1232
1233 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1234 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1235 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1236 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1237 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1238 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1239 $y += 3;
1240 $i++;
1241 }
1242
1243 return $tab3_top + $y + 3;
1244 } else {
1245 $this->error = $this->db->lasterror();
1246 return -1;
1247 }
1248 }
1249
1250
1261 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1262 {
1263 global $conf, $mysoc, $hookmanager;
1264
1265 $default_font_size = pdf_getPDFFontSize($outputlangs);
1266
1267 $pdf->SetFont('', '', $default_font_size - 1);
1268
1269 krsort($this->tva_array);
1270
1271 // Clean data type
1272 $object->total_tva = (float) $object->total_tva;
1273
1274 // Show VAT details
1275 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1276 $pdf->SetFillColor(224, 224, 224);
1277
1278 $pdf->SetFont('', '', $default_font_size - 2);
1279 $pdf->SetXY($this->marge_gauche, $posy);
1280 $titre = $outputlangs->transnoentities("VAT");
1281 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1282
1283 $pdf->SetFont('', '', $default_font_size - 2);
1284 $pdf->SetXY($this->marge_gauche + 25, $posy);
1285 $titre = $outputlangs->transnoentities("NetTotal");
1286 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1287
1288 $pdf->SetFont('', '', $default_font_size - 2);
1289 $pdf->SetXY($this->marge_gauche + 50, $posy);
1290 $titre = $outputlangs->transnoentities("VATAmount");
1291 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1292
1293 $pdf->SetFont('', '', $default_font_size - 2);
1294 $pdf->SetXY($this->marge_gauche + 75, $posy);
1295 $titre = $outputlangs->transnoentities("AmountTotal");
1296 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1297
1298 $posy = $pdf->GetY();
1299 $tot_ht = 0;
1300 $tot_tva = 0;
1301 $tot_ttc = 0;
1302
1303 foreach ($this->tva_array as $tvakey => $tvaval) {
1304 $pdf->SetFont('', '', $default_font_size - 2);
1305 $pdf->SetXY($this->marge_gauche, $posy);
1306 $titre = round((float) $tvakey, 2) . "%";
1307 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1308
1309 $pdf->SetFont('', '', $default_font_size - 2);
1310 $pdf->SetXY($this->marge_gauche + 25, $posy);
1311 $titre = price($tvaval['tot_ht']);
1312 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1313 $tot_ht += $tvaval['tot_ht'];
1314
1315 $pdf->SetFont('', '', $default_font_size - 2);
1316 $pdf->SetXY($this->marge_gauche + 50, $posy);
1317 $titre = price($tvaval['amount']);
1318 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1319 $tot_tva += $tvaval['amount'];
1320
1321 $pdf->SetFont('', '', $default_font_size - 2);
1322 $pdf->SetXY($this->marge_gauche + 75, $posy);
1323 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1324 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1325 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1326
1327 $posy = $pdf->GetY();
1328 }
1329 }
1330
1331 // If France, show VAT mention if applicable
1332 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1333 $pdf->SetFont('', '', $default_font_size - 2);
1334 $pdf->SetXY($this->marge_gauche, $posy);
1335 if (empty($mysoc->tva_assuj)) {
1336 if ($mysoc->forme_juridique_code == 92) {
1337 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1338 } else {
1339 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1340 }
1341 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1342 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', 0);
1343 }
1344 $posy = $pdf->GetY() + 4;
1345 }
1346
1347 $posxval = 52; // Position of values of properties shown on left side
1348 $posxend = 110; // End of x for text on left side
1349 if ($this->page_largeur < 210) { // To work with US executive format
1350 $posxend -= 10;
1351 }
1352
1353 // Show payments conditions
1354 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1355 $pdf->SetFont('', '', $default_font_size - 2);
1356 $pdf->SetXY($this->marge_gauche, $posy);
1357 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1358 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1359
1360 $pdf->SetFont('', '', $default_font_size - 2);
1361 $pdf->SetXY($posxval, $posy);
1362 $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);
1363 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1364 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1365
1366 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1367 }
1368
1369 // Show category of operations
1370 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1371 $pdf->SetFont('', '', $default_font_size - 2);
1372 $pdf->SetXY($this->marge_gauche, $posy);
1373 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1374 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1375
1376 $pdf->SetFont('', '', $default_font_size - 2);
1377 $pdf->SetXY($posxval, $posy);
1378 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1379 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1380
1381 $posy = $pdf->GetY() + 3; // for 2 lines
1382 }
1383
1384 if ($object->type != 2) {
1385 // Check a payment mode is defined
1386 if (empty($object->mode_reglement_code)
1387 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1388 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1389 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1390 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1391 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1392 // Avoid having any valid PDF with setup that is not complete
1393 $outputlangs->load("errors");
1394
1395 $pdf->SetXY($this->marge_gauche, $posy);
1396 $pdf->SetTextColor(200, 0, 0);
1397 $pdf->SetFont('', '', $default_font_size - 2);
1398 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1399 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
1400 $pdf->SetTextColor(0, 0, 0);
1401
1402 $posy = $pdf->GetY() + 1;
1403 }
1404
1405 // Show payment mode
1406 if (!empty($object->mode_reglement_code)
1407 && $object->mode_reglement_code != 'CHQ'
1408 && $object->mode_reglement_code != 'VIR') {
1409 $pdf->SetFont('', '', $default_font_size - 2);
1410 $pdf->SetXY($this->marge_gauche, $posy);
1411 $titre = $outputlangs->transnoentities("PaymentMode").':';
1412 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1413
1414 $pdf->SetFont('', '', $default_font_size - 2);
1415 $pdf->SetXY($posxval, $posy);
1416 $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);
1417
1418 //#21654: add account number used for the debit
1419 if ($object->mode_reglement_code == "PRE") {
1420 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1421 $bac = new CompanyBankAccount($this->db);
1422 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1423 $bac->fetch(0, '', $object->thirdparty->id);
1424 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1425 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1426 }
1427
1428 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1429
1430 $posy = $pdf->GetY();
1431 }
1432
1433 // Show if Option VAT debit option is on also if transmitter is french
1434 // Decret n°2099-1299 2022-10-07
1435 // French mention : "Option pour le paiement de la taxe d'après les débits"
1436 if ($this->emetteur->country_code == 'FR') {
1437 if (getDolGlobalInt('TAX_MODE') == 1) {
1438 $pdf->SetXY($this->marge_gauche, $posy);
1439 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1440
1441 $posy = $pdf->GetY() + 1;
1442 }
1443 }
1444
1445 // Show online payment link
1446 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1447 $useonlinepayment = 0;
1448 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1449 // Show online payment link
1450 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1451 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1452 $validpaymentmethod = getValidOnlinePaymentMethods('');
1453 $useonlinepayment = count($validpaymentmethod);
1454 }
1455
1456
1457 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1458 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1459 global $langs;
1460
1461 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1462 $servicename = $langs->transnoentities('Online');
1463 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1464 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1465
1466 $pdf->SetXY($this->marge_gauche, $posy);
1467 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1468
1469 $posy = $pdf->GetY() + 1;
1470 }
1471 }
1472
1473 // Show payment mode CHQ
1474 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1475 // If payment mode unregulated or payment mode forced to CHQ
1476 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1477 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1478
1479 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1480 $account = new Account($this->db);
1481 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1482
1483 $pdf->SetXY($this->marge_gauche, $posy);
1484 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1485 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
1486 $posy = $pdf->GetY() + 1;
1487
1488 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1489 $pdf->SetXY($this->marge_gauche, $posy);
1490 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1491 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1492 $posy = $pdf->GetY() + 2;
1493 }
1494 }
1495 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1496 $pdf->SetXY($this->marge_gauche, $posy);
1497 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1498 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1499 $posy = $pdf->GetY() + 1;
1500
1501 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1502 $pdf->SetXY($this->marge_gauche, $posy);
1503 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1504 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1505 $posy = $pdf->GetY() + 2;
1506 }
1507 }
1508 }
1509 }
1510
1511 // If payment mode not forced or forced to VIR, show payment with BAN
1512 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1513 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1514 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1515 if ($object->fk_bank > 0) {
1516 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1517 }
1518 $account = new Account($this->db);
1519 $account->fetch($bankid);
1520
1521 $curx = $this->marge_gauche;
1522 $cury = $posy;
1523
1524 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1525
1526 $posy += 2;
1527
1528 // SHOW EPC QR CODE
1529 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == 'bottom') {
1530 $qrPosX = 120;
1531 $qrPosY = $posy;
1532 $qrCodeColor = array('25', '25', '25');
1533 $styleQr = array(
1534 'border' => false,
1535 'padding' => 0,
1536 'fgcolor' => $qrCodeColor,
1537 'bgcolor' => false, //array(255,255,255)
1538 'module_width' => 1, // width of a single module in points
1539 'module_height' => 1 // height of a single module in points
1540 );
1541
1542 $EPCQrCodeString = $object->buildEPCQrCodeString();
1543 $pdf->write2DBarcode($EPCQrCodeString, 'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr, 'N');
1544
1545 $pdf->SetXY($qrPosX + 30, $posy + 5);
1546 $pdf->SetFont('', '', $default_font_size - 5);
1547 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0);
1548 $posy = $pdf->GetY() + 2;
1549 }
1550
1551 // Show structured communication
1552 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1553 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1554 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1555
1556 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', 0);
1557 }
1558 }
1559 }
1560 }
1561
1562 return $posy;
1563 }
1564
1565
1577 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1578 {
1579 global $mysoc, $hookmanager;
1580
1581 $sign = 1;
1582 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1583 $sign = -1;
1584 }
1585
1586 $default_font_size = pdf_getPDFFontSize($outputlangs);
1587
1588 $tab2_top = $posy;
1589 $tab2_hl = 4;
1590 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1591 $pdf->SetFont('', '', $default_font_size - 2);
1592 } else {
1593 $pdf->SetFont('', '', $default_font_size - 1);
1594 }
1595
1596 // Total table
1597 $col1x = 120;
1598 $col2x = 170;
1599 if ($this->page_largeur < 210) { // To work with US executive format
1600 $col1x -= 15;
1601 $col2x -= 10;
1602 }
1603 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1604
1605 $useborder = 0;
1606 $index = 0;
1607
1608 // Add trigger to allow to edit $object
1609 $parameters = array(
1610 'object' => &$object,
1611 'outputlangs' => $outputlangs,
1612 );
1613 $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1614
1615 // overall percentage of advancement
1616 $percent = 0;
1617 $i = 0;
1618 foreach ($object->lines as $line) {
1619 if ($line->product_type != 9) {
1620 $percent += $line->situation_percent;
1621 $i++;
1622 }
1623 }
1624
1625 if (!empty($i)) {
1626 $avancementGlobal = $percent / $i;
1627 } else {
1628 $avancementGlobal = 0;
1629 }
1630
1631 $object->fetchPreviousNextSituationInvoice();
1632 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1633
1634 $total_a_payer = 0;
1635 $total_a_payer_ttc = 0;
1636 foreach ($TPreviousIncoice as &$fac) {
1637 $total_a_payer += $fac->total_ht;
1638 $total_a_payer_ttc += $fac->total_ttc;
1639 }
1640 $total_a_payer += $object->total_ht;
1641 $total_a_payer_ttc += $object->total_ttc;
1642
1643 if (!empty($avancementGlobal)) {
1644 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1645 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1646 } else {
1647 $total_a_payer = 0;
1648 $total_a_payer_ttc = 0;
1649 }
1650
1651 $i = 1;
1652 if (!empty($TPreviousIncoice)) {
1653 $pdf->setY($tab2_top);
1654 $posy = $pdf->GetY();
1655
1656 foreach ($TPreviousIncoice as &$fac) {
1657 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1658 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1659 $pdf->addPage();
1660 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1661 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1662 $pdf->setY($this->tab_top_newpage);
1663 } else {
1664 $pdf->setY($this->marge_haute);
1665 }
1666 $posy = $pdf->GetY();
1667 }
1668
1669 // Cumulate preceding VAT
1670 $index++;
1671 $pdf->SetFillColor(255, 255, 255);
1672 $pdf->SetXY($col1x, $posy);
1673 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1674
1675 $pdf->SetXY($col2x, $posy);
1676
1677 $facSign = '';
1678 if ($i > 1) {
1679 $facSign = $fac->total_ht >= 0 ? '+' : '';
1680 }
1681
1682 $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1683
1684 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1685
1686 $i++;
1687 $posy += $tab2_hl;
1688
1689 $pdf->setY($posy);
1690 }
1691
1692 // Display current total
1693 $pdf->SetFillColor(255, 255, 255);
1694 $pdf->SetXY($col1x, $posy);
1695 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1696
1697 $pdf->SetXY($col2x, $posy);
1698 $facSign = '';
1699 if ($i > 1) {
1700 $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1701 }
1702
1703 if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1704 $facSign = '-'; // les avoirs
1705 }
1706
1707
1708 $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1709 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1710
1711 $posy += $tab2_hl;
1712
1713 // Display all total
1714 $pdf->SetFont('', '', $default_font_size - 1);
1715 $pdf->SetFillColor(255, 255, 255);
1716 $pdf->SetXY($col1x, $posy);
1717 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", $avancementGlobal), 0, 'L', 1);
1718
1719 $pdf->SetXY($col2x, $posy);
1720 $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', 1);
1721 $pdf->SetFont('', '', $default_font_size - 2);
1722
1723 $posy += $tab2_hl;
1724
1725 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1726 $pdf->addPage();
1727 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1728 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1729 $pdf->setY($this->tab_top_newpage);
1730 } else {
1731 $pdf->setY($this->marge_haute);
1732 }
1733
1734 $posy = $pdf->GetY();
1735 }
1736
1737 $tab2_top = $posy;
1738 $index = 0;
1739
1740 $tab2_top += 3;
1741 }
1742
1743
1744 // Get Total HT
1745 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1746
1747 // Total remise
1748 $total_line_remise_print = $total_line_remise = 0;
1749 foreach ($object->lines as $i => $line) {
1750 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1751 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1752 // Gestion remise sous forme de ligne négative
1753 if ($line->total_ht < 0) {
1754 $total_line_remise += -$line->total_ht;
1755 }
1756 $usemc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1);
1757 $total_line_remise_print = $total_line_remise;
1758 if ($usemc) {
1759 $ratio = (!empty($object->total_ht) ? (float) $object->multicurrency_total_ht / (float) $object->total_ht : 0);
1760 if (!empty($ratio)) $total_line_remise_print = price2num($total_line_remise * $ratio, 'MT');
1761 }
1762 }
1763 if ($total_line_remise > 0) {
1764 if (!getDolGlobalString('MAIN_HIDE_AMOUNT_DISCOUNT')) {
1765 $pdf->SetFillColor(255, 255, 255);
1766 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1767 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
1768 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1769 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise_print, 0, $outputlangs), 0, 'R', 1);
1770 $index++;
1771 }
1772 // Show total NET before discount
1773 if (!getDolGlobalString('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT')) {
1774 $pdf->SetFillColor(255, 255, 255);
1775 $pdf->SetXY($col1x, $tab2_top);
1776 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
1777 $pdf->SetXY($col2x, $tab2_top);
1778 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise_print + $total_ht, 0, $outputlangs), 0, 'R', 1);
1779 $index++;
1780 }
1781 }
1782
1783 // Total HT
1784 $pdf->SetFillColor(255, 255, 255);
1785 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1786 $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);
1787
1788 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1789 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1790 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1791
1792 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1793 $index++;
1794 $pdf->SetFillColor(255, 255, 255);
1795 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1796 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
1797
1798 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1799 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', 1);
1800 }
1801
1802 // Show VAT by rates and total
1803 $pdf->SetFillColor(248, 248, 248);
1804
1805 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1806
1807 $this->atleastoneratenotnull = 0;
1808 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1809 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1810 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1811 // Nothing to do
1812 } else {
1813 //Local tax 1 before VAT
1814 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1815 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1816 continue;
1817 }
1818
1819 foreach ($localtax_rate as $tvakey => $tvaval) {
1820 if ($tvakey != 0) { // On affiche pas taux 0
1821 //$this->atleastoneratenotnull++;
1822
1823 $index++;
1824 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1825
1826 $tvacompl = '';
1827 if (preg_match('/\*/', (string) $tvakey)) {
1828 $tvakey = str_replace('*', '', (string) $tvakey);
1829 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1830 }
1831
1832 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1833 $totalvat .= ' ';
1834
1835 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1836 $totalvat .= $tvacompl;
1837 } else {
1838 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1839 }
1840
1841 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1842
1843 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1844
1845 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1846 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1847 }
1848 }
1849 }
1850
1851 //Local tax 2 before VAT
1852 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1853 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1854 continue;
1855 }
1856
1857 foreach ($localtax_rate as $tvakey => $tvaval) {
1858 if ($tvakey != 0) { // On affiche pas taux 0
1859 //$this->atleastoneratenotnull++;
1860
1861 $index++;
1862 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1863
1864 $tvacompl = '';
1865 if (preg_match('/\*/', (string) $tvakey)) {
1866 $tvakey = str_replace('*', '', (string) $tvakey);
1867 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1868 }
1869 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1870 $totalvat .= ' ';
1871
1872 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1873 $totalvat .= $tvacompl;
1874 } else {
1875 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1876 }
1877
1878 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1879
1880 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1881
1882 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1883 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1884 }
1885 }
1886 }
1887
1888 // Situations totals might be wrong on huge amounts with old mode 1
1889 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1890 $sum_pdf_tva = 0;
1891 foreach ($this->tva as $tvakey => $tvaval) {
1892 $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1893 }
1894
1895 if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1896 if (!empty($sum_pdf_tva)) {
1897 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1898 } else {
1899 $coef_fix_tva = 1;
1900 }
1901
1902
1903 foreach ($this->tva as $tvakey => $tvaval) {
1904 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1905 }
1906 foreach ($this->tva_array as $tvakey => $tvaval) {
1907 $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
1908 }
1909 }
1910 }
1911
1912 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1913 // VAT
1914 foreach ($this->tva_array as $tvakey => $tvaval) {
1915 if ($tvakey != 0) { // On affiche pas taux 0
1916 $this->atleastoneratenotnull++;
1917
1918 $index++;
1919 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1920
1921 $tvacompl = '';
1922 if (preg_match('/\*/', $tvakey)) {
1923 $tvakey = str_replace('*', '', $tvakey);
1924 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1925 }
1926 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1927 $totalvat .= ' ';
1928 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1929 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1930 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1931 $totalvat .= $tvaval['vatcode'].$tvacompl;
1932 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1933 $totalvat .= $tvacompl;
1934 } else {
1935 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1936 }
1937 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1938
1939 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1940 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1941 }
1942 }
1943 }
1944
1945 //Local tax 1 after VAT
1946 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1947 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1948 continue;
1949 }
1950
1951 foreach ($localtax_rate as $tvakey => $tvaval) {
1952 if ($tvakey != 0) { // On affiche pas taux 0
1953 //$this->atleastoneratenotnull++;
1954
1955 $index++;
1956 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1957
1958 $tvacompl = '';
1959 if (preg_match('/\*/', (string) $tvakey)) {
1960 $tvakey = str_replace('*', '', (string) $tvakey);
1961 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1962 }
1963 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1964 $totalvat .= ' ';
1965
1966 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1967 $totalvat .= $tvacompl;
1968 } else {
1969 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1970 }
1971
1972 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1973
1974 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1975
1976 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1977 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1978 }
1979 }
1980 }
1981
1982 //Local tax 2 after VAT
1983 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1984 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1985 continue;
1986 }
1987
1988 foreach ($localtax_rate as $tvakey => $tvaval) {
1989 // retrieve global local tax
1990 if ($tvakey != 0) { // On affiche pas taux 0
1991 //$this->atleastoneratenotnull++;
1992
1993 $index++;
1994 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1995
1996 $tvacompl = '';
1997 if (preg_match('/\*/', (string) $tvakey)) {
1998 $tvakey = str_replace('*', '', (string) $tvakey);
1999 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
2000 }
2001 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
2002 $totalvat .= ' ';
2003
2004 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
2005 $totalvat .= $tvacompl;
2006 } else {
2007 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
2008 }
2009
2010 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
2011
2012 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
2013
2014 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2015 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
2016 }
2017 }
2018 }
2019
2020 // Revenue stamp
2021 if (price2num($object->revenuestamp, 'MT') != 0) {
2022 $index++;
2023 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2024 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
2025
2026 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2027 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
2028 }
2029
2030 // Total TTC
2031 $index++;
2032 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2033 $pdf->SetTextColor(0, 0, 60);
2034 $pdf->SetFillColor(224, 224, 224);
2035 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
2036
2037 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2038 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
2039
2040
2041 // Retained warranty
2042 if ($object->displayRetainedWarranty()) {
2043 $pdf->SetTextColor(40, 40, 40);
2044 $pdf->SetFillColor(255, 255, 255);
2045
2046 $retainedWarranty = $object->getRetainedWarrantyAmount();
2047 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
2048
2049 // Billed - retained warranty
2050 $index++;
2051 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2052 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
2053
2054 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2055 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
2056
2057 // retained warranty
2058 $index++;
2059 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2060
2061 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
2062 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
2063
2064 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
2065 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2066 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
2067 }
2068 }
2069 }
2070
2071 $pdf->SetTextColor(0, 0, 0);
2072
2073 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
2074 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
2075
2076 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
2077 if (!empty($object->paye)) {
2078 $resteapayer = 0;
2079 }
2080
2081 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
2082 // Already paid + Deposits
2083 $index++;
2084 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2085 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
2086 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2087 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
2088
2089 // Credit note
2090 if ($creditnoteamount) {
2091 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
2092 $labeltouse .= (is_object($outputlangsbis) ? (' / '.(($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes"))) : '');
2093 $index++;
2094 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2095 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
2096 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2097 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
2098 }
2099
2100 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2101 $index++;
2102 $pdf->SetFillColor(255, 255, 255);
2103
2104 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2105 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
2106 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2107 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'), 0, $outputlangs), $useborder, 'R', 1);
2108
2109 $resteapayer = 0;
2110 }
2111
2112 $index++;
2113 $pdf->SetTextColor(0, 0, 60);
2114 $pdf->SetFillColor(224, 224, 224);
2115 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2116 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
2117 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2118 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
2119
2120 $pdf->SetFont('', '', $default_font_size - 1);
2121 $pdf->SetTextColor(0, 0, 0);
2122 }
2123
2124 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2125
2126 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2127 if ($reshook < 0) {
2128 $this->error = $hookmanager->error;
2129 $this->errors = $hookmanager->errors;
2130 }
2131
2132 $index++;
2133 return ($tab2_top + ($tab2_hl * $index));
2134 }
2135
2136 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2144 public static function liste_modeles($db, $maxfilenamelength = 0)
2145 {
2146 // phpcs:enable
2147 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2148 }
2149
2150 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2165 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2166 {
2167 global $conf;
2168
2169 // Force to disable hidetop and hidebottom
2170 $hidebottom = 0;
2171 if ($hidetop) {
2172 $hidetop = -1;
2173 }
2174
2175 $currency = !empty($currency) ? $currency : $conf->currency;
2176 $default_font_size = pdf_getPDFFontSize($outputlangs);
2177
2178 // Amount in (at tab_top - 1)
2179 $pdf->SetTextColor(0, 0, 0);
2180 $pdf->SetFont('', '', $default_font_size - 2);
2181
2182 if (empty($hidetop)) {
2183 // Show category of operations
2184 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2185 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2186 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2187 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2188 }
2189
2190 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2191 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2192 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2193 }
2194
2195 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2196 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2197
2198 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2199 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2200 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2201 }
2202 }
2203
2204 $pdf->SetDrawColor(128, 128, 128);
2205 $pdf->SetFont('', '', $default_font_size - 1);
2206
2207 // Output Rect
2208 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
2209
2210
2211 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2212
2213 if (empty($hidetop)) {
2214 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
2215 }
2216 }
2217
2218 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2229 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2230 {
2231 // phpcs:enable
2232 global $conf, $langs;
2233
2234 $ltrdirection = 'L';
2235 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2236 $ltrdirection = 'R';
2237 }
2238
2239 // Load traductions files required by page
2240 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2241
2242 $default_font_size = pdf_getPDFFontSize($outputlangs);
2243
2244 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2245
2246 $pdf->SetTextColor(0, 0, 60);
2247 $pdf->SetFont('', 'B', $default_font_size + 3);
2248
2249 $w = 110;
2250
2251 $posy = $this->marge_haute;
2252 $posx = $this->page_largeur - $this->marge_droite - $w;
2253
2254 $pdf->SetXY($this->marge_gauche, $posy);
2255
2256 // Logo
2257 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2258 if ($this->emetteur->logo) {
2259 $logodir = $conf->mycompany->dir_output;
2260 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2261 $logodir = $conf->mycompany->multidir_output[$object->entity];
2262 }
2263 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2264 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2265 } else {
2266 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2267 }
2268 if (is_readable($logo)) {
2269 $height = pdf_getHeightForLogo($logo);
2270 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2271 } else {
2272 $pdf->SetTextColor(200, 0, 0);
2273 $pdf->SetFont('', 'B', $default_font_size - 2);
2274 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2275 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2276 }
2277 } else {
2278 $text = $this->emetteur->name;
2279 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2280 }
2281 }
2282
2283 $pdf->SetFont('', 'B', $default_font_size + 3);
2284 $pdf->SetXY($posx, $posy);
2285 $pdf->SetTextColor(0, 0, 60);
2286 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2287 if ($object->type == 1) {
2288 $title = $outputlangs->transnoentities("InvoiceReplacement");
2289 }
2290 if ($object->type == 2) {
2291 $title = $outputlangs->transnoentities("InvoiceAvoir");
2292 }
2293 if ($object->type == 3) {
2294 $title = $outputlangs->transnoentities("InvoiceDeposit");
2295 }
2296 if ($object->type == 4) {
2297 $title = $outputlangs->transnoentities("InvoiceProForma");
2298 }
2299 if ($this->situationinvoice) {
2300 $outputlangs->loadLangs(array("other"));
2301 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2302 }
2303 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2304 $title .= ' - ';
2305 if ($object->type == 0) {
2306 if ($this->situationinvoice) {
2307 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2308 }
2309 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2310 } elseif ($object->type == 1) {
2311 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2312 } elseif ($object->type == 2) {
2313 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2314 } elseif ($object->type == 3) {
2315 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2316 } elseif ($object->type == 4) {
2317 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2318 }
2319 }
2320 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2321 if ($object->status == $object::STATUS_DRAFT) {
2322 $pdf->SetTextColor(128, 0, 0);
2323 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2324 }
2325
2326 $pdf->MultiCell($w, 3, $title, '', 'R');
2327
2328 $pdf->SetFont('', 'B', $default_font_size);
2329
2330 /*
2331 $posy += 5;
2332 $pdf->SetXY($posx, $posy);
2333 $pdf->SetTextColor(0, 0, 60);
2334 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2335 if ($object->status == $object::STATUS_DRAFT) {
2336 $pdf->SetTextColor(128, 0, 0);
2337 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2338 }
2339 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2340
2341 $posy += 3;
2342 $pdf->SetFont('', '', $default_font_size - 2);
2343
2344 if ($object->ref_customer) {
2345 $posy += 4;
2346 $pdf->SetXY($posx, $posy);
2347 $pdf->SetTextColor(0, 0, 60);
2348 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2349 }
2350
2351 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2352 $object->fetchProject();
2353 if (!empty($object->project->ref)) {
2354 $posy += 3;
2355 $pdf->SetXY($posx, $posy);
2356 $pdf->SetTextColor(0, 0, 60);
2357 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2358 }
2359 }
2360
2361 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2362 $object->fetchProject();
2363 if (!empty($object->project->ref)) {
2364 $outputlangs->load("projects");
2365 $posy += 3;
2366 $pdf->SetXY($posx, $posy);
2367 $pdf->SetTextColor(0, 0, 60);
2368 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2369 }
2370 }
2371
2372 $objectidnext = $object->getIdReplacingInvoice('validated');
2373 if ($object->type == 0 && $objectidnext) {
2374 $objectreplacing = new Facture($this->db);
2375 $objectreplacing->fetch($objectidnext);
2376
2377 $posy += 3;
2378 $pdf->SetXY($posx, $posy);
2379 $pdf->SetTextColor(0, 0, 60);
2380 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2381 }
2382 if ($object->type == 1) {
2383 $objectreplaced = new Facture($this->db);
2384 $objectreplaced->fetch($object->fk_facture_source);
2385
2386 $posy += 4;
2387 $pdf->SetXY($posx, $posy);
2388 $pdf->SetTextColor(0, 0, 60);
2389 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2390 }
2391 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2392 $objectreplaced = new Facture($this->db);
2393 $objectreplaced->fetch($object->fk_facture_source);
2394
2395 $posy += 3;
2396 $pdf->SetXY($posx, $posy);
2397 $pdf->SetTextColor(0, 0, 60);
2398 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2399 }
2400
2401 $posy += 4;
2402 $pdf->SetXY($posx, $posy);
2403 $pdf->SetTextColor(0, 0, 60);
2404
2405 $title = $outputlangs->transnoentities("DateInvoice");
2406 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2407 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2408 }
2409 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2410
2411 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2412 $posy += 4;
2413 $pdf->SetXY($posx, $posy);
2414 $pdf->SetTextColor(0, 0, 60);
2415 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2416 }
2417
2418 if ($object->type != 2) {
2419 $posy += 3;
2420 $pdf->SetXY($posx, $posy);
2421 $pdf->SetTextColor(0, 0, 60);
2422 $title = $outputlangs->transnoentities("DateDue");
2423 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2424 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2425 }
2426 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2427 }
2428
2429 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2430 $posy += 3;
2431 $pdf->SetXY($posx, $posy);
2432 $pdf->SetTextColor(0, 0, 60);
2433 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2434 }
2435
2436 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2437 $posy += 3;
2438 $pdf->SetXY($posx, $posy);
2439 $pdf->SetTextColor(0, 0, 60);
2440 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
2441 }
2442
2443 // Get contact
2444 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2445 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2446 if (count($arrayidcontact) > 0) {
2447 $usertmp = new User($this->db);
2448 $usertmp->fetch($arrayidcontact[0]);
2449 $posy += 4;
2450 $pdf->SetXY($posx, $posy);
2451 $pdf->SetTextColor(0, 0, 60);
2452 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2453 }
2454 }
2455
2456 $posy += 1;
2457
2458 $top_shift = 0;
2459 $shipp_shift = 0;
2460 // Show list of linked objects
2461 $current_y = $pdf->getY();
2462 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2463 if ($current_y < $pdf->getY()) {
2464 $top_shift = $pdf->getY() - $current_y;
2465 }
2466
2467 if ($showaddress) {
2468 // Sender properties
2469 $carac_emetteur = '';
2470 // Add internal contact of object if defined
2471 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2472 if (count($arrayidcontact) > 0) {
2473 $object->fetch_user($arrayidcontact[0]);
2474 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2475 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2476 $carac_emetteur .= "\n";
2477 }
2478
2479 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2480
2481 // Show sender
2482 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2483 $posy += $top_shift;
2484 $posx = $this->marge_gauche;
2485 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2486 $posx = $this->page_largeur - $this->marge_droite - 80;
2487 }
2488
2489 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2490 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2491
2492 // Show sender frame
2493 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2494 $pdf->SetTextColor(0, 0, 0);
2495 $pdf->SetFont('', '', $default_font_size - 2);
2496 $pdf->SetXY($posx, $posy - 5);
2497 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2498 $pdf->SetXY($posx, $posy);
2499 $pdf->SetFillColor(230, 230, 230);
2500 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2501 $pdf->SetTextColor(0, 0, 60);
2502 }
2503
2504 // Show sender name
2505 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2506 $pdf->SetXY($posx + 2, $posy + 3);
2507 $pdf->SetFont('', 'B', $default_font_size);
2508 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2509 $posy = $pdf->getY();
2510 }
2511
2512 // Show sender information
2513 $pdf->SetXY($posx + 2, $posy);
2514 $pdf->SetFont('', '', $default_font_size - 1);
2515 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2516
2517 // If BILLING contact defined on invoice, we use it
2518 $usecontact = false;
2519 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2520 if (count($arrayidcontact) > 0) {
2521 $usecontact = true;
2522 $result = $object->fetch_contact($arrayidcontact[0]);
2523 }
2524
2525 // Recipient name
2526 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2527 $thirdparty = $object->contact;
2528 } else {
2529 $thirdparty = $object->thirdparty;
2530 }
2531
2532 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2533
2534 $mode = 'target';
2535 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2536
2537 // Show recipient
2538 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2539 if ($this->page_largeur < 210) {
2540 $widthrecbox = 84; // To work with US executive format
2541 }
2542 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2543 $posy += $top_shift;
2544 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2545 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2546 $posx = $this->marge_gauche;
2547 }
2548
2549 // Show recipient frame
2550 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2551 $pdf->SetTextColor(0, 0, 0);
2552 $pdf->SetFont('', '', $default_font_size - 2);
2553 $pdf->SetXY($posx + 2, $posy - 5);
2554 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2555 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2556 }
2557
2558 // Show recipient name
2559 $pdf->SetXY($posx + 2, $posy + 3);
2560 $pdf->SetFont('', 'B', $default_font_size);
2561 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2562 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2563
2564 $posy = $pdf->getY();
2565
2566 // Show recipient information
2567 $pdf->SetFont('', '', $default_font_size - 1);
2568 $pdf->SetXY($posx + 2, $posy);
2569 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2570 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2571
2572 // Show shipping/delivery address
2573 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2574 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2575
2576 if (!empty($idaddressshipping)) {
2577 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2578 $companystatic = new Societe($this->db);
2579 $companystatic->fetch($object->contact->fk_soc);
2580 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2581 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
2582 } else {
2583 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2584 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2585 }
2586 if (!empty($carac_client_shipping)) {
2587 $posy += $hautcadre;
2588
2589 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2590
2591 // Show shipping frame
2592 $pdf->SetXY($posx + 2, $posy - 5);
2593 $pdf->SetFont('', '', $default_font_size - 2);
2594 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2595 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2596
2597 // Show shipping name
2598 $pdf->SetXY($posx + 2, $posy + 3);
2599 $pdf->SetFont('', 'B', $default_font_size);
2600 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2601
2602 $posy = $pdf->getY();
2603
2604 // Show shipping information
2605 $pdf->SetXY($posx + 2, $posy);
2606 $pdf->SetFont('', '', $default_font_size - 1);
2607 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2608
2609 $shipp_shift += $hautcadre + 10;
2610 }
2611 }
2612 }
2613
2614 $pdf->SetTextColor(0, 0, 0);
2615
2616 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2617
2618 return $pagehead;
2619 }
2620
2621 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2632 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2633 {
2634 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2635 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);
2636 }
2637
2648 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2649 {
2650 global $hookmanager;
2651
2652 // Default field style for content
2653 $this->defaultContentsFieldsStyle = array(
2654 'align' => 'R', // R,C,L
2655 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2656 );
2657
2658 // Default field style for content
2659 $this->defaultTitlesFieldsStyle = array(
2660 'align' => 'C', // R,C,L
2661 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2662 );
2663
2664 /*
2665 * For example
2666 $this->cols['theColKey'] = array(
2667 'rank' => $rank, // int : use for ordering columns
2668 'width' => 20, // the column width in mm
2669 'title' => array(
2670 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2671 'label' => ' ', // the final label : used fore final generated text
2672 'align' => 'L', // text alignment : R,C,L
2673 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2674 ),
2675 'content' => array(
2676 'align' => 'L', // text alignment : R,C,L
2677 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2678 ),
2679 );
2680 */
2681
2682 $rank = 0; // do not use negative rank
2683 $this->cols['position'] = array(
2684 'rank' => $rank,
2685 'width' => 10,
2686 'status' => getDolGlobalInt('PDF_SPONGE_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2687 'title' => array(
2688 'textkey' => '#', // use lang key is useful in somme case with module
2689 'align' => 'C',
2690 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2691 // 'label' => ' ', // the final label
2692 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2693 ),
2694 'content' => array(
2695 'align' => 'C',
2696 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2697 ),
2698 );
2699
2700 $rank = 5; // do not use negative rank
2701 $this->cols['desc'] = array(
2702 'rank' => $rank,
2703 'width' => false, // only for desc
2704 'status' => true,
2705 'title' => array(
2706 'textkey' => 'Designation', // use lang key is useful in somme case with module
2707 'align' => 'L',
2708 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2709 // 'label' => ' ', // the final label
2710 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2711 ),
2712 'content' => array(
2713 'align' => 'L',
2714 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2715 ),
2716 );
2717
2718 // Image of product
2719 $rank += 10;
2720 $this->cols['photo'] = array(
2721 'rank' => $rank,
2722 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2723 'status' => false,
2724 'title' => array(
2725 'textkey' => 'Photo',
2726 'label' => ' '
2727 ),
2728 'content' => array(
2729 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2730 ),
2731 'border-left' => false, // remove left line separator
2732 );
2733
2734 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2735 $this->cols['photo']['status'] = true;
2736 }
2737
2738
2739 $rank += 10;
2740 $this->cols['vat'] = array(
2741 'rank' => $rank,
2742 'status' => false,
2743 'width' => 16, // in mm
2744 'title' => array(
2745 'textkey' => 'VAT'
2746 ),
2747 'border-left' => true, // add left line separator
2748 );
2749
2750 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2751 $this->cols['vat']['status'] = true;
2752 }
2753
2754 $rank += 10;
2755 $this->cols['subprice'] = array(
2756 'rank' => $rank,
2757 'width' => 19, // in mm
2758 'status' => true,
2759 'title' => array(
2760 'textkey' => 'PriceUHT'
2761 ),
2762 'border-left' => true, // add left line separator
2763 );
2764
2765 // Adapt dynamically the width of subprice, if text is too long.
2766 $tmpwidth = 0;
2767 $nblines = count($object->lines);
2768 for ($i = 0; $i < $nblines; $i++) {
2769 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2770 $tmpwidth = max($tmpwidth, $tmpwidth2);
2771 }
2772 if ($tmpwidth > 10) {
2773 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2774 }
2775
2776 $rank += 10;
2777 $this->cols['qty'] = array(
2778 'rank' => $rank,
2779 'width' => 16, // in mm
2780 'status' => true,
2781 'title' => array(
2782 'textkey' => 'Qty'
2783 ),
2784 'border-left' => true, // add left line separator
2785 );
2786
2787 $rank += 10;
2788 $this->cols['progress'] = array(
2789 'rank' => $rank,
2790 'width' => 19, // in mm
2791 'status' => false,
2792 'title' => array(
2793 'textkey' => 'ProgressShort'
2794 ),
2795 'border-left' => true, // add left line separator
2796 );
2797
2798 if ($this->situationinvoice) {
2799 $this->cols['progress']['status'] = true;
2800 }
2801
2802 $rank += 10;
2803 $this->cols['unit'] = array(
2804 'rank' => $rank,
2805 'width' => 11, // in mm
2806 'status' => false,
2807 'title' => array(
2808 'textkey' => 'Unit'
2809 ),
2810 'border-left' => true, // add left line separator
2811 );
2812 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2813 $this->cols['unit']['status'] = true;
2814 }
2815
2816 $rank += 10;
2817 $this->cols['discount'] = array(
2818 'rank' => $rank,
2819 'width' => 13, // in mm
2820 'status' => false,
2821 'title' => array(
2822 'textkey' => 'ReductionShort'
2823 ),
2824 'border-left' => true, // add left line separator
2825 );
2826 if ($this->atleastonediscount) {
2827 $this->cols['discount']['status'] = true;
2828 }
2829
2830 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2831 $this->cols['totalexcltax'] = array(
2832 'rank' => $rank,
2833 'width' => 26, // in mm
2834 'status' => !getDolGlobalBool('PDF_INVOICE_HIDE_PRICE_EXCL_TAX'),
2835 'title' => array(
2836 'textkey' => 'TotalHTShort'
2837 ),
2838 'border-left' => true, // add left line separator
2839 );
2840
2841 $rank += 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2842 $this->cols['totalincltax'] = array(
2843 'rank' => $rank,
2844 'width' => 26, // in mm
2845 'status' => getDolGlobalBool('PDF_INVOICE_SHOW_PRICE_INCL_TAX'),
2846 'title' => array(
2847 'textkey' => 'TotalTTCShort'
2848 ),
2849 'border-left' => true, // add left line separator
2850 );
2851
2852 // Add extrafields cols
2853 if (!empty($object->lines)) {
2854 $line = reset($object->lines);
2855 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2856 }
2857
2858 $parameters = array(
2859 'object' => $object,
2860 'outputlangs' => $outputlangs,
2861 'hidedetails' => $hidedetails,
2862 'hidedesc' => $hidedesc,
2863 'hideref' => $hideref
2864 );
2865
2866 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2867 if ($reshook < 0) {
2868 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2869 } elseif (empty($reshook)) {
2870 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2871 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2872 } else {
2873 $this->cols = $hookmanager->resArray;
2874 }
2875 }
2876}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage bank accounts.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getMaxAfterColsLinePositionsData()
Get position in PDF after col display.
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
Used for to set afterColsLinePositions var in a pdf draw line loop.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
resetAfterColsLinePositionsData(float $y, int $pageNumb)
Used for reset afterColsLinePositions var in start of a new pdf draw line loop.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_CREDIT_NOTE
Credit note invoice.
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 manage PDF invoice template sponge.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
__construct($db)
Constructor.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0, $heightforqrinvoice=0)
Show footer of page.
drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a 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)
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:2705
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2436
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0)
Return line total amount discount.
Definition pdf.lib.php:2735
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition pdf.lib.php:2492
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:1031
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2054
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2385
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1992
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1409
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:854
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:438
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2299
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2342
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2139
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:769
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:390
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:153