dolibarr 18.0.6
pdf_standard_asset.modules.php
1<?php
2/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5 * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 * or see https://www.gnu.org/
26 */
27
34dol_include_once('/asset/core/modules/asset/modules_asset.php');
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
39
40
45{
49 public $db;
50
54 public $name;
55
59 public $description;
60
64 public $update_main_doc_field;
65
69 public $type;
70
75 public $version = 'dolibarr';
76
80 public $page_largeur;
81
85 public $page_hauteur;
86
90 public $format;
91
95 public $marge_gauche;
96
100 public $marge_droite;
101
105 public $marge_haute;
106
110 public $marge_basse;
111
116 public $emetteur;
117
121 public $situationinvoice;
122
123
127 public $cols;
128
129
135 public function __construct($db)
136 {
137 global $conf, $langs, $mysoc;
138
139 // Translations
140 $langs->loadLangs(array("main", "bills"));
141
142 $this->db = $db;
143 $this->name = "standard";
144 $this->description = $langs->trans('DocumentModelStandardPDF');
145 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
146
147 // Dimension page
148 $this->type = 'pdf';
149 $formatarray = pdf_getFormat();
150 $this->page_largeur = $formatarray['width'];
151 $this->page_hauteur = $formatarray['height'];
152 $this->format = array($this->page_largeur, $this->page_hauteur);
153 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
154 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
155 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
156 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
157
158 // Get source company
159 $this->emetteur = $mysoc;
160 if (empty($this->emetteur->country_code)) {
161 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
162 }
163
164 // Define position of columns
165 $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
166
167
168 $this->tabTitleHeight = 5; // default height
169
170 // Use new system for position of columns, view $this->defineColumnField()
171
172 $this->tva = array();
173 $this->localtax1 = array();
174 $this->localtax2 = array();
175 $this->atleastoneratenotnull = 0;
176 $this->atleastonediscount = 0;
177 $this->situationinvoice = false;
178 }
179
180
181 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
193 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
194 {
195 // phpcs:enable
196 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
197
198 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
199
200 if (!is_object($outputlangs)) {
201 $outputlangs = $langs;
202 }
203 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
204 if (!empty($conf->global->MAIN_USE_FPDF)) {
205 $outputlangs->charset_output = 'ISO-8859-1';
206 }
207
208 // Load translation files required by the page
209 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
210
211 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
212 global $outputlangsbis;
213 $outputlangsbis = new Translate('', $conf);
214 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
215 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
216 }
217
218 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
219
220 $hidetop = 0;
221 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
222 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
223 }
224
225 // Loop on each lines to detect if there is at least one image to show
226 $realpatharray = array();
227 $this->atleastonephoto = false;
228 /*
229 if (!empty($conf->global->MAIN_GENERATE_ASSET_WITH_PICTURE))
230 {
231 $objphoto = new Product($this->db);
232
233 for ($i = 0; $i < $nblines; $i++)
234 {
235 if (empty($object->lines[$i]->fk_product)) continue;
236
237 //var_dump($objphoto->ref);exit;
238 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
239 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
240 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
241 } else {
242 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
243 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
244 }
245
246 $arephoto = false;
247 foreach ($pdir as $midir)
248 {
249 if (!$arephoto)
250 {
251 $dir = $conf->product->dir_output.'/'.$midir;
252
253 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
254 {
255 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
256 {
257 if ($obj['photo_vignette'])
258 {
259 $filename = $obj['photo_vignette'];
260 } else {
261 $filename = $obj['photo'];
262 }
263 } else {
264 $filename = $obj['photo'];
265 }
266
267 $realpath = $dir.$filename;
268 $arephoto = true;
269 $this->atleastonephoto = true;
270 }
271 }
272 }
273
274 if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
275 }
276 }
277 */
278
279 //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
280
281 if ($conf->asset->dir_output.'/asset') {
282 $object->fetch_thirdparty();
283
284 // Definition of $dir and $file
285 if ($object->specimen) {
286 $dir = $conf->asset->dir_output.'/asset';
287 $file = $dir."/SPECIMEN.pdf";
288 } else {
289 $objectref = dol_sanitizeFileName($object->ref);
290 $dir = $conf->asset->dir_output.'/asset/'.$objectref;
291 $file = $dir."/".$objectref.".pdf";
292 }
293 if (!file_exists($dir)) {
294 if (dol_mkdir($dir) < 0) {
295 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
296 return 0;
297 }
298 }
299
300 if (file_exists($dir)) {
301 // Add pdfgeneration hook
302 if (!is_object($hookmanager)) {
303 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
304 $hookmanager = new HookManager($this->db);
305 }
306 $hookmanager->initHooks(array('pdfgeneration'));
307 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
308 global $action;
309 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
310
311 // Set nblines with the new facture lines content after hook
312 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
313
314 // Create pdf instance
315 $pdf = pdf_getInstance($this->format);
316 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
317 $pdf->SetAutoPageBreak(1, 0);
318
319 $heightforinfotot = 50; // Height reserved to output the info and total part and payment part
320 $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
321 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
322
323 if (class_exists('TCPDF')) {
324 $pdf->setPrintHeader(false);
325 $pdf->setPrintFooter(false);
326 }
327 $pdf->SetFont(pdf_getPDFFont($outputlangs));
328
329 // Set path to the background PDF File
330 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
331 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
332 $tplidx = $pdf->importPage(1);
333 }
334
335 $pdf->Open();
336 $pagenb = 0;
337 $pdf->SetDrawColor(128, 128, 128);
338
339 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
340 $pdf->SetSubject($outputlangs->transnoentities("PdfTitle"));
341 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
342 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
343 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
344 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
345 $pdf->SetCompression(false);
346 }
347
348 // Set certificate
349 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
350 // If user has no certificate, we try to take the company one
351 if (!$cert) {
352 $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
353 }
354 // If a certificate is found
355 if ($cert) {
356 $info = array(
357 'Name' => $this->emetteur->name,
358 'Location' => getCountry($this->emetteur->country_code, 0),
359 'Reason' => 'ASSET',
360 'ContactInfo' => $this->emetteur->email
361 );
362 $pdf->setSignature($cert, $cert, $this->emetteur->name, '', 2, $info);
363 }
364
365 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
366
367 // New page
368 $pdf->AddPage();
369 if (!empty($tplidx)) {
370 $pdf->useTemplate($tplidx);
371 }
372 $pagenb++;
373
374 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
375 $pdf->SetFont('', '', $default_font_size - 1);
376 $pdf->MultiCell(0, 3, ''); // Set interline to 3
377 $pdf->SetTextColor(0, 0, 0);
378
379 $tab_top = 90 + $top_shift;
380 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
381 $tab_height = 130 - $top_shift;
382 $tab_height_newpage = 150;
383 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
384 $tab_height_newpage -= $top_shift;
385 }
386
387 $nexY = $tab_top - 1;
388
389 // Display notes
390 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
391 // Extrafields in note
392 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
393 if (!empty($extranote)) {
394 $notetoshow = dol_concatdesc($notetoshow, $extranote);
395 }
396
397 $pagenb = $pdf->getPage();
398 if ($notetoshow) {
399 $tab_top -= 2;
400
401 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
402 $pageposbeforenote = $pagenb;
403
404 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
405 complete_substitutions_array($substitutionarray, $outputlangs, $object);
406 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
407 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
408
409 $pdf->startTransaction();
410
411 $pdf->SetFont('', '', $default_font_size - 1);
412 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
413 // Description
414 $pageposafternote = $pdf->getPage();
415 $posyafter = $pdf->GetY();
416
417 if ($pageposafternote > $pageposbeforenote) {
418 $pdf->rollbackTransaction(true);
419
420 // prepare pages to receive notes
421 while ($pagenb < $pageposafternote) {
422 $pdf->AddPage();
423 $pagenb++;
424 if (!empty($tplidx)) {
425 $pdf->useTemplate($tplidx);
426 }
427 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
428 $this->_pagehead($pdf, $object, 0, $outputlangs);
429 }
430 // $this->_pagefoot($pdf,$object,$outputlangs,1);
431 $pdf->setTopMargin($tab_top_newpage);
432 // The only function to edit the bottom margin of current page to set it.
433 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
434 }
435
436 // back to start
437 $pdf->setPage($pageposbeforenote);
438 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
439 $pdf->SetFont('', '', $default_font_size - 1);
440 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
441 $pageposafternote = $pdf->getPage();
442
443 $posyafter = $pdf->GetY();
444
445 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
446 $pdf->AddPage('', '', true);
447 $pagenb++;
448 $pageposafternote++;
449 $pdf->setPage($pageposafternote);
450 $pdf->setTopMargin($tab_top_newpage);
451 // The only function to edit the bottom margin of current page to set it.
452 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
453 //$posyafter = $tab_top_newpage;
454 }
455
456
457 // apply note frame to previous pages
458 $i = $pageposbeforenote;
459 while ($i < $pageposafternote) {
460 $pdf->setPage($i);
461
462
463 $pdf->SetDrawColor(128, 128, 128);
464 // Draw note frame
465 if ($i > $pageposbeforenote) {
466 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
467 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
468 } else {
469 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
470 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
471 }
472
473 // Add footer
474 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
475 $this->_pagefoot($pdf, $object, $outputlangs, 1);
476
477 $i++;
478 }
479
480 // apply note frame to last page
481 $pdf->setPage($pageposafternote);
482 if (!empty($tplidx)) {
483 $pdf->useTemplate($tplidx);
484 }
485 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
486 $this->_pagehead($pdf, $object, 0, $outputlangs);
487 }
488 $height_note = $posyafter - $tab_top_newpage;
489 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
490 } else // No pagebreak
491 {
492 $pdf->commitTransaction();
493 $posyafter = $pdf->GetY();
494 $height_note = $posyafter - $tab_top;
495 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
496
497
498 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
499 // not enough space, need to add page
500 $pdf->AddPage('', '', true);
501 $pagenb++;
502 $pageposafternote++;
503 $pdf->setPage($pageposafternote);
504 if (!empty($tplidx)) {
505 $pdf->useTemplate($tplidx);
506 }
507 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
508 $this->_pagehead($pdf, $object, 0, $outputlangs);
509 }
510
511 $posyafter = $tab_top_newpage;
512 }
513 }
514
515 $tab_height = $tab_height - $height_note;
516 $tab_top = $posyafter + 6;
517 } else {
518 $height_note = 0;
519 }
520
521 // Use new auto column system
522 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
523
524 // Table simulation to know the height of the title line
525 $pdf->startTransaction();
526 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
527 $pdf->rollbackTransaction(true);
528
529 $nexY = $tab_top + $this->tabTitleHeight;
530
531 // Loop on each lines
532 $pageposbeforeprintlines = $pdf->getPage();
533 $pagenb = $pageposbeforeprintlines;
534 for ($i = 0; $i < $nblines; $i++) {
535 $curY = $nexY;
536 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
537 $pdf->SetTextColor(0, 0, 0);
538
539 // Define size of image if we need it
540 $imglinesize = array();
541 if (!empty($realpatharray[$i])) {
542 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
543 }
544
545 $pdf->setTopMargin($tab_top_newpage);
546 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
547 $pageposbefore = $pdf->getPage();
548
549 $showpricebeforepagebreak = 1;
550 $posYAfterImage = 0;
551
552 if ($this->getColumnStatus('photo')) {
553 // We start with Photo of product line
554 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
555 $pdf->AddPage('', '', true);
556 if (!empty($tplidx)) {
557 $pdf->useTemplate($tplidx);
558 }
559 $pdf->setPage($pageposbefore + 1);
560
561 $curY = $tab_top_newpage;
562
563 // Allows data in the first page if description is long enough to break in multiples pages
564 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
565 $showpricebeforepagebreak = 1;
566 } else {
567 $showpricebeforepagebreak = 0;
568 }
569 }
570
571 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
572 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
573 // $pdf->Image does not increase value return by getY, so we save it manually
574 $posYAfterImage = $curY + $imglinesize['height'];
575 }
576 }
577
578 // Description of product line
579 if ($this->getColumnStatus('desc')) {
580 $pdf->startTransaction();
581
582 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
583 $pageposafter = $pdf->getPage();
584
585 if ($pageposafter > $pageposbefore) { // There is a pagebreak
586 $pdf->rollbackTransaction(true);
587 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
588
589 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
590
591 $pageposafter = $pdf->getPage();
592 $posyafter = $pdf->GetY();
593 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
594 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
595 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
596 $pdf->AddPage('', '', true);
597 if (!empty($tplidx)) {
598 $pdf->useTemplate($tplidx);
599 }
600 $pdf->setPage($pageposafter + 1);
601 }
602 } else {
603 // We found a page break
604 // Allows data in the first page if description is long enough to break in multiples pages
605 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
606 $showpricebeforepagebreak = 1;
607 } else {
608 $showpricebeforepagebreak = 0;
609 }
610 }
611 } else // No pagebreak
612 {
613 $pdf->commitTransaction();
614 }
615 }
616
617 $nexY = $pdf->GetY();
618 $pageposafter = $pdf->getPage();
619 $pdf->setPage($pageposbefore);
620 $pdf->setTopMargin($this->marge_haute);
621 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
622
623 // We suppose that a too long description or photo were moved completely on next page
624 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
625 $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
626 }
627
628 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
629
630 // Quantity
631 // Enough for 6 chars
632 if ($this->getColumnStatus('qty')) {
633 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
634 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
635 $nexY = max($pdf->GetY(), $nexY);
636 }
637
638 // Extrafields
639 if (!empty($object->lines[$i]->array_options)) {
640 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
641 if ($this->getColumnStatus($extrafieldColKey)) {
642 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
643 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
644 $nexY = max($pdf->GetY(), $nexY);
645 }
646 }
647 }
648
649
650 $parameters = array(
651 'object' => $object,
652 'i' => $i,
653 'pdf' =>& $pdf,
654 'curY' =>& $curY,
655 'nexY' =>& $nexY,
656 'outputlangs' => $outputlangs,
657 'hidedetails' => $hidedetails
658 );
659 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
660
661
662 $sign = 1;
663 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
664 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
665 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
666 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
667 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
668 } else {
669 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
670 }
671 } else {
672 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
673 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
674 } else {
675 $tvaligne = $sign * $object->lines[$i]->total_tva;
676 }
677 }
678
679 $localtax1ligne = $object->lines[$i]->total_localtax1;
680 $localtax2ligne = $object->lines[$i]->total_localtax2;
681 $localtax1_rate = $object->lines[$i]->localtax1_tx;
682 $localtax2_rate = $object->lines[$i]->localtax2_tx;
683 $localtax1_type = $object->lines[$i]->localtax1_type;
684 $localtax2_type = $object->lines[$i]->localtax2_type;
685
686 // TODO remise_percent is an obsolete field for object parent
687 /*if ($object->remise_percent) {
688 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
689 }
690 if ($object->remise_percent) {
691 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
692 }
693 if ($object->remise_percent) {
694 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
695 }*/
696
697 $vatrate = (string) $object->lines[$i]->tva_tx;
698
699 // Retrieve type from database for backward compatibility with old records
700 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
701 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
702 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
703 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
704 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
705 }
706
707 // retrieve global local tax
708 if ($localtax1_type && $localtax1ligne != 0) {
709 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
710 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
711 } else {
712 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
713 }
714 }
715 if ($localtax2_type && $localtax2ligne != 0) {
716 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
717 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
718 } else {
719 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
720 }
721 }
722
723 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
724 $vatrate .= '*';
725 }
726 if (!isset($this->tva[$vatrate])) {
727 $this->tva[$vatrate] = 0;
728 }
729 $this->tva[$vatrate] += $tvaligne;
730
731 $nexY = max($nexY, $posYAfterImage);
732
733 // Add line
734 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
735 $pdf->setPage($pageposafter);
736 $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
737 //$pdf->SetDrawColor(190,190,200);
738 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
739 $pdf->SetLineStyle(array('dash'=>0));
740 }
741
742 // Detect if some page were added automatically and output _tableau for past pages
743 while ($pagenb < $pageposafter) {
744 $pdf->setPage($pagenb);
745 if ($pagenb == $pageposbeforeprintlines) {
746 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
747 } else {
748 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
749 }
750 $this->_pagefoot($pdf, $object, $outputlangs, 1);
751 $pagenb++;
752 $pdf->setPage($pagenb);
753 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
754 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
755 $this->_pagehead($pdf, $object, 0, $outputlangs);
756 }
757 }
758
759 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
760 if ($pagenb == $pageposafter) {
761 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
762 } else {
763 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
764 }
765 $this->_pagefoot($pdf, $object, $outputlangs, 1);
766 // New page
767 $pdf->AddPage();
768 if (!empty($tplidx)) {
769 $pdf->useTemplate($tplidx);
770 }
771 $pagenb++;
772 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
773 $this->_pagehead($pdf, $object, 0, $outputlangs);
774 }
775 }
776 }
777
778 // Show square
779 if ($pagenb == $pageposbeforeprintlines) {
780 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
781 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
782 } else {
783 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
784 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
785 }
786
787 // Display infos area
788 //$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
789
790 // Display total zone
791 //$posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
792
793 // Display payment area
794 /*
795 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
796 {
797 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
798 }
799 */
800
801 // Pagefoot
802 $this->_pagefoot($pdf, $object, $outputlangs);
803 if (method_exists($pdf, 'AliasNbPages')) {
804 $pdf->AliasNbPages();
805 }
806
807 $pdf->Close();
808
809 $pdf->Output($file, 'F');
810
811 // Add pdfgeneration hook
812 $hookmanager->initHooks(array('pdfgeneration'));
813 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
814 global $action;
815 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
816 if ($reshook < 0) {
817 $this->error = $hookmanager->error;
818 $this->errors = $hookmanager->errors;
819 }
820
821 dolChmod($file);
822
823 $this->result = array('fullpath'=>$file);
824
825 return 1; // No error
826 } else {
827 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
828 return 0;
829 }
830 } else {
831 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
832 return 0;
833 }
834 }
835
836 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
844 public static function liste_modeles($db, $maxfilenamelength = 0)
845 {
846 // phpcs:enable
847 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
848 }
849
850 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
865 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
866 {
867 global $conf;
868
869 // Force to disable hidetop and hidebottom
870 $hidebottom = 0;
871 if ($hidetop) {
872 $hidetop = -1;
873 }
874
875 $currency = !empty($currency) ? $currency : $conf->currency;
876 $default_font_size = pdf_getPDFFontSize($outputlangs);
877
878 // Amount in (at tab_top - 1)
879 $pdf->SetTextColor(0, 0, 0);
880 $pdf->SetFont('', '', $default_font_size - 2);
881
882 if (empty($hidetop)) {
883 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
884 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
885 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
886 }
887
888 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
889 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
890
891 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
892 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
893 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
894 }
895 }
896
897 $pdf->SetDrawColor(128, 128, 128);
898 $pdf->SetFont('', '', $default_font_size - 1);
899
900 // Output Rect
901 $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
902
903
904 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
905
906 if (empty($hidetop)) {
907 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
908 }
909 }
910
911 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
922 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
923 {
924 global $conf, $langs;
925
926 // Load traductions files required by page
927 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
928
929 $default_font_size = pdf_getPDFFontSize($outputlangs);
930
931 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
932
933 // Show Draft Watermark
934 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
935 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
936 }
937
938 $pdf->SetTextColor(0, 0, 60);
939 $pdf->SetFont('', 'B', $default_font_size + 3);
940
941 $w = 110;
942
943 $posy = $this->marge_haute;
944 $posx = $this->page_largeur - $this->marge_droite - $w;
945
946 $pdf->SetXY($this->marge_gauche, $posy);
947
948 // Logo
949 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
950 if ($this->emetteur->logo) {
951 $logodir = $conf->mycompany->dir_output;
952 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
953 $logodir = $conf->mycompany->multidir_output[$object->entity];
954 }
955 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
956 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
957 } else {
958 $logo = $logodir.'/logos/'.$this->emetteur->logo;
959 }
960 if (is_readable($logo)) {
961 $height = pdf_getHeightForLogo($logo);
962 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
963 } else {
964 $pdf->SetTextColor(200, 0, 0);
965 $pdf->SetFont('', 'B', $default_font_size - 2);
966 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
967 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
968 }
969 } else {
970 $text = $this->emetteur->name;
971 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
972 }
973 }
974
975 $pdf->SetFont('', 'B', $default_font_size + 3);
976 $pdf->SetXY($posx, $posy);
977 $pdf->SetTextColor(0, 0, 60);
978 $title = $outputlangs->transnoentities("PdfTitle");
979 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
980 $title .= ' - ';
981 $title .= $outputlangsbis->transnoentities("PdfTitle");
982 }
983 $pdf->MultiCell($w, 3, $title, '', 'R');
984
985 $pdf->SetFont('', 'B', $default_font_size);
986
987 $posy += 5;
988 $pdf->SetXY($posx, $posy);
989 $pdf->SetTextColor(0, 0, 60);
990 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
991 if ($object->statut == $object::STATUS_DRAFT) {
992 $pdf->SetTextColor(128, 0, 0);
993 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
994 }
995 $pdf->MultiCell($w, 4, $textref, '', 'R');
996
997 $posy += 1;
998 $pdf->SetFont('', '', $default_font_size - 2);
999
1000 if ($object->ref_client) {
1001 $posy += 4;
1002 $pdf->SetXY($posx, $posy);
1003 $pdf->SetTextColor(0, 0, 60);
1004 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1005 }
1006
1007 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1008 $object->fetch_projet();
1009 if (!empty($object->project->ref)) {
1010 $posy += 3;
1011 $pdf->SetXY($posx, $posy);
1012 $pdf->SetTextColor(0, 0, 60);
1013 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
1014 }
1015 }
1016
1017 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1018 $object->fetch_projet();
1019 if (!empty($object->project->ref)) {
1020 $outputlangs->load("projects");
1021 $posy += 3;
1022 $pdf->SetXY($posx, $posy);
1023 $pdf->SetTextColor(0, 0, 60);
1024 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1025 }
1026 }
1027
1028 $posy += 4;
1029 $pdf->SetXY($posx, $posy);
1030 $pdf->SetTextColor(0, 0, 60);
1031
1032 $title = $outputlangs->transnoentities("Date");
1033 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1034 $title .= ' - '.$outputlangsbis->transnoentities("Date");
1035 }
1036 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
1037
1038 if ($object->thirdparty->code_client) {
1039 $posy += 3;
1040 $pdf->SetXY($posx, $posy);
1041 $pdf->SetTextColor(0, 0, 60);
1042 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1043 }
1044
1045 // Get contact
1046 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1047 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1048 if (count($arrayidcontact) > 0) {
1049 $usertmp = new User($this->db);
1050 $usertmp->fetch($arrayidcontact[0]);
1051 $posy += 4;
1052 $pdf->SetXY($posx, $posy);
1053 $pdf->SetTextColor(0, 0, 60);
1054 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1055 }
1056 }
1057
1058 $posy += 1;
1059
1060 $top_shift = 0;
1061 // Show list of linked objects
1062 $current_y = $pdf->getY();
1063 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1064 if ($current_y < $pdf->getY()) {
1065 $top_shift = $pdf->getY() - $current_y;
1066 }
1067
1068 if ($showaddress) {
1069 // Sender properties
1070 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1071
1072 // Show sender
1073 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1074 $posy += $top_shift;
1075 $posx = $this->marge_gauche;
1076 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1077 $posx = $this->page_largeur - $this->marge_droite - 80;
1078 }
1079
1080 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1081 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1082
1083
1084 // Show sender frame
1085 $pdf->SetTextColor(0, 0, 0);
1086 $pdf->SetFont('', '', $default_font_size - 2);
1087 $pdf->SetXY($posx, $posy - 5);
1088 $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1089 $pdf->SetXY($posx, $posy);
1090 $pdf->SetFillColor(230, 230, 230);
1091 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1092 $pdf->SetTextColor(0, 0, 60);
1093
1094 // Show sender name
1095 $pdf->SetXY($posx + 2, $posy + 3);
1096 $pdf->SetFont('', 'B', $default_font_size);
1097 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1098 $posy = $pdf->getY();
1099
1100 // Show sender information
1101 $pdf->SetXY($posx + 2, $posy);
1102 $pdf->SetFont('', '', $default_font_size - 1);
1103 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1104
1105 // If BILLING contact defined on invoice, we use it
1106 $usecontact = false;
1107 $arrayidcontact = $object->getIdContact('external', 'BILLING');
1108 if (count($arrayidcontact) > 0) {
1109 $usecontact = true;
1110 $result = $object->fetch_contact($arrayidcontact[0]);
1111 }
1112
1113 // Recipient name
1114 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
1115 $thirdparty = $object->contact;
1116 } else {
1117 $thirdparty = $object->thirdparty;
1118 }
1119
1120 if (is_object($thirdparty)) {
1121 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1122 }
1123
1124 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1125
1126 // Show recipient
1127 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1128 if ($this->page_largeur < 210) {
1129 $widthrecbox = 84; // To work with US executive format
1130 }
1131 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1132 $posy += $top_shift;
1133 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1134 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1135 $posx = $this->marge_gauche;
1136 }
1137
1138 // Show recipient frame
1139 $pdf->SetTextColor(0, 0, 0);
1140 $pdf->SetFont('', '', $default_font_size - 2);
1141 $pdf->SetXY($posx + 2, $posy - 5);
1142 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1143 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1144
1145 // Show recipient name
1146 $pdf->SetXY($posx + 2, $posy + 3);
1147 $pdf->SetFont('', 'B', $default_font_size);
1148 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1149
1150 $posy = $pdf->getY();
1151
1152 // Show recipient information
1153 $pdf->SetFont('', '', $default_font_size - 1);
1154 $pdf->SetXY($posx + 2, $posy);
1155 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1156 }
1157
1158 $pdf->SetTextColor(0, 0, 0);
1159 return $top_shift;
1160 }
1161
1162 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1172 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1173 {
1174 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1175 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1176 }
1177
1188 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1189 {
1190 global $conf, $hookmanager;
1191
1192 // Default field style for content
1193 $this->defaultContentsFieldsStyle = array(
1194 'align' => 'R', // R,C,L
1195 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1196 );
1197
1198 // Default field style for content
1199 $this->defaultTitlesFieldsStyle = array(
1200 'align' => 'C', // R,C,L
1201 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1202 );
1203
1204 /*
1205 * For exemple
1206 $this->cols['theColKey'] = array(
1207 'rank' => $rank, // int : use for ordering columns
1208 'width' => 20, // the column width in mm
1209 'title' => array(
1210 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1211 'label' => ' ', // the final label : used fore final generated text
1212 'align' => 'L', // text alignement : R,C,L
1213 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1214 ),
1215 'content' => array(
1216 'align' => 'L', // text alignement : R,C,L
1217 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1218 ),
1219 );
1220 */
1221
1222 $rank = 0; // do not use negative rank
1223 $this->cols['desc'] = array(
1224 'rank' => $rank,
1225 'width' => false, // only for desc
1226 'status' => true,
1227 'title' => array(
1228 'textkey' => 'Designation', // use lang key is usefull in somme case with module
1229 'align' => 'L',
1230 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1231 // 'label' => ' ', // the final label
1232 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1233 ),
1234 'content' => array(
1235 'align' => 'L',
1236 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1237 ),
1238 );
1239
1240 // PHOTO
1241 $rank = $rank + 10;
1242 $this->cols['photo'] = array(
1243 'rank' => $rank,
1244 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1245 'status' => false,
1246 'title' => array(
1247 'textkey' => 'Photo',
1248 'label' => ' '
1249 ),
1250 'content' => array(
1251 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1252 ),
1253 'border-left' => false, // remove left line separator
1254 );
1255
1256 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1257 $this->cols['photo']['status'] = true;
1258 }
1259
1260
1261 $rank = $rank + 10;
1262 $this->cols['vat'] = array(
1263 'rank' => $rank,
1264 'status' => false,
1265 'width' => 16, // in mm
1266 'title' => array(
1267 'textkey' => 'VAT'
1268 ),
1269 'border-left' => true, // add left line separator
1270 );
1271
1272 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1273 $this->cols['vat']['status'] = true;
1274 }
1275
1276 $rank = $rank + 10;
1277 $this->cols['subprice'] = array(
1278 'rank' => $rank,
1279 'width' => 19, // in mm
1280 'status' => true,
1281 'title' => array(
1282 'textkey' => 'PriceUHT'
1283 ),
1284 'border-left' => true, // add left line separator
1285 );
1286
1287 $rank = $rank + 10;
1288 $this->cols['qty'] = array(
1289 'rank' => $rank,
1290 'width' => 16, // in mm
1291 'status' => true,
1292 'title' => array(
1293 'textkey' => 'Qty'
1294 ),
1295 'border-left' => true, // add left line separator
1296 );
1297
1298 $rank = $rank + 10;
1299 $this->cols['progress'] = array(
1300 'rank' => $rank,
1301 'width' => 19, // in mm
1302 'status' => false,
1303 'title' => array(
1304 'textkey' => 'Progress'
1305 ),
1306 'border-left' => true, // add left line separator
1307 );
1308
1309 if ($this->situationinvoice) {
1310 $this->cols['progress']['status'] = true;
1311 }
1312
1313 $rank = $rank + 10;
1314 $this->cols['unit'] = array(
1315 'rank' => $rank,
1316 'width' => 11, // in mm
1317 'status' => false,
1318 'title' => array(
1319 'textkey' => 'Unit'
1320 ),
1321 'border-left' => true, // add left line separator
1322 );
1323 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1324 $this->cols['unit']['status'] = true;
1325 }
1326
1327 $rank = $rank + 10;
1328 $this->cols['discount'] = array(
1329 'rank' => $rank,
1330 'width' => 13, // in mm
1331 'status' => false,
1332 'title' => array(
1333 'textkey' => 'ReductionShort'
1334 ),
1335 'border-left' => true, // add left line separator
1336 );
1337 if ($this->atleastonediscount) {
1338 $this->cols['discount']['status'] = true;
1339 }
1340
1341 $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1342 $this->cols['totalexcltax'] = array(
1343 'rank' => $rank,
1344 'width' => 26, // in mm
1345 'status' => true,
1346 'title' => array(
1347 'textkey' => 'TotalHT'
1348 ),
1349 'border-left' => true, // add left line separator
1350 );
1351
1352 // Add extrafields cols
1353 if (!empty($object->lines)) {
1354 $line = reset($object->lines);
1355 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1356 }
1357
1358 $parameters = array(
1359 'object' => $object,
1360 'outputlangs' => $outputlangs,
1361 'hidedetails' => $hidedetails,
1362 'hidedesc' => $hidedesc,
1363 'hideref' => $hideref
1364 );
1365
1366 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1367 if ($reshook < 0) {
1368 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1369 } elseif (empty($reshook)) {
1370 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1371 } else {
1372 $this->cols = $hookmanager->resArray;
1373 }
1374 }
1375}
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage hooks.
Parent class for documents models.
Class to manage translations.
Class to manage Dolibarr users.
Class to manage PDF template standard_asset.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:2529
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:85
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1010
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:726
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1338
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition pdf.lib.php:435
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:1986
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:758
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:387
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:778
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123