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