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