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