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