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