pdf_soleil.modules.php 27 KB

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