pdf_soleil.modules.php 27 KB

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