pdf_soleil.modules.php 27 KB

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