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