dolibarr 24.0.0-beta
pdf_canelle.modules.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024 Nick Fragoulis
9 * Copyright (C) 2025 Joachim Küter <git-jk@bloxera.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
32require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38
39
44{
48 public $db;
49
53 public $name;
54
58 public $description;
59
63 public $update_main_doc_field;
64
68 public $type;
69
74 public $version = 'dolibarr';
75
76
82 public function __construct($db)
83 {
84 global $conf, $langs, $mysoc;
85
86 // Translations
87 $langs->loadLangs(array("main", "bills"));
88
89 $this->db = $db;
90 $this->name = "canelle";
91 $this->description = $langs->trans('SuppliersInvoiceModel');
92 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
93
94 // Page dimensions
95 $this->type = 'pdf';
96 $formatarray = pdf_getFormat();
97 $this->page_largeur = $formatarray['width'];
98 $this->page_hauteur = $formatarray['height'];
99 $this->format = array($this->page_largeur, $this->page_hauteur);
100 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
101 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
102 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
103 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
104 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
105 $this->option_logo = 1; // Display logo
106 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
107 $this->option_modereg = 1; // Display payment mode
108 $this->option_condreg = 1; // Display payment terms
109 $this->option_multilang = 1; // Available in several languages
110
111 // Define column position
112 $this->posxdesc = $this->marge_gauche + 1;
113
114 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
115 $this->posxtva = 99;
116 $this->posxup = 114;
117 $this->posxqty = 130;
118 $this->posxunit = 147;
119 } else {
120 $this->posxtva = 106;
121 $this->posxup = 122;
122 $this->posxqty = 145;
123 $this->posxunit = 162;
124 }
125 $this->posxdiscount = 162;
126 $this->postotalht = 174;
127
128 /* if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') || getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
129 $this->posxtva = $this->posxup;
130 } */
131 $this->posxpicture = $this->posxtva - (getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20)); // width of images
132 if ($this->page_largeur < 210) { // To work with US executive format
133 $this->posxpicture -= 20;
134 $this->posxtva -= 20;
135 $this->posxup -= 20;
136 $this->posxqty -= 20;
137 $this->posxunit -= 20;
138 $this->posxdiscount -= 20;
139 $this->postotalht -= 20;
140 }
141
142 $this->tva = array();
143 $this->tva_array = array();
144 $this->localtax1 = array();
145 $this->localtax2 = array();
146 $this->atleastoneratenotnull = 0;
147 $this->atleastonediscount = 0;
148 }
149
150
151 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
163 public function write_file($object, $outputlangs = null, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
164 {
165 // phpcs:enable
166 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
167
168 // Get source company
169 if (!is_object($object->thirdparty)) {
170 $object->fetch_thirdparty();
171 }
172 if (!is_object($object->thirdparty)) {
173 $object->thirdparty = $mysoc; // If fetch_thirdparty fails, object has no socid (specimen)
174 }
175
176 $this->emetteur = $object->thirdparty;
177 if (!$this->emetteur->country_code) {
178 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
179 }
180
181 if (!is_object($outputlangs)) {
182 $outputlangs = $langs;
183 }
184 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
185 if (getDolGlobalString('MAIN_USE_FPDF')) {
186 $outputlangs->charset_output = 'ISO-8859-1';
187 }
188
189 // Load translation files required by the page
190 $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products"));
191
192 $nblines = count($object->lines);
193
194 if ($conf->fournisseur->facture->dir_output) {
195 $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
196 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
197 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
198
199 // Definition of $dir and $file
200 if ($object->specimen) {
201 $dir = $conf->fournisseur->facture->dir_output;
202 $file = $dir."/SPECIMEN.pdf";
203 } else {
204 $objectref = dol_sanitizeFileName($object->ref);
205 $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
206 $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$objectref;
207 $file = $dir."/".$objectref.".pdf";
208 if (getDolGlobalString('SUPPLIER_REF_IN_NAME')) {
209 $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
210 }
211 }
212
213 if (!file_exists($dir)) {
214 if (dol_mkdir($dir) < 0) {
215 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
216 return 0;
217 }
218 }
219
220 if (file_exists($dir)) {
221 // Add pdfgeneration hook
222 if (!is_object($hookmanager)) {
223 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
224 $hookmanager = new HookManager($this->db);
225 }
226 $hookmanager->initHooks(array('pdfgeneration'));
227 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
228 global $action;
229 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
230
231 // Set nblines with the new facture lines content after hook
232 $nblines = count($object->lines);
233 $nbpayments = count($object->getListOfPayments());
234
235 // Create pdf instance
236 $pdf = pdf_getInstance($this->format);
237 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
238 $pdf->setAutoPageBreak(true, 0);
239
240 $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
241 if ($heightforinfotot > 220) {
242 $heightforinfotot = 220;
243 }
244 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
245 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
246 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
247 $heightforfooter += 6;
248 }
249
250 if (class_exists('TCPDF')) {
251 $pdf->setPrintHeader(false);
252 $pdf->setPrintFooter(false);
253 }
254 $pdf->SetFont(pdf_getPDFFont($outputlangs));
255 // Set path to the background PDF File
256 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
257 $logodir = $conf->mycompany->dir_output;
258 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
259 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
260 }
261 $pagecount = $pdf->setSourceFile($logodir .'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
262 $tplidx = $pdf->importPage(1);
263 }
264
265 $pdf->Open();
266 $pagenb = 0;
267 $pdf->SetDrawColor(128, 128, 128);
268
269 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
270 $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
271 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
272 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
273 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
274 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
275 $pdf->SetCompression(false);
276 }
277
278 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
279 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
280
281 // Set $this->atleastonediscount if you have at least one discount
282 for ($i = 0; $i < $nblines; $i++) {
283 if ($object->lines[$i]->remise_percent) {
284 $this->atleastonediscount++;
285 }
286 }
287 if (empty($this->atleastonediscount)) {
288 $delta = ($this->postotalht - $this->posxdiscount);
289 $this->posxpicture += $delta;
290 $this->posxtva += $delta;
291 $this->posxup += $delta;
292 $this->posxqty += $delta;
293 $this->posxunit += $delta;
294 $this->posxdiscount += $delta;
295 // post of fields after are not modified, stay at same position
296 }
297
298 // New page
299 $pdf->AddPage();
300 if (!empty($tplidx)) {
301 $pdf->useTemplate($tplidx);
302 }
303 $pagenb++;
304 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
305 $pdf->SetFont('', '', $default_font_size - 1);
306 $pdf->MultiCell(0, 3, ''); // Set interline to 3
307 $pdf->SetTextColor(0, 0, 0);
308
309 $tab_top = 90 + $top_shift;
310 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
311
312 // Incoterm
313 if (isModEnabled('incoterm')) {
314 $desc_incoterms = $object->getIncotermsForPDF();
315 if ($desc_incoterms) {
316 $tab_top -= 2;
317
318 $pdf->SetFont('', '', $default_font_size - 1);
319 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
320 $nexY = $pdf->GetY();
321 $height_incoterms = $nexY - $tab_top;
322
323 // Rect takes a length in 3rd parameter
324 $pdf->SetDrawColor(192, 192, 192);
325 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
326
327 $tab_top = $nexY + 6;
328 }
329 }
330
331 // Displays notes
332 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
333
334 // Extrafields in note
335 if (getDolGlobalString('INVOICE_ADD_EXTRAFIELD_IN_NOTE')) {
336 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
337 if (!empty($extranote)) {
338 $notetoshow = dol_concatdesc($notetoshow, $extranote);
339 }
340 }
341
342 if ($notetoshow) {
343 $tab_top -= 2;
344
345 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
346 complete_substitutions_array($substitutionarray, $outputlangs, $object);
347 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
348 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
349
350 $pdf->SetFont('', '', $default_font_size - 1);
351 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
352 $nexY = $pdf->GetY();
353 $height_note = $nexY - $tab_top;
354
355 // Rect takes a length in 3rd parameter
356 $pdf->SetDrawColor(192, 192, 192);
357 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius, '1234', 'D');
358
359 $tab_top = $nexY + 6;
360 }
361
362 $iniY = $tab_top + 7;
363 $curY = $tab_top + 7;
364 $nexY = $tab_top + 7;
365 $pdf_sub_options = [
366 'titleshowuponpdf' => 1,
367 'titleshowtotalexludingvatonpdf' => 1,
368 ];
369
370 // Loop on each lines
371 for ($i = 0; $i < $nblines; $i++) {
372 $sub_options = $object->lines[$i]->extraparams["subtotal"] ?? array();
373
374 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
375 $level = $object->lines[$i]->qty;
376 if ($sub_options) {
377 if (isset($sub_options['titleshowuponpdf'])) {
378 $pdf_sub_options['titleshowuponpdf'] = isset($pdf_sub_options['titleshowuponpdf']) && $pdf_sub_options['titleshowuponpdf'] < $level ? $pdf_sub_options['titleshowuponpdf'] : $level;
379 } elseif (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
380 unset($pdf_sub_options['titleshowuponpdf']);
381 }
382 if (isset($sub_options['titleshowtotalexludingvatonpdf'])) {
383 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && $pdf_sub_options['titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options['titleshowtotalexludingvatonpdf'] : $level;
384 } elseif (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
385 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
386 }
387 } else {
388 if (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
389 unset($pdf_sub_options['titleshowuponpdf']);
390 }
391 if (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
392 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
393 }
394 }
395 }
396 $curY = $nexY;
397 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
398 $pdf->SetTextColor(0, 0, 0);
399
400 // Define size of image if we need it
401 //$imglinesize = array();
402 //if (!empty($realpatharray[$i])) {
403 // $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
404 //}
405
406 $pdf->setTopMargin($tab_top_newpage);
407 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
408 $pageposbefore = $pdf->getPage();
409
410 $showpricebeforepagebreak = 1;
411 $posYAfterImage = 0;
412
413 // Description of product line
414 $curX = $this->posxdesc - 1;
415
416 $pdf->startTransaction();
417 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
418 $pageposafter = $pdf->getPage();
419 if ($pageposafter > $pageposbefore) { // There is a pagebreak
420 $pdf->rollbackTransaction(true);
421 $pageposafter = $pageposbefore;
422 //print $pageposafter.'-'.$pageposbefore;exit;
423 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
424 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
425 $posyafter = $pdf->GetY();
426 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
427 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
428 $pdf->AddPage('', '', true);
429 if (!empty($tplidx)) {
430 $pdf->useTemplate($tplidx);
431 }
432 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
433 $this->_pagehead($pdf, $object, 0, $outputlangs);
434 }
435 $pdf->setPage($pageposafter + 1);
436 }
437 } else {
438 // We found a page break
439 // Allows data in the first page if description is long enough to break in multiples pages
440 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
441 $showpricebeforepagebreak = 1;
442 } else {
443 $showpricebeforepagebreak = 0;
444 }
445 }
446 } else { // No pagebreak
447 $pdf->commitTransaction();
448 }
449 $posYAfterDescription = $pdf->GetY();
450
451 $nexY = $pdf->GetY();
452 $pageposafter = $pdf->getPage();
453 $pdf->setPage($pageposbefore);
454 $pdf->setTopMargin($this->marge_haute);
455 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
456
457 // We suppose that a too long description or photo were moved completely on next page
458 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
459 $pdf->setPage($pageposafter);
460 $curY = $tab_top_newpage;
461 }
462
463 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
464
465 // VAT Rate
466 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
467 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
468 $pdf->SetXY($this->posxtva, $curY);
469 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
470 }
471
472 // Unit price before discount
473 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
474 $pdf->SetXY($this->posxup, $curY);
475 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', false);
476
477 // Quantity
478 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
479 $pdf->SetXY($this->posxqty, $curY);
480 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
481
482 // Unit
483 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
484 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
485 $pdf->SetXY($this->posxunit, $curY);
486 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
487 }
488
489 // Discount on line
490 if ($object->lines[$i]->remise_percent) {
491 $pdf->SetXY($this->posxdiscount - 2, $curY);
492 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
493 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0, 'R');
494 }
495
496 // Total HT line
497 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
498 $pdf->SetXY($this->postotalht, $curY);
499 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', false);
500
501 // Collection of totals by VAT value in $this->tva["taux"]=total_tva
502 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
503 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
504 } else {
505 $tvaligne = $object->lines[$i]->total_tva;
506 }
507
508 $localtax1ligne = $object->lines[$i]->total_localtax1;
509 $localtax2ligne = $object->lines[$i]->total_localtax2;
510
511 // TODO remise_percent is an obsolete field for object parent
512 /*if (!empty($object->remise_percent)) {
513 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
514 }*/
515
516 $vatrate = (string) $object->lines[$i]->tva_tx;
517 $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
518 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
519
520 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
521 $vatrate .= '*';
522 }
523 if (empty($this->tva[$vatrate])) {
524 $this->tva[$vatrate] = 0;
525 }
526 if (empty($this->localtax1[$localtax1rate])) {
527 $this->localtax1[$localtax1rate] = 0;
528 }
529 if (empty($this->localtax2[$localtax2rate])) {
530 $this->localtax2[$localtax2rate] = 0;
531 }
532 $this->tva[$vatrate] += $tvaligne;
533 $this->localtax1[$localtax1rate] += $localtax1ligne;
534 $this->localtax2[$localtax2rate] += $localtax2ligne;
535
536 if ($posYAfterImage > $posYAfterDescription) {
537 $nexY = $posYAfterImage;
538 }
539
540 // Add line
541 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
542 $pdf->setPage($pageposafter);
543 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
544 //$pdf->SetDrawColor(190,190,200);
545 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
546 $pdf->SetLineStyle(array('dash' => 0));
547 }
548
549 $nexY += 2; // Add space between lines
550
551 // Detect if some page were added automatically and output _tableau for past pages
552 while ($pagenb < $pageposafter) {
553 $pdf->setPage($pagenb);
554 if ($pagenb == 1) {
555 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
556 } else {
557 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
558 }
559 $this->_pagefoot($pdf, $object, $outputlangs, 1);
560 $pagenb++;
561 $pdf->setPage($pagenb);
562 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
563 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
564 $this->_pagehead($pdf, $object, 0, $outputlangs);
565 }
566 }
567 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty // @phan-suppress-current-line PhanUndeclaredProperty
568 if ($pagenb == 1) {
569 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
570 } else {
571 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
572 }
573 $this->_pagefoot($pdf, $object, $outputlangs, 1);
574 // New page
575 $pdf->AddPage();
576 if (!empty($tplidx)) {
577 $pdf->useTemplate($tplidx);
578 }
579 $pagenb++;
580 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
581 $this->_pagehead($pdf, $object, 0, $outputlangs);
582 }
583 }
584 }
585
586 // Show square
587 if ($pagenb == 1) {
588 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
589 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
590 } else {
591 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
592 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
593 }
594
595 // Display total area
596 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
597
598 $amount_credit_notes_included = 0;
599 $amount_deposits_included = 0;
600
601 // Display Payments area
602 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
603 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
604 }
605
606 // Pagefoot
607 $this->_pagefoot($pdf, $object, $outputlangs);
608 if (method_exists($pdf, 'AliasNbPages')) {
609 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
610 }
611
612 $pdf->Close();
613
614 $pdf->Output($file, 'F');
615
616 // Add pdfgeneration hook
617 $hookmanager->initHooks(array('pdfgeneration'));
618 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
619 global $action;
620 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
621 $this->warnings = $hookmanager->warnings;
622 if ($reshook < 0) {
623 $this->error = $hookmanager->error;
624 $this->errors = $hookmanager->errors;
625 dolChmod($file);
626 return -1;
627 }
628
629 dolChmod($file);
630
631 $this->result = array('fullpath' => $file);
632
633 return 1; // No error
634 } else {
635 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
636 return 0;
637 }
638 } else {
639 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
640 return 0;
641 }
642 }
643
644 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
645 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
656 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
657 {
658 // phpcs:enable
659 global $conf, $mysoc, $hookmanager;
660
661 $sign = 1;
662 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
663 $sign = -1;
664 }
665
666 $default_font_size = pdf_getPDFFontSize($outputlangs);
667
668 $tab2_top = $posy;
669 $tab2_hl = 4;
670 $pdf->SetFont('', '', $default_font_size - 1);
671
672 // Total table
673 $col1x = 120;
674 $col2x = 170;
675 if ($this->page_largeur < 210) { // To work with US executive format
676 $col2x -= 20;
677 }
678 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
679
680 $useborder = 0;
681 $index = 0;
682
683 // Total HT
684 $pdf->SetFillColor(255, 255, 255);
685 $pdf->SetXY($col1x, $tab2_top);
686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', true);
687
688 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
689 $pdf->SetXY($col2x, $tab2_top);
690 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', true);
691
692 // Show VAT by rates and total
693 $pdf->SetFillColor(248, 248, 248);
694
695 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
696
697 $this->atleastoneratenotnull = 0;
698 foreach ($this->tva as $tvakey => $tvaval) {
699 if ($tvakey > 0) { // We do not display rate 0
700 $this->atleastoneratenotnull++;
701
702 $index++;
703 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
704
705 $tvacompl = '';
706
707 if (preg_match('/\*/', $tvakey)) {
708 $tvakey = str_replace('*', '', $tvakey);
709 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
710 }
711
712 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
713 $totalvat .= vatrate($tvakey, true).$tvacompl;
714 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
715
716 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
717 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', true);
718 }
719 }
720 if (!$this->atleastoneratenotnull) { // If no vat at all
721 $index++;
722 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
723 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', true);
724 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
725 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', true);
726
727 // Total LocalTax1
728 if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on' && $object->total_localtax1 > 0) {
729 $index++;
730 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
731 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', true);
732 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
733 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', true);
734 }
735
736 // Total LocalTax2
737 if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on' && $object->total_localtax2 > 0) {
738 $index++;
739 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
740 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', true);
741 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
742 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', true);
743 }
744 } else {
745 //if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on')
746 //{
747 //Local tax 1
748 foreach ($this->localtax1 as $tvakey => $tvaval) {
749 if ($tvakey != 0) { // On affiche pas taux 0
750 //$this->atleastoneratenotnull++;
751
752 $index++;
753 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
754
755 $tvacompl = '';
756 if (preg_match('/\*/', (string) $tvakey)) {
757 $tvakey = str_replace('*', '', (string) $tvakey);
758 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
759 }
760 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
761 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
762 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
763
764 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
765 $pdf->MultiCell($largcol2, $tab2_hl, price((string) $tvaval, 0, $outputlangs), 0, 'R', true);
766 }
767 }
768 //}
769
770 //if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on')
771 //{
772 //Local tax 2
773 foreach ($this->localtax2 as $tvakey => $tvaval) {
774 if ($tvakey != 0) { // On affiche pas taux 0
775 //$this->atleastoneratenotnull++;
776
777 $index++;
778 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
779
780 $tvacompl = '';
781 if (preg_match('/\*/', (string) $tvakey)) {
782 $tvakey = str_replace('*', '', (string) $tvakey);
783 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
784 }
785 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
786 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
787 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
788
789 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
790 $pdf->MultiCell($largcol2, $tab2_hl, price((string) $tvaval, 0, $outputlangs), 0, 'R', true);
791 }
792 }
793 //}
794 }
795
796 // Total TTC
797 $index++;
798 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
799 $pdf->SetTextColor(0, 0, 60);
800 $pdf->SetFillColor(224, 224, 224);
801 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', true);
802
803 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
804 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
805
806 $pdf->SetTextColor(0, 0, 0);
807 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
808 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
809 //print "x".$creditnoteamount."-".$depositsamount;exit;
810 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
811 if (!empty($object->paid)) {
812 $resteapayer = 0;
813 }
814
815 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
816 // Already paid + Deposits
817 $index++;
818 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', false);
820 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
821 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
822
823 // Credit note
824 if ($creditnoteamount) {
825 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
826 $index++;
827 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
828 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', false);
829 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
830 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', false);
831 }
832
833 // Escompte
834 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
835 $index++;
836 $pdf->SetFillColor(255, 255, 255);
837
838 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
839 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', true);
840 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
841 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', true);
842
843 $resteapayer = 0;
844 }
845
846 $index++;
847 $pdf->SetTextColor(0, 0, 60);
848 $pdf->SetFillColor(224, 224, 224);
849 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
850 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', true);
851
852 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
853 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
854 $pdf->SetFont('', '', $default_font_size - 1);
855 $pdf->SetTextColor(0, 0, 0);
856 }
857
858 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
859
860 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
861 if ($reshook < 0) {
862 $this->error = $hookmanager->error;
863 $this->errors = $hookmanager->errors;
864 }
865
866 $index++;
867 return ($tab2_top + ($tab2_hl * $index));
868 }
869
870 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
884 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
885 {
886 global $conf;
887
888 // Force to disable hidetop and hidebottom
889 $hidebottom = 0;
890 if ($hidetop) {
891 $hidetop = -1;
892 }
893
894 $currency = !empty($currency) ? $currency : $conf->currency;
895 $default_font_size = pdf_getPDFFontSize($outputlangs);
896
897 // Amount in (at tab_top - 1)
898 $pdf->SetTextColor(0, 0, 0);
899 $pdf->SetFont('', '', $default_font_size - 2);
900
901 if (empty($hidetop)) {
902 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
903 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
904 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
905
906 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
907 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
908 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
909 }
910 }
911
912 $pdf->SetDrawColor(128, 128, 128);
913 $pdf->SetFont('', '', $default_font_size - 1);
914
915 // Output Rect
916 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
917
918 if (empty($hidetop)) {
919 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
920
921 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
922 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
923 }
924
925 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
926 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
927 if (empty($hidetop)) {
928 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
929 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
930 }
931 }
932
933 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
934 if (empty($hidetop)) {
935 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
936 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
937 }
938
939 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
940 if (empty($hidetop)) {
941 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
942 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
943 }
944
945 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
946 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
947 if (empty($hidetop)) {
948 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
949 $pdf->MultiCell(
950 $this->posxdiscount - $this->posxunit - 1,
951 2,
952 $outputlangs->transnoentities("Unit"),
953 '',
954 'C'
955 );
956 }
957 }
958
959 if ($this->atleastonediscount) {
960 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
961 if (empty($hidetop)) {
962 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
963 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
964 }
965 }
966
967 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
968 if (empty($hidetop)) {
969 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
970 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
971 }
972 }
973
974 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
975 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
986 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
987 {
988 // phpcs:enable
989 global $conf;
990
991 $sign = 1;
992 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
993 $sign = -1;
994 }
995
996 $tab3_posx = 120;
997 $tab3_top = $posy + 8;
998 $tab3_width = 80;
999 $tab3_height = 4;
1000 if ($this->page_largeur < 210) { // To work with US executive format
1001 $tab3_posx -= 20;
1002 }
1003
1004 $default_font_size = pdf_getPDFFontSize($outputlangs);
1005
1006 $pdf->SetFont('', '', $default_font_size - 3);
1007 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1008 $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', false);
1009
1010 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1011
1012 $pdf->SetFont('', '', $default_font_size - 4);
1013 $pdf->SetXY($tab3_posx, $tab3_top);
1014 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
1015 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1016 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
1017 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1018 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
1019 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1020 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
1021
1022 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1023
1024 $y = 0;
1025
1026 $pdf->SetFont('', '', $default_font_size - 4);
1027
1028 // Loop on each deposits and credit notes included
1029 //
1030
1031 // Loop on each payment
1032 $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1033 $sql .= " cp.code";
1034 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
1035 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1036 $sql .= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1037 $sql .= " ORDER BY p.datep";
1038 $resql = $this->db->query($sql);
1039 if ($resql) {
1040 $num = $this->db->num_rows($resql);
1041 $i = 0;
1042 while ($i < $num) {
1043 $y += 3;
1044 $row = $this->db->fetch_object($resql);
1045
1046 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1047 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1048 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1049 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', false);
1050 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1051 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1052
1053 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1054 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1055 $pdf->MultiCell(30, 3, $row->num_payment, 0, 'L', false);
1056
1057 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1058
1059 $i++;
1060 }
1061 } else {
1062 $this->error = $this->db->lasterror();
1063 return -1;
1064 }
1065 return -1;
1066 }
1067
1068 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1078 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1079 {
1080 global $langs, $conf, $mysoc;
1081
1082 // Load translation files required by the page
1083 $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1084
1085 $default_font_size = pdf_getPDFFontSize($outputlangs);
1086
1087 // Do not add the BACKGROUND as this is for suppliers
1088 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1089
1090 $pdf->SetTextColor(0, 0, 60);
1091 $pdf->SetFont('', 'B', $default_font_size + 3);
1092
1093 $w = 100;
1094
1095 $posy = $this->marge_haute;
1096 $posx = $this->page_largeur - $this->marge_droite - 100;
1097
1098 $pdf->SetXY($this->marge_gauche, $posy);
1099
1100 // Logo
1101 /*
1102 $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1103 if ($mysoc->logo)
1104 {
1105 if (is_readable($logo))
1106 {
1107 $height=pdf_getHeightForLogo($logo);
1108 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1109 }
1110 else
1111 {
1112 $pdf->SetTextColor(200,0,0);
1113 $pdf->SetFont('','B', $default_font_size - 2);
1114 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1115 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1116 }
1117 }
1118 else
1119 {*/
1120 $text = $this->emetteur->name;
1121 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1122 //}
1123
1124 $pdf->SetFont('', 'B', $default_font_size + 3);
1125 $pdf->SetXY($posx, $posy);
1126 $pdf->SetTextColor(0, 0, 60);
1127 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1128 if ($object->type == 1) {
1129 $title = $outputlangs->transnoentities("InvoiceReplacement");
1130 }
1131 if ($object->type == 2) {
1132 $title = $outputlangs->transnoentities("InvoiceAvoir");
1133 }
1134 if ($object->type == 3) {
1135 $title = $outputlangs->transnoentities("InvoiceDeposit");
1136 }
1137 $pdf->MultiCell($w, 3, $title." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1138 $posy += 1;
1139
1140 if ($object->ref_supplier) {
1141 $posy += 4;
1142 $pdf->SetFont('', 'B', $default_font_size);
1143 $pdf->SetXY($posx, $posy);
1144 $pdf->SetTextColor(0, 0, 60);
1145 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSupplier")." : ".$object->ref_supplier, '', 'R');
1146 $posy += 1;
1147 }
1148
1149 $pdf->SetFont('', '', $default_font_size - 1);
1150
1151 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1152 $object->fetchProject();
1153 if (!empty($object->project->ref)) {
1154 $posy += 3;
1155 $pdf->SetXY($posx, $posy);
1156 $pdf->SetTextColor(0, 0, 60);
1157 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1158 }
1159 }
1160
1161 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1162 $object->fetchProject();
1163 if (!empty($object->project->ref)) {
1164 $outputlangs->load("projects");
1165 $posy += 4;
1166 $pdf->SetXY($posx, $posy);
1167 $langs->load("projects");
1168 $pdf->SetTextColor(0, 0, 60);
1169 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1170 }
1171 }
1172
1173 if ($object->date) {
1174 $posy += 4;
1175 $pdf->SetXY($posx, $posy);
1176 $pdf->SetTextColor(0, 0, 60);
1177 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1178 } else {
1179 $posy += 4;
1180 $pdf->SetXY($posx, $posy);
1181 $pdf->SetTextColor(255, 0, 0);
1182 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1183 }
1184
1185 if ($object->thirdparty->code_fournisseur) {
1186 $posy += 4;
1187 $pdf->SetXY($posx, $posy);
1188 $pdf->SetTextColor(0, 0, 60);
1189 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_fournisseur), '', 'R');
1190 }
1191
1192 $posy += 1;
1193 $pdf->SetTextColor(0, 0, 60);
1194
1195 $top_shift = 0;
1196 // Show list of linked objects
1197 $current_y = $pdf->getY();
1198 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1199 if ($current_y < $pdf->getY()) {
1200 $top_shift = $pdf->getY() - $current_y;
1201 }
1202
1203 if ($showaddress) {
1204 // Sender properties
1205 $carac_emetteur = '';
1206 // Add internal contact of object if defined
1207 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1208 if (count($arrayidcontact) > 0) {
1209 $object->fetch_user($arrayidcontact[0]);
1210 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1211 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1212 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1213 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1214 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1215 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1216 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1217 $carac_emetteur .= "\n";
1218 }
1219
1220 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1221
1222 // Show sender
1223 $posy = 42 + $top_shift;
1224 $posx = $this->marge_gauche;
1225 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1226 $posx = $this->page_largeur - $this->marge_droite - 80;
1227 }
1228 $hautcadre = 40;
1229
1230 // Show sender frame
1231 $pdf->SetTextColor(0, 0, 0);
1232 $pdf->SetFont('', '', $default_font_size - 2);
1233 $pdf->SetXY($posx, $posy - 5);
1234 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1235 $pdf->SetXY($posx, $posy);
1236 $pdf->SetFillColor(230, 230, 230);
1237 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
1238 $pdf->SetTextColor(0, 0, 60);
1239
1240 // Show sender name
1241 $pdf->SetXY($posx + 2, $posy + 3);
1242 $pdf->SetFont('', 'B', $default_font_size);
1243 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1244 $posy = $pdf->getY();
1245
1246 // Show sender information
1247 $pdf->SetXY($posx + 2, $posy);
1248 $pdf->SetFont('', '', $default_font_size - 1);
1249 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1250
1251
1252
1253 // If BILLING contact defined on invoice, we use it
1254 $usecontact = false;
1255 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
1256 if (count($arrayidcontact) > 0) {
1257 $usecontact = true;
1258 $result = $object->fetch_contact($arrayidcontact[0]);
1259 }
1260
1261 // Recipient name
1262 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1263 $thirdparty = $object->contact;
1264 } else {
1265 $thirdparty = $mysoc;
1266 }
1267
1268 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1269
1270 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact : null), ($usecontact ? 1 : 0), 'target', $object);
1271
1272 // Show recipient
1273 $widthrecbox = 100;
1274 if ($this->page_largeur < 210) {
1275 $widthrecbox = 84; // To work with US executive format
1276 }
1277 $posy = 42 + $top_shift;
1278 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1279 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1280 $posx = $this->marge_gauche;
1281 }
1282
1283 // Show recipient frame
1284 $pdf->SetTextColor(0, 0, 0);
1285 $pdf->SetFont('', '', $default_font_size - 2);
1286 $pdf->SetXY($posx + 2, $posy - 5);
1287 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1288 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1289
1290 // Show recipient name
1291 $pdf->SetXY($posx + 2, $posy + 3);
1292 $pdf->SetFont('', 'B', $default_font_size);
1293 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1294
1295 $posy = $pdf->getY();
1296
1297 // Show recipient information
1298 $pdf->SetFont('', '', $default_font_size - 1);
1299 $pdf->SetXY($posx + 2, $posy);
1300 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1301 }
1302
1303 return $top_shift;
1304 }
1305
1306 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1316 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1317 {
1318 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1319 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1320 }
1321}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage hooks.
Parent class for supplier invoices models.
Class to generate the supplier invoices PDF with the template canelle.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
write_file($object, $outputlangs=null, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
__construct($db)
Constructor.
global $mysoc
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(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2861
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1808
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:294
pdf_writelinedesc($pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1846
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2464
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2402
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:1421
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:273
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:438
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2709
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2752
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2549
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:1135
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:393
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133