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