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