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