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