dolibarr 18.0.6
pdf_standard.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@products.sourceforge.net>
3 * Copyright (C) 2023 Anthony Berton <anthony.berton@bb2a.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
26require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
27require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
28require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33
34
39{
43 public $db;
44
48 public $name;
49
53 public $description;
54
58 public $type;
59
64 public $version = 'dolibarr';
65
70 public $emetteur;
71
72
78 public function __construct($db)
79 {
80 global $conf, $langs, $mysoc;
81
82 // Load traductions files required by page
83 $langs->loadLangs(array("main", "companies"));
84
85 $this->db = $db;
86 $this->name = "standard";
87 $this->description = $langs->trans("DocumentModelStandardPDF");
88
89 // Page size for A4 format
90 $this->type = 'pdf';
91 $formatarray = pdf_getFormat();
92 $this->page_largeur = $formatarray['width'];
93 $this->page_hauteur = $formatarray['height'];
94 $this->format = array($this->page_largeur, $this->page_hauteur);
95 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
96 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
97 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
98 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
99
100 $this->option_logo = 1; // Display logo
101 $this->option_multilang = 1; // Available in several languages
102 $this->option_freetext = 0; // Support add of a personalised text
103
104 // Get source company
105 $this->emetteur = $mysoc;
106 if (!$this->emetteur->country_code) {
107 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
108 }
109 }
110
111
112 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
124 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
125 {
126 // phpcs:enable
127 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
128
129 if (!is_object($outputlangs)) {
130 $outputlangs = $langs;
131 }
132 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
133 if (!empty($conf->global->MAIN_USE_FPDF)) {
134 $outputlangs->charset_output = 'ISO-8859-1';
135 }
136
137 // Load traductions files required by page
138 $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
139
140 if (is_array($object->lines)) {
141 $nblines = count($object->lines);
142 } else {
143 $nblines = 0;
144 }
145
146 if ($conf->product->dir_output) {
147 // Definition of $dir and $file
148 if ($object->specimen) {
149 $dir = $conf->product->dir_output;
150 $file = $dir."/SPECIMEN.pdf";
151 } else {
152 $objectref = dol_sanitizeFileName($object->ref);
153 $dir = $conf->product->dir_output."/".$objectref;
154 $file = $dir."/".$objectref.".pdf";
155 }
156
157 $productFournisseur = new ProductFournisseur($this->db);
158 $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
159 $object->supplierprices = $supplierprices;
160
161 if (!file_exists($dir)) {
162 if (dol_mkdir($dir) < 0) {
163 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
164 return -1;
165 }
166 }
167
168 if (file_exists($dir)) {
169 // Add pdfgeneration hook
170 if (!is_object($hookmanager)) {
171 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
172 $hookmanager = new HookManager($this->db);
173 }
174 $hookmanager->initHooks(array('pdfgeneration'));
175 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
176 global $action;
177 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
178
179 // Create pdf instance
180 $pdf = pdf_getInstance($this->format);
181 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
182 $pdf->SetAutoPageBreak(1, 0);
183
184 $heightforinfotot = 40; // Height reserved to output the info and total part
185 $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
186 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
187 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
188 $heightforfooter += 6;
189 }
190
191 if (class_exists('TCPDF')) {
192 $pdf->setPrintHeader(false);
193 $pdf->setPrintFooter(false);
194 }
195 $pdf->SetFont(pdf_getPDFFont($outputlangs));
196 // Set path to the background PDF File
197 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
198 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
199 $tplidx = $pdf->importPage(1);
200 }
201
202 $pdf->Open();
203 $pagenb = 0;
204 $pdf->SetDrawColor(128, 128, 128);
205
206 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
207 $pdf->SetSubject($outputlangs->transnoentities("Product"));
208 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
209 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
210 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Product"));
211 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
212 $pdf->SetCompression(false);
213 }
214
215 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
216
217
218 // New page
219 $pdf->AddPage();
220 if (!empty($tplidx)) {
221 $pdf->useTemplate($tplidx);
222 }
223 $pagenb++;
224 $this->_pagehead($pdf, $object, 1, $outputlangs);
225 $pdf->SetFont('', '', $default_font_size - 1);
226 $pdf->MultiCell(0, 3, ''); // Set interline to 3
227 $pdf->SetTextColor(0, 0, 0);
228
229
230 $tab_top = 42;
231 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
232
233 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
234
235 // Label of product
236 $pdf->SetFont('', 'B', $default_font_size);
237 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
238 $nexY = $pdf->GetY();
239
240 // Show photo
241 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
242 $pdir[0] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/";
243 $pdir[1] = get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref).'/';
244 } else {
245 $pdir[0] = get_exdir(0, 0, 0, 0, $object, 'product'); // default
246 $pdir[1] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/"; // alternative
247 }
248
249 $arephoto = false;
250 foreach ($pdir as $midir) {
251 if (!$arephoto) {
252 if ($conf->entity != $object->entity) {
253 $dir = $conf->product->multidir_output[$object->entity].'/'.$midir; //Check repertories of current entities
254 } else {
255 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
256 }
257 foreach ($object->liste_photos($dir, 1) as $key => $obj) {
258 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
259 if ($obj['photo_vignette']) {
260 $filename = $obj['photo_vignette'];
261 } else {
262 $filename = $obj['photo'];
263 }
264 } else {
265 $filename = $obj['photo'];
266 }
267 $realpath = $dir.$filename;
268 $arephoto = true;
269 }
270 }
271 }
272 // Define size of image if we need it
273 $imglinesize = array();
274 if (!empty($realpath) && $arephoto) {
275 $imgsize = pdf_getSizeForImage($realpath);
276 $imgsizewidth = $imgsize['width'] + 20;
277 $imgsizeheight = $imgsize['height'] + 20;
278
279 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
280 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
281 $posyphoto = $tab_top - 1;
282 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight, '', '', '', 2, 300); // Use 300 dpi
283 $nexyafterphoto = $tab_top + $imgsizeheight;
284 }
285
286 // Description
287 $pdf->SetFont('', '', $default_font_size);
288 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
289 $nexY = $pdf->GetY();
290
291 $nexY += 5;
292
293 $outputlangs->load("other");
294 if ($object->weight) {
295 $texttoshow = $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight);
296 if (isset($object->weight_units)) {
297 $texttoshow .= ' '.measuring_units_string($object->weight_units, 'weight', 0, 0, $outputlangs);
298 }
299 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
300 $nexY = $pdf->GetY();
301 }
302 if ($object->length) {
303 $texttoshow = $langs->trans("Length") . ' x ' . $langs->trans("Width") . ' x ' . $langs->trans("Height") . ': ' . ($object->length != '' ? $object->length : '?') . ' x ' . ($object->width != '' ? $object->width : '?') . ' x ' . ($object->height != '' ? $object->height : '?');
304 $texttoshow .= ' ' . measuringUnitString(0, "size", $object->length_units);
305 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
306 $nexY = $pdf->GetY();
307 }
308 if ($object->surface) {
309 $texttoshow = $langs->trans("Surface") . ': ' . dol_htmlentitiesbr($object->surface);
310 $texttoshow .= ' ' . measuringUnitString(0, "surface", $object->surface_units);
311 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
312 $nexY = $pdf->GetY();
313 }
314 if ($object->volume) {
315 $texttoshow = $langs->trans("Volume") . ': ' . dol_htmlentitiesbr($object->volume);
316 $texttoshow .= ' ' . measuringUnitString(0, "volume", $object->volume_units);
317 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
318 $nexY = $pdf->GetY();
319 }
320
321 $tab_top = 88;
322 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
323 $tab_top = $nexyafterphoto;
324 }
325
326 // Show notes
327 // TODO There is no public note on product yet
328 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
329 if ($notetoshow) {
330 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
331 complete_substitutions_array($substitutionarray, $outputlangs, $object);
332 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
333 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
334
335 $pdf->SetFont('', '', $default_font_size - 1);
336 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
337 $nexY = $pdf->GetY();
338 $height_note = $nexY - $tab_top;
339
340 // Rect takes a length in 3rd parameter
341 $pdf->SetDrawColor(192, 192, 192);
342 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
343
344 $tab_height = $tab_height - $height_note;
345 $tab_top = $nexY + 6;
346 } else {
347 $height_note = 0;
348 }
349
350 $iniY = $tab_top + 7;
351 $curY = $tab_top + 7;
352 $nexY = $tab_top + 7;
353
354 // Loop on each lines
355 /*
356 for ($i = 0 ; $i < $nblines ; $i++)
357 {
358 $curY = $nexY;
359 $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
360 $pdf->SetTextColor(0,0,0);
361
362 $pdf->setTopMargin($tab_top_newpage);
363 $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
364 $pageposbefore=$pdf->getPage();
365
366 // Description of product line
367 $curX = $this->posxdesc-1;
368
369 $showpricebeforepagebreak=1;
370
371 $pdf->startTransaction();
372 pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
373 $pageposafter=$pdf->getPage();
374 if ($pageposafter > $pageposbefore) // There is a pagebreak
375 {
376 $pdf->rollbackTransaction(true);
377 $pageposafter=$pageposbefore;
378 //print $pageposafter.'-'.$pageposbefore;exit;
379 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
380 pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
381 $pageposafter=$pdf->getPage();
382 $posyafter=$pdf->GetY();
383 if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
384 {
385 if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
386 {
387 $pdf->AddPage('','',true);
388 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
389 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
390 $pdf->setPage($pageposafter+1);
391 }
392 }
393 else
394 {
395 // We found a page break
396 $showpricebeforepagebreak=0;
397 }
398 }
399 else // No pagebreak
400 {
401 $pdf->commitTransaction();
402 }
403
404 $nexY = $pdf->GetY();
405 $pageposafter=$pdf->getPage();
406 $pdf->setPage($pageposbefore);
407 $pdf->setTopMargin($this->marge_haute);
408 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
409
410 // We suppose that a too long description is moved completely on next page
411 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
412 $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
413 }
414
415 $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
416
417 // VAT Rate
418 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
419 {
420 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
421 $pdf->SetXY($this->posxtva, $curY);
422 $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
423 }
424
425 // Unit price before discount
426 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
427 $pdf->SetXY($this->posxup, $curY);
428 $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
429
430 // Quantity
431 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
432 $pdf->SetXY($this->posxqty, $curY);
433 $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
434
435 // Unit
436 if($conf->global->PRODUCT_USE_UNITS)
437 {
438 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
439 $pdf->SetXY($this->posxunit, $curY);
440 $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
441 }
442
443 // Discount on line
444 $pdf->SetXY($this->posxdiscount, $curY);
445 if ($object->lines[$i]->remise_percent)
446 {
447 $pdf->SetXY($this->posxdiscount-2, $curY);
448 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
449 $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
450 }
451
452 // Total HT line
453 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
454 $pdf->SetXY($this->postotalht, $curY);
455 $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
456
457 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
458 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
459 else $tvaligne=$object->lines[$i]->total_tva;
460
461 $localtax1ligne=$object->lines[$i]->total_localtax1;
462 $localtax2ligne=$object->lines[$i]->total_localtax2;
463 $localtax1_rate=$object->lines[$i]->localtax1_tx;
464 $localtax2_rate=$object->lines[$i]->localtax2_tx;
465 $localtax1_type=$object->lines[$i]->localtax1_type;
466 $localtax2_type=$object->lines[$i]->localtax2_type;
467
468 if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
469 if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
470 if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
471
472 $vatrate=(string) $object->lines[$i]->tva_tx;
473
474 // Retrieve type from database for backward compatibility with old records
475 if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
476 && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
477 {
478 $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
479 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
480 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
481 }
482
483 // retrieve global local tax
484 if ($localtax1_type && $localtax1ligne != 0) {
485 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
486 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
487 } else {
488 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
489 }
490 }
491 if ($localtax2_type && $localtax2ligne != 0) {
492 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
493 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
494 } else {
495 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
496 }
497 }
498
499 if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
500 if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
501 $this->tva[$vatrate] += $tvaligne;
502
503 // Add line
504 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
505 {
506 $pdf->setPage($pageposafter);
507 $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
508 //$pdf->SetDrawColor(190,190,200);
509 $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
510 $pdf->SetLineStyle(array('dash'=>0));
511 }
512
513 $nexY+=2; // Add space between lines
514
515 // Detect if some page were added automatically and output _tableau for past pages
516 while ($pagenb < $pageposafter)
517 {
518 $pdf->setPage($pagenb);
519 if ($pagenb == 1)
520 {
521 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
522 }
523 else
524 {
525 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
526 }
527 $this->_pagefoot($pdf,$object,$outputlangs,1);
528 $pagenb++;
529 $pdf->setPage($pagenb);
530 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
531 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
532 }
533 if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
534 {
535 if ($pagenb == 1)
536 {
537 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
538 }
539 else
540 {
541 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
542 }
543 $this->_pagefoot($pdf,$object,$outputlangs,1);
544 // New page
545 $pdf->AddPage();
546 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
547 $pagenb++;
548 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
549 }
550 }
551
552 // Show square
553 if ($pagenb == 1)
554 {
555 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
556 $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
557 }
558 else
559 {
560 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
561 $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
562 }
563 */
564
565 // Affiche zone infos
566 //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
567
568 // Pied de page
569 $this->_pagefoot($pdf, $object, $outputlangs);
570 if (method_exists($pdf, 'AliasNbPages')) {
571 $pdf->AliasNbPages();
572 }
573
574 $pdf->Close();
575
576 $pdf->Output($file, 'F');
577
578 // Add pdfgeneration hook
579 $hookmanager->initHooks(array('pdfgeneration'));
580 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
581 global $action;
582 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
583 if ($reshook < 0) {
584 $this->error = $hookmanager->error;
585 $this->errors = $hookmanager->errors;
586 }
587
588 dolChmod($file);
589
590 $this->result = array('fullpath'=>$file);
591
592 return 1; // No error
593 } else {
594 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
595 return 0;
596 }
597 } else {
598 $this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
599 return 0;
600 }
601 }
602
603 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
617 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
618 {
619 global $conf;
620
621 // Force to disable hidetop and hidebottom
622 $hidebottom = 0;
623 if ($hidetop) {
624 $hidetop = -1;
625 }
626
627 $currency = !empty($currency) ? $currency : $conf->currency;
628 $default_font_size = pdf_getPDFFontSize($outputlangs);
629
630 // Amount in (at tab_top - 1)
631 $pdf->SetTextColor(0, 0, 0);
632 $pdf->SetFont('', '', $default_font_size - 2);
633
634 if (empty($hidetop)) {
635 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
636 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
637 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
638
639 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
640 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
641 $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));
642 }
643 }
644
645 $pdf->SetDrawColor(128, 128, 128);
646 $pdf->SetFont('', '', $default_font_size - 1);
647
648 // Output Rect
649 $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
650
651 if (empty($hidetop)) {
652 $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
653
654 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
655 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
656 }
657
658 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
659 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
660 if (empty($hidetop)) {
661 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
662 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
663 }
664 }
665
666 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
667 if (empty($hidetop)) {
668 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
669 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
670 }
671
672 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
673 if (empty($hidetop)) {
674 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
675 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
676 }
677
678 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
679 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
680 if (empty($hidetop)) {
681 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
682 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
683 }
684 }
685
686 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
687 if (empty($hidetop)) {
688 if ($this->atleastonediscount) {
689 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
690 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
691 }
692 }
693
694 if ($this->atleastonediscount) {
695 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
696 }
697 if (empty($hidetop)) {
698 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
699 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
700 }
701 }
702
703 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
714 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
715 {
716 global $conf, $langs, $hookmanager;
717
718 $ltrdirection = 'L';
719 if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
720
721 // Load traductions files required by page
722 $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders"));
723
724 $default_font_size = pdf_getPDFFontSize($outputlangs);
725
726 if ($object->type == 1) {
727 $titlekey = 'ServiceSheet';
728 } else {
729 $titlekey = 'ProductSheet';
730 }
731
732 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
733
734 // Show Draft Watermark
735 if ($object->statut == 0 && getDolGlobalString('PRODUCT_DRAFT_WATERMARK')) {
736 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
737 }
738
739 $pdf->SetTextColor(0, 0, 60);
740 $pdf->SetFont('', 'B', $default_font_size + 3);
741
742 $w = 100;
743
744 $posy = $this->marge_haute;
745 $posx = $this->page_largeur - $this->marge_droite - 100;
746
747 $pdf->SetXY($this->marge_gauche, $posy);
748
749 // Logo
750 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
751 if ($this->emetteur->logo) {
752 $logodir = $conf->mycompany->dir_output;
753 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
754 $logodir = $conf->mycompany->multidir_output[$object->entity];
755 }
756 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
757 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
758 } else {
759 $logo = $logodir.'/logos/'.$this->emetteur->logo;
760 }
761 if (is_readable($logo)) {
762 $height = pdf_getHeightForLogo($logo);
763 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
764 } else {
765 $pdf->SetTextColor(200, 0, 0);
766 $pdf->SetFont('', 'B', $default_font_size - 2);
767 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
768 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
769 }
770 } else {
771 $text = $this->emetteur->name;
772 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
773 }
774 }
775
776
777 $pdf->SetFont('', 'B', $default_font_size + 3);
778 $pdf->SetXY($posx, $posy);
779 $pdf->SetTextColor(0, 0, 60);
780 $title = $outputlangs->transnoentities($titlekey);
781 $pdf->MultiCell(100, 3, $title, '', 'R');
782
783 $pdf->SetFont('', 'B', $default_font_size);
784
785 $posy += 5;
786 $pdf->SetXY($posx, $posy);
787 $pdf->SetTextColor(0, 0, 60);
788 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
789
790 $posy += 1;
791 $pdf->SetFont('', '', $default_font_size - 1);
792
793 /*if ($object->ref_client)
794 {
795 $posy+=5;
796 $pdf->SetXY($posx,$posy);
797 $pdf->SetTextColor(0,0,60);
798 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
799 }*/
800
801 /*$posy+=4;
802 $pdf->SetXY($posx,$posy);
803 $pdf->SetTextColor(0,0,60);
804 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
805 */
806
807 // Get contact
808 /*
809 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
810 {
811 $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
812 if (count($arrayidcontact) > 0)
813 {
814 $usertmp=new User($this->db);
815 $usertmp->fetch($arrayidcontact[0]);
816 $posy+=4;
817 $pdf->SetXY($posx,$posy);
818 $pdf->SetTextColor(0,0,60);
819 $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
820 }
821 }*/
822
823 $posy += 2;
824
825 // Show list of linked objects
826 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
827
828 if ($showaddress) {
829 /*
830 // Sender properties
831 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
832
833 // Show sender
834 $posy=42;
835 $posx=$this->marge_gauche;
836 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
837 $hautcadre=40;
838
839 // Show sender frame
840 $pdf->SetTextColor(0,0,0);
841 $pdf->SetFont('','', $default_font_size - 2);
842 $pdf->SetXY($posx,$posy-5);
843 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
844 $pdf->SetXY($posx,$posy);
845 $pdf->SetFillColor(230,230,230);
846 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
847 $pdf->SetTextColor(0,0,60);
848
849 // Show sender name
850 $pdf->SetXY($posx+2,$posy+3);
851 $pdf->SetFont('','B', $default_font_size);
852 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
853 $posy=$pdf->getY();
854
855 // Show sender information
856 $pdf->SetXY($posx+2,$posy);
857 $pdf->SetFont('','', $default_font_size - 1);
858 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
859 */
860 }
861
862 $pdf->SetTextColor(0, 0, 0);
863 }
864
865 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
875 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
876 {
877 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
878 return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
879 }
880}
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage hooks.
Parent class to manage intervention document templates.
Class to manage predefined suppliers products.
Class to generate expense report based on standard model.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
write_file($object, $outputlangs, $srctemplatepath, $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
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...
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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_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_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
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_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:726
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_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
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:778
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
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