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