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