dolibarr 23.0.3
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->getFullName($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
366 // Loop on each lines
367 for ($i = 0; $i < $nblines; $i++) {
368 $curY = $nexY;
369 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
370 $pdf->SetTextColor(0, 0, 0);
371
372 // Define size of image if we need it
373 //$imglinesize = array();
374 //if (!empty($realpatharray[$i])) {
375 // $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
376 //}
377
378 $pdf->setTopMargin($tab_top_newpage);
379 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
380 $pageposbefore = $pdf->getPage();
381
382 $showpricebeforepagebreak = 1;
383 $posYAfterImage = 0;
384
385 // Description of product line
386 $curX = $this->posxdesc - 1;
387
388 $pdf->startTransaction();
389 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
390 $pageposafter = $pdf->getPage();
391 if ($pageposafter > $pageposbefore) { // There is a pagebreak
392 $pdf->rollbackTransaction(true);
393 $pageposafter = $pageposbefore;
394 //print $pageposafter.'-'.$pageposbefore;exit;
395 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
396 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
397 $posyafter = $pdf->GetY();
398 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
399 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
400 $pdf->AddPage('', '', true);
401 if (!empty($tplidx)) {
402 $pdf->useTemplate($tplidx);
403 }
404 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
405 $this->_pagehead($pdf, $object, 0, $outputlangs);
406 }
407 $pdf->setPage($pageposafter + 1);
408 }
409 } else {
410 // We found a page break
411 // Allows data in the first page if description is long enough to break in multiples pages
412 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
413 $showpricebeforepagebreak = 1;
414 } else {
415 $showpricebeforepagebreak = 0;
416 }
417 }
418 } else { // No pagebreak
419 $pdf->commitTransaction();
420 }
421 $posYAfterDescription = $pdf->GetY();
422
423 $nexY = $pdf->GetY();
424 $pageposafter = $pdf->getPage();
425 $pdf->setPage($pageposbefore);
426 $pdf->setTopMargin($this->marge_haute);
427 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
428
429 // We suppose that a too long description or photo were moved completely on next page
430 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
431 $pdf->setPage($pageposafter);
432 $curY = $tab_top_newpage;
433 }
434
435 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
436
437 // VAT Rate
438 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
439 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
440 $pdf->SetXY($this->posxtva, $curY);
441 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
442 }
443
444 // Unit price before discount
445 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
446 $pdf->SetXY($this->posxup, $curY);
447 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', false);
448
449 // Quantity
450 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
451 $pdf->SetXY($this->posxqty, $curY);
452 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
453
454 // Unit
455 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
456 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
457 $pdf->SetXY($this->posxunit, $curY);
458 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
459 }
460
461 // Discount on line
462 if ($object->lines[$i]->remise_percent) {
463 $pdf->SetXY($this->posxdiscount - 2, $curY);
464 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
465 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0, 'R');
466 }
467
468 // Total HT line
469 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
470 $pdf->SetXY($this->postotalht, $curY);
471 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', false);
472
473 // Collection of totals by VAT value in $this->tva["taux"]=total_tva
474 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
475 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
476 } else {
477 $tvaligne = $object->lines[$i]->total_tva;
478 }
479
480 $localtax1ligne = $object->lines[$i]->total_localtax1;
481 $localtax2ligne = $object->lines[$i]->total_localtax2;
482
483 // TODO remise_percent is an obsolete field for object parent
484 /*if (!empty($object->remise_percent)) {
485 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
486 }*/
487
488 $vatrate = (string) $object->lines[$i]->tva_tx;
489 $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
490 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
491
492 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
493 $vatrate .= '*';
494 }
495 if (empty($this->tva[$vatrate])) {
496 $this->tva[$vatrate] = 0;
497 }
498 if (empty($this->localtax1[$localtax1rate])) {
499 $this->localtax1[$localtax1rate] = 0;
500 }
501 if (empty($this->localtax2[$localtax2rate])) {
502 $this->localtax2[$localtax2rate] = 0;
503 }
504 $this->tva[$vatrate] += $tvaligne;
505 $this->localtax1[$localtax1rate] += $localtax1ligne;
506 $this->localtax2[$localtax2rate] += $localtax2ligne;
507
508 if ($posYAfterImage > $posYAfterDescription) {
509 $nexY = $posYAfterImage;
510 }
511
512 // Add line
513 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
514 $pdf->setPage($pageposafter);
515 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
516 //$pdf->SetDrawColor(190,190,200);
517 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
518 $pdf->SetLineStyle(array('dash' => 0));
519 }
520
521 $nexY += 2; // Add space between lines
522
523 // Detect if some page were added automatically and output _tableau for past pages
524 while ($pagenb < $pageposafter) {
525 $pdf->setPage($pagenb);
526 if ($pagenb == 1) {
527 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
528 } else {
529 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
530 }
531 $this->_pagefoot($pdf, $object, $outputlangs, 1);
532 $pagenb++;
533 $pdf->setPage($pagenb);
534 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
535 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
536 $this->_pagehead($pdf, $object, 0, $outputlangs);
537 }
538 }
539 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty // @phan-suppress-current-line PhanUndeclaredProperty
540 if ($pagenb == 1) {
541 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
542 } else {
543 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
544 }
545 $this->_pagefoot($pdf, $object, $outputlangs, 1);
546 // New page
547 $pdf->AddPage();
548 if (!empty($tplidx)) {
549 $pdf->useTemplate($tplidx);
550 }
551 $pagenb++;
552 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
553 $this->_pagehead($pdf, $object, 0, $outputlangs);
554 }
555 }
556 }
557
558 // Show square
559 if ($pagenb == 1) {
560 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
561 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
562 } else {
563 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
564 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
565 }
566
567 // Display total area
568 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
569
570 $amount_credit_notes_included = 0;
571 $amount_deposits_included = 0;
572
573 // Display Payments area
574 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
575 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
576 }
577
578 // Pagefoot
579 $this->_pagefoot($pdf, $object, $outputlangs);
580 if (method_exists($pdf, 'AliasNbPages')) {
581 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
582 }
583
584 $pdf->Close();
585
586 $pdf->Output($file, 'F');
587
588 // Add pdfgeneration hook
589 $hookmanager->initHooks(array('pdfgeneration'));
590 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
591 global $action;
592 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
593 $this->warnings = $hookmanager->warnings;
594 if ($reshook < 0) {
595 $this->error = $hookmanager->error;
596 $this->errors = $hookmanager->errors;
597 dolChmod($file);
598 return -1;
599 }
600
601 dolChmod($file);
602
603 $this->result = array('fullpath' => $file);
604
605 return 1; // No error
606 } else {
607 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
608 return 0;
609 }
610 } else {
611 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
612 return 0;
613 }
614 }
615
616 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
617 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
628 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
629 {
630 // phpcs:enable
631 global $conf, $mysoc, $hookmanager;
632
633 $sign = 1;
634 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
635 $sign = -1;
636 }
637
638 $default_font_size = pdf_getPDFFontSize($outputlangs);
639
640 $tab2_top = $posy;
641 $tab2_hl = 4;
642 $pdf->SetFont('', '', $default_font_size - 1);
643
644 // Total table
645 $col1x = 120;
646 $col2x = 170;
647 if ($this->page_largeur < 210) { // To work with US executive format
648 $col2x -= 20;
649 }
650 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
651
652 $useborder = 0;
653 $index = 0;
654
655 // Total HT
656 $pdf->SetFillColor(255, 255, 255);
657 $pdf->SetXY($col1x, $tab2_top);
658 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', true);
659
660 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
661 $pdf->SetXY($col2x, $tab2_top);
662 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', true);
663
664 // Show VAT by rates and total
665 $pdf->SetFillColor(248, 248, 248);
666
667 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
668
669 $this->atleastoneratenotnull = 0;
670 foreach ($this->tva as $tvakey => $tvaval) {
671 if ($tvakey > 0) { // We do not display rate 0
672 $this->atleastoneratenotnull++;
673
674 $index++;
675 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
676
677 $tvacompl = '';
678
679 if (preg_match('/\*/', $tvakey)) {
680 $tvakey = str_replace('*', '', $tvakey);
681 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
682 }
683
684 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
685 $totalvat .= vatrate($tvakey, true).$tvacompl;
686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
687
688 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
689 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', true);
690 }
691 }
692 if (!$this->atleastoneratenotnull) { // If no vat at all
693 $index++;
694 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
695 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', true);
696 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
697 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', true);
698
699 // Total LocalTax1
700 if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on' && $object->total_localtax1 > 0) {
701 $index++;
702 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
703 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', true);
704 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
705 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', true);
706 }
707
708 // Total LocalTax2
709 if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on' && $object->total_localtax2 > 0) {
710 $index++;
711 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
712 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', true);
713 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
714 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', true);
715 }
716 } else {
717 //if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on')
718 //{
719 //Local tax 1
720 foreach ($this->localtax1 as $tvakey => $tvaval) {
721 if ($tvakey != 0) { // On affiche pas taux 0
722 //$this->atleastoneratenotnull++;
723
724 $index++;
725 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
726
727 $tvacompl = '';
728 if (preg_match('/\*/', (string) $tvakey)) {
729 $tvakey = str_replace('*', '', (string) $tvakey);
730 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
731 }
732 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
733 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
734 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
735
736 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
737 $pdf->MultiCell($largcol2, $tab2_hl, price((string) $tvaval, 0, $outputlangs), 0, 'R', true);
738 }
739 }
740 //}
741
742 //if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on')
743 //{
744 //Local tax 2
745 foreach ($this->localtax2 as $tvakey => $tvaval) {
746 if ($tvakey != 0) { // On affiche pas taux 0
747 //$this->atleastoneratenotnull++;
748
749 $index++;
750 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
751
752 $tvacompl = '';
753 if (preg_match('/\*/', (string) $tvakey)) {
754 $tvakey = str_replace('*', '', (string) $tvakey);
755 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
756 }
757 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
758 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
759 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
760
761 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
762 $pdf->MultiCell($largcol2, $tab2_hl, price((string) $tvaval, 0, $outputlangs), 0, 'R', true);
763 }
764 }
765 //}
766 }
767
768 // Total TTC
769 $index++;
770 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
771 $pdf->SetTextColor(0, 0, 60);
772 $pdf->SetFillColor(224, 224, 224);
773 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', true);
774
775 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
776 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
777
778 $pdf->SetTextColor(0, 0, 0);
779 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
780 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
781 //print "x".$creditnoteamount."-".$depositsamount;exit;
782 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
783 if (!empty($object->paid)) {
784 $resteapayer = 0;
785 }
786
787 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
788 // Already paid + Deposits
789 $index++;
790 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
791 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', false);
792 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
793 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
794
795 // Credit note
796 if ($creditnoteamount) {
797 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
798 $index++;
799 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
800 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', false);
801 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
802 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', false);
803 }
804
805 // Escompte
806 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
807 $index++;
808 $pdf->SetFillColor(255, 255, 255);
809
810 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
811 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', true);
812 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
813 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', true);
814
815 $resteapayer = 0;
816 }
817
818 $index++;
819 $pdf->SetTextColor(0, 0, 60);
820 $pdf->SetFillColor(224, 224, 224);
821 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
822 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', true);
823
824 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
825 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
826 $pdf->SetFont('', '', $default_font_size - 1);
827 $pdf->SetTextColor(0, 0, 0);
828 }
829
830 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
831
832 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
833 if ($reshook < 0) {
834 $this->error = $hookmanager->error;
835 $this->errors = $hookmanager->errors;
836 }
837
838 $index++;
839 return ($tab2_top + ($tab2_hl * $index));
840 }
841
842 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
856 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
857 {
858 global $conf;
859
860 // Force to disable hidetop and hidebottom
861 $hidebottom = 0;
862 if ($hidetop) {
863 $hidetop = -1;
864 }
865
866 $currency = !empty($currency) ? $currency : $conf->currency;
867 $default_font_size = pdf_getPDFFontSize($outputlangs);
868
869 // Amount in (at tab_top - 1)
870 $pdf->SetTextColor(0, 0, 0);
871 $pdf->SetFont('', '', $default_font_size - 2);
872
873 if (empty($hidetop)) {
874 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
875 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
876 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
877
878 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
879 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
880 $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')));
881 }
882 }
883
884 $pdf->SetDrawColor(128, 128, 128);
885 $pdf->SetFont('', '', $default_font_size - 1);
886
887 // Output Rect
888 $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
889
890 if (empty($hidetop)) {
891 $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
892
893 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
894 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
895 }
896
897 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
898 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
899 if (empty($hidetop)) {
900 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
901 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
902 }
903 }
904
905 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
906 if (empty($hidetop)) {
907 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
908 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
909 }
910
911 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
912 if (empty($hidetop)) {
913 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
914 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
915 }
916
917 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
918 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
919 if (empty($hidetop)) {
920 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
921 $pdf->MultiCell(
922 $this->posxdiscount - $this->posxunit - 1,
923 2,
924 $outputlangs->transnoentities("Unit"),
925 '',
926 'C'
927 );
928 }
929 }
930
931 if ($this->atleastonediscount) {
932 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
933 if (empty($hidetop)) {
934 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
935 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
936 }
937 }
938
939 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
940 if (empty($hidetop)) {
941 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
942 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
943 }
944 }
945
946 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
947 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
958 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
959 {
960 // phpcs:enable
961 global $conf;
962
963 $sign = 1;
964 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
965 $sign = -1;
966 }
967
968 $tab3_posx = 120;
969 $tab3_top = $posy + 8;
970 $tab3_width = 80;
971 $tab3_height = 4;
972 if ($this->page_largeur < 210) { // To work with US executive format
973 $tab3_posx -= 20;
974 }
975
976 $default_font_size = pdf_getPDFFontSize($outputlangs);
977
978 $pdf->SetFont('', '', $default_font_size - 3);
979 $pdf->SetXY($tab3_posx, $tab3_top - 4);
980 $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', false);
981
982 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
983
984 $pdf->SetFont('', '', $default_font_size - 4);
985 $pdf->SetXY($tab3_posx, $tab3_top);
986 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
987 $pdf->SetXY($tab3_posx + 21, $tab3_top);
988 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
989 $pdf->SetXY($tab3_posx + 40, $tab3_top);
990 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
991 $pdf->SetXY($tab3_posx + 58, $tab3_top);
992 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
993
994 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
995
996 $y = 0;
997
998 $pdf->SetFont('', '', $default_font_size - 4);
999
1000 // Loop on each deposits and credit notes included
1001 //
1002
1003 // Loop on each payment
1004 $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1005 $sql .= " cp.code";
1006 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
1007 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1008 $sql .= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1009 $sql .= " ORDER BY p.datep";
1010 $resql = $this->db->query($sql);
1011 if ($resql) {
1012 $num = $this->db->num_rows($resql);
1013 $i = 0;
1014 while ($i < $num) {
1015 $y += 3;
1016 $row = $this->db->fetch_object($resql);
1017
1018 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1019 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1020 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1021 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', false);
1022 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1023 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1024
1025 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1026 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1027 $pdf->MultiCell(30, 3, $row->num_payment, 0, 'L', false);
1028
1029 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1030
1031 $i++;
1032 }
1033 } else {
1034 $this->error = $this->db->lasterror();
1035 return -1;
1036 }
1037 return -1;
1038 }
1039
1040 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1050 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1051 {
1052 global $langs, $conf, $mysoc;
1053
1054 // Load translation files required by the page
1055 $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1056
1057 $default_font_size = pdf_getPDFFontSize($outputlangs);
1058
1059 // Do not add the BACKGROUND as this is for suppliers
1060 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1061
1062 $pdf->SetTextColor(0, 0, 60);
1063 $pdf->SetFont('', 'B', $default_font_size + 3);
1064
1065 $w = 100;
1066
1067 $posy = $this->marge_haute;
1068 $posx = $this->page_largeur - $this->marge_droite - 100;
1069
1070 $pdf->SetXY($this->marge_gauche, $posy);
1071
1072 // Logo
1073 /*
1074 $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1075 if ($mysoc->logo)
1076 {
1077 if (is_readable($logo))
1078 {
1079 $height=pdf_getHeightForLogo($logo);
1080 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1081 }
1082 else
1083 {
1084 $pdf->SetTextColor(200,0,0);
1085 $pdf->SetFont('','B', $default_font_size - 2);
1086 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1087 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1088 }
1089 }
1090 else
1091 {*/
1092 $text = $this->emetteur->name;
1093 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1094 //}
1095
1096 $pdf->SetFont('', 'B', $default_font_size + 3);
1097 $pdf->SetXY($posx, $posy);
1098 $pdf->SetTextColor(0, 0, 60);
1099 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1100 if ($object->type == 1) {
1101 $title = $outputlangs->transnoentities("InvoiceReplacement");
1102 }
1103 if ($object->type == 2) {
1104 $title = $outputlangs->transnoentities("InvoiceAvoir");
1105 }
1106 if ($object->type == 3) {
1107 $title = $outputlangs->transnoentities("InvoiceDeposit");
1108 }
1109 $pdf->MultiCell($w, 3, $title." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1110 $posy += 1;
1111
1112 if ($object->ref_supplier) {
1113 $posy += 4;
1114 $pdf->SetFont('', 'B', $default_font_size);
1115 $pdf->SetXY($posx, $posy);
1116 $pdf->SetTextColor(0, 0, 60);
1117 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSupplier")." : ".$object->ref_supplier, '', 'R');
1118 $posy += 1;
1119 }
1120
1121 $pdf->SetFont('', '', $default_font_size - 1);
1122
1123 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1124 $object->fetchProject();
1125 if (!empty($object->project->ref)) {
1126 $posy += 3;
1127 $pdf->SetXY($posx, $posy);
1128 $pdf->SetTextColor(0, 0, 60);
1129 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1130 }
1131 }
1132
1133 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1134 $object->fetchProject();
1135 if (!empty($object->project->ref)) {
1136 $outputlangs->load("projects");
1137 $posy += 4;
1138 $pdf->SetXY($posx, $posy);
1139 $langs->load("projects");
1140 $pdf->SetTextColor(0, 0, 60);
1141 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1142 }
1143 }
1144
1145 if ($object->date) {
1146 $posy += 4;
1147 $pdf->SetXY($posx, $posy);
1148 $pdf->SetTextColor(0, 0, 60);
1149 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1150 } else {
1151 $posy += 4;
1152 $pdf->SetXY($posx, $posy);
1153 $pdf->SetTextColor(255, 0, 0);
1154 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1155 }
1156
1157 if ($object->thirdparty->code_fournisseur) {
1158 $posy += 4;
1159 $pdf->SetXY($posx, $posy);
1160 $pdf->SetTextColor(0, 0, 60);
1161 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1162 }
1163
1164 $posy += 1;
1165 $pdf->SetTextColor(0, 0, 60);
1166
1167 $top_shift = 0;
1168 // Show list of linked objects
1169 $current_y = $pdf->getY();
1170 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1171 if ($current_y < $pdf->getY()) {
1172 $top_shift = $pdf->getY() - $current_y;
1173 }
1174
1175 if ($showaddress) {
1176 // Sender properties
1177 $carac_emetteur = '';
1178 // Add internal contact of object if defined
1179 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1180 if (count($arrayidcontact) > 0) {
1181 $object->fetch_user($arrayidcontact[0]);
1182 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1183 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1184 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1185 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1186 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1187 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1188 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1189 $carac_emetteur .= "\n";
1190 }
1191
1192 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1193
1194 // Show sender
1195 $posy = 42 + $top_shift;
1196 $posx = $this->marge_gauche;
1197 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1198 $posx = $this->page_largeur - $this->marge_droite - 80;
1199 }
1200 $hautcadre = 40;
1201
1202 // Show sender frame
1203 $pdf->SetTextColor(0, 0, 0);
1204 $pdf->SetFont('', '', $default_font_size - 2);
1205 $pdf->SetXY($posx, $posy - 5);
1206 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1207 $pdf->SetXY($posx, $posy);
1208 $pdf->SetFillColor(230, 230, 230);
1209 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
1210 $pdf->SetTextColor(0, 0, 60);
1211
1212 // Show sender name
1213 $pdf->SetXY($posx + 2, $posy + 3);
1214 $pdf->SetFont('', 'B', $default_font_size);
1215 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1216 $posy = $pdf->getY();
1217
1218 // Show sender information
1219 $pdf->SetXY($posx + 2, $posy);
1220 $pdf->SetFont('', '', $default_font_size - 1);
1221 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1222
1223
1224
1225 // If BILLING contact defined on invoice, we use it
1226 $usecontact = false;
1227 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
1228 if (count($arrayidcontact) > 0) {
1229 $usecontact = true;
1230 $result = $object->fetch_contact($arrayidcontact[0]);
1231 }
1232
1233 // Recipient name
1234 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1235 $thirdparty = $object->contact;
1236 } else {
1237 $thirdparty = $mysoc;
1238 }
1239
1240 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1241
1242 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact : null), ($usecontact ? 1 : 0), 'target', $object);
1243
1244 // Show recipient
1245 $widthrecbox = 100;
1246 if ($this->page_largeur < 210) {
1247 $widthrecbox = 84; // To work with US executive format
1248 }
1249 $posy = 42 + $top_shift;
1250 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1251 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1252 $posx = $this->marge_gauche;
1253 }
1254
1255 // Show recipient frame
1256 $pdf->SetTextColor(0, 0, 0);
1257 $pdf->SetFont('', '', $default_font_size - 2);
1258 $pdf->SetXY($posx + 2, $posy - 5);
1259 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1260 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1261
1262 // Show recipient name
1263 $pdf->SetXY($posx + 2, $posy + 3);
1264 $pdf->SetFont('', 'B', $default_font_size);
1265 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1266
1267 $posy = $pdf->getY();
1268
1269 // Show recipient information
1270 $pdf->SetFont('', '', $default_font_size - 1);
1271 $pdf->SetXY($posx + 2, $posy);
1272 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1273 }
1274
1275 return $top_shift;
1276 }
1277
1278 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1288 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1289 {
1290 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1291 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1292 }
1293}
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(!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)
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:1535
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2550
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
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:1110
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2153
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2091
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1497
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:268
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:433
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2398
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2441
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2238
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:824
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:388
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:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128