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 // Do not take into account lines of the type “deposit.”
418 $is_deposit = false;
419 if (preg_match('/^\‍((.*)\‍)$/', $object->lines[$i]->desc, $reg)) {
420 if ($reg[1] == 'DEPOSIT') {
421 $is_deposit = true;
422 }
423 }
424 // If DEPOSIT, this line is completely ignored for calculations.
425 if ($is_deposit) {
426 continue;
427 }
428
429
430 // determine category of operation
431 if ($categoryOfOperation < 2) {
432 $lineProductType = $object->lines[$i]->product_type;
433 if ($lineProductType == Product::TYPE_PRODUCT) {
434 $nbProduct++;
435 } elseif ($lineProductType == Product::TYPE_SERVICE) {
436 $nbService++;
437 }
438 if ($nbProduct > 0 && $nbService > 0) {
439 // mixed products and services
440 $categoryOfOperation = 2;
441 }
442 }
443 }
444 // determine category of operation
445 if ($categoryOfOperation <= 0) {
446 // only services
447 if ($nbProduct == 0 && $nbService > 0) {
448 $categoryOfOperation = 1;
449 }
450 }
451 $this->categoryOfOperation = $categoryOfOperation;
452
453 // Situation invoice handling
454 if ($object->situation_cycle_ref) {
455 $this->situationinvoice = true;
456 }
457
458 // New page
459 $pdf->AddPage();
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
462 }
463 $pagenb++;
464
465 // Output header (logo, ref and address blocks). This is first call for first page.
466 $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
467 $top_shift = $pagehead['top_shift'];
468 $shipp_shift = $pagehead['shipp_shift'];
469 $pdf->SetFont('', '', $default_font_size - 1);
470 $pdf->MultiCell(0, 3, ''); // Set interline to 3
471 $pdf->SetTextColor(0, 0, 0);
472
473 // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher
474
475 // $this->tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
476 $this->tab_top = 90 + $top_shift + $shipp_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
477 $this->tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
478
479 // You can add more thing under header here, if you increase $extra_under_address_shift too.
480 $extra_under_address_shift = 0;
481 $qrcodestring = '';
482 if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) {
483 $qrcodestring = $object->buildZATCAQRString();
484 } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
485 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
486 $qrcodestring = $object->buildSwitzerlandQRString();
487 }
488 } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
489 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
490 $qrcodestring = $object->buildEPCQrCodeString();
491 }
492 }
493
494 if ($qrcodestring) {
495 $qrcodecolor = array('25', '25', '25');
496 // set style for QR-code
497 $styleQr = array(
498 'border' => false,
499 'padding' => 0,
500 'fgcolor' => $qrcodecolor,
501 'bgcolor' => false, //array(255,255,255)
502 'module_width' => 1, // width of a single module in points
503 'module_height' => 1 // height of a single module in points
504 );
505 $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr, 'N');
506
507 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
508 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
509 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
510 $pdf->SetFont('', '', $default_font_size - 4);
511 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0);
512 }
513 }
514
515 $extra_under_address_shift += 25;
516 }
517
518 // Call hook printUnderHeaderPDFline
519 $parameters = array(
520 'object' => $object,
521 'i' => $i,
522 'pdf' => &$pdf,
523 'outputlangs' => $outputlangs,
524 'hidedetails' => $hidedetails
525 );
526 $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
527 if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
528 $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift'];
529 }
530
531 $this->tab_top += $extra_under_address_shift;
532 $this->tab_top_newpage += 0;
533
534
535 // Define height of table for lines (for first page)
536 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->getHeightForQRInvoice(1, $object, $langs);
537
538 $nexY = $this->tab_top - 1;
539
540 // Incoterm
541 $height_incoterms = 0;
542 if (isModEnabled('incoterm')) {
543 $desc_incoterms = $object->getIncotermsForPDF();
544 if ($desc_incoterms) {
545 $this->tab_top -= 2;
546
547 $pdf->SetFont('', '', $default_font_size - 1);
548 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
549 $nexY = max($pdf->GetY(), $nexY);
550 $height_incoterms = $nexY - $this->tab_top;
551
552 // Rect takes a length in 3rd parameter
553 $pdf->SetDrawColor(192, 192, 192);
554 $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');
555
556 $this->tab_top = $nexY + 6;
557 $height_incoterms += 4;
558 }
559 }
560
561 // Displays notes. Here we are still on code executed only for the first page.
562 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
563 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
564 // Get first sale rep
565 if (is_object($object->thirdparty)) {
566 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
567 $salerepobj = new User($this->db);
568 $salerepobj->fetch($salereparray[0]['id']);
569 if (!empty($salerepobj->signature)) {
570 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
571 }
572 }
573 }
574
575 // Extrafields in note
576 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
577 if (!empty($extranote)) {
578 $notetoshow = dol_concatdesc($notetoshow, $extranote);
579 }
580
581 $pagenb = $pdf->getPage();
582 if ($notetoshow) {
583 $this->tab_top -= 2;
584
585 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
586 $pageposbeforenote = $pagenb;
587
588 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
589 complete_substitutions_array($substitutionarray, $outputlangs, $object);
590 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
591 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
592
593 $pdf->startTransaction();
594
595 $pdf->SetFont('', '', $default_font_size - 1);
596 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
597 // Description
598 $pageposafternote = $pdf->getPage();
599 $posyafter = $pdf->GetY();
600
601 if ($pageposafternote > $pageposbeforenote) {
602 $pdf->rollbackTransaction(true);
603
604 // prepare pages to receive notes
605 while ($pagenb < $pageposafternote) {
606 $pdf->AddPage();
607 $pagenb++;
608 if (!empty($tplidx)) {
609 $pdf->useTemplate($tplidx);
610 }
611 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
612 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
613 }
614 $pdf->setTopMargin($this->tab_top_newpage);
615 // The only function to edit the bottom margin of current page to set it.
616 $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
617 }
618
619 // back to start
620 $pdf->setPage($pageposbeforenote);
621 $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
622 $pdf->SetFont('', '', $default_font_size - 1);
623 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
624 $pageposafternote = $pdf->getPage();
625
626 $posyafter = $pdf->GetY();
627
628 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) { // There is no space left for total+free text
629 $pdf->AddPage('', '', true);
630 $pagenb++;
631 $pageposafternote++;
632 $pdf->setPage($pageposafternote);
633 $pdf->setTopMargin($this->tab_top_newpage);
634 // The only function to edit the bottom margin of current page to set it.
635 $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
636 //$posyafter = $this->tab_top_newpage;
637 }
638
639
640 // apply note frame to previous pages
641 $i = $pageposbeforenote;
642 while ($i < $pageposafternote) {
643 $pdf->setPage($i);
644
645
646 $pdf->SetDrawColor(128, 128, 128);
647 // Draw note frame
648 if ($i > $pageposbeforenote) {
649 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
650 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
651 } else {
652 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
653 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
654 }
655
656 // Add footer
657 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
658 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($i, $object, $outputlangs));
659
660 $i++;
661 }
662
663 // apply note frame to last page
664 $pdf->setPage($pageposafternote);
665 if (!empty($tplidx)) {
666 $pdf->useTemplate($tplidx);
667 }
668 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
669 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
670 }
671 $height_note = $posyafter - $this->tab_top_newpage;
672 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
673 } else {
674 // No pagebreak
675 $pdf->commitTransaction();
676 $posyafter = $pdf->GetY();
677 $height_note = $posyafter - $this->tab_top;
678 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
679
680
681 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
682 // not enough space, need to add page
683 $pdf->AddPage('', '', true);
684 $pagenb++;
685 $pageposafternote++;
686 $pdf->setPage($pageposafternote);
687 if (!empty($tplidx)) {
688 $pdf->useTemplate($tplidx);
689 }
690 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
691 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
692 }
693
694 $posyafter = $this->tab_top_newpage;
695 }
696 }
697
698 $tab_height -= $height_note;
699 $this->tab_top = $posyafter + 6;
700 } else {
701 $height_note = 0;
702 }
703
704 // Use new auto column system
705 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
706
707 // Table simulation to know the height of the title line (this set this->tableTitleHeight)
708 $pdf->startTransaction();
709 $this->pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
710 $pdf->rollbackTransaction(true);
711
712 $nexY = $this->tab_top + $this->tabTitleHeight;
713
714 // Loop on each lines
715 $pageposbeforeprintlines = $pdf->getPage();
716 $pagenb = $pageposbeforeprintlines;
717 for ($i = 0; $i < $nblines; $i++) {
718 $linePosition = $i + 1;
719 $curY = $nexY;
720
721 // in First Check line page break and add page if needed
722 if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
723 // New page
724 $pdf->AddPage();
725 if (!empty($tplidx)) {
726 $pdf->useTemplate($tplidx);
727 }
728
729 $pdf->setPage($pdf->getNumPages());
730 $nexY = $this->tab_top_newpage;
731 }
732
733 $this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
734
735 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
736 $pdf->SetTextColor(0, 0, 0);
737
738 // Define size of image if we need it
739 $imglinesize = array();
740 if (!empty($realpatharray[$i])) {
741 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
742 }
743
744 $pdf->setTopMargin($this->tab_top_newpage);
745 $pdf->setPageOrientation('', 1, $this->heightforfooter);
746 $pageposbefore = $pdf->getPage();
747 $curYBefore = $curY;
748
749 // Allows data in the first page if description is long enough to break in multiples pages
750 $showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
751
752 if ($this->getColumnStatus('photo')) {
753 // We start with Photo of product line
754 $imageTopMargin = 1;
755 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
756 $pdf->AddPage('', '', true);
757 if (!empty($tplidx)) {
758 $pdf->useTemplate($tplidx);
759 }
760 $pdf->setPage($pageposbefore + 1);
761 $pdf->setPageOrientation('', 1, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
762 $curY = $this->tab_top_newpage;
763 $showpricebeforepagebreak = 0;
764 }
765
766 $pdf->setPageOrientation('', 0, $this->heightforfooter + $this->heightforfreetext); // The only function to edit the bottom margin of current page to set it.
767 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
768 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
769 // $pdf->Image does not increase value return by getY, so we save it manually
770 $posYAfterImage = $curY + $imglinesize['height'];
771
772 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
773 }
774 }
775
776 // restore Page orientation for text
777 $pdf->setPageOrientation('', 1, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
778
779 // Description of product line
780 if ($this->getColumnStatus('desc')) {
781 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
782 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
783 }
784
785
786 $afterPosData = $this->getMaxAfterColsLinePositionsData();
787 $pdf->setPage($pageposbefore);
788 $pdf->setTopMargin($this->marge_haute);
789 $curY = $curYBefore;
790 $pdf->setPageOrientation('', 0, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
791
792 // We suppose that a too long description or photo were moved completely on next page
793 if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
794 $pdf->setPage($afterPosData['page']);
795 $curY = $this->tab_top_newpage;
796 }
797
798 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
799
800 // Line position
801 if ($this->getColumnStatus('position')) {
802 $this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
803 }
804
805 // VAT Rate
806 if ($this->getColumnStatus('vat')) {
807 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
808 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
809 }
810
811 // Unit price before discount
812 if ($this->getColumnStatus('subprice')) {
813 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
814 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
815 }
816
817 // Quantity
818 // Enough for 6 chars
819 if ($this->getColumnStatus('qty')) {
820 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
821 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
822 }
823
824 // Situation progress
825 if ($this->getColumnStatus('progress')) {
826 $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
827 $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
828 }
829
830 // Unit
831 if ($this->getColumnStatus('unit')) {
832 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
833 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
834 }
835
836 // Discount on line
837 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
838 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
839 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
840 }
841
842 // Total excl tax line (HT)
843 if ($this->getColumnStatus('totalexcltax')) {
844 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
845 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
846 }
847
848 // Total with tax line (TTC)
849 if ($this->getColumnStatus('totalincltax')) {
850 $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
851 $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
852 }
853
854 // Extrafields
855 if (!empty($object->lines[$i]->array_options)) {
856 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
857 if ($this->getColumnStatus($extrafieldColKey)) {
858 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
859 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
860
861 $this->setAfterColsLinePositionsData('options_' . $extrafieldColKey, $pdf->GetY(), $pdf->getPage());
862 }
863 }
864 }
865
866 $afterPosData = $this->getMaxAfterColsLinePositionsData();
867 $parameters = array(
868 'object' => $object,
869 'i' => $i,
870 'pdf' => & $pdf,
871 'curY' => & $curY,
872 'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
873 'outputlangs' => $outputlangs,
874 'hidedetails' => $hidedetails
875 );
876 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
877
878
879 $sign = 1;
880 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
881 $sign = -1;
882 }
883 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
884 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
885 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
886 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
887 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
888 } else {
889 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
890 }
891 } else {
892 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
893 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
894 } else {
895 $tvaligne = $sign * $object->lines[$i]->total_tva;
896 }
897 }
898
899 $localtax1ligne = $object->lines[$i]->total_localtax1;
900 $localtax2ligne = $object->lines[$i]->total_localtax2;
901 $localtax1_rate = $object->lines[$i]->localtax1_tx;
902 $localtax2_rate = $object->lines[$i]->localtax2_tx;
903 $localtax1_type = $object->lines[$i]->localtax1_type;
904 $localtax2_type = $object->lines[$i]->localtax2_type;
905
906 // TODO remise_percent is an obsolete field for object parent
907 /*if ($object->remise_percent) {
908 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
909 }
910 if ($object->remise_percent) {
911 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
912 }
913 if ($object->remise_percent) {
914 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
915 }*/
916
917 $vatrate = (string) $object->lines[$i]->tva_tx;
918
919 // Retrieve type from database for backward compatibility with old records
920 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
921 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
922 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
923 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
924 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
925 }
926
927 // retrieve global local tax
928 if ($localtax1_type && $localtax1ligne != 0) {
929 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
930 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
931 } else {
932 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
933 }
934 }
935 if ($localtax2_type && $localtax2ligne != 0) {
936 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
937 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
938 } else {
939 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
940 }
941 }
942
943 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
944 $vatrate .= '*';
945 }
946
947 // Fill $this->tva and $this->tva_array
948 if (!isset($this->tva[$vatrate])) {
949 $this->tva[$vatrate] = 0;
950 }
951 $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete
952 $vatcode = $object->lines[$i]->vat_src_code;
953 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
954 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
955 $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
956 }
957 $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);
958 } else {
959 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
960 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
961 }
962 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
963 }
964
965 $afterPosData = $this->getMaxAfterColsLinePositionsData();
966 $pdf->setPage($afterPosData['page']);
967 $nexY = $afterPosData['y'];
968
969 // Add line
970 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $this->heightforfooter - 5) {
971 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
972 //$pdf->SetDrawColor(190,190,200);
973 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
974 $pdf->SetLineStyle(array('dash' => 0));
975 }
976
977 $nexY += 2; // Add space between lines
978 }
979
980 // Add last page for document footer if there are not enough size left
981 $afterPosData = $this->getMaxAfterColsLinePositionsData();
982 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
983
984 if (isset($afterPosData['y']) && $afterPosData['y'] > $this->page_hauteur - $page_bottom_margin) {
985 $pdf->AddPage();
986 if (!empty($tplidx)) {
987 $pdf->useTemplate($tplidx);
988 }
989 $pagenb++;
990 $pdf->setPage($pagenb);
991 }
992
993 // Draw table frames and columns borders
994 $drawTabNumbPage = $pdf->getNumPages();
995 for ($i=$pageposbeforeprintlines; $i<=$drawTabNumbPage; $i++) {
996 $pdf->setPage($i);
997 // reset page orientation each loop to override it if it was changed
998 $pdf->setPageOrientation('', 0, 0); // The only function to edit the bottom margin of current page to set it.
999
1000 $drawTabHideTop = $hidetop;
1001 $drawTabTop = $this->tab_top_newpage;
1002 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1003 $hideBottom = 0; // TODO understand why it change to 1 or 0 during process
1004
1005 if ($i == $pageposbeforeprintlines) {
1006 // first page need to start after notes
1007 $drawTabTop = $this->tab_top;
1008 } elseif (!$drawTabHideTop) {
1009 if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
1010 $drawTabTop-= $this->tabTitleHeight;
1011 } else {
1012 $drawTabHideTop = 1;
1013 }
1014 }
1015
1016 // last page need to include document footer
1017 if ($i == $pdf->getNumPages()) {
1018 // remove document footer height to tab bottom position
1019 $drawTabBottom-= $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs);
1020 }
1021
1022 $drawTabHeight = $drawTabBottom - $drawTabTop;
1023 $this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object->multicurrency_code, $outputlangsbis);
1024
1025 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
1026
1027 $this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1028
1029 $pdf->setPage($i); // in case of _pagefoot or _tableau change it
1030
1031 // reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
1032 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
1033
1034 // Don't print head on first page ($pageposbeforeprintlines) because already added previously
1035 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1036 $this->_pagehead($pdf, $object, 0, $outputlangs);
1037 }
1038 if (!empty($tplidx)) {
1039 $pdf->useTemplate($tplidx);
1040 }
1041 }
1042
1043
1044 // reset text color before print footers
1045 $pdf->SetTextColor(0, 0, 0);
1046
1047 $pdf->setPage($pdf->getNumPages());
1048
1049 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1050
1051 // Display infos area
1052 $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1053
1054 // Display total zone
1055 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1056
1057 // Display payment area
1058 $listofpayments = $object->getListOfPayments('', 0, 1);
1059 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
1060 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1061 }
1062
1063 // Add number of pages in footer
1064 if (method_exists($pdf, 'AliasNbPages')) {
1065 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
1066 }
1067 // Add terms to sale
1068 if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) {
1069 $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale;
1070 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1071 $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale;
1072 }
1073 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1074 $pagecount = $pdf->setSourceFile($termsofsale);
1075 for ($i = 1; $i <= $pagecount; $i++) {
1076 $tplIdx = $pdf->importPage($i);
1077 if ($tplIdx!==false) {
1078 $s = $pdf->getTemplatesize($tplIdx);
1079 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1080 $pdf->useTemplate($tplIdx);
1081 } else {
1082 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
1083 }
1084 }
1085 }
1086 }
1087
1088 if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
1089 $this->addBottomQRInvoice($pdf, $object, $outputlangs);
1090 }
1091
1092 $pdf->Close();
1093
1094 $pdf->Output($file, 'F');
1095
1096 // Add pdfgeneration hook
1097 $hookmanager->initHooks(array('pdfgeneration'));
1098 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
1099 global $action;
1100 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1101 if ($reshook < 0) {
1102 $this->error = $hookmanager->error;
1103 $this->errors = $hookmanager->errors;
1104 }
1105
1106 dolChmod($file);
1107
1108 $this->result = array('fullpath' => $file);
1109
1110 return 1; // No error
1111 } else {
1112 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1113 return 0;
1114 }
1115 } else {
1116 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1117 return 0;
1118 }
1119 }
1120
1121
1131 public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1132 {
1133 $sign = 1;
1134 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1135 $sign = -1;
1136 }
1137
1138 $tab3_posx = 120;
1139 $tab3_top = $posy + 8;
1140 $tab3_width = 80;
1141 $tab3_height = 4;
1142 if ($this->page_largeur < 210) { // To work with US executive format
1143 $tab3_posx -= 15;
1144 }
1145
1146 $default_font_size = pdf_getPDFFontSize($outputlangs);
1147
1148 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1149 if ($object->type == 2) {
1150 $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1151 }
1152
1153 $pdf->SetFont('', '', $default_font_size - 3);
1154 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1155 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1156
1157 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1158
1159 $pdf->SetFont('', '', $default_font_size - 4);
1160 $pdf->SetXY($tab3_posx, $tab3_top);
1161 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1162 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1163 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1164 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1165 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1166 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1167 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1168
1169 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1170
1171 $y = 0;
1172
1173 $pdf->SetFont('', '', $default_font_size - 4);
1174
1175
1176 // Loop on each discount available (deposits and credit notes and excess of payment included)
1177 $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,";
1178 $sql .= " re.description, re.fk_facture_source,";
1179 $sql .= " f.type, f.datef";
1180 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1181 $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1182 $resql = $this->db->query($sql);
1183 if ($resql) {
1184 $num = $this->db->num_rows($resql);
1185 $i = 0;
1186 $invoice = new Facture($this->db);
1187 while ($i < $num) {
1188 $y += 3;
1189 $obj = $this->db->fetch_object($resql);
1190
1191 if ($obj->type == 2) {
1192 $text = $outputlangs->transnoentities("CreditNote");
1193 } elseif ($obj->type == 3) {
1194 $text = $outputlangs->transnoentities("Deposit");
1195 } elseif ($obj->type == 0) {
1196 $text = $outputlangs->transnoentities("ExcessReceived");
1197 } else {
1198 $text = $outputlangs->transnoentities("UnknownType");
1199 }
1200
1201 $invoice->fetch($obj->fk_facture_source);
1202
1203 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1204 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1205 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1206 $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1207 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1208 $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1209 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1210 $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1211
1212 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1213
1214 $i++;
1215 }
1216 } else {
1217 $this->error = $this->db->lasterror();
1218 return -1;
1219 }
1220
1221 // Loop on each payment
1222 // TODO Call getListOfPayments instead of hard coded sql
1223 $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1224 $sql .= " cp.code";
1225 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1226 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1227 $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1228 //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1229 $sql .= " ORDER BY p.datep";
1230
1231 $resql = $this->db->query($sql);
1232 if ($resql) {
1233 $num = $this->db->num_rows($resql);
1234 $i = 0;
1235 $y += 3;
1236 $maxY = $y;
1237 while ($i < $num) {
1238 $row = $this->db->fetch_object($resql);
1239 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1240 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1241 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1242 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1243 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1244 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1245
1246 $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1247 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1248 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1249 $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1250 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1251 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1252 $y += 3;
1253 $i++;
1254 }
1255
1256 return $tab3_top + $y + 3;
1257 } else {
1258 $this->error = $this->db->lasterror();
1259 return -1;
1260 }
1261 }
1262
1263
1274 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1275 {
1276 global $conf, $mysoc, $hookmanager;
1277
1278 $default_font_size = pdf_getPDFFontSize($outputlangs);
1279
1280 $pdf->SetFont('', '', $default_font_size - 1);
1281
1282 krsort($this->tva_array);
1283
1284 // Clean data type
1285 $object->total_tva = (float) $object->total_tva;
1286
1287 // Show VAT details
1288 if ($object->total_tva != 0 && getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1289 $pdf->SetFillColor(224, 224, 224);
1290
1291 $pdf->SetFont('', '', $default_font_size - 2);
1292 $pdf->SetXY($this->marge_gauche, $posy);
1293 $titre = $outputlangs->transnoentities("VAT");
1294 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1295
1296 $pdf->SetFont('', '', $default_font_size - 2);
1297 $pdf->SetXY($this->marge_gauche + 25, $posy);
1298 $titre = $outputlangs->transnoentities("NetTotal");
1299 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1300
1301 $pdf->SetFont('', '', $default_font_size - 2);
1302 $pdf->SetXY($this->marge_gauche + 50, $posy);
1303 $titre = $outputlangs->transnoentities("VATAmount");
1304 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1305
1306 $pdf->SetFont('', '', $default_font_size - 2);
1307 $pdf->SetXY($this->marge_gauche + 75, $posy);
1308 $titre = $outputlangs->transnoentities("AmountTotal");
1309 $pdf->MultiCell(25, 4, $titre, 0, 'L', true);
1310
1311 $posy = $pdf->GetY();
1312 $tot_ht = 0;
1313 $tot_tva = 0;
1314 $tot_ttc = 0;
1315
1316 foreach ($this->tva_array as $tvakey => $tvaval) {
1317 $pdf->SetFont('', '', $default_font_size - 2);
1318 $pdf->SetXY($this->marge_gauche, $posy);
1319 $titre = round((float) $tvakey, 2) . "%";
1320 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1321
1322 $pdf->SetFont('', '', $default_font_size - 2);
1323 $pdf->SetXY($this->marge_gauche + 25, $posy);
1324 $titre = price($tvaval['tot_ht']);
1325 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1326 $tot_ht += $tvaval['tot_ht'];
1327
1328 $pdf->SetFont('', '', $default_font_size - 2);
1329 $pdf->SetXY($this->marge_gauche + 50, $posy);
1330 $titre = price($tvaval['amount']);
1331 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1332 $tot_tva += $tvaval['amount'];
1333
1334 $pdf->SetFont('', '', $default_font_size - 2);
1335 $pdf->SetXY($this->marge_gauche + 75, $posy);
1336 $titre = price($tvaval['tot_ht'] + $tvaval['amount']);
1337 $pdf->MultiCell(25, 4, $titre, 0, 'L');
1338 $tot_ttc += ($tvaval['tot_ht'] + $tvaval['amount']);
1339
1340 $posy = $pdf->GetY();
1341 }
1342 }
1343
1344 // If France, show VAT mention if applicable
1345 if (in_array($this->emetteur->country_code, array('FR')) && empty($object->total_tva)) {
1346 $pdf->SetFont('', '', $default_font_size - 2);
1347 $pdf->SetXY($this->marge_gauche, $posy);
1348 if (empty($mysoc->tva_assuj)) {
1349 if ($mysoc->forme_juridique_code == 92) {
1350 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1351 } else {
1352 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1353 }
1354 } elseif (getDolGlobalString("INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code != $object->thirdparty->country_code && $this->emetteur->isInEEC() && $object->thirdparty->isInEEC()) {
1355 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedReverseChargeProcedure"), 0, 'L', 0);
1356 }
1357 $posy = $pdf->GetY() + 4;
1358 }
1359
1360 $posxval = 52; // Position of values of properties shown on left side
1361 $posxend = 110; // End of x for text on left side
1362 if ($this->page_largeur < 210) { // To work with US executive format
1363 $posxend -= 10;
1364 }
1365
1366 // Show payments conditions
1367 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1368 $pdf->SetFont('', '', $default_font_size - 2);
1369 $pdf->SetXY($this->marge_gauche, $posy);
1370 $titre = $outputlangs->transnoentities("PaymentConditions").':';
1371 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1372
1373 $pdf->SetFont('', '', $default_font_size - 2);
1374 $pdf->SetXY($posxval, $posy);
1375 $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);
1376 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1377 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1378
1379 $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1380 }
1381
1382 // Show category of operations
1383 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1384 $pdf->SetFont('', '', $default_font_size - 2);
1385 $pdf->SetXY($this->marge_gauche, $posy);
1386 $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1387 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1388
1389 $pdf->SetFont('', '', $default_font_size - 2);
1390 $pdf->SetXY($posxval, $posy);
1391 $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1392 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1393
1394 $posy = $pdf->GetY() + 3; // for 2 lines
1395 }
1396
1397 if ($object->type != 2) {
1398 // Check a payment mode is defined
1399 if (empty($object->mode_reglement_code)
1400 && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1401 && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1402 $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1403 } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1404 || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1405 // Avoid having any valid PDF with setup that is not complete
1406 $outputlangs->load("errors");
1407
1408 $pdf->SetXY($this->marge_gauche, $posy);
1409 $pdf->SetTextColor(200, 0, 0);
1410 $pdf->SetFont('', '', $default_font_size - 2);
1411 $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1412 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
1413 $pdf->SetTextColor(0, 0, 0);
1414
1415 $posy = $pdf->GetY() + 1;
1416 }
1417
1418 // Show payment mode
1419 if (!empty($object->mode_reglement_code)
1420 && $object->mode_reglement_code != 'CHQ'
1421 && $object->mode_reglement_code != 'VIR') {
1422 $pdf->SetFont('', '', $default_font_size - 2);
1423 $pdf->SetXY($this->marge_gauche, $posy);
1424 $titre = $outputlangs->transnoentities("PaymentMode").':';
1425 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1426
1427 $pdf->SetFont('', '', $default_font_size - 2);
1428 $pdf->SetXY($posxval, $posy);
1429 $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);
1430
1431 //#21654: add account number used for the debit
1432 if ($object->mode_reglement_code == "PRE") {
1433 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1434 $bac = new CompanyBankAccount($this->db);
1435 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1436 $bac->fetch(0, '', $object->thirdparty->id);
1437 $iban = $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1438 $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1439 }
1440
1441 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1442
1443 $posy = $pdf->GetY();
1444 }
1445
1446 // Show if Option VAT debit option is on also if transmitter is french
1447 // Decret n°2099-1299 2022-10-07
1448 // French mention : "Option pour le paiement de la taxe d'après les débits"
1449 if ($this->emetteur->country_code == 'FR') {
1450 if (getDolGlobalInt('TAX_MODE') == 1) {
1451 $pdf->SetXY($this->marge_gauche, $posy);
1452 $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1453
1454 $posy = $pdf->GetY() + 1;
1455 }
1456 }
1457
1458 // Show online payment link
1459 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1460 $useonlinepayment = 0;
1461 if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) {
1462 // Show online payment link
1463 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
1464 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1465 $validpaymentmethod = getValidOnlinePaymentMethods('');
1466 $useonlinepayment = count($validpaymentmethod);
1467 }
1468
1469
1470 if ($object->status != Facture::STATUS_DRAFT && $useonlinepayment) {
1471 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1472 global $langs;
1473
1474 $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1475 $servicename = $langs->transnoentities('Online');
1476 $paiement_url = getOnlinePaymentUrl(0, 'invoice', $object->ref, 0, '', 0);
1477 $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1478
1479 $pdf->SetXY($this->marge_gauche, $posy);
1480 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1481
1482 $posy = $pdf->GetY() + 1;
1483 }
1484 }
1485
1486 // Show payment mode CHQ
1487 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1488 // If payment mode unregulated or payment mode forced to CHQ
1489 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1490 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1491
1492 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
1493 $account = new Account($this->db);
1494 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1495
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', $account->owner_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($account->owner_address), 0, 'L', 0);
1505 $posy = $pdf->GetY() + 2;
1506 }
1507 }
1508 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
1509 $pdf->SetXY($this->marge_gauche, $posy);
1510 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1511 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1512 $posy = $pdf->GetY() + 1;
1513
1514 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
1515 $pdf->SetXY($this->marge_gauche, $posy);
1516 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1517 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1518 $posy = $pdf->GetY() + 2;
1519 }
1520 }
1521 }
1522 }
1523
1524 // If payment mode not forced or forced to VIR, show payment with BAN
1525 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1526 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1527 $bankid = ($object->fk_account <= 0 ? getDolGlobalInt('FACTURE_RIB_NUMBER') : $object->fk_account);
1528 if ($object->fk_bank > 0) {
1529 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1530 }
1531 $account = new Account($this->db);
1532 $account->fetch($bankid);
1533
1534 $curx = $this->marge_gauche;
1535 $cury = $posy;
1536
1537 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1538
1539 $posy += 2;
1540
1541 // SHOW EPC QR CODE
1542 if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == 'bottom') {
1543 $qrPosX = 120;
1544 $qrPosY = $posy;
1545 $qrCodeColor = array('25', '25', '25');
1546 $styleQr = array(
1547 'border' => false,
1548 'padding' => 0,
1549 'fgcolor' => $qrCodeColor,
1550 'bgcolor' => false, //array(255,255,255)
1551 'module_width' => 1, // width of a single module in points
1552 'module_height' => 1 // height of a single module in points
1553 );
1554
1555 $EPCQrCodeString = $object->buildEPCQrCodeString();
1556 $pdf->write2DBarcode($EPCQrCodeString, 'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr, 'N');
1557
1558 $pdf->SetXY($qrPosX + 30, $posy + 5);
1559 $pdf->SetFont('', '', $default_font_size - 5);
1560 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0);
1561 $posy = $pdf->GetY() + 2;
1562 }
1563
1564 // Show structured communication
1565 if (getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION')) {
1566 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_be.lib.php';
1567 $invoicePaymentKey = dolBECalculateStructuredCommunication($object->ref, $object->type);
1568
1569 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('StructuredCommunication').": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0, 'L', 0);
1570 }
1571 }
1572 }
1573 }
1574
1575 return $posy;
1576 }
1577
1578
1590 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1591 {
1592 global $mysoc, $hookmanager;
1593
1594 $sign = 1;
1595 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
1596 $sign = -1;
1597 }
1598
1599 $default_font_size = pdf_getPDFFontSize($outputlangs);
1600
1601 $tab2_top = $posy;
1602 $tab2_hl = 4;
1603 if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1604 $pdf->SetFont('', '', $default_font_size - 2);
1605 } else {
1606 $pdf->SetFont('', '', $default_font_size - 1);
1607 }
1608
1609 // Total table
1610 $col1x = 120;
1611 $col2x = 170;
1612 if ($this->page_largeur < 210) { // To work with US executive format
1613 $col1x -= 15;
1614 $col2x -= 10;
1615 }
1616 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1617
1618 $useborder = 0;
1619 $index = 0;
1620
1621 // Add trigger to allow to edit $object
1622 $parameters = array(
1623 'object' => &$object,
1624 'outputlangs' => $outputlangs,
1625 );
1626 $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1627
1628 // overall percentage of advancement
1629 $percent = 0;
1630 $i = 0;
1631 foreach ($object->lines as $line) {
1632 if ($line->product_type != 9) {
1633 $percent += $line->situation_percent;
1634 $i++;
1635 }
1636 }
1637
1638 if (!empty($i)) {
1639 $avancementGlobal = $percent / $i;
1640 } else {
1641 $avancementGlobal = 0;
1642 }
1643
1644 $object->fetchPreviousNextSituationInvoice();
1645 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1646
1647 $total_a_payer = 0;
1648 $total_a_payer_ttc = 0;
1649 foreach ($TPreviousIncoice as &$fac) {
1650 $total_a_payer += $fac->total_ht;
1651 $total_a_payer_ttc += $fac->total_ttc;
1652 }
1653 $total_a_payer += $object->total_ht;
1654 $total_a_payer_ttc += $object->total_ttc;
1655
1656 if (!empty($avancementGlobal)) {
1657 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1658 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1659 } else {
1660 $total_a_payer = 0;
1661 $total_a_payer_ttc = 0;
1662 }
1663
1664 $i = 1;
1665 if (!empty($TPreviousIncoice)) {
1666 $pdf->setY($tab2_top);
1667 $posy = $pdf->GetY();
1668
1669 foreach ($TPreviousIncoice as &$fac) {
1670 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1671 $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1672 $pdf->addPage();
1673 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1674 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1675 $pdf->setY($this->tab_top_newpage);
1676 } else {
1677 $pdf->setY($this->marge_haute);
1678 }
1679 $posy = $pdf->GetY();
1680 }
1681
1682 // Cumulate preceding VAT
1683 $index++;
1684 $pdf->SetFillColor(255, 255, 255);
1685 $pdf->SetXY($col1x, $posy);
1686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1687
1688 $pdf->SetXY($col2x, $posy);
1689
1690 $facSign = '';
1691 if ($i > 1) {
1692 $facSign = $fac->total_ht >= 0 ? '+' : '';
1693 }
1694
1695 $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1696
1697 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1698
1699 $i++;
1700 $posy += $tab2_hl;
1701
1702 $pdf->setY($posy);
1703 }
1704
1705 // Display current total
1706 $pdf->SetFillColor(255, 255, 255);
1707 $pdf->SetXY($col1x, $posy);
1708 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1709
1710 $pdf->SetXY($col2x, $posy);
1711 $facSign = '';
1712 if ($i > 1) {
1713 $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1714 }
1715
1716 if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1717 $facSign = '-'; // les avoirs
1718 }
1719
1720
1721 $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1722 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1723
1724 $posy += $tab2_hl;
1725
1726 // Display all total
1727 $pdf->SetFont('', '', $default_font_size - 1);
1728 $pdf->SetFillColor(255, 255, 255);
1729 $pdf->SetXY($col1x, $posy);
1730 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", $avancementGlobal), 0, 'L', 1);
1731
1732 $pdf->SetXY($col2x, $posy);
1733 $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', 1);
1734 $pdf->SetFont('', '', $default_font_size - 2);
1735
1736 $posy += $tab2_hl;
1737
1738 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1739 $pdf->addPage();
1740 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1741 $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1742 $pdf->setY($this->tab_top_newpage);
1743 } else {
1744 $pdf->setY($this->marge_haute);
1745 }
1746
1747 $posy = $pdf->GetY();
1748 }
1749
1750 $tab2_top = $posy;
1751 $index = 0;
1752
1753 $tab2_top += 3;
1754 }
1755
1756
1757 // Get Total HT
1758 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1759
1760 // Total remise
1761 $total_line_remise_print = $total_line_remise = 0;
1762 foreach ($object->lines as $i => $line) {
1763 $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2);
1764 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1765 // Gestion remise sous forme de ligne négative
1766 if ($line->total_ht < 0) {
1767 $total_line_remise += -$line->total_ht;
1768 }
1769 $usemc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1);
1770 $total_line_remise_print = $total_line_remise;
1771 if ($usemc) {
1772 $ratio = (!empty($object->total_ht) ? (float) $object->multicurrency_total_ht / (float) $object->total_ht : 0);
1773 if (!empty($ratio)) $total_line_remise_print = price2num($total_line_remise * $ratio, 'MT');
1774 }
1775 }
1776 if ($total_line_remise > 0) {
1777 if (!getDolGlobalString('MAIN_HIDE_AMOUNT_DISCOUNT')) {
1778 $pdf->SetFillColor(255, 255, 255);
1779 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1780 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
1781 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1782 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise_print, 0, $outputlangs), 0, 'R', 1);
1783 $index++;
1784 }
1785 // Show total NET before discount
1786 if (!getDolGlobalString('MAIN_HIDE_AMOUNT_BEFORE_DISCOUNT')) {
1787 $pdf->SetFillColor(255, 255, 255);
1788 $pdf->SetXY($col1x, $tab2_top);
1789 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
1790 $pdf->SetXY($col2x, $tab2_top);
1791 $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise_print + $total_ht, 0, $outputlangs), 0, 'R', 1);
1792 $index++;
1793 }
1794 }
1795
1796 // Total HT
1797 $pdf->SetFillColor(255, 255, 255);
1798 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1799 $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);
1800
1801 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1802 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1803 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1804
1805 if (getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1806 $index++;
1807 $pdf->SetFillColor(255, 255, 255);
1808 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1809 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
1810
1811 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1812 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', 1);
1813 }
1814
1815 // Show VAT by rates and total
1816 $pdf->SetFillColor(248, 248, 248);
1817
1818 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1819
1820 $this->atleastoneratenotnull = 0;
1821 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1822 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']));
1823 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1824 // Nothing to do
1825 } else {
1826 //Local tax 1 before VAT
1827 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1828 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1829 continue;
1830 }
1831
1832 foreach ($localtax_rate as $tvakey => $tvaval) {
1833 if ($tvakey != 0) { // On affiche pas taux 0
1834 //$this->atleastoneratenotnull++;
1835
1836 $index++;
1837 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1838
1839 $tvacompl = '';
1840 if (preg_match('/\*/', (string) $tvakey)) {
1841 $tvakey = str_replace('*', '', (string) $tvakey);
1842 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1843 }
1844
1845 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1846 $totalvat .= ' ';
1847
1848 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1849 $totalvat .= $tvacompl;
1850 } else {
1851 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1852 }
1853
1854 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1855
1856 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1857
1858 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1859 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1860 }
1861 }
1862 }
1863
1864 //Local tax 2 before VAT
1865 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1866 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1867 continue;
1868 }
1869
1870 foreach ($localtax_rate as $tvakey => $tvaval) {
1871 if ($tvakey != 0) { // On affiche pas taux 0
1872 //$this->atleastoneratenotnull++;
1873
1874 $index++;
1875 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1876
1877 $tvacompl = '';
1878 if (preg_match('/\*/', (string) $tvakey)) {
1879 $tvakey = str_replace('*', '', (string) $tvakey);
1880 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1881 }
1882 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1883 $totalvat .= ' ';
1884
1885 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1886 $totalvat .= $tvacompl;
1887 } else {
1888 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1889 }
1890
1891 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1892
1893 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1894
1895 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1896 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1897 }
1898 }
1899 }
1900
1901 // Situations totals might be wrong on huge amounts with old mode 1
1902 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1903 $sum_pdf_tva = 0;
1904 foreach ($this->tva as $tvakey => $tvaval) {
1905 $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1906 }
1907
1908 if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1909 if (!empty($sum_pdf_tva)) {
1910 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1911 } else {
1912 $coef_fix_tva = 1;
1913 }
1914
1915
1916 foreach ($this->tva as $tvakey => $tvaval) {
1917 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1918 }
1919 foreach ($this->tva_array as $tvakey => $tvaval) {
1920 $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
1921 }
1922 }
1923 }
1924
1925 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) {
1926 // VAT
1927 foreach ($this->tva_array as $tvakey => $tvaval) {
1928 if ($tvakey != 0) { // On affiche pas taux 0
1929 $this->atleastoneratenotnull++;
1930
1931 $index++;
1932 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1933
1934 $tvacompl = '';
1935 if (preg_match('/\*/', $tvakey)) {
1936 $tvakey = str_replace('*', '', $tvakey);
1937 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1938 }
1939 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1940 $totalvat .= ' ';
1941 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1942 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1943 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1944 $totalvat .= $tvaval['vatcode'].$tvacompl;
1945 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1946 $totalvat .= $tvacompl;
1947 } else {
1948 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1949 }
1950 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1951
1952 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1953 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1954 }
1955 }
1956 }
1957
1958 //Local tax 1 after VAT
1959 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1960 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1961 continue;
1962 }
1963
1964 foreach ($localtax_rate as $tvakey => $tvaval) {
1965 if ($tvakey != 0) { // On affiche pas taux 0
1966 //$this->atleastoneratenotnull++;
1967
1968 $index++;
1969 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1970
1971 $tvacompl = '';
1972 if (preg_match('/\*/', (string) $tvakey)) {
1973 $tvakey = str_replace('*', '', (string) $tvakey);
1974 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1975 }
1976 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1977 $totalvat .= ' ';
1978
1979 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1980 $totalvat .= $tvacompl;
1981 } else {
1982 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
1983 }
1984
1985 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1986
1987 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1988
1989 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1990 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1991 }
1992 }
1993 }
1994
1995 //Local tax 2 after VAT
1996 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1997 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1998 continue;
1999 }
2000
2001 foreach ($localtax_rate as $tvakey => $tvaval) {
2002 // retrieve global local tax
2003 if ($tvakey != 0) { // On affiche pas taux 0
2004 //$this->atleastoneratenotnull++;
2005
2006 $index++;
2007 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2008
2009 $tvacompl = '';
2010 if (preg_match('/\*/', (string) $tvakey)) {
2011 $tvakey = str_replace('*', '', (string) $tvakey);
2012 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
2013 }
2014 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
2015 $totalvat .= ' ';
2016
2017 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
2018 $totalvat .= $tvacompl;
2019 } else {
2020 $totalvat .= vatrate((string) abs((float) $tvakey), 1).$tvacompl;
2021 }
2022
2023 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
2024
2025 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
2026
2027 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2028 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
2029 }
2030 }
2031 }
2032
2033 // Revenue stamp
2034 if (price2num($object->revenuestamp, 'MT') != 0) {
2035 $index++;
2036 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2037 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
2038
2039 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2040 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
2041 }
2042
2043 // Total TTC
2044 $index++;
2045 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2046 $pdf->SetTextColor(0, 0, 60);
2047 $pdf->SetFillColor(224, 224, 224);
2048 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
2049
2050 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2051 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
2052
2053
2054 // Retained warranty
2055 if ($object->displayRetainedWarranty()) {
2056 $pdf->SetTextColor(40, 40, 40);
2057 $pdf->SetFillColor(255, 255, 255);
2058
2059 $retainedWarranty = $object->getRetainedWarrantyAmount();
2060 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
2061
2062 // Billed - retained warranty
2063 $index++;
2064 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2065 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
2066
2067 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2068 $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
2069
2070 // retained warranty
2071 $index++;
2072 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2073
2074 $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
2075 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
2076
2077 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
2078 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2079 $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
2080 }
2081 }
2082 }
2083
2084 $pdf->SetTextColor(0, 0, 0);
2085
2086 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
2087 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
2088
2089 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
2090 if (!empty($object->paye)) {
2091 $resteapayer = 0;
2092 }
2093
2094 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
2095 // Already paid + Deposits
2096 $index++;
2097 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2098 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
2099 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2100 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
2101
2102 // Credit note
2103 if ($creditnoteamount) {
2104 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
2105 $labeltouse .= (is_object($outputlangsbis) ? (' / '.(($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes"))) : '');
2106 $index++;
2107 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2108 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
2109 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2110 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
2111 }
2112
2113 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2114 $index++;
2115 $pdf->SetFillColor(255, 255, 255);
2116
2117 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2118 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
2119 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2120 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'), 0, $outputlangs), $useborder, 'R', 1);
2121
2122 $resteapayer = 0;
2123 }
2124
2125 $index++;
2126 $pdf->SetTextColor(0, 0, 60);
2127 $pdf->SetFillColor(224, 224, 224);
2128 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2129 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
2130 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2131 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
2132
2133 $pdf->SetFont('', '', $default_font_size - 1);
2134 $pdf->SetTextColor(0, 0, 0);
2135 }
2136
2137 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
2138
2139 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2140 if ($reshook < 0) {
2141 $this->error = $hookmanager->error;
2142 $this->errors = $hookmanager->errors;
2143 }
2144
2145 $index++;
2146 return ($tab2_top + ($tab2_hl * $index));
2147 }
2148
2149 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2157 public static function liste_modeles($db, $maxfilenamelength = 0)
2158 {
2159 // phpcs:enable
2160 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
2161 }
2162
2163 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2178 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2179 {
2180 global $conf;
2181
2182 // Force to disable hidetop and hidebottom
2183 $hidebottom = 0;
2184 if ($hidetop) {
2185 $hidetop = -1;
2186 }
2187
2188 $currency = !empty($currency) ? $currency : $conf->currency;
2189 $default_font_size = pdf_getPDFFontSize($outputlangs);
2190
2191 // Amount in (at tab_top - 1)
2192 $pdf->SetTextColor(0, 0, 0);
2193 $pdf->SetFont('', '', $default_font_size - 2);
2194
2195 if (empty($hidetop)) {
2196 // Show category of operations
2197 if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2198 $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2199 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2200 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2201 }
2202
2203 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2204 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2205 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2206 }
2207
2208 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2209 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2210
2211 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2212 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
2213 $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')));
2214 }
2215 }
2216
2217 $pdf->SetDrawColor(128, 128, 128);
2218 $pdf->SetFont('', '', $default_font_size - 1);
2219
2220 // Output Rect
2221 $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
2222
2223
2224 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2225
2226 if (empty($hidetop)) {
2227 $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
2228 }
2229 }
2230
2231 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2242 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2243 {
2244 // phpcs:enable
2245 global $conf, $langs;
2246
2247 $ltrdirection = 'L';
2248 if ($outputlangs->trans("DIRECTION") == 'rtl') {
2249 $ltrdirection = 'R';
2250 }
2251
2252 // Load traductions files required by page
2253 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2254
2255 $default_font_size = pdf_getPDFFontSize($outputlangs);
2256
2257 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2258
2259 $pdf->SetTextColor(0, 0, 60);
2260 $pdf->SetFont('', 'B', $default_font_size + 3);
2261
2262 $w = 110;
2263
2264 $posy = $this->marge_haute;
2265 $posx = $this->page_largeur - $this->marge_droite - $w;
2266
2267 $pdf->SetXY($this->marge_gauche, $posy);
2268
2269 // Logo
2270 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2271 if ($this->emetteur->logo) {
2272 $logodir = $conf->mycompany->dir_output;
2273 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2274 $logodir = $conf->mycompany->multidir_output[$object->entity];
2275 }
2276 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2277 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2278 } else {
2279 $logo = $logodir.'/logos/'.$this->emetteur->logo;
2280 }
2281 if (is_readable($logo)) {
2282 $height = pdf_getHeightForLogo($logo);
2283 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2284 } else {
2285 $pdf->SetTextColor(200, 0, 0);
2286 $pdf->SetFont('', 'B', $default_font_size - 2);
2287 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2288 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2289 }
2290 } else {
2291 $text = $this->emetteur->name;
2292 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2293 }
2294 }
2295
2296 $pdf->SetFont('', 'B', $default_font_size + 3);
2297 $pdf->SetXY($posx, $posy);
2298 $pdf->SetTextColor(0, 0, 60);
2299 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2300 if ($object->type == 1) {
2301 $title = $outputlangs->transnoentities("InvoiceReplacement");
2302 }
2303 if ($object->type == 2) {
2304 $title = $outputlangs->transnoentities("InvoiceAvoir");
2305 }
2306 if ($object->type == 3) {
2307 $title = $outputlangs->transnoentities("InvoiceDeposit");
2308 }
2309 if ($object->type == 4) {
2310 $title = $outputlangs->transnoentities("InvoiceProForma");
2311 }
2312 if ($this->situationinvoice) {
2313 $outputlangs->loadLangs(array("other"));
2314 $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2315 }
2316 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2317 $title .= ' - ';
2318 if ($object->type == 0) {
2319 if ($this->situationinvoice) {
2320 $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2321 }
2322 $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2323 } elseif ($object->type == 1) {
2324 $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2325 } elseif ($object->type == 2) {
2326 $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2327 } elseif ($object->type == 3) {
2328 $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2329 } elseif ($object->type == 4) {
2330 $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2331 }
2332 }
2333 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2334 if ($object->status == $object::STATUS_DRAFT) {
2335 $pdf->SetTextColor(128, 0, 0);
2336 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2337 }
2338
2339 $pdf->MultiCell($w, 3, $title, '', 'R');
2340
2341 $pdf->SetFont('', 'B', $default_font_size);
2342
2343 /*
2344 $posy += 5;
2345 $pdf->SetXY($posx, $posy);
2346 $pdf->SetTextColor(0, 0, 60);
2347 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2348 if ($object->status == $object::STATUS_DRAFT) {
2349 $pdf->SetTextColor(128, 0, 0);
2350 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2351 }
2352 $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2353
2354 $posy += 3;
2355 $pdf->SetFont('', '', $default_font_size - 2);
2356
2357 if ($object->ref_customer) {
2358 $posy += 4;
2359 $pdf->SetXY($posx, $posy);
2360 $pdf->SetTextColor(0, 0, 60);
2361 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2362 }
2363
2364 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
2365 $object->fetchProject();
2366 if (!empty($object->project->ref)) {
2367 $posy += 3;
2368 $pdf->SetXY($posx, $posy);
2369 $pdf->SetTextColor(0, 0, 60);
2370 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2371 }
2372 }
2373
2374 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
2375 $object->fetchProject();
2376 if (!empty($object->project->ref)) {
2377 $outputlangs->load("projects");
2378 $posy += 3;
2379 $pdf->SetXY($posx, $posy);
2380 $pdf->SetTextColor(0, 0, 60);
2381 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2382 }
2383 }
2384
2385 $objectidnext = $object->getIdReplacingInvoice('validated');
2386 if ($object->type == 0 && $objectidnext) {
2387 $objectreplacing = new Facture($this->db);
2388 $objectreplacing->fetch($objectidnext);
2389
2390 $posy += 3;
2391 $pdf->SetXY($posx, $posy);
2392 $pdf->SetTextColor(0, 0, 60);
2393 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2394 }
2395 if ($object->type == 1) {
2396 $objectreplaced = new Facture($this->db);
2397 $objectreplaced->fetch($object->fk_facture_source);
2398
2399 $posy += 4;
2400 $pdf->SetXY($posx, $posy);
2401 $pdf->SetTextColor(0, 0, 60);
2402 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2403 }
2404 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2405 $objectreplaced = new Facture($this->db);
2406 $objectreplaced->fetch($object->fk_facture_source);
2407
2408 $posy += 3;
2409 $pdf->SetXY($posx, $posy);
2410 $pdf->SetTextColor(0, 0, 60);
2411 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2412 }
2413
2414 $posy += 4;
2415 $pdf->SetXY($posx, $posy);
2416 $pdf->SetTextColor(0, 0, 60);
2417
2418 $title = $outputlangs->transnoentities("DateInvoice");
2419 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2420 $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2421 }
2422 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2423
2424 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2425 $posy += 4;
2426 $pdf->SetXY($posx, $posy);
2427 $pdf->SetTextColor(0, 0, 60);
2428 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2429 }
2430
2431 if ($object->type != 2) {
2432 $posy += 3;
2433 $pdf->SetXY($posx, $posy);
2434 $pdf->SetTextColor(0, 0, 60);
2435 $title = $outputlangs->transnoentities("DateDue");
2436 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2437 $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2438 }
2439 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2440 }
2441
2442 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
2443 $posy += 3;
2444 $pdf->SetXY($posx, $posy);
2445 $pdf->SetTextColor(0, 0, 60);
2446 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2447 }
2448
2449 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
2450 $posy += 3;
2451 $pdf->SetXY($posx, $posy);
2452 $pdf->SetTextColor(0, 0, 60);
2453 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
2454 }
2455
2456 // Get contact
2457 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
2458 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2459 if (count($arrayidcontact) > 0) {
2460 $usertmp = new User($this->db);
2461 $usertmp->fetch($arrayidcontact[0]);
2462 $posy += 4;
2463 $pdf->SetXY($posx, $posy);
2464 $pdf->SetTextColor(0, 0, 60);
2465 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2466 }
2467 }
2468
2469 $posy += 1;
2470
2471 $top_shift = 0;
2472 $shipp_shift = 0;
2473 // Show list of linked objects
2474 $current_y = $pdf->getY();
2475 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2476 if ($current_y < $pdf->getY()) {
2477 $top_shift = $pdf->getY() - $current_y;
2478 }
2479
2480 if ($showaddress) {
2481 // Sender properties
2482 $carac_emetteur = '';
2483 // Add internal contact of object if defined
2484 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2485 if (count($arrayidcontact) > 0) {
2486 $object->fetch_user($arrayidcontact[0]);
2487 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2488 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2489 $carac_emetteur .= "\n";
2490 }
2491
2492 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2493
2494 // Show sender
2495 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2496 $posy += $top_shift;
2497 $posx = $this->marge_gauche;
2498 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2499 $posx = $this->page_largeur - $this->marge_droite - 80;
2500 }
2501
2502 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
2503 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
2504
2505 // Show sender frame
2506 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
2507 $pdf->SetTextColor(0, 0, 0);
2508 $pdf->SetFont('', '', $default_font_size - 2);
2509 $pdf->SetXY($posx, $posy - 5);
2510 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2511 $pdf->SetXY($posx, $posy);
2512 $pdf->SetFillColor(230, 230, 230);
2513 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
2514 $pdf->SetTextColor(0, 0, 60);
2515 }
2516
2517 // Show sender name
2518 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
2519 $pdf->SetXY($posx + 2, $posy + 3);
2520 $pdf->SetFont('', 'B', $default_font_size);
2521 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2522 $posy = $pdf->getY();
2523 }
2524
2525 // Show sender information
2526 $pdf->SetXY($posx + 2, $posy);
2527 $pdf->SetFont('', '', $default_font_size - 1);
2528 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2529
2530 // If BILLING contact defined on invoice, we use it
2531 $usecontact = false;
2532 $arrayidcontact = $object->getIdContact('external', 'BILLING');
2533 if (count($arrayidcontact) > 0) {
2534 $usecontact = true;
2535 $result = $object->fetch_contact($arrayidcontact[0]);
2536 }
2537
2538 // Recipient name
2539 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2540 $thirdparty = $object->contact;
2541 } else {
2542 $thirdparty = $object->thirdparty;
2543 }
2544
2545 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2546
2547 $mode = 'target';
2548 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
2549
2550 // Show recipient
2551 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
2552 if ($this->page_largeur < 210) {
2553 $widthrecbox = 84; // To work with US executive format
2554 }
2555 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
2556 $posy += $top_shift;
2557 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2558 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
2559 $posx = $this->marge_gauche;
2560 }
2561
2562 // Show recipient frame
2563 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
2564 $pdf->SetTextColor(0, 0, 0);
2565 $pdf->SetFont('', '', $default_font_size - 2);
2566 $pdf->SetXY($posx + 2, $posy - 5);
2567 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2568 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2569 }
2570
2571 // Show recipient name
2572 $pdf->SetXY($posx + 2, $posy + 3);
2573 $pdf->SetFont('', 'B', $default_font_size);
2574 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2575 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2576
2577 $posy = $pdf->getY();
2578
2579 // Show recipient information
2580 $pdf->SetFont('', '', $default_font_size - 1);
2581 $pdf->SetXY($posx + 2, $posy);
2582 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2583 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2584
2585 // Show shipping/delivery address
2586 if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2587 $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2588
2589 if (!empty($idaddressshipping)) {
2590 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2591 $companystatic = new Societe($this->db);
2592 $companystatic->fetch($object->contact->fk_soc);
2593 $carac_client_name_shipping = pdfBuildThirdpartyName($object->contact, $outputlangs);
2594 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, 1, 'target', $object);
2595 } else {
2596 $carac_client_name_shipping = pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2597 $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2598 }
2599 if (!empty($carac_client_shipping)) {
2600 $posy += $hautcadre;
2601
2602 $hautcadre -= 10; // Height for the shipping address does not need to be as high as main box
2603
2604 // Show shipping frame
2605 $pdf->SetXY($posx + 2, $posy - 5);
2606 $pdf->SetFont('', '', $default_font_size - 2);
2607 $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2608 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
2609
2610 // Show shipping name
2611 $pdf->SetXY($posx + 2, $posy + 3);
2612 $pdf->SetFont('', 'B', $default_font_size);
2613 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2614
2615 $posy = $pdf->getY();
2616
2617 // Show shipping information
2618 $pdf->SetXY($posx + 2, $posy);
2619 $pdf->SetFont('', '', $default_font_size - 1);
2620 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2621
2622 $shipp_shift += $hautcadre + 10;
2623 }
2624 }
2625 }
2626
2627 $pdf->SetTextColor(0, 0, 0);
2628
2629 $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2630
2631 return $pagehead;
2632 }
2633
2634 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2645 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2646 {
2647 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2648 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);
2649 }
2650
2661 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2662 {
2663 global $hookmanager;
2664
2665 // Default field style for content
2666 $this->defaultContentsFieldsStyle = array(
2667 'align' => 'R', // R,C,L
2668 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2669 );
2670
2671 // Default field style for content
2672 $this->defaultTitlesFieldsStyle = array(
2673 'align' => 'C', // R,C,L
2674 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2675 );
2676
2677 /*
2678 * For example
2679 $this->cols['theColKey'] = array(
2680 'rank' => $rank, // int : use for ordering columns
2681 'width' => 20, // the column width in mm
2682 'title' => array(
2683 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2684 'label' => ' ', // the final label : used fore final generated text
2685 'align' => 'L', // text alignment : R,C,L
2686 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2687 ),
2688 'content' => array(
2689 'align' => 'L', // text alignment : R,C,L
2690 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2691 ),
2692 );
2693 */
2694
2695 $rank = 0; // do not use negative rank
2696 $this->cols['position'] = array(
2697 'rank' => $rank,
2698 'width' => 10,
2699 'status' => getDolGlobalInt('PDF_SPONGE_ADD_POSITION') ? true : (getDolGlobalInt('PDF_ADD_POSITION') ? true : false),
2700 'title' => array(
2701 'textkey' => '#', // use lang key is useful in somme case with module
2702 'align' => 'C',
2703 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2704 // 'label' => ' ', // the final label
2705 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2706 ),
2707 'content' => array(
2708 'align' => 'C',
2709 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2710 ),
2711 );
2712
2713 $rank = 5; // do not use negative rank
2714 $this->cols['desc'] = array(
2715 'rank' => $rank,
2716 'width' => false, // only for desc
2717 'status' => true,
2718 'title' => array(
2719 'textkey' => 'Designation', // use lang key is useful in somme case with module
2720 'align' => 'L',
2721 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2722 // 'label' => ' ', // the final label
2723 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2724 ),
2725 'content' => array(
2726 'align' => 'L',
2727 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2728 ),
2729 );
2730
2731 // Image of product
2732 $rank += 10;
2733 $this->cols['photo'] = array(
2734 'rank' => $rank,
2735 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
2736 'status' => false,
2737 'title' => array(
2738 'textkey' => 'Photo',
2739 'label' => ' '
2740 ),
2741 'content' => array(
2742 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2743 ),
2744 'border-left' => false, // remove left line separator
2745 );
2746
2747 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
2748 $this->cols['photo']['status'] = true;
2749 }
2750
2751
2752 $rank += 10;
2753 $this->cols['vat'] = array(
2754 'rank' => $rank,
2755 'status' => false,
2756 'width' => 16, // in mm
2757 'title' => array(
2758 'textkey' => 'VAT'
2759 ),
2760 'border-left' => true, // add left line separator
2761 );
2762
2763 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
2764 $this->cols['vat']['status'] = true;
2765 }
2766
2767 $rank += 10;
2768 $this->cols['subprice'] = array(
2769 'rank' => $rank,
2770 'width' => 19, // in mm
2771 'status' => true,
2772 'title' => array(
2773 'textkey' => 'PriceUHT'
2774 ),
2775 'border-left' => true, // add left line separator
2776 );
2777
2778 // Adapt dynamically the width of subprice, if text is too long.
2779 $tmpwidth = 0;
2780 $nblines = count($object->lines);
2781 for ($i = 0; $i < $nblines; $i++) {
2782 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2783 $tmpwidth = max($tmpwidth, $tmpwidth2);
2784 }
2785 if ($tmpwidth > 10) {
2786 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2787 }
2788
2789 $rank += 10;
2790 $this->cols['qty'] = array(
2791 'rank' => $rank,
2792 'width' => 16, // in mm
2793 'status' => true,
2794 'title' => array(
2795 'textkey' => 'Qty'
2796 ),
2797 'border-left' => true, // add left line separator
2798 );
2799
2800 $rank += 10;
2801 $this->cols['progress'] = array(
2802 'rank' => $rank,
2803 'width' => 19, // in mm
2804 'status' => false,
2805 'title' => array(
2806 'textkey' => 'ProgressShort'
2807 ),
2808 'border-left' => true, // add left line separator
2809 );
2810
2811 if ($this->situationinvoice) {
2812 $this->cols['progress']['status'] = true;
2813 }
2814
2815 $rank += 10;
2816 $this->cols['unit'] = array(
2817 'rank' => $rank,
2818 'width' => 11, // in mm
2819 'status' => false,
2820 'title' => array(
2821 'textkey' => 'Unit'
2822 ),
2823 'border-left' => true, // add left line separator
2824 );
2825 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2826 $this->cols['unit']['status'] = true;
2827 }
2828
2829 $rank += 10;
2830 $this->cols['discount'] = array(
2831 'rank' => $rank,
2832 'width' => 13, // in mm
2833 'status' => false,
2834 'title' => array(
2835 'textkey' => 'ReductionShort'
2836 ),
2837 'border-left' => true, // add left line separator
2838 );
2839 if ($this->atleastonediscount) {
2840 $this->cols['discount']['status'] = true;
2841 }
2842
2843 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2844 $this->cols['totalexcltax'] = array(
2845 'rank' => $rank,
2846 'width' => 26, // in mm
2847 'status' => !getDolGlobalBool('PDF_INVOICE_HIDE_PRICE_EXCL_TAX'),
2848 'title' => array(
2849 'textkey' => 'TotalHTShort'
2850 ),
2851 'border-left' => true, // add left line separator
2852 );
2853
2854 $rank += 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2855 $this->cols['totalincltax'] = array(
2856 'rank' => $rank,
2857 'width' => 26, // in mm
2858 'status' => getDolGlobalBool('PDF_INVOICE_SHOW_PRICE_INCL_TAX'),
2859 'title' => array(
2860 'textkey' => 'TotalTTCShort'
2861 ),
2862 'border-left' => true, // add left line separator
2863 );
2864
2865 // Add extrafields cols
2866 if (!empty($object->lines)) {
2867 $line = reset($object->lines);
2868 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2869 }
2870
2871 $parameters = array(
2872 'object' => $object,
2873 'outputlangs' => $outputlangs,
2874 'hidedetails' => $hidedetails,
2875 'hidedesc' => $hidedesc,
2876 'hideref' => $hideref
2877 );
2878
2879 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2880 if ($reshook < 0) {
2881 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2882 } elseif (empty($reshook)) {
2883 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
2884 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2885 } else {
2886 $this->cols = $hookmanager->resArray;
2887 }
2888 }
2889}
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