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