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