dolibarr 21.0.0-alpha
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-2024 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Nick Fragoulis
12 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 * or see https://www.gnu.org/
27 */
28
34require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.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 $version = 'dolibarr';
81
86 public $recipient;
87
93 public function __construct($db)
94 {
95 global $langs, $mysoc;
96
97 $this->db = $db;
98 $this->name = 'strato';
99 $this->description = $langs->trans("StandardContractsTemplate");
100 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
101
102 // Dimension page
103 $this->type = 'pdf';
104 $formatarray = pdf_getFormat();
105
106 $this->page_largeur = $formatarray['width'];
107 $this->page_hauteur = $formatarray['height'];
108 $this->format = array($this->page_largeur, $this->page_hauteur);
109 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
110 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
111 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
112 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
113 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
114 $this->option_logo = 1; // Display logo
115 $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
116 $this->option_modereg = 0; // Display payment mode
117 $this->option_condreg = 0; // Display payment terms
118 $this->option_multilang = 0; // Available in several languages
119 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
120
121 // Define position of columns
122 $this->posxdesc = $this->marge_gauche + 1;
123
124 if ($mysoc === null) {
125 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
126 return;
127 }
128
129 // Get source company
130 $this->emetteur = $mysoc;
131 if (empty($this->emetteur->country_code)) {
132 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
133 }
134 }
135
136 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
148 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
149 {
150 // phpcs:enable
151 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
152
153 if (!is_object($outputlangs)) {
154 $outputlangs = $langs;
155 }
156 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
157 if (getDolGlobalString('MAIN_USE_FPDF')) {
158 $outputlangs->charset_output = 'ISO-8859-1';
159 }
160
161 // Load translation files required by page
162 $outputlangs->loadLangs(array("main", "dict", "companies", "contracts", "compta"));
163
164 // Show Draft Watermark
165 if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('CONTRACT_DRAFT_WATERMARK'))) {
166 $this->watermark = getDolGlobalString('CONTRACT_DRAFT_WATERMARK');
167 }
168
169 global $outputlangsbis;
170 $outputlangsbis = null;
171 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
172 $outputlangsbis = new Translate('', $conf);
173 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
174 $outputlangsbis->loadLangs(array("main", "dict", "companies", "contracts", "compta"));
175 }
176
177 $nblines = count($object->lines);
178
179 if ($conf->contract->multidir_output[$conf->entity]) {
180 $object->fetch_thirdparty();
181
182 // Definition of $dir and $file
183 if ($object->specimen) {
185 $file = $dir."/SPECIMEN.pdf";
186 } else {
187 $objectref = dol_sanitizeFileName($object->ref);
188 $dir = getMultidirOutput($object)."/".$objectref;
189 $file = $dir."/".$objectref.".pdf";
190 }
191
192 if (!file_exists($dir)) {
193 if (dol_mkdir($dir) < 0) {
194 $this->error = $langs->transnoentitiesnoconv("ErrorCanNotCreateDir", $dir);
195 return 0;
196 }
197 }
198
199 if (file_exists($dir)) {
200 // Add pdfgeneration hook
201 if (!is_object($hookmanager)) {
202 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
203 $hookmanager = new HookManager($this->db);
204 }
205 $hookmanager->initHooks(array('pdfgeneration'));
206 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
207 global $action;
208 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
209
210 // Set nblines with the new lines content after hook
211 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
212
213 // Create pdf instance
214 $pdf = pdf_getInstance($this->format);
215 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
216 $pdf->SetAutoPageBreak(1, 0);
217
218 $heightforinfotot = 50; // Height reserved to output the info and total part
219 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
220 $heightforfooter = $this->marge_basse + 9; // Height reserved to output the footer (value include bottom margin)
221 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
222 $heightforfooter += 6;
223 }
224
225 if (class_exists('TCPDF')) {
226 $pdf->setPrintHeader(false);
227 $pdf->setPrintFooter(false);
228 }
229 $pdf->SetFont(pdf_getPDFFont($outputlangs));
230 // Set path to the background PDF File
231 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
232 $logodir = $conf->mycompany->dir_output;
233 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
234 $logodir = $conf->mycompany->multidir_output[$object->entity];
235 }
236 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
237 $tplidx = $pdf->importPage(1);
238 }
239
240 $pdf->Open();
241 $pagenb = 0;
242 $pdf->SetDrawColor(128, 128, 128);
243
244 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
245 $pdf->SetSubject($outputlangs->transnoentities("Contract"));
246 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
247 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
248 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Contract")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
249 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
250 $pdf->SetCompression(false);
251 }
252
253 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
254 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
255
256 // New page
257 $pdf->AddPage();
258 if (!empty($tplidx)) {
259 $pdf->useTemplate($tplidx);
260 }
261 $pagenb++;
262 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
263 $pdf->SetFont('', '', $default_font_size - 1);
264 $pdf->MultiCell(0, 3, ''); // Set interline to 3
265 $pdf->SetTextColor(0, 0, 0);
266
267 $tab_top = 90;
268 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
269
270 // Display notes
271 if (!empty($object->note_public)) {
272 $tab_top -= 2;
273
274 $pdf->SetFont('', '', $default_font_size - 1);
275 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1);
276 $nexY = $pdf->GetY();
277 $height_note = $nexY - $tab_top;
278
279 // Rect takes a length in 3rd parameter
280 $pdf->SetDrawColor(192, 192, 192);
281 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius, '1234', 'D');
282
283 $tab_top = $nexY + 6;
284 }
285
286 $iniY = $tab_top + 7;
287 $curY = $tab_top + 7;
288 $nexY = $tab_top + 2;
289
290 $pdf->SetXY($this->marge_gauche, $tab_top);
291
292 $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
293
294 $nblines = count($object->lines);
295
296 // Loop on each lines
297 for ($i = 0; $i < $nblines; $i++) {
298 $objectligne = $object->lines[$i];
299
300 $valide = $objectligne->id ? 1 : 0;
301
302 if ($valide > 0 || $object->specimen) {
303 $curX = $this->posxdesc - 1;
304 $curY = $nexY;
305 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
306 $pdf->SetTextColor(0, 0, 0);
307
308 $pdf->setTopMargin($tab_top_newpage);
309 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
310 $pageposbefore = $pdf->getPage();
311
312 // Description of product line
313
314 if (!empty($objectligne->date_start)) {
315 $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
316 } else {
317 $datei = $langs->trans("Unknown");
318 }
319
320 if (!empty($objectligne->date_end)) {
321 $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
322 $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
323 } else {
324 $durationi = $langs->trans("Unknown");
325 $datee = $langs->trans("Unknown");
326 }
327
328 if (!empty($objectligne->date_start_real)) {
329 $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
330 } else {
331 $daters = $langs->trans("Unknown");
332 }
333
334 if (!empty($objectligne->date_end_real)) {
335 $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
336 } else {
337 $datere = $langs->trans("Unknown");
338 }
339
340 $txtpredefinedservice = $objectligne->product_ref;
341 if ($objectligne->product_label) {
342 $txtpredefinedservice .= ' - ';
343 $txtpredefinedservice .= $objectligne->product_label;
344 }
345
346 $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
347 $txt = '';
348 if (!getDolGlobalString('CONTRACT_HIDE_QTY_ON_PDF')) {
349 $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
350 }
351 if (!getDolGlobalString('CONTRACT_HIDE_PRICE_ON_PDF')) {
352 $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
353 }
354 if (!getDolGlobalString('CONTRACT_HIDE_PLANNED_DATE_ON_PDF')) {
355 $txt .= '<br>';
356 $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
357 }
358 if (!getDolGlobalString('CONTRACT_HIDE_REAL_DATE_ON_PDF')) {
359 $txt .= '<br>';
360 $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
361 if (!empty($objectligne->date_end_real)) {
362 $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : <strong>".$datere.'</strong>';
363 }
364 }
365
366 $pdf->startTransaction();
367 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
368 $pageposafter = $pdf->getPage();
369 if ($pageposafter > $pageposbefore) { // There is a pagebreak
370 $pdf->rollbackTransaction(true);
371 $pageposafter = $pageposbefore;
372 //print $pageposafter.'-'.$pageposbefore;exit;
373 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
374 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
375 $pageposafter = $pdf->getPage();
376 $posyafter = $pdf->GetY();
377 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
378 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
379 $pdf->AddPage('', '', true);
380 if (!empty($tplidx)) {
381 $pdf->useTemplate($tplidx);
382 }
383 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
384 $this->_pagehead($pdf, $object, 0, $outputlangs);
385 }
386 $pdf->setPage($pageposafter + 1);
387 }
388 } else {
389 // We found a page break
390
391 // Allows data in the first page if description is long enough to break in multiples pages
392 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
393 $showpricebeforepagebreak = 1;
394 } else {
395 $showpricebeforepagebreak = 0;
396 }
397 }
398 } else { // No pagebreak
399 $pdf->commitTransaction();
400 }
401 $posYAfterDescription = $pdf->GetY();
402
403 $nexY = $pdf->GetY() + 2;
404 $pageposafter = $pdf->getPage();
405
406 $pdf->setPage($pageposbefore);
407 $pdf->setTopMargin($this->marge_haute);
408 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
409
410 // We suppose that a too long description is moved completely on next page
411 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
412 $pdf->setPage($pageposafter);
413 $curY = $tab_top_newpage;
414 }
415
416 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
417
418 // Detect if some page were added automatically and output _tableau for past pages
419 while ($pagenb < $pageposafter) {
420 $pdf->setPage($pagenb);
421 if ($pagenb == 1) {
422 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
423 } else {
424 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
425 }
426 $this->_pagefoot($pdf, $object, $outputlangs, 1);
427 $pagenb++;
428 $pdf->setPage($pagenb);
429 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
430 if (!getDolGlobalString('MAIN_PDF_DONOTREPEAT_HEAD')) {
431 $this->_pagehead($pdf, $object, 0, $outputlangs);
432 }
433 if (!empty($tplidx)) {
434 $pdf->useTemplate($tplidx);
435 }
436 }
437
438 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
439 if ($pagenb == 1) {
440 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
441 } else {
442 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
443 }
444 $this->_pagefoot($pdf, $object, $outputlangs, 1);
445 // New page
446 $pdf->AddPage();
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
449 }
450 $pagenb++;
451 }
452 }
453 }
454
455
456 // Show square
457 if ($pagenb == 1) {
458 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
459 $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
460 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
461 } else {
462 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
463 $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
464 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
465 }
466
467 $this->_pagefoot($pdf, $object, $outputlangs);
468 if (method_exists($pdf, 'AliasNbPages')) {
469 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
470 }
471
472 $pdf->Close();
473
474 $pdf->Output($file, 'F');
475
476 // Add pdfgeneration hook
477 $hookmanager->initHooks(array('pdfgeneration'));
478 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
479 global $action;
480 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
481 if ($reshook < 0) {
482 $this->error = $hookmanager->error;
483 $this->errors = $hookmanager->errors;
484 }
485
486 dolChmod($file);
487
488 $this->result = array('fullpath' => $file);
489
490 return 1; // No error
491 } else {
492 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
493 return 0;
494 }
495 } else {
496 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
497 return 0;
498 }
499 }
500
501 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
514 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
515 {
516 global $conf;
517
518 // Force to disable hidetop and hidebottom
519 $hidebottom = 0;
520 if ($hidetop) {
521 $hidetop = -1;
522 }
523
524 //$default_font_size = pdf_getPDFFontSize($outputlangs);
525
526 /*
527 $pdf->SetXY($this->marge_gauche, $tab_top);
528 $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
529 $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
530
531 $pdf->SetFont('','', $default_font_size - 1);
532
533 $pdf->MultiCell(0, 3, ''); // Set interline to 3
534 $pdf->SetXY($this->marge_gauche, $tab_top + 8);
535 $text=$object->description;
536 if ($object->duree > 0)
537 {
538 $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
539 $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
540 }
541 $desc=dol_htmlentitiesbr($text,1);
542 //print $outputlangs->convToOutputCharset($desc); exit;
543
544 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
545 $nexY = $pdf->GetY();
546
547 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
548
549 $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
550 */
551
552 // Output Rect
553 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 3, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
554 }
555
565 protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
566 {
567 $pdf->SetDrawColor(128, 128, 128);
568 $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
569 $posy = $tab_top + $tab_height + 3 + 3;
570
571 if (!getDolGlobalString('CONTRACT_HIDE_MYCOMPANY_SIGNATURE_SECTION_PDF')) {
572 $pdf->SetXY($this->marge_gauche, $posy);
573 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
574
575 $pdf->SetXY($this->marge_gauche, $posy + 5);
576 $pdf->RoundedRect($this->marge_gauche, $posy + 5, $posmiddle - $this->marge_gauche - 5, 20, $this->corner_radius, '1234', 'D');
577 }
578
579 if (!getDolGlobalString('CONTRACT_HIDE_THIRPARTY_SIGNATURE_SECTION_PDF')) {
580 $pdf->SetXY($posmiddle + 5, $posy);
581 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
582
583 $pdf->SetXY($posmiddle + 5, $posy + 5);
584 $pdf->RoundedRect($posmiddle + 5, $posy + 5, $this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, $this->corner_radius, '1234', 'D');
585 }
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 (getMultidirOutput($object, 'mycompany')) {
634 $logodir = getMultidirOutput($object, 'mycompany');
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 (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
692 $posy += 4;
693 $pdf->SetXY($posx, $posy);
694 $pdf->SetTextColor(0, 0, 60);
695 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
696 }
697
698 if ($showaddress) {
699 // Sender properties
700 $carac_emetteur = '';
701 // Add internal contact of object if defined
702 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
703 if (count($arrayidcontact) > 0) {
704 $object->fetch_user($arrayidcontact[0]);
705 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
706 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
707 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
708 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
709 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
710 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
711 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
712 $carac_emetteur .= "\n";
713 }
714
715 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
716
717 // Show sender
718 $posy = 42;
719 $posx = $this->marge_gauche;
720 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
721 $posx = $this->page_largeur - $this->marge_droite - 80;
722 }
723 $hautcadre = 40;
724
725 // Show sender frame
726 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
727 $pdf->SetTextColor(0, 0, 0);
728 $pdf->SetFont('', '', $default_font_size - 2);
729 $pdf->SetXY($posx, $posy - 5);
730 $pdf->SetXY($posx, $posy);
731 $pdf->SetFillColor(230, 230, 230);
732 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
733 $pdf->SetTextColor(0, 0, 60);
734 }
735
736 // Show sender name
737 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
738 $pdf->SetXY($posx + 2, $posy + 3);
739 $pdf->SetTextColor(0, 0, 60);
740 $pdf->SetFont('', 'B', $default_font_size);
741 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
742 $posy = $pdf->getY();
743 }
744
745 // Show sender information
746 $pdf->SetXY($posx + 2, $posy);
747 $pdf->SetFont('', '', $default_font_size - 1);
748 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
749
750
751 // If CUSTOMER contact defined, we use it
752 $usecontact = false;
753 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
754 if (count($arrayidcontact) > 0) {
755 $usecontact = true;
756 $result = $object->fetch_contact($arrayidcontact[0]);
757 }
758
759 $this->recipient = $object->thirdparty;
760
761 // Recipient name
762 if ($usecontact && ($object->contact->socid != $object->thirdparty->id) && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
763 $thirdparty = $object->contact;
764 } else {
765 $thirdparty = $object->thirdparty;
766 }
767
768 $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
769
770 $mode = 'target';
771 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
772
773 // Show recipient
774 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
775 if ($this->page_largeur < 210) {
776 $widthrecbox = 84; // To work with US executive format
777 }
778 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
779 $posy += $top_shift;
780 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
781 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
782 $posx = $this->marge_gauche;
783 }
784
785 // Show recipient frame
786 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
787 $pdf->SetTextColor(0, 0, 0);
788 $pdf->SetFont('', '', $default_font_size - 2);
789 $pdf->SetXY($posx + 2, $posy - 5);
790 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
791 $pdf->SetTextColor(0, 0, 0);
792 }
793
794 // Show recipient name
795 $pdf->SetXY($posx + 2, $posy + 3);
796 $pdf->SetFont('', 'B', $default_font_size);
797 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, $ltrdirection);
798
799 $posy = $pdf->getY();
800
801 // Show recipient information
802 $pdf->SetFont('', '', $default_font_size - 1);
803 $pdf->SetXY($posx + 2, $posy);
804 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
805 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
806 }
807
808 $pdf->SetTextColor(0, 0, 0);
809
810 return $top_shift;
811 }
812
813 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
823 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
824 {
825 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
826 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);
827 }
828}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the 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 on 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:242
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.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
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.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1027
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:729
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:434
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:386
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140