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