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