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