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