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