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