pdf_soleil.modules.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. * or see https://www.gnu.org/
  23. */
  24. /**
  25. * \file htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php
  26. * \ingroup ficheinter
  27. * \brief File of Class to build interventions documents with model Soleil
  28. */
  29. require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  34. /**
  35. * Class to build interventions documents with model Soleil
  36. */
  37. class pdf_soleil extends ModelePDFFicheinter
  38. {
  39. /**
  40. * @var DoliDb Database handler
  41. */
  42. public $db;
  43. /**
  44. * @var string model name
  45. */
  46. public $name;
  47. /**
  48. * @var string model description (short text)
  49. */
  50. public $description;
  51. /**
  52. * @var string document type
  53. */
  54. public $type;
  55. /**
  56. * @var array Minimum version of PHP required by module.
  57. * e.g.: PHP ≥ 5.5 = array(5, 5)
  58. */
  59. public $phpmin = array(5, 5);
  60. /**
  61. * Dolibarr version of the loaded document
  62. * @var string
  63. */
  64. public $version = 'dolibarr';
  65. /**
  66. * @var int page_largeur
  67. */
  68. public $page_largeur;
  69. /**
  70. * @var int page_hauteur
  71. */
  72. public $page_hauteur;
  73. /**
  74. * @var array format
  75. */
  76. public $format;
  77. /**
  78. * @var int marge_gauche
  79. */
  80. public $marge_gauche;
  81. /**
  82. * @var int marge_droite
  83. */
  84. public $marge_droite;
  85. /**
  86. * @var int marge_haute
  87. */
  88. public $marge_haute;
  89. /**
  90. * @var int marge_basse
  91. */
  92. public $marge_basse;
  93. /**
  94. * Issuer
  95. * @var Company object that emits
  96. */
  97. public $emetteur;
  98. /**
  99. * Constructor
  100. *
  101. * @param DoliDB $db Database handler
  102. */
  103. public function __construct($db)
  104. {
  105. global $conf,$langs,$mysoc;
  106. $this->db = $db;
  107. $this->name = 'soleil';
  108. $this->description = $langs->trans("DocumentModelStandardPDF");
  109. // Page size for A4 format
  110. $this->type = 'pdf';
  111. $formatarray=pdf_getFormat();
  112. $this->page_largeur = $formatarray['width'];
  113. $this->page_hauteur = $formatarray['height'];
  114. $this->format = array($this->page_largeur,$this->page_hauteur);
  115. $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
  116. $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
  117. $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
  118. $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
  119. $this->option_logo = 1; // Display logo
  120. $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
  121. $this->option_modereg = 0; // Display payment mode
  122. $this->option_condreg = 0; // Display payment terms
  123. $this->option_codeproduitservice = 0; // Display product-service code
  124. $this->option_multilang = 1; // Available in several languages
  125. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  126. // Get source company
  127. $this->emetteur=$mysoc;
  128. if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang, -2); // By default, if not defined
  129. // Define position of columns
  130. $this->posxdesc=$this->marge_gauche+1;
  131. }
  132. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  133. /**
  134. * Function to build pdf onto disk
  135. *
  136. * @param Object $object Object to generate
  137. * @param Translate $outputlangs Lang output object
  138. * @param string $srctemplatepath Full path of source filename for generator using a template file
  139. * @param int $hidedetails Do not show line details
  140. * @param int $hidedesc Do not show desc
  141. * @param int $hideref Do not show ref
  142. * @return int 1=OK, 0=KO
  143. */
  144. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  145. {
  146. // phpcs:enable
  147. global $user,$langs,$conf,$mysoc,$db,$hookmanager;
  148. if (! is_object($outputlangs)) $outputlangs=$langs;
  149. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  150. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  151. // Load traductions files required by page
  152. $outputlangs->loadLangs(array("main", "interventions", "dict", "companies"));
  153. if ($conf->ficheinter->dir_output)
  154. {
  155. $object->fetch_thirdparty();
  156. // Definition of $dir and $file
  157. if ($object->specimen)
  158. {
  159. $dir = $conf->ficheinter->dir_output;
  160. $file = $dir . "/SPECIMEN.pdf";
  161. }
  162. else
  163. {
  164. $objectref = dol_sanitizeFileName($object->ref);
  165. $dir = $conf->ficheinter->dir_output . "/" . $objectref;
  166. $file = $dir . "/" . $objectref . ".pdf";
  167. }
  168. if (! file_exists($dir))
  169. {
  170. if (dol_mkdir($dir) < 0)
  171. {
  172. $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
  173. return 0;
  174. }
  175. }
  176. if (file_exists($dir))
  177. {
  178. // Add pdfgeneration hook
  179. if (! is_object($hookmanager))
  180. {
  181. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  182. $hookmanager=new HookManager($this->db);
  183. }
  184. $hookmanager->initHooks(array('pdfgeneration'));
  185. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  186. global $action;
  187. $reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  188. $nblines = count($object->lines);
  189. // Create pdf instance
  190. $pdf=pdf_getInstance($this->format);
  191. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  192. $heightforinfotot = 50; // Height reserved to output the info and total part
  193. $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
  194. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  195. if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
  196. $pdf->SetAutoPageBreak(1, 0);
  197. if (class_exists('TCPDF'))
  198. {
  199. $pdf->setPrintHeader(false);
  200. $pdf->setPrintFooter(false);
  201. }
  202. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  203. // Set path to the background PDF File
  204. if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  205. {
  206. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  207. $tplidx = $pdf->importPage(1);
  208. }
  209. $pdf->Open();
  210. $pagenb=0;
  211. $pdf->SetDrawColor(128, 128, 128);
  212. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  213. $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
  214. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  215. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  216. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
  217. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  218. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  219. // New page
  220. $pdf->AddPage();
  221. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  222. $pagenb++;
  223. $this->_pagehead($pdf, $object, 1, $outputlangs);
  224. $pdf->SetFont('', '', $default_font_size - 1);
  225. $pdf->SetTextColor(0, 0, 0);
  226. $tab_top = 90;
  227. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  228. $tab_height = 130;
  229. $tab_height_newpage = 150;
  230. // Display notes
  231. $notetoshow=empty($object->note_public)?'':$object->note_public;
  232. if ($notetoshow)
  233. {
  234. $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
  235. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  236. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  237. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  238. $tab_top = 88;
  239. $pdf->SetFont('', '', $default_font_size - 1);
  240. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  241. $nexY = $pdf->GetY();
  242. $height_note=$nexY-$tab_top;
  243. // Rect takes a length in 3rd parameter
  244. $pdf->SetDrawColor(192, 192, 192);
  245. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  246. $tab_height = $tab_height - $height_note;
  247. $tab_top = $nexY+6;
  248. }
  249. else
  250. {
  251. $height_note=0;
  252. }
  253. $iniY = $tab_top + 7;
  254. $curY = $tab_top + 7;
  255. $nexY = $tab_top + 7;
  256. $pdf->SetXY($this->marge_gauche, $tab_top);
  257. $pdf->MultiCell(190, 5, $outputlangs->transnoentities("Description"), 0, 'L', 0);
  258. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur-$this->marge_droite, $tab_top + 5);
  259. $pdf->SetFont('', '', $default_font_size - 1);
  260. $pdf->SetXY($this->marge_gauche, $tab_top + 5);
  261. $text=$object->description;
  262. if ($object->duration > 0)
  263. {
  264. $totaltime=convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  265. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  266. }
  267. $desc=dol_htmlentitiesbr($text, 1);
  268. //print $outputlangs->convToOutputCharset($desc); exit;
  269. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
  270. $nexY = $pdf->GetY();
  271. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  272. $nblines = count($object->lines);
  273. // Loop on each lines
  274. for ($i = 0; $i < $nblines; $i++)
  275. {
  276. $objectligne = $object->lines[$i];
  277. $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
  278. if ($valide > 0 || $object->specimen)
  279. {
  280. $curY = $nexY;
  281. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  282. $pdf->SetTextColor(0, 0, 0);
  283. $pdf->setTopMargin($tab_top_newpage);
  284. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  285. $pageposbefore=$pdf->getPage();
  286. // Description of product line
  287. $curX = $this->posxdesc-1;
  288. // Description of product line
  289. if (empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
  290. $txt=$outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true);
  291. } else {
  292. $txt=$outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'day', false, $outputlangs, true);
  293. }
  294. if ($objectligne->duration > 0)
  295. {
  296. $txt.=" - ".$outputlangs->transnoentities("Duration")." : ".convertSecondToTime($objectligne->duration);
  297. }
  298. $txt='<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).'</strong>';
  299. $desc=dol_htmlentitiesbr($objectligne->desc, 1);
  300. $pdf->startTransaction();
  301. $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, 0);
  302. $pageposafter=$pdf->getPage();
  303. if ($pageposafter > $pageposbefore) // There is a pagebreak
  304. {
  305. $pdf->rollbackTransaction(true);
  306. $pageposafter=$pageposbefore;
  307. //print $pageposafter.'-'.$pageposbefore;exit;
  308. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  309. $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt, $desc), 0, 1, 0);
  310. $pageposafter=$pdf->getPage();
  311. $posyafter=$pdf->GetY();
  312. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  313. if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
  314. {
  315. if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
  316. {
  317. $pdf->AddPage('', '', true);
  318. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  319. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  320. $pdf->setPage($pageposafter+1);
  321. }
  322. }
  323. }
  324. else // No pagebreak
  325. {
  326. $pdf->commitTransaction();
  327. }
  328. $nexY = $pdf->GetY();
  329. $pageposafter=$pdf->getPage();
  330. $pdf->setPage($pageposbefore);
  331. $pdf->setTopMargin($this->marge_haute);
  332. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  333. // We suppose that a too long description is moved completely on next page
  334. if ($pageposafter > $pageposbefore) {
  335. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  336. }
  337. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  338. // Detect if some page were added automatically and output _tableau for past pages
  339. while ($pagenb < $pageposafter)
  340. {
  341. $pdf->setPage($pagenb);
  342. if ($pagenb == 1)
  343. {
  344. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  345. }
  346. else
  347. {
  348. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  349. }
  350. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  351. $pagenb++;
  352. $pdf->setPage($pagenb);
  353. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  354. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  355. }
  356. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  357. {
  358. if ($pagenb == 1)
  359. {
  360. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  361. }
  362. else
  363. {
  364. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  365. }
  366. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  367. // New page
  368. $pdf->AddPage();
  369. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  370. $pagenb++;
  371. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  372. }
  373. }
  374. }
  375. // Show square
  376. if ($pagenb == 1)
  377. {
  378. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  379. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  380. }
  381. else
  382. {
  383. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  384. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  385. }
  386. $this->_pagefoot($pdf, $object, $outputlangs);
  387. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  388. $pdf->Close();
  389. $pdf->Output($file, 'F');
  390. // Add pdfgeneration hook
  391. $hookmanager->initHooks(array('pdfgeneration'));
  392. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  393. global $action;
  394. $reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  395. if ($reshook < 0)
  396. {
  397. $this->error = $hookmanager->error;
  398. $this->errors = $hookmanager->errors;
  399. }
  400. if (! empty($conf->global->MAIN_UMASK))
  401. @chmod($file, octdec($conf->global->MAIN_UMASK));
  402. $this->result = array('fullpath'=>$file);
  403. return 1;
  404. }
  405. else
  406. {
  407. $this->error=$langs->trans("ErrorCanNotCreateDir", $dir);
  408. return 0;
  409. }
  410. }
  411. else
  412. {
  413. $this->error=$langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
  414. return 0;
  415. }
  416. }
  417. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  418. /**
  419. * Show table for lines
  420. *
  421. * @param PDF $pdf Object PDF
  422. * @param string $tab_top Top position of table
  423. * @param string $tab_height Height of table (rectangle)
  424. * @param int $nexY Y
  425. * @param Translate $outputlangs Langs object
  426. * @param int $hidetop Hide top bar of array
  427. * @param int $hidebottom Hide bottom bar of array
  428. * @return void
  429. */
  430. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  431. {
  432. global $conf;
  433. $default_font_size = pdf_getPDFFontSize($outputlangs);
  434. /*
  435. $pdf->SetXY($this->marge_gauche, $tab_top);
  436. $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
  437. $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
  438. $pdf->SetFont('','', $default_font_size - 1);
  439. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  440. $pdf->SetXY($this->marge_gauche, $tab_top + 8);
  441. $text=$object->description;
  442. if ($object->duration > 0)
  443. {
  444. $totaltime=convertSecondToTime($object->duration,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
  445. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  446. }
  447. $desc=dol_htmlentitiesbr($text,1);
  448. //print $outputlangs->convToOutputCharset($desc); exit;
  449. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
  450. $nexY = $pdf->GetY();
  451. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  452. $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  453. */
  454. // Output Rect
  455. $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height+1, 0, 0); // Rect takes a length in 3rd parameter and 4th parameter
  456. if (empty($hidebottom))
  457. {
  458. $pdf->SetXY(20, 230);
  459. $pdf->MultiCell(66, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', 0);
  460. $pdf->SetXY(20, 235);
  461. $pdf->MultiCell(80, 25, '', 1);
  462. $pdf->SetXY(110, 230);
  463. $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', 0);
  464. $pdf->SetXY(110, 235);
  465. $pdf->MultiCell(80, 25, '', 1);
  466. }
  467. }
  468. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  469. /**
  470. * Show top header of page.
  471. *
  472. * @param PDF $pdf Object PDF
  473. * @param Object $object Object to show
  474. * @param int $showaddress 0=no, 1=yes
  475. * @param Translate $outputlangs Object lang for output
  476. * @return void
  477. */
  478. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  479. {
  480. global $conf,$langs;
  481. $default_font_size = pdf_getPDFFontSize($outputlangs);
  482. // Load traductions files required by page
  483. $outputlangs->loadLangs(array("main", "dict", "companies", "interventions"));
  484. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  485. //Affiche le filigrane brouillon - Print Draft Watermark
  486. if($object->statut==0 && (! empty($conf->global->FICHINTER_DRAFT_WATERMARK)) )
  487. {
  488. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FICHINTER_DRAFT_WATERMARK);
  489. }
  490. //Prepare next
  491. $pdf->SetTextColor(0, 0, 60);
  492. $pdf->SetFont('', 'B', $default_font_size + 3);
  493. $posx=$this->page_largeur-$this->marge_droite-100;
  494. $posy=$this->marge_haute;
  495. $pdf->SetXY($this->marge_gauche, $posy);
  496. // Logo
  497. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  498. if ($this->emetteur->logo)
  499. {
  500. if (is_readable($logo))
  501. {
  502. $height=pdf_getHeightForLogo($logo);
  503. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  504. }
  505. else
  506. {
  507. $pdf->SetTextColor(200, 0, 0);
  508. $pdf->SetFont('', 'B', $default_font_size - 2);
  509. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  510. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  511. }
  512. }
  513. else
  514. {
  515. $text=$this->emetteur->name;
  516. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  517. }
  518. $pdf->SetFont('', 'B', $default_font_size + 3);
  519. $pdf->SetXY($posx, $posy);
  520. $pdf->SetTextColor(0, 0, 60);
  521. $title=$outputlangs->transnoentities("InterventionCard");
  522. $pdf->MultiCell(100, 4, $title, '', 'R');
  523. $pdf->SetFont('', 'B', $default_font_size + 2);
  524. $posy+=5;
  525. $pdf->SetXY($posx, $posy);
  526. $pdf->SetTextColor(0, 0, 60);
  527. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
  528. $posy+=1;
  529. $pdf->SetFont('', '', $default_font_size);
  530. $posy+=4;
  531. $pdf->SetXY($posx, $posy);
  532. $pdf->SetTextColor(0, 0, 60);
  533. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
  534. if ($object->thirdparty->code_client)
  535. {
  536. $posy+=4;
  537. $pdf->SetXY($posx, $posy);
  538. $pdf->SetTextColor(0, 0, 60);
  539. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  540. }
  541. if ($showaddress)
  542. {
  543. // Sender properties
  544. $carac_emetteur='';
  545. // Add internal contact of proposal if defined
  546. $arrayidcontact=$object->getIdContact('internal', 'INTERREPFOLL');
  547. if (count($arrayidcontact) > 0)
  548. {
  549. $object->fetch_user($arrayidcontact[0]);
  550. $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  551. }
  552. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  553. // Show sender
  554. $posy=42;
  555. $posx=$this->marge_gauche;
  556. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  557. $hautcadre=40;
  558. // Show sender frame
  559. $pdf->SetTextColor(0, 0, 0);
  560. $pdf->SetFont('', '', $default_font_size - 2);
  561. $pdf->SetXY($posx, $posy-5);
  562. $pdf->SetXY($posx, $posy);
  563. $pdf->SetFillColor(230, 230, 230);
  564. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  565. // Show sender name
  566. $pdf->SetXY($posx+2, $posy+3);
  567. $pdf->SetTextColor(0, 0, 60);
  568. $pdf->SetFont('', 'B', $default_font_size);
  569. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  570. $posy=$pdf->getY();
  571. // Show sender information
  572. $pdf->SetFont('', '', $default_font_size - 1);
  573. $pdf->SetXY($posx+2, $posy);
  574. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  575. // If CUSTOMER contact defined, we use it
  576. $usecontact=false;
  577. $arrayidcontact=$object->getIdContact('external', 'CUSTOMER');
  578. if (count($arrayidcontact) > 0)
  579. {
  580. $usecontact=true;
  581. $result=$object->fetch_contact($arrayidcontact[0]);
  582. }
  583. //Recipient name
  584. // On peut utiliser le nom de la societe du contact
  585. if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
  586. $thirdparty = $object->contact;
  587. } else {
  588. $thirdparty = $object->thirdparty;
  589. }
  590. $carac_client_name=pdfBuildThirdpartyName($thirdparty, $outputlangs);
  591. $carac_client=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact)?$object->contact:''), $usecontact, 'target', $object);
  592. // Show recipient
  593. $widthrecbox=100;
  594. if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
  595. $posy=42;
  596. $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
  597. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  598. // Show recipient frame
  599. $pdf->SetTextColor(0, 0, 0);
  600. $pdf->SetFont('', '', $default_font_size - 2);
  601. $pdf->SetXY($posx+2, $posy-5);
  602. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  603. $pdf->SetTextColor(0, 0, 0);
  604. // Show recipient name
  605. $pdf->SetXY($posx+2, $posy+3);
  606. $pdf->SetFont('', 'B', $default_font_size);
  607. $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
  608. $posy = $pdf->getY();
  609. // Show recipient information
  610. $pdf->SetFont('', '', $default_font_size - 1);
  611. $pdf->SetXY($posx+2, $posy);
  612. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  613. }
  614. }
  615. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  616. /**
  617. * Show footer of page. Need this->emetteur object
  618. *
  619. * @param PDF $pdf PDF
  620. * @param Object $object Object to show
  621. * @param Translate $outputlangs Object lang for output
  622. * @param int $hidefreetext 1=Hide free text
  623. * @return integer
  624. */
  625. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  626. {
  627. global $conf;
  628. $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  629. return pdf_pagefoot($pdf, $outputlangs, 'FICHINTER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  630. }
  631. }