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