dolibarr 19.0.3
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 $situationinvoice;
81
85 public $cols;
86
87
93 public function __construct($db)
94 {
95 global $conf, $langs, $mysoc;
96
97 // Translations
98 $langs->loadLangs(array("main", "bills"));
99
100 $this->db = $db;
101 $this->name = "standard";
102 $this->description = $langs->trans('DocumentModelStandardPDF');
103 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
104
105 // Dimension page
106 $this->type = 'pdf';
107 $formatarray = pdf_getFormat();
108 $this->page_largeur = $formatarray['width'];
109 $this->page_hauteur = $formatarray['height'];
110 $this->format = array($this->page_largeur, $this->page_hauteur);
111 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
112 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
113 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
114 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
115
116 // Get source company
117 $this->emetteur = $mysoc;
118 if (empty($this->emetteur->country_code)) {
119 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
120 }
121
122 // Define position of columns
123 $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
124
125
126 $this->tabTitleHeight = 5; // default height
127
128 // Use new system for position of columns, view $this->defineColumnField()
129
130 $this->tva = array();
131 $this->localtax1 = array();
132 $this->localtax2 = array();
133 $this->atleastoneratenotnull = 0;
134 $this->atleastonediscount = 0;
135 $this->situationinvoice = false;
136 }
137
138
139 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
151 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
152 {
153 // phpcs:enable
154 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
155
156 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
157
158 if (!is_object($outputlangs)) {
159 $outputlangs = $langs;
160 }
161 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
162 if (getDolGlobalString('MAIN_USE_FPDF')) {
163 $outputlangs->charset_output = 'ISO-8859-1';
164 }
165
166 // Load translation files required by the page
167 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
168
169 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
170 global $outputlangsbis;
171 $outputlangsbis = new Translate('', $conf);
172 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
173 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
174 }
175
176 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
177
178 $hidetop = 0;
179 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
180 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
181 }
182
183 // Loop on each lines to detect if there is at least one image to show
184 $realpatharray = array();
185 $this->atleastonephoto = false;
186 /*
187 if (!empty($conf->global->MAIN_GENERATE_ASSET_WITH_PICTURE))
188 {
189 $objphoto = new Product($this->db);
190
191 for ($i = 0; $i < $nblines; $i++)
192 {
193 if (empty($object->lines[$i]->fk_product)) continue;
194
195 //var_dump($objphoto->ref);exit;
196 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
197 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
198 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
199 } else {
200 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
201 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
202 }
203
204 $arephoto = false;
205 foreach ($pdir as $midir)
206 {
207 if (!$arephoto)
208 {
209 $dir = $conf->product->dir_output.'/'.$midir;
210
211 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
212 {
213 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
214 {
215 if ($obj['photo_vignette'])
216 {
217 $filename = $obj['photo_vignette'];
218 } else {
219 $filename = $obj['photo'];
220 }
221 } else {
222 $filename = $obj['photo'];
223 }
224
225 $realpath = $dir.$filename;
226 $arephoto = true;
227 $this->atleastonephoto = true;
228 }
229 }
230 }
231
232 if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
233 }
234 }
235 */
236
237 //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
238
239 if ($conf->asset->dir_output.'/asset') {
240 $object->fetch_thirdparty();
241
242 // Definition of $dir and $file
243 if ($object->specimen) {
244 $dir = $conf->asset->dir_output.'/asset';
245 $file = $dir."/SPECIMEN.pdf";
246 } else {
247 $objectref = dol_sanitizeFileName($object->ref);
248 $dir = $conf->asset->dir_output.'/asset/'.$objectref;
249 $file = $dir."/".$objectref.".pdf";
250 }
251 if (!file_exists($dir)) {
252 if (dol_mkdir($dir) < 0) {
253 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
254 return 0;
255 }
256 }
257
258 if (file_exists($dir)) {
259 // Add pdfgeneration hook
260 if (!is_object($hookmanager)) {
261 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
262 $hookmanager = new HookManager($this->db);
263 }
264 $hookmanager->initHooks(array('pdfgeneration'));
265 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
266 global $action;
267 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
268
269 // Set nblines with the new facture lines content after hook
270 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
271
272 // Create pdf instance
273 $pdf = pdf_getInstance($this->format);
274 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
275 $pdf->SetAutoPageBreak(1, 0);
276
277 $heightforinfotot = 50; // Height reserved to output the info and total part and payment part
278 $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
279 $heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
280
281 if (class_exists('TCPDF')) {
282 $pdf->setPrintHeader(false);
283 $pdf->setPrintFooter(false);
284 }
285 $pdf->SetFont(pdf_getPDFFont($outputlangs));
286
287 // Set path to the background PDF File
288 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
289 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
290 $tplidx = $pdf->importPage(1);
291 }
292
293 $pdf->Open();
294 $pagenb = 0;
295 $pdf->SetDrawColor(128, 128, 128);
296
297 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
298 $pdf->SetSubject($outputlangs->transnoentities("PdfTitle"));
299 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
300 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
301 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
302 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
303 $pdf->SetCompression(false);
304 }
305
306 // Set certificate
307 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
308 // If user has no certificate, we try to take the company one
309 if (!$cert) {
310 $cert = !getDolGlobalString('CERTIFICATE_CRT') ? '' : $conf->global->CERTIFICATE_CRT;
311 }
312 // If a certificate is found
313 if ($cert) {
314 $info = array(
315 'Name' => $this->emetteur->name,
316 'Location' => getCountry($this->emetteur->country_code, 0),
317 'Reason' => 'ASSET',
318 'ContactInfo' => $this->emetteur->email
319 );
320 $pdf->setSignature($cert, $cert, $this->emetteur->name, '', 2, $info);
321 }
322
323 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
324
325 // New page
326 $pdf->AddPage();
327 if (!empty($tplidx)) {
328 $pdf->useTemplate($tplidx);
329 }
330 $pagenb++;
331
332 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
333 $pdf->SetFont('', '', $default_font_size - 1);
334 $pdf->MultiCell(0, 3, ''); // Set interline to 3
335 $pdf->SetTextColor(0, 0, 0);
336
337 $tab_top = 90 + $top_shift;
338 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
339 $tab_height = 130 - $top_shift;
340 $tab_height_newpage = 150;
341 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
342 $tab_height_newpage -= $top_shift;
343 }
344
345 $nexY = $tab_top - 1;
346
347 // Display notes
348 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
349 // Extrafields in note
350 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
351 if (!empty($extranote)) {
352 $notetoshow = dol_concatdesc($notetoshow, $extranote);
353 }
354
355 $pagenb = $pdf->getPage();
356 if ($notetoshow) {
357 $tab_top -= 2;
358
359 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
360 $pageposbeforenote = $pagenb;
361
362 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
363 complete_substitutions_array($substitutionarray, $outputlangs, $object);
364 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
365 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
366
367 $pdf->startTransaction();
368
369 $pdf->SetFont('', '', $default_font_size - 1);
370 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
371 // Description
372 $pageposafternote = $pdf->getPage();
373 $posyafter = $pdf->GetY();
374
375 if ($pageposafternote > $pageposbeforenote) {
376 $pdf->rollbackTransaction(true);
377
378 // prepare pages to receive notes
379 while ($pagenb < $pageposafternote) {
380 $pdf->AddPage();
381 $pagenb++;
382 if (!empty($tplidx)) {
383 $pdf->useTemplate($tplidx);
384 }
385 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
386 $this->_pagehead($pdf, $object, 0, $outputlangs);
387 }
388 // $this->_pagefoot($pdf,$object,$outputlangs,1);
389 $pdf->setTopMargin($tab_top_newpage);
390 // The only function to edit the bottom margin of current page to set it.
391 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
392 }
393
394 // back to start
395 $pdf->setPage($pageposbeforenote);
396 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
397 $pdf->SetFont('', '', $default_font_size - 1);
398 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
399 $pageposafternote = $pdf->getPage();
400
401 $posyafter = $pdf->GetY();
402
403 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
404 $pdf->AddPage('', '', true);
405 $pagenb++;
406 $pageposafternote++;
407 $pdf->setPage($pageposafternote);
408 $pdf->setTopMargin($tab_top_newpage);
409 // The only function to edit the bottom margin of current page to set it.
410 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
411 //$posyafter = $tab_top_newpage;
412 }
413
414
415 // apply note frame to previous pages
416 $i = $pageposbeforenote;
417 while ($i < $pageposafternote) {
418 $pdf->setPage($i);
419
420
421 $pdf->SetDrawColor(128, 128, 128);
422 // Draw note frame
423 if ($i > $pageposbeforenote) {
424 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
425 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
426 } else {
427 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
428 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
429 }
430
431 // Add footer
432 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
433 $this->_pagefoot($pdf, $object, $outputlangs, 1);
434
435 $i++;
436 }
437
438 // apply note frame to last page
439 $pdf->setPage($pageposafternote);
440 if (!empty($tplidx)) {
441 $pdf->useTemplate($tplidx);
442 }
443 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
444 $this->_pagehead($pdf, $object, 0, $outputlangs);
445 }
446 $height_note = $posyafter - $tab_top_newpage;
447 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
448 } else { // No pagebreak
449 $pdf->commitTransaction();
450 $posyafter = $pdf->GetY();
451 $height_note = $posyafter - $tab_top;
452 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
453
454
455 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
456 // not enough space, need to add page
457 $pdf->AddPage('', '', true);
458 $pagenb++;
459 $pageposafternote++;
460 $pdf->setPage($pageposafternote);
461 if (!empty($tplidx)) {
462 $pdf->useTemplate($tplidx);
463 }
464 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
465 $this->_pagehead($pdf, $object, 0, $outputlangs);
466 }
467
468 $posyafter = $tab_top_newpage;
469 }
470 }
471
472 $tab_height = $tab_height - $height_note;
473 $tab_top = $posyafter + 6;
474 } else {
475 $height_note = 0;
476 }
477
478 // Use new auto column system
479 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
480
481 // Table simulation to know the height of the title line
482 $pdf->startTransaction();
483 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
484 $pdf->rollbackTransaction(true);
485
486 $nexY = $tab_top + $this->tabTitleHeight;
487
488 // Loop on each lines
489 $pageposbeforeprintlines = $pdf->getPage();
490 $pagenb = $pageposbeforeprintlines;
491 for ($i = 0; $i < $nblines; $i++) {
492 $curY = $nexY;
493 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
494 $pdf->SetTextColor(0, 0, 0);
495
496 // Define size of image if we need it
497 $imglinesize = array();
498 if (!empty($realpatharray[$i])) {
499 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
500 }
501
502 $pdf->setTopMargin($tab_top_newpage);
503 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
504 $pageposbefore = $pdf->getPage();
505
506 $showpricebeforepagebreak = 1;
507 $posYAfterImage = 0;
508
509 if ($this->getColumnStatus('photo')) {
510 // We start with Photo of product line
511 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
512 $pdf->AddPage('', '', true);
513 if (!empty($tplidx)) {
514 $pdf->useTemplate($tplidx);
515 }
516 $pdf->setPage($pageposbefore + 1);
517
518 $curY = $tab_top_newpage;
519
520 // Allows data in the first page if description is long enough to break in multiples pages
521 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
522 $showpricebeforepagebreak = 1;
523 } else {
524 $showpricebeforepagebreak = 0;
525 }
526 }
527
528 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
529 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
530 // $pdf->Image does not increase value return by getY, so we save it manually
531 $posYAfterImage = $curY + $imglinesize['height'];
532 }
533 }
534
535 // Description of product line
536 if ($this->getColumnStatus('desc')) {
537 $pdf->startTransaction();
538
539 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
540 $pageposafter = $pdf->getPage();
541
542 if ($pageposafter > $pageposbefore) { // There is a pagebreak
543 $pdf->rollbackTransaction(true);
544 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
545
546 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
547
548 $pageposafter = $pdf->getPage();
549 $posyafter = $pdf->GetY();
550 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
551 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
552 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
553 $pdf->AddPage('', '', true);
554 if (!empty($tplidx)) {
555 $pdf->useTemplate($tplidx);
556 }
557 $pdf->setPage($pageposafter + 1);
558 }
559 } else {
560 // We found a page break
561 // Allows data in the first page if description is long enough to break in multiples pages
562 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
563 $showpricebeforepagebreak = 1;
564 } else {
565 $showpricebeforepagebreak = 0;
566 }
567 }
568 } else { // No pagebreak
569 $pdf->commitTransaction();
570 }
571 }
572
573 $nexY = $pdf->GetY();
574 $pageposafter = $pdf->getPage();
575 $pdf->setPage($pageposbefore);
576 $pdf->setTopMargin($this->marge_haute);
577 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
578
579 // We suppose that a too long description or photo were moved completely on next page
580 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
581 $pdf->setPage($pageposafter);
582 $curY = $tab_top_newpage;
583 }
584
585 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
586
587 // Quantity
588 // Enough for 6 chars
589 if ($this->getColumnStatus('qty')) {
590 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
591 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
592 $nexY = max($pdf->GetY(), $nexY);
593 }
594
595 // Extrafields
596 if (!empty($object->lines[$i]->array_options)) {
597 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
598 if ($this->getColumnStatus($extrafieldColKey)) {
599 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
600 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
601 $nexY = max($pdf->GetY(), $nexY);
602 }
603 }
604 }
605
606
607 $parameters = array(
608 'object' => $object,
609 'i' => $i,
610 'pdf' =>& $pdf,
611 'curY' =>& $curY,
612 'nexY' =>& $nexY,
613 'outputlangs' => $outputlangs,
614 'hidedetails' => $hidedetails
615 );
616 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
617
618
619 $sign = 1;
620 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
621 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
622 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
623 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
624 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
625 } else {
626 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
627 }
628 } else {
629 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
630 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
631 } else {
632 $tvaligne = $sign * $object->lines[$i]->total_tva;
633 }
634 }
635
636 $localtax1ligne = $object->lines[$i]->total_localtax1;
637 $localtax2ligne = $object->lines[$i]->total_localtax2;
638 $localtax1_rate = $object->lines[$i]->localtax1_tx;
639 $localtax2_rate = $object->lines[$i]->localtax2_tx;
640 $localtax1_type = $object->lines[$i]->localtax1_type;
641 $localtax2_type = $object->lines[$i]->localtax2_type;
642
643 // TODO remise_percent is an obsolete field for object parent
644 /*if ($object->remise_percent) {
645 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
646 }
647 if ($object->remise_percent) {
648 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
649 }
650 if ($object->remise_percent) {
651 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
652 }*/
653
654 $vatrate = (string) $object->lines[$i]->tva_tx;
655
656 // Retrieve type from database for backward compatibility with old records
657 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
658 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
659 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
660 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
661 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
662 }
663
664 // retrieve global local tax
665 if ($localtax1_type && $localtax1ligne != 0) {
666 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
667 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
668 } else {
669 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
670 }
671 }
672 if ($localtax2_type && $localtax2ligne != 0) {
673 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
674 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
675 } else {
676 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
677 }
678 }
679
680 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
681 $vatrate .= '*';
682 }
683 if (!isset($this->tva[$vatrate])) {
684 $this->tva[$vatrate] = 0;
685 }
686 $this->tva[$vatrate] += $tvaligne;
687
688 $nexY = max($nexY, $posYAfterImage);
689
690 // Add line
691 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
692 $pdf->setPage($pageposafter);
693 $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
694 //$pdf->SetDrawColor(190,190,200);
695 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
696 $pdf->SetLineStyle(array('dash'=>0));
697 }
698
699 // Detect if some page were added automatically and output _tableau for past pages
700 while ($pagenb < $pageposafter) {
701 $pdf->setPage($pagenb);
702 if ($pagenb == $pageposbeforeprintlines) {
703 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
704 } else {
705 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
706 }
707 $this->_pagefoot($pdf, $object, $outputlangs, 1);
708 $pagenb++;
709 $pdf->setPage($pagenb);
710 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
711 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
712 $this->_pagehead($pdf, $object, 0, $outputlangs);
713 }
714 }
715
716 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
717 if ($pagenb == $pageposafter) {
718 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
719 } else {
720 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
721 }
722 $this->_pagefoot($pdf, $object, $outputlangs, 1);
723 // New page
724 $pdf->AddPage();
725 if (!empty($tplidx)) {
726 $pdf->useTemplate($tplidx);
727 }
728 $pagenb++;
729 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
730 $this->_pagehead($pdf, $object, 0, $outputlangs);
731 }
732 }
733 }
734
735 // Show square
736 if ($pagenb == $pageposbeforeprintlines) {
737 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
738 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
739 } else {
740 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
741 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
742 }
743
744 // Display infos area
745 //$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
746
747 // Display total zone
748 //$posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
749
750 // Display payment area
751 /*
752 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
753 {
754 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
755 }
756 */
757
758 // Pagefoot
759 $this->_pagefoot($pdf, $object, $outputlangs);
760 if (method_exists($pdf, 'AliasNbPages')) {
761 $pdf->AliasNbPages();
762 }
763
764 $pdf->Close();
765
766 $pdf->Output($file, 'F');
767
768 // Add pdfgeneration hook
769 $hookmanager->initHooks(array('pdfgeneration'));
770 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
771 global $action;
772 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
773 if ($reshook < 0) {
774 $this->error = $hookmanager->error;
775 $this->errors = $hookmanager->errors;
776 }
777
778 dolChmod($file);
779
780 $this->result = array('fullpath'=>$file);
781
782 return 1; // No error
783 } else {
784 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
785 return 0;
786 }
787 } else {
788 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
789 return 0;
790 }
791 }
792
793 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
801 public static function liste_modeles($db, $maxfilenamelength = 0)
802 {
803 // phpcs:enable
804 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
805 }
806
807 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
822 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
823 {
824 global $conf;
825
826 // Force to disable hidetop and hidebottom
827 $hidebottom = 0;
828 if ($hidetop) {
829 $hidetop = -1;
830 }
831
832 $currency = !empty($currency) ? $currency : $conf->currency;
833 $default_font_size = pdf_getPDFFontSize($outputlangs);
834
835 // Amount in (at tab_top - 1)
836 $pdf->SetTextColor(0, 0, 0);
837 $pdf->SetFont('', '', $default_font_size - 2);
838
839 if (empty($hidetop)) {
840 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
841 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
842 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
843 }
844
845 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
846 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
847
848 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
849 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
850 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
851 }
852 }
853
854 $pdf->SetDrawColor(128, 128, 128);
855 $pdf->SetFont('', '', $default_font_size - 1);
856
857 // Output Rect
858 $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
859
860
861 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
862
863 if (empty($hidetop)) {
864 $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
865 }
866 }
867
868 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
879 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
880 {
881 global $conf, $langs;
882
883 // Load traductions files required by page
884 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
885
886 $default_font_size = pdf_getPDFFontSize($outputlangs);
887
888 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
889
890 // Show Draft Watermark
891 if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
892 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
893 }
894
895 $pdf->SetTextColor(0, 0, 60);
896 $pdf->SetFont('', 'B', $default_font_size + 3);
897
898 $w = 110;
899
900 $posy = $this->marge_haute;
901 $posx = $this->page_largeur - $this->marge_droite - $w;
902
903 $pdf->SetXY($this->marge_gauche, $posy);
904
905 // Logo
906 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
907 if ($this->emetteur->logo) {
908 $logodir = $conf->mycompany->dir_output;
909 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
910 $logodir = $conf->mycompany->multidir_output[$object->entity];
911 }
912 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
913 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
914 } else {
915 $logo = $logodir.'/logos/'.$this->emetteur->logo;
916 }
917 if (is_readable($logo)) {
918 $height = pdf_getHeightForLogo($logo);
919 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
920 } else {
921 $pdf->SetTextColor(200, 0, 0);
922 $pdf->SetFont('', 'B', $default_font_size - 2);
923 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
924 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
925 }
926 } else {
927 $text = $this->emetteur->name;
928 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
929 }
930 }
931
932 $pdf->SetFont('', 'B', $default_font_size + 3);
933 $pdf->SetXY($posx, $posy);
934 $pdf->SetTextColor(0, 0, 60);
935 $title = $outputlangs->transnoentities("PdfTitle");
936 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
937 $title .= ' - ';
938 $title .= $outputlangsbis->transnoentities("PdfTitle");
939 }
940 $pdf->MultiCell($w, 3, $title, '', 'R');
941
942 $pdf->SetFont('', 'B', $default_font_size);
943
944 $posy += 5;
945 $pdf->SetXY($posx, $posy);
946 $pdf->SetTextColor(0, 0, 60);
947 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
948 if ($object->statut == $object::STATUS_DRAFT) {
949 $pdf->SetTextColor(128, 0, 0);
950 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
951 }
952 $pdf->MultiCell($w, 4, $textref, '', 'R');
953
954 $posy += 1;
955 $pdf->SetFont('', '', $default_font_size - 2);
956
957 if ($object->ref_client) {
958 $posy += 4;
959 $pdf->SetXY($posx, $posy);
960 $pdf->SetTextColor(0, 0, 60);
961 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
962 }
963
964 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
965 $object->fetch_projet();
966 if (!empty($object->project->ref)) {
967 $posy += 3;
968 $pdf->SetXY($posx, $posy);
969 $pdf->SetTextColor(0, 0, 60);
970 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
971 }
972 }
973
974 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
975 $object->fetch_projet();
976 if (!empty($object->project->ref)) {
977 $outputlangs->load("projects");
978 $posy += 3;
979 $pdf->SetXY($posx, $posy);
980 $pdf->SetTextColor(0, 0, 60);
981 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
982 }
983 }
984
985 $posy += 4;
986 $pdf->SetXY($posx, $posy);
987 $pdf->SetTextColor(0, 0, 60);
988
989 $title = $outputlangs->transnoentities("Date");
990 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
991 $title .= ' - '.$outputlangsbis->transnoentities("Date");
992 }
993 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
994
995 if ($object->thirdparty->code_client) {
996 $posy += 3;
997 $pdf->SetXY($posx, $posy);
998 $pdf->SetTextColor(0, 0, 60);
999 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1000 }
1001
1002 // Get contact
1003 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1004 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1005 if (count($arrayidcontact) > 0) {
1006 $usertmp = new User($this->db);
1007 $usertmp->fetch($arrayidcontact[0]);
1008 $posy += 4;
1009 $pdf->SetXY($posx, $posy);
1010 $pdf->SetTextColor(0, 0, 60);
1011 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1012 }
1013 }
1014
1015 $posy += 1;
1016
1017 $top_shift = 0;
1018 // Show list of linked objects
1019 $current_y = $pdf->getY();
1020 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1021 if ($current_y < $pdf->getY()) {
1022 $top_shift = $pdf->getY() - $current_y;
1023 }
1024
1025 if ($showaddress) {
1026 // Sender properties
1027 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1028
1029 // Show sender
1030 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1031 $posy += $top_shift;
1032 $posx = $this->marge_gauche;
1033 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1034 $posx = $this->page_largeur - $this->marge_droite - 80;
1035 }
1036
1037 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1038 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1039
1040
1041 // Show sender frame
1042 $pdf->SetTextColor(0, 0, 0);
1043 $pdf->SetFont('', '', $default_font_size - 2);
1044 $pdf->SetXY($posx, $posy - 5);
1045 $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1046 $pdf->SetXY($posx, $posy);
1047 $pdf->SetFillColor(230, 230, 230);
1048 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1049 $pdf->SetTextColor(0, 0, 60);
1050
1051 // Show sender name
1052 $pdf->SetXY($posx + 2, $posy + 3);
1053 $pdf->SetFont('', 'B', $default_font_size);
1054 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1055 $posy = $pdf->getY();
1056
1057 // Show sender information
1058 $pdf->SetXY($posx + 2, $posy);
1059 $pdf->SetFont('', '', $default_font_size - 1);
1060 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1061
1062 // If BILLING contact defined on invoice, we use it
1063 $usecontact = false;
1064 $arrayidcontact = $object->getIdContact('external', 'BILLING');
1065 if (count($arrayidcontact) > 0) {
1066 $usecontact = true;
1067 $result = $object->fetch_contact($arrayidcontact[0]);
1068 }
1069
1070 // Recipient name
1071 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
1072 $thirdparty = $object->contact;
1073 } else {
1074 $thirdparty = $object->thirdparty;
1075 }
1076
1077 if (is_object($thirdparty)) {
1078 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1079 }
1080
1081 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1082
1083 // Show recipient
1084 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1085 if ($this->page_largeur < 210) {
1086 $widthrecbox = 84; // To work with US executive format
1087 }
1088 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1089 $posy += $top_shift;
1090 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1091 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1092 $posx = $this->marge_gauche;
1093 }
1094
1095 // Show recipient frame
1096 $pdf->SetTextColor(0, 0, 0);
1097 $pdf->SetFont('', '', $default_font_size - 2);
1098 $pdf->SetXY($posx + 2, $posy - 5);
1099 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1100 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1101
1102 // Show recipient name
1103 $pdf->SetXY($posx + 2, $posy + 3);
1104 $pdf->SetFont('', 'B', $default_font_size);
1105 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1106
1107 $posy = $pdf->getY();
1108
1109 // Show recipient information
1110 $pdf->SetFont('', '', $default_font_size - 1);
1111 $pdf->SetXY($posx + 2, $posy);
1112 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1113 }
1114
1115 $pdf->SetTextColor(0, 0, 0);
1116 return $top_shift;
1117 }
1118
1119 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1129 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1130 {
1131 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1132 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1133 }
1134
1145 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1146 {
1147 global $conf, $hookmanager;
1148
1149 // Default field style for content
1150 $this->defaultContentsFieldsStyle = array(
1151 'align' => 'R', // R,C,L
1152 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1153 );
1154
1155 // Default field style for content
1156 $this->defaultTitlesFieldsStyle = array(
1157 'align' => 'C', // R,C,L
1158 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1159 );
1160
1161 /*
1162 * For exemple
1163 $this->cols['theColKey'] = array(
1164 'rank' => $rank, // int : use for ordering columns
1165 'width' => 20, // the column width in mm
1166 'title' => array(
1167 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1168 'label' => ' ', // the final label : used fore final generated text
1169 'align' => 'L', // text alignement : R,C,L
1170 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1171 ),
1172 'content' => array(
1173 'align' => 'L', // text alignement : R,C,L
1174 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1175 ),
1176 );
1177 */
1178
1179 $rank = 0; // do not use negative rank
1180 $this->cols['desc'] = array(
1181 'rank' => $rank,
1182 'width' => false, // only for desc
1183 'status' => true,
1184 'title' => array(
1185 'textkey' => 'Designation', // use lang key is usefull in somme case with module
1186 'align' => 'L',
1187 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1188 // 'label' => ' ', // the final label
1189 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1190 ),
1191 'content' => array(
1192 'align' => 'L',
1193 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1194 ),
1195 );
1196
1197 // PHOTO
1198 $rank = $rank + 10;
1199 $this->cols['photo'] = array(
1200 'rank' => $rank,
1201 'width' => (!getDolGlobalString('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH') ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1202 'status' => false,
1203 'title' => array(
1204 'textkey' => 'Photo',
1205 'label' => ' '
1206 ),
1207 'content' => array(
1208 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1209 ),
1210 'border-left' => false, // remove left line separator
1211 );
1212
1213 if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
1214 $this->cols['photo']['status'] = true;
1215 }
1216
1217
1218 $rank = $rank + 10;
1219 $this->cols['vat'] = array(
1220 'rank' => $rank,
1221 'status' => false,
1222 'width' => 16, // in mm
1223 'title' => array(
1224 'textkey' => 'VAT'
1225 ),
1226 'border-left' => true, // add left line separator
1227 );
1228
1229 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1230 $this->cols['vat']['status'] = true;
1231 }
1232
1233 $rank = $rank + 10;
1234 $this->cols['subprice'] = array(
1235 'rank' => $rank,
1236 'width' => 19, // in mm
1237 'status' => true,
1238 'title' => array(
1239 'textkey' => 'PriceUHT'
1240 ),
1241 'border-left' => true, // add left line separator
1242 );
1243
1244 $rank = $rank + 10;
1245 $this->cols['qty'] = array(
1246 'rank' => $rank,
1247 'width' => 16, // in mm
1248 'status' => true,
1249 'title' => array(
1250 'textkey' => 'Qty'
1251 ),
1252 'border-left' => true, // add left line separator
1253 );
1254
1255 $rank = $rank + 10;
1256 $this->cols['progress'] = array(
1257 'rank' => $rank,
1258 'width' => 19, // in mm
1259 'status' => false,
1260 'title' => array(
1261 'textkey' => 'Progress'
1262 ),
1263 'border-left' => true, // add left line separator
1264 );
1265
1266 if ($this->situationinvoice) {
1267 $this->cols['progress']['status'] = true;
1268 }
1269
1270 $rank = $rank + 10;
1271 $this->cols['unit'] = array(
1272 'rank' => $rank,
1273 'width' => 11, // in mm
1274 'status' => false,
1275 'title' => array(
1276 'textkey' => 'Unit'
1277 ),
1278 'border-left' => true, // add left line separator
1279 );
1280 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1281 $this->cols['unit']['status'] = true;
1282 }
1283
1284 $rank = $rank + 10;
1285 $this->cols['discount'] = array(
1286 'rank' => $rank,
1287 'width' => 13, // in mm
1288 'status' => false,
1289 'title' => array(
1290 'textkey' => 'ReductionShort'
1291 ),
1292 'border-left' => true, // add left line separator
1293 );
1294 if ($this->atleastonediscount) {
1295 $this->cols['discount']['status'] = true;
1296 }
1297
1298 $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1299 $this->cols['totalexcltax'] = array(
1300 'rank' => $rank,
1301 'width' => 26, // in mm
1302 'status' => true,
1303 'title' => array(
1304 'textkey' => 'TotalHT'
1305 ),
1306 'border-left' => true, // add left line separator
1307 );
1308
1309 // Add extrafields cols
1310 if (!empty($object->lines)) {
1311 $line = reset($object->lines);
1312 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1313 }
1314
1315 $parameters = array(
1316 'object' => $object,
1317 'outputlangs' => $outputlangs,
1318 'hidedetails' => $hidedetails,
1319 'hidedesc' => $hidedesc,
1320 'hideref' => $hideref
1321 );
1322
1323 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1324 if ($reshook < 0) {
1325 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1326 } elseif (empty($reshook)) {
1327 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1328 } else {
1329 $this->cols = $hookmanager->resArray;
1330 }
1331 }
1332}
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 a 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: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_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:2062
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
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:782
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