dolibarr 19.0.4
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
84 public $recipient;
85
91 public function __construct($db)
92 {
93 global $langs, $mysoc;
94
95 $this->db = $db;
96 $this->name = 'strato';
97 $this->description = $langs->trans("StandardContractsTemplate");
98 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
99
100 // Dimension page
101 $this->type = 'pdf';
102 $formatarray = pdf_getFormat();
103
104 $this->page_largeur = $formatarray['width'];
105 $this->page_hauteur = $formatarray['height'];
106 $this->format = array($this->page_largeur, $this->page_hauteur);
107 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
108 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
109 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
110 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
111
112 $this->option_logo = 1; // Display logo
113 $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
114 $this->option_modereg = 0; // Display payment mode
115 $this->option_condreg = 0; // Display payment terms
116 $this->option_multilang = 0; // Available in several languages
117 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
118
119 // Get source company
120 $this->emetteur = $mysoc;
121 if (empty($this->emetteur->country_code)) {
122 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
123 }
124
125 // Define position of columns
126 $this->posxdesc = $this->marge_gauche + 1;
127 }
128
129 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
141 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
142 {
143 // phpcs:enable
144 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
145
146 if (!is_object($outputlangs)) {
147 $outputlangs = $langs;
148 }
149 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
150 if (getDolGlobalString('MAIN_USE_FPDF')) {
151 $outputlangs->charset_output = 'ISO-8859-1';
152 }
153
154 // Load translation files required by page
155 $outputlangs->loadLangs(array("main", "dict", "companies", "contracts"));
156
157 // Show Draft Watermark
158 if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('CONTRACT_DRAFT_WATERMARK'))) {
159 $this->watermark = $conf->global->CONTRACT_DRAFT_WATERMARK;
160 }
161
162 global $outputlangsbis;
163 $outputlangsbis = null;
164 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
165 $outputlangsbis = new Translate('', $conf);
166 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
167 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
168 }
169
170 $nblines = count($object->lines);
171
172 if ($conf->contract->multidir_output[$conf->entity]) {
173 $object->fetch_thirdparty();
174
175 // Definition of $dir and $file
176 if ($object->specimen) {
177 $dir = $conf->contract->multidir_output[$conf->entity];
178 $file = $dir."/SPECIMEN.pdf";
179 } else {
180 $objectref = dol_sanitizeFileName($object->ref);
181 $dir = $conf->contrat->multidir_output[$object->entity]."/".$objectref;
182 $file = $dir."/".$objectref.".pdf";
183 }
184
185 if (!file_exists($dir)) {
186 if (dol_mkdir($dir) < 0) {
187 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
188 return 0;
189 }
190 }
191
192 if (file_exists($dir)) {
193 // Add pdfgeneration hook
194 if (!is_object($hookmanager)) {
195 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
196 $hookmanager = new HookManager($this->db);
197 }
198 $hookmanager->initHooks(array('pdfgeneration'));
199 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
200 global $action;
201 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
202
203 // Set nblines with the new command lines content after hook
204 $nblines = count($object->lines);
205
206 // Create pdf instance
207 $pdf = pdf_getInstance($this->format);
208 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
209 $pdf->SetAutoPageBreak(1, 0);
210
211 $heightforinfotot = 50; // Height reserved to output the info and total part
212 $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
213 $heightforfooter = $this->marge_basse + 9; // Height reserved to output the footer (value include bottom margin)
214 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
215 $heightforfooter += 6;
216 }
217
218 if (class_exists('TCPDF')) {
219 $pdf->setPrintHeader(false);
220 $pdf->setPrintFooter(false);
221 }
222 $pdf->SetFont(pdf_getPDFFont($outputlangs));
223 // Set path to the background PDF File
224 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
225 $logodir = $conf->mycompany->dir_output;
226 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
227 $logodir = $conf->mycompany->multidir_output[$object->entity];
228 }
229 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
230 $tplidx = $pdf->importPage(1);
231 }
232
233 $pdf->Open();
234 $pagenb = 0;
235 $pdf->SetDrawColor(128, 128, 128);
236
237 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
238 $pdf->SetSubject($outputlangs->transnoentities("Contract"));
239 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
240 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
241 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Contract")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
242 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
243 $pdf->SetCompression(false);
244 }
245
246 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
247
248 // New page
249 $pdf->AddPage();
250 if (!empty($tplidx)) {
251 $pdf->useTemplate($tplidx);
252 }
253 $pagenb++;
254 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
255 $pdf->SetFont('', '', $default_font_size - 1);
256 $pdf->MultiCell(0, 3, ''); // Set interline to 3
257 $pdf->SetTextColor(0, 0, 0);
258
259 $tab_top = 90;
260 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
261
262 // Display notes
263 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
264
265 // Extrafields in note
266 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
267 if (!empty($extranote)) {
268 $notetoshow = dol_concatdesc($notetoshow, $extranote);
269 }
270
271 if (!empty($notetoshow)) {
272 $tab_top -= 2;
273
274 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
275 complete_substitutions_array($substitutionarray, $outputlangs, $object);
276 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
277 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
278
279 $pdf->SetFont('', '', $default_font_size - 1);
280 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
281 $nexY = $pdf->GetY();
282 $height_note = $nexY - $tab_top;
283
284 // Rect takes a length in 3rd parameter
285 $pdf->SetDrawColor(192, 192, 192);
286 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
287
288 $tab_top = $nexY + 6;
289 }
290
291 $iniY = $tab_top + 7;
292 $curY = $tab_top + 7;
293 $nexY = $tab_top + 2;
294
295 $pdf->SetXY($this->marge_gauche, $tab_top);
296
297 $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
298
299 $nblines = count($object->lines);
300
301 // Loop on each lines
302 for ($i = 0; $i < $nblines; $i++) {
303 $objectligne = $object->lines[$i];
304
305 $valide = $objectligne->id ? 1 : 0;
306
307 if ($valide > 0 || $object->specimen) {
308 $curX = $this->posxdesc - 1;
309 $curY = $nexY;
310 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
311 $pdf->SetTextColor(0, 0, 0);
312
313 $pdf->setTopMargin($tab_top_newpage);
314 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
315 $pageposbefore = $pdf->getPage();
316
317 // Description of product line
318
319 if (!empty($objectligne->date_start)) {
320 $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
321 } else {
322 $datei = $langs->trans("Unknown");
323 }
324
325 if (!empty($objectligne->date_end)) {
326 $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
327 $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
328 } else {
329 $durationi = $langs->trans("Unknown");
330 $datee = $langs->trans("Unknown");
331 }
332
333 if (!empty($objectligne->date_start_real)) {
334 $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
335 } else {
336 $daters = $langs->trans("Unknown");
337 }
338
339 if (!empty($objectligne->date_end_real)) {
340 $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
341 } else {
342 $datere = $langs->trans("Unknown");
343 }
344
345 $txtpredefinedservice = $objectligne->product_ref;
346 if ($objectligne->product_label) {
347 $txtpredefinedservice .= ' - ';
348 $txtpredefinedservice .= $objectligne->product_label;
349 }
350
351 $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
352 $txt = '';
353 if (!getDolGlobalString('CONTRACT_HIDE_QTY_ON_PDF')) {
354 $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
355 }
356 if (!getDolGlobalString('CONTRACT_HIDE_PRICE_ON_PDF')) {
357 $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
358 }
359 if (!getDolGlobalString('CONTRACT_HIDE_PLANNED_DATE_ON_PDF')) {
360 $txt .= '<br>';
361 $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
362 }
363 if (!getDolGlobalString('CONTRACT_HIDE_REAL_DATE_ON_PDF')) {
364 $txt .= '<br>';
365 $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
366 if (!empty($objectligne->date_end_real)) {
367 $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : '<strong>'".$datere.'</strong>';
368 }
369 }
370
371 $pdf->startTransaction();
372 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
373 $pageposafter = $pdf->getPage();
374 if ($pageposafter > $pageposbefore) { // There is a pagebreak
375 $pdf->rollbackTransaction(true);
376 $pageposafter = $pageposbefore;
377 //print $pageposafter.'-'.$pageposbefore;exit;
378 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
379 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
380 $pageposafter = $pdf->getPage();
381 $posyafter = $pdf->GetY();
382 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
383 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
384 $pdf->AddPage('', '', true);
385 if (!empty($tplidx)) {
386 $pdf->useTemplate($tplidx);
387 }
388 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
389 $this->_pagehead($pdf, $object, 0, $outputlangs);
390 }
391 $pdf->setPage($pageposafter + 1);
392 }
393 } else {
394 // We found a page break
395
396 // Allows data in the first page if description is long enough to break in multiples pages
397 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
398 $showpricebeforepagebreak = 1;
399 } else {
400 $showpricebeforepagebreak = 0;
401 }
402 }
403 } else { // No pagebreak
404 $pdf->commitTransaction();
405 }
406 $posYAfterDescription = $pdf->GetY();
407
408 $nexY = $pdf->GetY() + 2;
409 $pageposafter = $pdf->getPage();
410
411 $pdf->setPage($pageposbefore);
412 $pdf->setTopMargin($this->marge_haute);
413 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
414
415 // We suppose that a too long description is moved completely on next page
416 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
417 $pdf->setPage($pageposafter);
418 $curY = $tab_top_newpage;
419 }
420
421 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
422
423 // Detect if some page were added automatically and output _tableau for past pages
424 while ($pagenb < $pageposafter) {
425 $pdf->setPage($pagenb);
426 if ($pagenb == 1) {
427 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
428 } else {
429 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
430 }
431 $this->_pagefoot($pdf, $object, $outputlangs, 1);
432 $pagenb++;
433 $pdf->setPage($pagenb);
434 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
435 if (!getDolGlobalString('MAIN_PDF_DONOTREPEAT_HEAD')) {
436 $this->_pagehead($pdf, $object, 0, $outputlangs);
437 }
438 if (!empty($tplidx)) {
439 $pdf->useTemplate($tplidx);
440 }
441 }
442
443 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
444 if ($pagenb == 1) {
445 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
446 } else {
447 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
448 }
449 $this->_pagefoot($pdf, $object, $outputlangs, 1);
450 // New page
451 $pdf->AddPage();
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
454 }
455 $pagenb++;
456 }
457 }
458 }
459
460
461 // Show square
462 if ($pagenb == 1) {
463 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
464 $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
465 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
466 } else {
467 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
468 $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
469 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
470 }
471
472 $this->_pagefoot($pdf, $object, $outputlangs);
473 if (method_exists($pdf, 'AliasNbPages')) {
474 $pdf->AliasNbPages();
475 }
476
477 $pdf->Close();
478
479 $pdf->Output($file, 'F');
480
481 // Add pdfgeneration hook
482 $hookmanager->initHooks(array('pdfgeneration'));
483 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
484 global $action;
485 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
486 if ($reshook < 0) {
487 $this->error = $hookmanager->error;
488 $this->errors = $hookmanager->errors;
489 }
490
491 dolChmod($file);
492
493 $this->result = array('fullpath'=>$file);
494
495 return 1; // No error
496 } else {
497 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
498 return 0;
499 }
500 } else {
501 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
502 return 0;
503 }
504 }
505
506 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
519 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
520 {
521 global $conf;
522
523 // Force to disable hidetop and hidebottom
524 $hidebottom = 0;
525 if ($hidetop) {
526 $hidetop = -1;
527 }
528
529 //$default_font_size = pdf_getPDFFontSize($outputlangs);
530
531 /*
532 $pdf->SetXY($this->marge_gauche, $tab_top);
533 $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
534 $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
535
536 $pdf->SetFont('','', $default_font_size - 1);
537
538 $pdf->MultiCell(0, 3, ''); // Set interline to 3
539 $pdf->SetXY($this->marge_gauche, $tab_top + 8);
540 $text=$object->description;
541 if ($object->duree > 0)
542 {
543 $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
544 $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
545 }
546 $desc=dol_htmlentitiesbr($text,1);
547 //print $outputlangs->convToOutputCharset($desc); exit;
548
549 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
550 $nexY = $pdf->GetY();
551
552 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
553
554 $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
555 */
556
557 // Output Rect
558 $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
559 }
560
569 protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
570 {
571 $pdf->SetDrawColor(128, 128, 128);
572 $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
573 $posy = $tab_top + $tab_height + 3 + 3;
574
575 $pdf->SetXY($this->marge_gauche, $posy);
576 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
577
578 $pdf->SetXY($this->marge_gauche, $posy + 5);
579 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 20, '', 1);
580
581 $pdf->SetXY($posmiddle + 5, $posy);
582 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
583
584 $pdf->SetXY($posmiddle + 5, $posy + 5);
585 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, '', 1);
586 }
587
588 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
600 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "Contract")
601 {
602 // phpcs:enable
603 global $conf;
604
605 $top_shift = 0;
606
607 $ltrdirection = 'L';
608 if ($outputlangs->trans("DIRECTION") == 'rtl') {
609 $ltrdirection = 'R';
610 }
611
612 // Load traductions files required by page
613 $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
614
615 $default_font_size = pdf_getPDFFontSize($outputlangs);
616
617 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
618
619 $pdf->SetTextColor(0, 0, 60);
620 $pdf->SetFont('', 'B', $default_font_size + 3);
621
622 $w = 100;
623
624 $posy = $this->marge_haute;
625 $posx = $this->page_largeur - $this->marge_droite - $w;
626
627 $pdf->SetXY($this->marge_gauche, $posy);
628
629 // Logo
630 if (!getDolGlobalString('PDF_DISABLE_MYCOMPANY_LOGO')) {
631 if ($this->emetteur->logo) {
632 $logodir = $conf->mycompany->dir_output;
633 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
634 $logodir = $conf->mycompany->multidir_output[$object->entity];
635 }
636 if (!getDolGlobalString('MAIN_PDF_USE_LARGE_LOGO')) {
637 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
638 } else {
639 $logo = $logodir.'/logos/'.$this->emetteur->logo;
640 }
641 if (is_readable($logo)) {
642 $height = pdf_getHeightForLogo($logo);
643 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
644 } else {
645 $pdf->SetTextColor(200, 0, 0);
646 $pdf->SetFont('', 'B', $default_font_size - 2);
647 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
648 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
649 }
650 } else {
651 $text = $this->emetteur->name;
652 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
653 }
654 }
655
656 $pdf->SetFont('', 'B', $default_font_size + 3);
657 $pdf->SetXY($posx, $posy);
658 $pdf->SetTextColor(0, 0, 60);
659 $title = $outputlangs->transnoentities($titlekey);
660 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
661 if ($object->statut == $object::STATUS_DRAFT) {
662 $pdf->SetTextColor(128, 0, 0);
663 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
664 }
665 $pdf->MultiCell($w, 3, $title, '', 'R');
666
667 $pdf->SetFont('', 'B', $default_font_size);
668
669 /*
670 $posy += 5;
671 $pdf->SetXY($posx, $posy);
672 $pdf->SetTextColor(0, 0, 60);
673 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
674 */
675
676 $posy += 3;
677 $pdf->SetFont('', '', $default_font_size - 1);
678
679 $posy += 4;
680 $pdf->SetXY($posx, $posy);
681 $pdf->SetTextColor(0, 0, 60);
682 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
683
684 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
685 $posy += 4;
686 $pdf->SetXY($posx, $posy);
687 $pdf->SetTextColor(0, 0, 60);
688 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
689 }
690
691 if ($showaddress) {
692 // Sender properties
693 $carac_emetteur = '';
694 // Add internal contact of object if defined
695 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
696 if (count($arrayidcontact) > 0) {
697 $object->fetch_user($arrayidcontact[0]);
698 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
699 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
700 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
701 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
702 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
703 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
704 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
705 $carac_emetteur .= "\n";
706 }
707
708 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
709
710 // Show sender
711 $posy = 42;
712 $posx = $this->marge_gauche;
713 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
714 $posx = $this->page_largeur - $this->marge_droite - 80;
715 }
716 $hautcadre = 40;
717
718 // Show sender frame
719 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
720 $pdf->SetTextColor(0, 0, 0);
721 $pdf->SetFont('', '', $default_font_size - 2);
722 $pdf->SetXY($posx, $posy - 5);
723 $pdf->SetXY($posx, $posy);
724 $pdf->SetFillColor(230, 230, 230);
725 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
726 $pdf->SetTextColor(0, 0, 60);
727 }
728
729 // Show sender name
730 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
731 $pdf->SetXY($posx + 2, $posy + 3);
732 $pdf->SetTextColor(0, 0, 60);
733 $pdf->SetFont('', 'B', $default_font_size);
734 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
735 $posy = $pdf->getY();
736 }
737
738 // Show sender information
739 $pdf->SetXY($posx + 2, $posy);
740 $pdf->SetFont('', '', $default_font_size - 1);
741 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
742
743
744 // If CUSTOMER contact defined, we use it
745 $usecontact = false;
746 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
747 if (count($arrayidcontact) > 0) {
748 $usecontact = true;
749 $result = $object->fetch_contact($arrayidcontact[0]);
750 }
751
752 $this->recipient = $object->thirdparty;
753
754 // Recipient name
755 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
756 $thirdparty = $object->contact;
757 } else {
758 $thirdparty = $object->thirdparty;
759 }
760
761 $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
762
763 $mode = 'target';
764 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), $usecontact, $mode, $object);
765
766 // Show recipient
767 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
768 if ($this->page_largeur < 210) {
769 $widthrecbox = 84; // To work with US executive format
770 }
771 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
772 $posy += $top_shift;
773 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
774 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
775 $posx = $this->marge_gauche;
776 }
777
778 // Show recipient frame
779 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
780 $pdf->SetTextColor(0, 0, 0);
781 $pdf->SetFont('', '', $default_font_size - 2);
782 $pdf->SetXY($posx + 2, $posy - 5);
783 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
784 $pdf->SetTextColor(0, 0, 0);
785 }
786
787 // Show recipient name
788 $pdf->SetXY($posx + 2, $posy + 3);
789 $pdf->SetFont('', 'B', $default_font_size);
790 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, $ltrdirection);
791
792 $posy = $pdf->getY();
793
794 // Show recipient information
795 $pdf->SetFont('', '', $default_font_size - 1);
796 $pdf->SetXY($posx + 2, $posy);
797 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
798 }
799
800 $pdf->SetTextColor(0, 0, 0);
801 return $top_shift;
802 }
803
804 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
814 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
815 {
816 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
817 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);
818 }
819}
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:243
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 a 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:1014
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: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
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