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