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