dolibarr 21.0.0-beta
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 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 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", "deliveries"));
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 $productFournisseur = new ProductFournisseur($this->db);
163 $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
164 $object->supplierprices = $supplierprices;
165
166 if (!file_exists($dir)) {
167 if (dol_mkdir($dir) < 0) {
168 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
169 return -1;
170 }
171 }
172
173 if (file_exists($dir)) {
174 // Add pdfgeneration hook
175 if (!is_object($hookmanager)) {
176 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
177 $hookmanager = new HookManager($this->db);
178 }
179 $hookmanager->initHooks(array('pdfgeneration'));
180 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
181 global $action;
182 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
183
184 // Create pdf instance
185 $pdf = pdf_getInstance($this->format);
186 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
187 $pdf->SetAutoPageBreak(1, 0);
188
189 $heightforinfotot = 40; // Height reserved to output the info and total part
190 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
191 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
192 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
193 $heightforfooter += 6;
194 }
195
196 if (class_exists('TCPDF')) {
197 $pdf->setPrintHeader(false);
198 $pdf->setPrintFooter(false);
199 }
200 $pdf->SetFont(pdf_getPDFFont($outputlangs));
201 // Set path to the background PDF File
202 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
203 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
204 $tplidx = $pdf->importPage(1);
205 }
206
207 $pdf->Open();
208 $pagenb = 0;
209 $pdf->SetDrawColor(128, 128, 128);
210
211 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
212 $pdf->SetSubject($outputlangs->transnoentities("Product"));
213 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
214 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
215 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Product"));
216 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
217 $pdf->SetCompression(false);
218 }
219
220 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
221 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
222
223
224 // New page
225 $pdf->AddPage();
226 if (!empty($tplidx)) {
227 $pdf->useTemplate($tplidx);
228 }
229 $pagenb++;
230 $this->_pagehead($pdf, $object, 1, $outputlangs);
231 $pdf->SetFont('', '', $default_font_size - 1);
232 $pdf->MultiCell(0, 3, ''); // Set interline to 3
233 $pdf->SetTextColor(0, 0, 0);
234
235
236 $tab_top = 42;
237 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
238
239 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
240
241 // Label of product
242 $pdf->SetFont('', 'B', $default_font_size);
243 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
244 $nexY = $pdf->GetY();
245
246 // Show photo
247 $pdir = array();
248 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
249 $pdir[0] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/";
250 $pdir[1] = get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref).'/';
251 } else {
252 $pdir[0] = get_exdir(0, 0, 0, 0, $object, 'product'); // default
253 $pdir[1] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/"; // alternative
254 }
255
256 $arephoto = false;
257 foreach ($pdir as $midir) {
258 if (!$arephoto) {
259 if ($conf->entity != $object->entity) {
260 $dir = $conf->product->multidir_output[$object->entity].'/'.$midir; //Check repertories of current entities
261 } else {
262 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
263 }
264 foreach ($object->liste_photos($dir, 1) as $key => $obj) {
265 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
266 if ($obj['photo_vignette']) {
267 $filename = $obj['photo_vignette'];
268 } else {
269 $filename = $obj['photo'];
270 }
271 } else {
272 $filename = $obj['photo'];
273 }
274 $realpath = $dir.$filename;
275 $arephoto = true;
276 }
277 }
278 }
279 // Define size of image if we need it
280 $imglinesize = array();
281 if (!empty($realpath) && $arephoto) {
282 $imgsize = pdf_getSizeForImage($realpath);
283 $imgsizewidth = $imgsize['width'] + 20;
284 $imgsizeheight = $imgsize['height'] + 20;
285
286 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
287 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
288 $posyphoto = $tab_top - 1;
289 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight, '', '', '', 2, 300); // Use 300 dpi
290 $nexyafterphoto = $tab_top + $imgsizeheight;
291 }
292
293 // Description
294 $pdf->SetFont('', '', $default_font_size);
295 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
296 $nexY = $pdf->GetY();
297
298 $nexY += 5;
299
300 $outputlangs->load("other");
301 if ($object->weight) {
302 $texttoshow = $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight);
303 if (isset($object->weight_units)) {
304 $texttoshow .= ' '.measuring_units_string($object->weight_units, 'weight', 0, 0, $outputlangs);
305 }
306 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
307 $nexY = $pdf->GetY();
308 }
309 if ($object->length) {
310 $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 : '?');
311 $texttoshow .= ' ' . measuringUnitString(0, "size", $object->length_units);
312 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
313 $nexY = $pdf->GetY();
314 }
315 if ($object->surface) {
316 $texttoshow = $langs->trans("Surface") . ': ' . dol_htmlentitiesbr($object->surface);
317 $texttoshow .= ' ' . measuringUnitString(0, "surface", $object->surface_units);
318 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
319 $nexY = $pdf->GetY();
320 }
321 if ($object->volume) {
322 $texttoshow = $langs->trans("Volume") . ': ' . dol_htmlentitiesbr($object->volume);
323 $texttoshow .= ' ' . measuringUnitString(0, "volume", $object->volume_units);
324 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
325 $nexY = $pdf->GetY();
326 }
327
328 $tab_top = 88;
329 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
330 $tab_top = $nexyafterphoto;
331 }
332
333 // Show notes
334 // TODO There is no public note on product yet
335 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
336 if ($notetoshow) {
337 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
338 complete_substitutions_array($substitutionarray, $outputlangs, $object);
339 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
340 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
341
342 $pdf->SetFont('', '', $default_font_size - 1);
343 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
344 $nexY = $pdf->GetY();
345 $height_note = $nexY - $tab_top;
346
347 // Rect takes a length in 3rd parameter
348 $pdf->SetDrawColor(192, 192, 192);
349 $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');
350
351 $tab_height -= $height_note;
352 $tab_top = $nexY + 6;
353 } else {
354 $height_note = 0;
355 }
356
357 $iniY = $tab_top + 7;
358 $curY = $tab_top + 7;
359 $nexY = $tab_top + 7;
360
361 // Loop on each lines
362 /*
363 for ($i = 0 ; $i < $nblines ; $i++)
364 {
365 $curY = $nexY;
366 $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
367 $pdf->SetTextColor(0,0,0);
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 // Description of product line
374 $curX = $this->posxdesc-1;
375
376 $showpricebeforepagebreak=1;
377
378 $pdf->startTransaction();
379 pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
380 $pageposafter=$pdf->getPage();
381 if ($pageposafter > $pageposbefore) // There is a pagebreak
382 {
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);
388 $pageposafter=$pdf->getPage();
389 $posyafter=$pdf->GetY();
390 if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
391 {
392 if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
393 {
394 $pdf->AddPage('','',true);
395 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
396 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
397 $pdf->setPage($pageposafter+1);
398 }
399 }
400 else
401 {
402 // We found a page break
403 $showpricebeforepagebreak=0;
404 }
405 }
406 else // No pagebreak
407 {
408 $pdf->commitTransaction();
409 }
410
411 $nexY = $pdf->GetY();
412 $pageposafter=$pdf->getPage();
413 $pdf->setPage($pageposbefore);
414 $pdf->setTopMargin($this->marge_haute);
415 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
416
417 // We suppose that a too long description is moved completely on next page
418 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
419 $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
420 }
421
422 $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par default
423
424 // VAT Rate
425 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
426 {
427 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
428 $pdf->SetXY($this->posxtva, $curY);
429 $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
430 }
431
432 // Unit price before discount
433 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
434 $pdf->SetXY($this->posxup, $curY);
435 $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
436
437 // Quantity
438 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
439 $pdf->SetXY($this->posxqty, $curY);
440 $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
441
442 // Unit
443 if($conf->global->PRODUCT_USE_UNITS)
444 {
445 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
446 $pdf->SetXY($this->posxunit, $curY);
447 $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
448 }
449
450 // Discount on line
451 $pdf->SetXY($this->posxdiscount, $curY);
452 if ($object->lines[$i]->remise_percent)
453 {
454 $pdf->SetXY($this->posxdiscount-2, $curY);
455 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
456 $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 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 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
465 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
466 else $tvaligne=$object->lines[$i]->total_tva;
467
468 $localtax1ligne=$object->lines[$i]->total_localtax1;
469 $localtax2ligne=$object->lines[$i]->total_localtax2;
470 $localtax1_rate=$object->lines[$i]->localtax1_tx;
471 $localtax2_rate=$object->lines[$i]->localtax2_tx;
472 $localtax1_type=$object->lines[$i]->localtax1_type;
473 $localtax2_type=$object->lines[$i]->localtax2_type;
474
475 if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
476 if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
477 if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
478
479 $vatrate=(string) $object->lines[$i]->tva_tx;
480
481 // Retrieve type from database for backward compatibility with old records
482 if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
483 && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
484 {
485 $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
486 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
487 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
488 }
489
490 // retrieve global local tax
491 if ($localtax1_type && $localtax1ligne != 0) {
492 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
493 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
494 } else {
495 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
496 }
497 }
498 if ($localtax2_type && $localtax2ligne != 0) {
499 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
500 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
501 } else {
502 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
503 }
504 }
505
506 if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
507 if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
508 $this->tva[$vatrate] += $tvaligne;
509
510 // Add line
511 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
512 {
513 $pdf->setPage($pageposafter);
514 $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
515 //$pdf->SetDrawColor(190,190,200);
516 $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
517 $pdf->SetLineStyle(array('dash'=>0));
518 }
519
520 $nexY+=2; // Add space between lines
521
522 // Detect if some page were added automatically and output _tableau for past pages
523 while ($pagenb < $pageposafter)
524 {
525 $pdf->setPage($pagenb);
526 if ($pagenb == 1)
527 {
528 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
529 }
530 else
531 {
532 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
533 }
534 $this->_pagefoot($pdf,$object,$outputlangs,1);
535 $pagenb++;
536 $pdf->setPage($pagenb);
537 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
538 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
539 }
540 if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
541 {
542 if ($pagenb == 1)
543 {
544 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
545 }
546 else
547 {
548 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
549 }
550 $this->_pagefoot($pdf,$object,$outputlangs,1);
551 // New page
552 $pdf->AddPage();
553 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
554 $pagenb++;
555 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
556 }
557 }
558
559 // Show square
560 if ($pagenb == 1)
561 {
562 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
563 $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
564 }
565 else
566 {
567 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
568 $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
569 }
570 */
571
572 // Affiche zone infos
573 //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
574
575 // Pied de page
576 $this->_pagefoot($pdf, $object, $outputlangs);
577 if (method_exists($pdf, 'AliasNbPages')) {
578 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
579 }
580
581 $pdf->Close();
582
583 $pdf->Output($file, 'F');
584
585 // Add pdfgeneration hook
586 $hookmanager->initHooks(array('pdfgeneration'));
587 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
588 global $action;
589 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
590 if ($reshook < 0) {
591 $this->error = $hookmanager->error;
592 $this->errors = $hookmanager->errors;
593 }
594
595 dolChmod($file);
596
597 $this->result = array('fullpath' => $file);
598
599 return 1; // No error
600 } else {
601 $this->error = $langs->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])) {
763 $logodir = $conf->mycompany->multidir_output[$object->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 (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
819 {
820 $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
821 if (count($arrayidcontact) > 0)
822 {
823 $usertmp=new User($this->db);
824 $usertmp->fetch($arrayidcontact[0]);
825 $posy+=4;
826 $pdf->SetXY($posx,$posy);
827 $pdf->SetTextColor(0,0,60);
828 $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
829 }
830 }*/
831
832 $posy += 2;
833
834 // Show list of linked objects
835 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
836
837 if ($showaddress) {
838 /*
839 // Sender properties
840 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
841
842 // Show sender
843 $posy=42;
844 $posx=$this->marge_gauche;
845 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
846 $hautcadre=40;
847
848 // Show sender frame
849 $pdf->SetTextColor(0,0,0);
850 $pdf->SetFont('','', $default_font_size - 2);
851 $pdf->SetXY($posx,$posy-5);
852 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
853 $pdf->SetXY($posx,$posy);
854 $pdf->SetFillColor(230,230,230);
855 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
856 $pdf->SetTextColor(0,0,60);
857
858 // Show sender name
859 $pdf->SetXY($posx+2,$posy+3);
860 $pdf->SetFont('','B', $default_font_size);
861 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
862 $posy=$pdf->getY();
863
864 // Show sender information
865 $pdf->SetXY($posx+2,$posy);
866 $pdf->SetFont('','', $default_font_size - 1);
867 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
868 */
869 }
870
871 $pdf->SetTextColor(0, 0, 0);
872
873 return 0;
874 }
875
876 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
886 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
887 {
888 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
889 return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
890 }
891}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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 manage predefined suppliers products.
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.
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.
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_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 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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:2648
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1027
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:729
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1405
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
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:765
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:785
measuringUnitString($unitid, $measuring_style='', $unitscale='', $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:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152