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