dolibarr 18.0.6
pdf_strato.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
6 * Copyright (C) 2011 Fabrice CHERRIER
7 * Copyright (C) 2013-2020 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
10 * Copyright (C) 2024 Éric Seigne <eric.seigne@cap-rel.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
32require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
37
38
43{
47 public $db;
48
52 public $entity;
53
57 public $name;
58
62 public $description;
63
67 public $update_main_doc_field;
68
72 public $type;
73
78 public $version = 'dolibarr';
79
83 public $page_largeur;
84
88 public $page_hauteur;
89
93 public $format;
94
98 public $marge_gauche;
99
103 public $marge_droite;
104
108 public $marge_haute;
109
113 public $marge_basse;
114
119 public $emetteur;
120
125 public $recipient;
126
132 public function __construct($db)
133 {
134 global $conf, $langs, $mysoc;
135
136 $this->db = $db;
137 $this->name = 'strato';
138 $this->description = $langs->trans("StandardContractsTemplate");
139 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
140
141 // Dimension page
142 $this->type = 'pdf';
143 $formatarray = pdf_getFormat();
144
145 $this->page_largeur = $formatarray['width'];
146 $this->page_hauteur = $formatarray['height'];
147 $this->format = array($this->page_largeur, $this->page_hauteur);
148 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
149 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
150 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
151 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
152
153 $this->option_logo = 1; // Display logo
154 $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
155 $this->option_modereg = 0; // Display payment mode
156 $this->option_condreg = 0; // Display payment terms
157 $this->option_multilang = 0; // Available in several languages
158 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
159
160 // Get source company
161 $this->emetteur = $mysoc;
162 if (empty($this->emetteur->country_code)) {
163 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
164 }
165
166 // Define position of columns
167 $this->posxdesc = $this->marge_gauche + 1;
168 }
169
170 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
182 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
183 {
184 // phpcs:enable
185 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
186
187 if (!is_object($outputlangs)) {
188 $outputlangs = $langs;
189 }
190 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
191 if (!empty($conf->global->MAIN_USE_FPDF)) {
192 $outputlangs->charset_output = 'ISO-8859-1';
193 }
194
195 // Load translation files required by page
196 $outputlangs->loadLangs(array("main", "dict", "companies", "contracts"));
197
198 // Show Draft Watermark
199 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->CONTRACT_DRAFT_WATERMARK))) {
200 $this->watermark = $conf->global->CONTRACT_DRAFT_WATERMARK;
201 }
202
203 global $outputlangsbis;
204 $outputlangsbis = null;
205 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
206 $outputlangsbis = new Translate('', $conf);
207 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
208 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
209 }
210
211 $nblines = count($object->lines);
212
213 if ($conf->contract->multidir_output[$conf->entity]) {
214 $object->fetch_thirdparty();
215
216 // Definition of $dir and $file
217 if ($object->specimen) {
218 $dir = $conf->contract->multidir_output[$conf->entity];
219 $file = $dir."/SPECIMEN.pdf";
220 } else {
221 $objectref = dol_sanitizeFileName($object->ref);
222 $dir = $conf->contrat->multidir_output[$object->entity]."/".$objectref;
223 $file = $dir."/".$objectref.".pdf";
224 }
225
226 if (!file_exists($dir)) {
227 if (dol_mkdir($dir) < 0) {
228 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
229 return 0;
230 }
231 }
232
233 if (file_exists($dir)) {
234 // Add pdfgeneration hook
235 if (!is_object($hookmanager)) {
236 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
237 $hookmanager = new HookManager($this->db);
238 }
239 $hookmanager->initHooks(array('pdfgeneration'));
240 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
241 global $action;
242 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
243
244 // Set nblines with the new command lines content after hook
245 $nblines = count($object->lines);
246
247 // Create pdf instance
248 $pdf = pdf_getInstance($this->format);
249 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
250 $pdf->SetAutoPageBreak(1, 0);
251
252 $heightforinfotot = 50; // Height reserved to output the info and total part
253 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
254 $heightforfooter = $this->marge_basse + 9; // Height reserved to output the footer (value include bottom margin)
255 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
256 $heightforfooter += 6;
257 }
258
259 if (class_exists('TCPDF')) {
260 $pdf->setPrintHeader(false);
261 $pdf->setPrintFooter(false);
262 }
263 $pdf->SetFont(pdf_getPDFFont($outputlangs));
264 // Set path to the background PDF File
265 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
266 $logodir = $conf->mycompany->dir_output;
267 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
268 $logodir = $conf->mycompany->multidir_output[$object->entity];
269 }
270 $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
271 $tplidx = $pdf->importPage(1);
272 }
273
274 $pdf->Open();
275 $pagenb = 0;
276 $pdf->SetDrawColor(128, 128, 128);
277
278 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
279 $pdf->SetSubject($outputlangs->transnoentities("Contract"));
280 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
281 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
282 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Contract")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
283 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
284 $pdf->SetCompression(false);
285 }
286
287 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
288
289 // New page
290 $pdf->AddPage();
291 if (!empty($tplidx)) {
292 $pdf->useTemplate($tplidx);
293 }
294 $pagenb++;
295 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
296 $pdf->SetFont('', '', $default_font_size - 1);
297 $pdf->MultiCell(0, 3, ''); // Set interline to 3
298 $pdf->SetTextColor(0, 0, 0);
299
300 $tab_top = 90;
301 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
302
303 // Display notes
304 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
305
306 // Extrafields in note
307 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
308 if (!empty($extranote)) {
309 $notetoshow = dol_concatdesc($notetoshow, $extranote);
310 }
311
312 if (!empty($notetoshow)) {
313 $tab_top -= 2;
314
315 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
316 complete_substitutions_array($substitutionarray, $outputlangs, $object);
317 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
318 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
319
320 $pdf->SetFont('', '', $default_font_size - 1);
321 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
322 $nexY = $pdf->GetY();
323 $height_note = $nexY - $tab_top;
324
325 // Rect takes a length in 3rd parameter
326 $pdf->SetDrawColor(192, 192, 192);
327 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
328
329 $tab_top = $nexY + 6;
330 }
331
332 $iniY = $tab_top + 7;
333 $curY = $tab_top + 7;
334 $nexY = $tab_top + 2;
335
336 $pdf->SetXY($this->marge_gauche, $tab_top);
337
338 $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
339
340 $nblines = count($object->lines);
341
342 // Loop on each lines
343 for ($i = 0; $i < $nblines; $i++) {
344 $objectligne = $object->lines[$i];
345
346 $valide = $objectligne->id ? 1 : 0;
347
348 if ($valide > 0 || $object->specimen) {
349 $curX = $this->posxdesc - 1;
350 $curY = $nexY;
351 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
352 $pdf->SetTextColor(0, 0, 0);
353
354 $pdf->setTopMargin($tab_top_newpage);
355 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
356 $pageposbefore = $pdf->getPage();
357
358 // Description of product line
359
360 if (!empty($objectligne->date_start)) {
361 $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
362 } else {
363 $datei = $langs->trans("Unknown");
364 }
365
366 if (!empty($objectligne->date_end)) {
367 $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
368 $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
369 } else {
370 $durationi = $langs->trans("Unknown");
371 $datee = $langs->trans("Unknown");
372 }
373
374 if (!empty($objectligne->date_start_real)) {
375 $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
376 } else {
377 $daters = $langs->trans("Unknown");
378 }
379
380 if (!empty($objectligne->date_end_real)) {
381 $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
382 } else {
383 $datere = $langs->trans("Unknown");
384 }
385
386 $txtpredefinedservice = $objectligne->product_ref;
387 if ($objectligne->product_label) {
388 $txtpredefinedservice .= ' - ';
389 $txtpredefinedservice .= $objectligne->product_label;
390 }
391
392 $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
393 $txt = '';
394 if (empty($conf->global->CONTRACT_HIDE_QTY_ON_PDF)) {
395 $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
396 }
397 if (empty($conf->global->CONTRACT_HIDE_PRICE_ON_PDF)) {
398 $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
399 }
400 if (empty($conf->global->CONTRACT_HIDE_PLANNED_DATE_ON_PDF)) {
401 $txt .= '<br>';
402 $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
403 }
404 if (empty($conf->global->CONTRACT_HIDE_REAL_DATE_ON_PDF)) {
405 $txt .= '<br>';
406 $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
407 if (!empty($objectligne->date_end_real)) {
408 $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : '<strong>'".$datere.'</strong>';
409 }
410 }
411
412 $pdf->startTransaction();
413 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
414 $pageposafter = $pdf->getPage();
415 if ($pageposafter > $pageposbefore) { // There is a pagebreak
416 $pdf->rollbackTransaction(true);
417 $pageposafter = $pageposbefore;
418 //print $pageposafter.'-'.$pageposbefore;exit;
419 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
420 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
421 $pageposafter = $pdf->getPage();
422 $posyafter = $pdf->GetY();
423 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
424 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
425 $pdf->AddPage('', '', true);
426 if (!empty($tplidx)) {
427 $pdf->useTemplate($tplidx);
428 }
429 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
430 $this->_pagehead($pdf, $object, 0, $outputlangs);
431 }
432 $pdf->setPage($pageposafter + 1);
433 }
434 } else {
435 // We found a page break
436
437 // Allows data in the first page if description is long enough to break in multiples pages
438 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
439 $showpricebeforepagebreak = 1;
440 } else {
441 $showpricebeforepagebreak = 0;
442 }
443 }
444 } else // No pagebreak
445 {
446 $pdf->commitTransaction();
447 }
448 $posYAfterDescription = $pdf->GetY();
449
450 $nexY = $pdf->GetY() + 2;
451 $pageposafter = $pdf->getPage();
452
453 $pdf->setPage($pageposbefore);
454 $pdf->setTopMargin($this->marge_haute);
455 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
456
457 // We suppose that a too long description is moved completely on next page
458 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
459 $pdf->setPage($pageposafter);
460 $curY = $tab_top_newpage;
461 }
462
463 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
464
465 // Detect if some page were added automatically and output _tableau for past pages
466 while ($pagenb < $pageposafter) {
467 $pdf->setPage($pagenb);
468 if ($pagenb == 1) {
469 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
470 } else {
471 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
472 }
473 $this->_pagefoot($pdf, $object, $outputlangs, 1);
474 $pagenb++;
475 $pdf->setPage($pagenb);
476 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
477 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
478 $this->_pagehead($pdf, $object, 0, $outputlangs);
479 }
480 if (!empty($tplidx)) {
481 $pdf->useTemplate($tplidx);
482 }
483 }
484
485 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
486 if ($pagenb == 1) {
487 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
488 } else {
489 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
490 }
491 $this->_pagefoot($pdf, $object, $outputlangs, 1);
492 // New page
493 $pdf->AddPage();
494 if (!empty($tplidx)) {
495 $pdf->useTemplate($tplidx);
496 }
497 $pagenb++;
498 }
499 }
500 }
501
502
503 // Show square
504 if ($pagenb == 1) {
505 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
506 $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
507 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
508 } else {
509 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
510 $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
511 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
512 }
513
514 $this->_pagefoot($pdf, $object, $outputlangs);
515 if (method_exists($pdf, 'AliasNbPages')) {
516 $pdf->AliasNbPages();
517 }
518
519 $pdf->Close();
520
521 $pdf->Output($file, 'F');
522
523 // Add pdfgeneration hook
524 $hookmanager->initHooks(array('pdfgeneration'));
525 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
526 global $action;
527 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
528 if ($reshook < 0) {
529 $this->error = $hookmanager->error;
530 $this->errors = $hookmanager->errors;
531 }
532
533 dolChmod($file);
534
535 $this->result = array('fullpath'=>$file);
536
537 return 1; // No error
538 } else {
539 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
540 return 0;
541 }
542 } else {
543 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
544 return 0;
545 }
546 }
547
548 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
561 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
562 {
563 global $conf;
564
565 // Force to disable hidetop and hidebottom
566 $hidebottom = 0;
567 if ($hidetop) {
568 $hidetop = -1;
569 }
570
571 $currency = !empty($currency) ? $currency : $conf->currency;
572 $default_font_size = pdf_getPDFFontSize($outputlangs);
573
574 /*
575 $pdf->SetXY($this->marge_gauche, $tab_top);
576 $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
577 $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
578
579 $pdf->SetFont('','', $default_font_size - 1);
580
581 $pdf->MultiCell(0, 3, ''); // Set interline to 3
582 $pdf->SetXY($this->marge_gauche, $tab_top + 8);
583 $text=$object->description;
584 if ($object->duree > 0)
585 {
586 $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
587 $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
588 }
589 $desc=dol_htmlentitiesbr($text,1);
590 //print $outputlangs->convToOutputCharset($desc); exit;
591
592 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
593 $nexY = $pdf->GetY();
594
595 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
596
597 $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
598 */
599
600 // Output Rect
601 $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 3); // Rect takes a length in 3rd parameter and 4th parameter
602 }
603
612 protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
613 {
614 $pdf->SetDrawColor(128, 128, 128);
615 $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
616 $posy = $tab_top + $tab_height + 3 + 3;
617
618 $pdf->SetXY($this->marge_gauche, $posy);
619 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
620
621 $pdf->SetXY($this->marge_gauche, $posy + 5);
622 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 20, '', 1);
623
624 $pdf->SetXY($posmiddle + 5, $posy);
625 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
626
627 $pdf->SetXY($posmiddle + 5, $posy + 5);
628 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, '', 1);
629 }
630
631 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
643 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "Contract")
644 {
645 // phpcs:enable
646 global $conf, $langs, $hookmanager;
647
648 $ltrdirection = 'L';
649 if ($outputlangs->trans("DIRECTION") == 'rtl') {
650 $ltrdirection = 'R';
651 }
652
653 // Load traductions files required by page
654 $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
655
656 $default_font_size = pdf_getPDFFontSize($outputlangs);
657
658 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
659
660 $pdf->SetTextColor(0, 0, 60);
661 $pdf->SetFont('', 'B', $default_font_size + 3);
662
663 $w = 100;
664
665 $posy = $this->marge_haute;
666 $posx = $this->page_largeur - $this->marge_droite - $w;
667
668 $pdf->SetXY($this->marge_gauche, $posy);
669
670 // Logo
671 if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
672 if ($this->emetteur->logo) {
673 $logodir = $conf->mycompany->dir_output;
674 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
675 $logodir = $conf->mycompany->multidir_output[$object->entity];
676 }
677 if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
678 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
679 } else {
680 $logo = $logodir.'/logos/'.$this->emetteur->logo;
681 }
682 if (is_readable($logo)) {
683 $height = pdf_getHeightForLogo($logo);
684 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
685 } else {
686 $pdf->SetTextColor(200, 0, 0);
687 $pdf->SetFont('', 'B', $default_font_size - 2);
688 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
689 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
690 }
691 } else {
692 $text = $this->emetteur->name;
693 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
694 }
695 }
696
697 $pdf->SetFont('', 'B', $default_font_size + 3);
698 $pdf->SetXY($posx, $posy);
699 $pdf->SetTextColor(0, 0, 60);
700 $title = $outputlangs->transnoentities($titlekey);
701 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
702 if ($object->statut == $object::STATUS_DRAFT) {
703 $pdf->SetTextColor(128, 0, 0);
704 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
705 }
706 $pdf->MultiCell($w, 3, $title, '', 'R');
707
708 $pdf->SetFont('', 'B', $default_font_size);
709
710 /*
711 $posy += 5;
712 $pdf->SetXY($posx, $posy);
713 $pdf->SetTextColor(0, 0, 60);
714 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
715 */
716
717 $posy += 3;
718 $pdf->SetFont('', '', $default_font_size - 1);
719
720 $posy += 4;
721 $pdf->SetXY($posx, $posy);
722 $pdf->SetTextColor(0, 0, 60);
723 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
724
725 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
726 $posy += 4;
727 $pdf->SetXY($posx, $posy);
728 $pdf->SetTextColor(0, 0, 60);
729 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
730 }
731
732 if ($showaddress) {
733 // Sender properties
734 $carac_emetteur = '';
735 // Add internal contact of object if defined
736 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
737 if (count($arrayidcontact) > 0) {
738 $object->fetch_user($arrayidcontact[0]);
739 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
740 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
741 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
742 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
743 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
744 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
745 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
746 $carac_emetteur .= "\n";
747 }
748
749 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
750
751 // Show sender
752 $posy = 42;
753 $posx = $this->marge_gauche;
754 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
755 $posx = $this->page_largeur - $this->marge_droite - 80;
756 }
757 $hautcadre = 40;
758
759 // Show sender frame
760 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
761 $pdf->SetTextColor(0, 0, 0);
762 $pdf->SetFont('', '', $default_font_size - 2);
763 $pdf->SetXY($posx, $posy - 5);
764 $pdf->SetXY($posx, $posy);
765 $pdf->SetFillColor(230, 230, 230);
766 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
767 $pdf->SetTextColor(0, 0, 60);
768 }
769
770 // Show sender name
771 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
772 $pdf->SetXY($posx + 2, $posy + 3);
773 $pdf->SetTextColor(0, 0, 60);
774 $pdf->SetFont('', 'B', $default_font_size);
775 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
776 $posy = $pdf->getY();
777 }
778
779 // Show sender information
780 $pdf->SetXY($posx + 2, $posy);
781 $pdf->SetFont('', '', $default_font_size - 1);
782 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
783
784
785 // If CUSTOMER contact defined, we use it
786 $usecontact = false;
787 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
788 if (count($arrayidcontact) > 0) {
789 $usecontact = true;
790 $result = $object->fetch_contact($arrayidcontact[0]);
791 }
792
793 $this->recipient = $object->thirdparty;
794
795 // Recipient name
796 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
797 $thirdparty = $object->contact;
798 } else {
799 $thirdparty = $object->thirdparty;
800 }
801
802 $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
803
804 $mode = 'target';
805 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), $usecontact, $mode, $object);
806
807 // Show recipient
808 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
809 if ($this->page_largeur < 210) {
810 $widthrecbox = 84; // To work with US executive format
811 }
812 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
813 $posy += $top_shift;
814 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
815 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
816 $posx = $this->marge_gauche;
817 }
818
819 // Show recipient frame
820 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
821 $pdf->SetTextColor(0, 0, 0);
822 $pdf->SetFont('', '', $default_font_size - 2);
823 $pdf->SetXY($posx + 2, $posy - 5);
824 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
825 $pdf->SetTextColor(0, 0, 0);
826 }
827
828 // Show recipient name
829 $pdf->SetXY($posx + 2, $posy + 3);
830 $pdf->SetFont('', 'B', $default_font_size);
831 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, $ltrdirection);
832
833 $posy = $pdf->getY();
834
835 // Show recipient information
836 $pdf->SetFont('', '', $default_font_size - 1);
837 $pdf->SetXY($posx + 2, $posy);
838 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
839 }
840
841 $pdf->SetTextColor(0, 0, 0);
842 return $top_shift;
843 }
844
845 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
855 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
856 {
857 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
858 return pdf_pagefoot($pdf, $outputlangs, 'CONTRACT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
859 }
860}
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage hooks.
Parent class to manage intervention document templates.
Class to manage translations.
Class to build contracts documents with model Strato.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
Show footer signature of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="Contract")
Show top header of page.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:241
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...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:85
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1010
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:726
pdf_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_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:758
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:387
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123