dolibarr 22.0.5
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])) {
259 $logodir = $conf->mycompany->multidir_output[$object->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 if ($reshook < 0) {
594 $this->error = $hookmanager->error;
595 $this->errors = $hookmanager->errors;
596 }
597
598 dolChmod($file);
599
600 $this->result = array('fullpath' => $file);
601
602 return 1; // No error
603 } else {
604 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
605 return 0;
606 }
607 } else {
608 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
609 return 0;
610 }
611 }
612
613 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
614 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
625 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
626 {
627 // phpcs:enable
628 global $conf, $mysoc, $hookmanager;
629
630 $sign = 1;
631 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
632 $sign = -1;
633 }
634
635 $default_font_size = pdf_getPDFFontSize($outputlangs);
636
637 $tab2_top = $posy;
638 $tab2_hl = 4;
639 $pdf->SetFont('', '', $default_font_size - 1);
640
641 // Total table
642 $col1x = 120;
643 $col2x = 170;
644 if ($this->page_largeur < 210) { // To work with US executive format
645 $col2x -= 20;
646 }
647 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
648
649 $useborder = 0;
650 $index = 0;
651
652 // Total HT
653 $pdf->SetFillColor(255, 255, 255);
654 $pdf->SetXY($col1x, $tab2_top);
655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', true);
656
657 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
658 $pdf->SetXY($col2x, $tab2_top);
659 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', true);
660
661 // Show VAT by rates and total
662 $pdf->SetFillColor(248, 248, 248);
663
664 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
665
666 $this->atleastoneratenotnull = 0;
667 foreach ($this->tva as $tvakey => $tvaval) {
668 if ($tvakey > 0) { // We do not display rate 0
669 $this->atleastoneratenotnull++;
670
671 $index++;
672 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
673
674 $tvacompl = '';
675
676 if (preg_match('/\*/', $tvakey)) {
677 $tvakey = str_replace('*', '', $tvakey);
678 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
679 }
680
681 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
682 $totalvat .= vatrate($tvakey, true).$tvacompl;
683 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
684
685 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
686 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', true);
687 }
688 }
689 if (!$this->atleastoneratenotnull) { // If no vat at all
690 $index++;
691 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
692 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', true);
693 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
694 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', true);
695
696 // Total LocalTax1
697 if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on' && $object->total_localtax1 > 0) {
698 $index++;
699 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
700 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', true);
701 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
702 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', true);
703 }
704
705 // Total LocalTax2
706 if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on' && $object->total_localtax2 > 0) {
707 $index++;
708 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
709 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', true);
710 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
711 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', true);
712 }
713 } else {
714 //if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on')
715 //{
716 //Local tax 1
717 foreach ($this->localtax1 as $tvakey => $tvaval) {
718 if ($tvakey != 0) { // On affiche pas taux 0
719 //$this->atleastoneratenotnull++;
720
721 $index++;
722 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
723
724 $tvacompl = '';
725 if (preg_match('/\*/', (string) $tvakey)) {
726 $tvakey = str_replace('*', '', (string) $tvakey);
727 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
728 }
729 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
730 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
731 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
732
733 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
734 $pdf->MultiCell($largcol2, $tab2_hl, price((string) $tvaval, 0, $outputlangs), 0, 'R', true);
735 }
736 }
737 //}
738
739 //if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on')
740 //{
741 //Local tax 2
742 foreach ($this->localtax2 as $tvakey => $tvaval) {
743 if ($tvakey != 0) { // On affiche pas taux 0
744 //$this->atleastoneratenotnull++;
745
746 $index++;
747 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
748
749 $tvacompl = '';
750 if (preg_match('/\*/', (string) $tvakey)) {
751 $tvakey = str_replace('*', '', (string) $tvakey);
752 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
753 }
754 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
755 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
756 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
757
758 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
759 $pdf->MultiCell($largcol2, $tab2_hl, price((string) $tvaval, 0, $outputlangs), 0, 'R', true);
760 }
761 }
762 //}
763 }
764
765 // Total TTC
766 $index++;
767 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
768 $pdf->SetTextColor(0, 0, 60);
769 $pdf->SetFillColor(224, 224, 224);
770 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', true);
771
772 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
773 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', true);
774
775 $pdf->SetTextColor(0, 0, 0);
776 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
777 $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
778 //print "x".$creditnoteamount."-".$depositsamount;exit;
779 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
780 if (!empty($object->paid)) {
781 $resteapayer = 0;
782 }
783
784 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) {
785 // Already paid + Deposits
786 $index++;
787 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
788 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', false);
789 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
790 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
791
792 // Credit note
793 if ($creditnoteamount) {
794 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
795 $index++;
796 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
797 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', false);
798 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
799 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', false);
800 }
801
802 // Escompte
803 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
804 $index++;
805 $pdf->SetFillColor(255, 255, 255);
806
807 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
808 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', true);
809 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
810 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', true);
811
812 $resteapayer = 0;
813 }
814
815 $index++;
816 $pdf->SetTextColor(0, 0, 60);
817 $pdf->SetFillColor(224, 224, 224);
818 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', true);
820
821 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
822 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
823 $pdf->SetFont('', '', $default_font_size - 1);
824 $pdf->SetTextColor(0, 0, 0);
825 }
826
827 $parameters = array('pdf' => &$pdf, 'object' => &$object, 'outputlangs' => $outputlangs, 'index' => &$index, 'posy' => $posy);
828
829 $reshook = $hookmanager->executeHooks('afterPDFTotalTable', $parameters, $this); // Note that $action and $object may have been modified by some hooks
830 if ($reshook < 0) {
831 $this->error = $hookmanager->error;
832 $this->errors = $hookmanager->errors;
833 }
834
835 $index++;
836 return ($tab2_top + ($tab2_hl * $index));
837 }
838
839 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
853 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
854 {
855 global $conf;
856
857 // Force to disable hidetop and hidebottom
858 $hidebottom = 0;
859 if ($hidetop) {
860 $hidetop = -1;
861 }
862
863 $currency = !empty($currency) ? $currency : $conf->currency;
864 $default_font_size = pdf_getPDFFontSize($outputlangs);
865
866 // Amount in (at tab_top - 1)
867 $pdf->SetTextColor(0, 0, 0);
868 $pdf->SetFont('', '', $default_font_size - 2);
869
870 if (empty($hidetop)) {
871 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
872 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
873 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
874
875 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
876 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
877 $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')));
878 }
879 }
880
881 $pdf->SetDrawColor(128, 128, 128);
882 $pdf->SetFont('', '', $default_font_size - 1);
883
884 // Output Rect
885 $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
886
887 if (empty($hidetop)) {
888 $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
889
890 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
891 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
892 }
893
894 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
895 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
896 if (empty($hidetop)) {
897 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
898 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
899 }
900 }
901
902 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
903 if (empty($hidetop)) {
904 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
905 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
906 }
907
908 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
909 if (empty($hidetop)) {
910 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
911 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
912 }
913
914 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
915 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
916 if (empty($hidetop)) {
917 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
918 $pdf->MultiCell(
919 $this->posxdiscount - $this->posxunit - 1,
920 2,
921 $outputlangs->transnoentities("Unit"),
922 '',
923 'C'
924 );
925 }
926 }
927
928 if ($this->atleastonediscount) {
929 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
930 if (empty($hidetop)) {
931 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
932 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
933 }
934 }
935
936 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
937 if (empty($hidetop)) {
938 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
939 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
940 }
941 }
942
943 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
944 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
955 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
956 {
957 // phpcs:enable
958 global $conf;
959
960 $sign = 1;
961 if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
962 $sign = -1;
963 }
964
965 $tab3_posx = 120;
966 $tab3_top = $posy + 8;
967 $tab3_width = 80;
968 $tab3_height = 4;
969 if ($this->page_largeur < 210) { // To work with US executive format
970 $tab3_posx -= 20;
971 }
972
973 $default_font_size = pdf_getPDFFontSize($outputlangs);
974
975 $pdf->SetFont('', '', $default_font_size - 3);
976 $pdf->SetXY($tab3_posx, $tab3_top - 4);
977 $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', false);
978
979 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
980
981 $pdf->SetFont('', '', $default_font_size - 4);
982 $pdf->SetXY($tab3_posx, $tab3_top);
983 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', false);
984 $pdf->SetXY($tab3_posx + 21, $tab3_top);
985 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', false);
986 $pdf->SetXY($tab3_posx + 40, $tab3_top);
987 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', false);
988 $pdf->SetXY($tab3_posx + 58, $tab3_top);
989 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', false);
990
991 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
992
993 $y = 0;
994
995 $pdf->SetFont('', '', $default_font_size - 4);
996
997 // Loop on each deposits and credit notes included
998 //
999
1000 // Loop on each payment
1001 $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1002 $sql .= " cp.code";
1003 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
1004 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1005 $sql .= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1006 $sql .= " ORDER BY p.datep";
1007 $resql = $this->db->query($sql);
1008 if ($resql) {
1009 $num = $this->db->num_rows($resql);
1010 $i = 0;
1011 while ($i < $num) {
1012 $y += 3;
1013 $row = $this->db->fetch_object($resql);
1014
1015 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1016 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', false);
1017 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1018 $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', false);
1019 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1020 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1021
1022 $pdf->MultiCell(20, 3, $oper, 0, 'L', false);
1023 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1024 $pdf->MultiCell(30, 3, $row->num_payment, 0, 'L', false);
1025
1026 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1027
1028 $i++;
1029 }
1030 } else {
1031 $this->error = $this->db->lasterror();
1032 return -1;
1033 }
1034 return -1;
1035 }
1036
1037 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1047 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1048 {
1049 global $langs, $conf, $mysoc;
1050
1051 // Load translation files required by the page
1052 $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1053
1054 $default_font_size = pdf_getPDFFontSize($outputlangs);
1055
1056 // Do not add the BACKGROUND as this is for suppliers
1057 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1058
1059 $pdf->SetTextColor(0, 0, 60);
1060 $pdf->SetFont('', 'B', $default_font_size + 3);
1061
1062 $w = 100;
1063
1064 $posy = $this->marge_haute;
1065 $posx = $this->page_largeur - $this->marge_droite - 100;
1066
1067 $pdf->SetXY($this->marge_gauche, $posy);
1068
1069 // Logo
1070 /*
1071 $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1072 if ($mysoc->logo)
1073 {
1074 if (is_readable($logo))
1075 {
1076 $height=pdf_getHeightForLogo($logo);
1077 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1078 }
1079 else
1080 {
1081 $pdf->SetTextColor(200,0,0);
1082 $pdf->SetFont('','B', $default_font_size - 2);
1083 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1084 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1085 }
1086 }
1087 else
1088 {*/
1089 $text = $this->emetteur->name;
1090 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1091 //}
1092
1093 $pdf->SetFont('', 'B', $default_font_size + 3);
1094 $pdf->SetXY($posx, $posy);
1095 $pdf->SetTextColor(0, 0, 60);
1096 $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1097 if ($object->type == 1) {
1098 $title = $outputlangs->transnoentities("InvoiceReplacement");
1099 }
1100 if ($object->type == 2) {
1101 $title = $outputlangs->transnoentities("InvoiceAvoir");
1102 }
1103 if ($object->type == 3) {
1104 $title = $outputlangs->transnoentities("InvoiceDeposit");
1105 }
1106 $pdf->MultiCell($w, 3, $title." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1107 $posy += 1;
1108
1109 if ($object->ref_supplier) {
1110 $posy += 4;
1111 $pdf->SetFont('', 'B', $default_font_size);
1112 $pdf->SetXY($posx, $posy);
1113 $pdf->SetTextColor(0, 0, 60);
1114 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSupplier")." : ".$object->ref_supplier, '', 'R');
1115 $posy += 1;
1116 }
1117
1118 $pdf->SetFont('', '', $default_font_size - 1);
1119
1120 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1121 $object->fetchProject();
1122 if (!empty($object->project->ref)) {
1123 $posy += 3;
1124 $pdf->SetXY($posx, $posy);
1125 $pdf->SetTextColor(0, 0, 60);
1126 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1127 }
1128 }
1129
1130 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1131 $object->fetchProject();
1132 if (!empty($object->project->ref)) {
1133 $outputlangs->load("projects");
1134 $posy += 4;
1135 $pdf->SetXY($posx, $posy);
1136 $langs->load("projects");
1137 $pdf->SetTextColor(0, 0, 60);
1138 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1139 }
1140 }
1141
1142 if ($object->date) {
1143 $posy += 4;
1144 $pdf->SetXY($posx, $posy);
1145 $pdf->SetTextColor(0, 0, 60);
1146 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1147 } else {
1148 $posy += 4;
1149 $pdf->SetXY($posx, $posy);
1150 $pdf->SetTextColor(255, 0, 0);
1151 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1152 }
1153
1154 if ($object->thirdparty->code_fournisseur) {
1155 $posy += 4;
1156 $pdf->SetXY($posx, $posy);
1157 $pdf->SetTextColor(0, 0, 60);
1158 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1159 }
1160
1161 $posy += 1;
1162 $pdf->SetTextColor(0, 0, 60);
1163
1164 $top_shift = 0;
1165 // Show list of linked objects
1166 $current_y = $pdf->getY();
1167 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1168 if ($current_y < $pdf->getY()) {
1169 $top_shift = $pdf->getY() - $current_y;
1170 }
1171
1172 if ($showaddress) {
1173 // Sender properties
1174 $carac_emetteur = '';
1175 // Add internal contact of object if defined
1176 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1177 if (count($arrayidcontact) > 0) {
1178 $object->fetch_user($arrayidcontact[0]);
1179 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1180 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1181 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1182 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1183 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1184 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1185 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1186 $carac_emetteur .= "\n";
1187 }
1188
1189 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1190
1191 // Show sender
1192 $posy = 42 + $top_shift;
1193 $posx = $this->marge_gauche;
1194 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1195 $posx = $this->page_largeur - $this->marge_droite - 80;
1196 }
1197 $hautcadre = 40;
1198
1199 // Show sender frame
1200 $pdf->SetTextColor(0, 0, 0);
1201 $pdf->SetFont('', '', $default_font_size - 2);
1202 $pdf->SetXY($posx, $posy - 5);
1203 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1204 $pdf->SetXY($posx, $posy);
1205 $pdf->SetFillColor(230, 230, 230);
1206 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
1207 $pdf->SetTextColor(0, 0, 60);
1208
1209 // Show sender name
1210 $pdf->SetXY($posx + 2, $posy + 3);
1211 $pdf->SetFont('', 'B', $default_font_size);
1212 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1213 $posy = $pdf->getY();
1214
1215 // Show sender information
1216 $pdf->SetXY($posx + 2, $posy);
1217 $pdf->SetFont('', '', $default_font_size - 1);
1218 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1219
1220
1221
1222 // If BILLING contact defined on invoice, we use it
1223 $usecontact = false;
1224 $arrayidcontact = $object->getIdContact('internal', 'BILLING');
1225 if (count($arrayidcontact) > 0) {
1226 $usecontact = true;
1227 $result = $object->fetch_contact($arrayidcontact[0]);
1228 }
1229
1230 // Recipient name
1231 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1232 $thirdparty = $object->contact;
1233 } else {
1234 $thirdparty = $mysoc;
1235 }
1236
1237 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1238
1239 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact : null), ($usecontact ? 1 : 0), 'target', $object);
1240
1241 // Show recipient
1242 $widthrecbox = 100;
1243 if ($this->page_largeur < 210) {
1244 $widthrecbox = 84; // To work with US executive format
1245 }
1246 $posy = 42 + $top_shift;
1247 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1248 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1249 $posx = $this->marge_gauche;
1250 }
1251
1252 // Show recipient frame
1253 $pdf->SetTextColor(0, 0, 0);
1254 $pdf->SetFont('', '', $default_font_size - 2);
1255 $pdf->SetXY($posx + 2, $posy - 5);
1256 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1257 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1258
1259 // Show recipient name
1260 $pdf->SetXY($posx + 2, $posy + 3);
1261 $pdf->SetFont('', 'B', $default_font_size);
1262 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1263
1264 $posy = $pdf->getY();
1265
1266 // Show recipient information
1267 $pdf->SetFont('', '', $default_font_size - 1);
1268 $pdf->SetXY($posx + 2, $posy);
1269 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1270 }
1271
1272 return $top_shift;
1273 }
1274
1275 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1285 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1286 {
1287 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1288 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1289 }
1290}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
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 '.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:1463
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2462
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:1047
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2080
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2018
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1425
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:439
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2325
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2368
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2165
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:778
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:391
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161