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