pdf_baleine.modules.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/project/doc/pdf_baleine.modules.php
  21. * \ingroup project
  22. * \brief File of the class allowing to generate projects with the baleine model
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. /**
  32. * Class to manage generation of project document Baleine
  33. */
  34. class pdf_baleine extends ModelePDFProjects
  35. {
  36. /**
  37. * @var DoliDb Database handler
  38. */
  39. public $db;
  40. /**
  41. * @var string model name
  42. */
  43. public $name;
  44. /**
  45. * @var string model description (short text)
  46. */
  47. public $description;
  48. /**
  49. * @var int Save the name of generated file as the main doc when generating a doc with this template
  50. */
  51. public $update_main_doc_field;
  52. /**
  53. * @var string document type
  54. */
  55. public $type;
  56. /**
  57. * @var array Minimum version of PHP required by module.
  58. * e.g.: PHP ≥ 5.6 = array(5, 6)
  59. */
  60. public $phpmin = array(5, 6);
  61. /**
  62. * Dolibarr version of the loaded document
  63. * @var string
  64. */
  65. public $version = 'dolibarr';
  66. /**
  67. * @var int page_largeur
  68. */
  69. public $page_largeur;
  70. /**
  71. * @var int page_hauteur
  72. */
  73. public $page_hauteur;
  74. /**
  75. * @var array format
  76. */
  77. public $format;
  78. /**
  79. * @var int marge_gauche
  80. */
  81. public $marge_gauche;
  82. /**
  83. * @var int marge_droite
  84. */
  85. public $marge_droite;
  86. /**
  87. * @var int marge_haute
  88. */
  89. public $marge_haute;
  90. /**
  91. * @var int marge_basse
  92. */
  93. public $marge_basse;
  94. /**
  95. * Issuer
  96. * @var Societe Object that emits
  97. */
  98. public $emetteur;
  99. /**
  100. * Constructor
  101. *
  102. * @param DoliDB $db Database handler
  103. */
  104. public function __construct($db)
  105. {
  106. global $conf, $langs, $mysoc;
  107. // Translations
  108. $langs->loadLangs(array("main", "projects", "companies"));
  109. $this->db = $db;
  110. $this->name = "baleine";
  111. $this->description = $langs->trans("DocumentModelBaleine");
  112. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  113. // Page size for A4 format
  114. $this->type = 'pdf';
  115. $formatarray = pdf_getFormat();
  116. $this->page_largeur = $formatarray['width'];
  117. $this->page_hauteur = $formatarray['height'];
  118. $this->format = array($this->page_largeur, $this->page_hauteur);
  119. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  120. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  121. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  122. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  123. $this->option_logo = 1; // Display logo FAC_PDF_LOGO
  124. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  125. $this->option_codeproduitservice = 1; // Display product-service code
  126. // Get source company
  127. $this->emetteur = $mysoc;
  128. if (!$this->emetteur->country_code) {
  129. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  130. }
  131. // Define position of columns
  132. $this->posxref = $this->marge_gauche + 1;
  133. $this->posxlabel = $this->marge_gauche + 25;
  134. $this->posxworkload = $this->marge_gauche + 117;
  135. $this->posxprogress = $this->marge_gauche + 137;
  136. $this->posxdatestart = $this->marge_gauche + 147;
  137. $this->posxdateend = $this->marge_gauche + 169;
  138. if ($this->page_largeur < 210) { // To work with US executive format
  139. $this->posxref -= 20;
  140. $this->posxlabel -= 20;
  141. $this->posxworkload -= 20;
  142. $this->posxprogress -= 20;
  143. $this->posxdatestart -= 20;
  144. $this->posxdateend -= 20;
  145. }
  146. }
  147. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  148. /**
  149. * Function to build pdf project onto disk
  150. *
  151. * @param Project $object Object project a generer
  152. * @param Translate $outputlangs Lang output object
  153. * @return int 1 if OK, <=0 if KO
  154. */
  155. public function write_file($object, $outputlangs)
  156. {
  157. // phpcs:enable
  158. global $conf, $hookmanager, $langs, $user;
  159. if (!is_object($outputlangs)) {
  160. $outputlangs = $langs;
  161. }
  162. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  163. if (!empty($conf->global->MAIN_USE_FPDF)) {
  164. $outputlangs->charset_output = 'ISO-8859-1';
  165. }
  166. // Load traductions files required by page
  167. $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
  168. if ($conf->projet->dir_output) {
  169. //$nblines = count($object->lines); // This is set later with array of tasks
  170. $objectref = dol_sanitizeFileName($object->ref);
  171. $dir = $conf->projet->dir_output;
  172. if (!preg_match('/specimen/i', $objectref)) {
  173. $dir .= "/".$objectref;
  174. }
  175. $file = $dir."/".$objectref.".pdf";
  176. if (!file_exists($dir)) {
  177. if (dol_mkdir($dir) < 0) {
  178. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  179. return 0;
  180. }
  181. }
  182. if (file_exists($dir)) {
  183. // Add pdfgeneration hook
  184. if (!is_object($hookmanager)) {
  185. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  186. $hookmanager = new HookManager($this->db);
  187. }
  188. $hookmanager->initHooks(array('pdfgeneration'));
  189. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  190. global $action;
  191. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  192. // Create pdf instance
  193. $pdf = pdf_getInstance($this->format);
  194. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  195. $pdf->SetAutoPageBreak(1, 0);
  196. $heightforinfotot = 40; // Height reserved to output the info and total part
  197. $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
  198. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  199. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  200. $heightforfooter += 6;
  201. }
  202. if (class_exists('TCPDF')) {
  203. $pdf->setPrintHeader(false);
  204. $pdf->setPrintFooter(false);
  205. }
  206. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  207. // Set path to the background PDF File
  208. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  209. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  210. $tplidx = $pdf->importPage(1);
  211. }
  212. // Complete object by loading several other informations
  213. $task = new Task($this->db);
  214. $tasksarray = $task->getTasksArray(0, 0, $object->id);
  215. if (!$object->id > 0) { // Special case when used with object = specimen, we may return all lines
  216. $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
  217. }
  218. $object->lines = $tasksarray;
  219. $nblines = count($object->lines);
  220. $pdf->Open();
  221. $pagenb = 0;
  222. $pdf->SetDrawColor(128, 128, 128);
  223. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  224. $pdf->SetSubject($outputlangs->transnoentities("Project"));
  225. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  226. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  227. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
  228. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  229. $pdf->SetCompression(false);
  230. }
  231. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  232. // New page
  233. $pdf->AddPage();
  234. if (!empty($tplidx)) {
  235. $pdf->useTemplate($tplidx);
  236. }
  237. $pagenb++;
  238. $this->_pagehead($pdf, $object, 1, $outputlangs);
  239. $pdf->SetFont('', '', $default_font_size - 1);
  240. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  241. $pdf->SetTextColor(0, 0, 0);
  242. $tab_top = 50;
  243. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  244. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  245. // Show public note
  246. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  247. if ($notetoshow) {
  248. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  249. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  250. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  251. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  252. $tab_top -= 2;
  253. $pdf->SetFont('', '', $default_font_size - 1);
  254. $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($notetoshow), 0, 1);
  255. $nexY = $pdf->GetY();
  256. $height_note = $nexY - $tab_top;
  257. // Rect takes a length in 3rd parameter
  258. $pdf->SetDrawColor(192, 192, 192);
  259. $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
  260. $tab_height = $tab_height - $height_note;
  261. $tab_top = $nexY + 6;
  262. } else {
  263. $height_note = 0;
  264. }
  265. $heightoftitleline = 10;
  266. $iniY = $tab_top + $heightoftitleline + 1;
  267. $curY = $tab_top + $heightoftitleline + 1;
  268. $nexY = $tab_top + $heightoftitleline + 1;
  269. // Loop on each lines
  270. for ($i = 0; $i < $nblines; $i++) {
  271. $curY = $nexY;
  272. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  273. $pdf->SetTextColor(0, 0, 0);
  274. $pdf->setTopMargin($tab_top_newpage);
  275. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  276. $pageposbefore = $pdf->getPage();
  277. // Description of line
  278. $ref = $object->lines[$i]->ref;
  279. $libelleline = $object->lines[$i]->label;
  280. $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.'%' : '');
  281. $datestart = dol_print_date($object->lines[$i]->date_start, 'day');
  282. $dateend = dol_print_date($object->lines[$i]->date_end, 'day');
  283. $planned_workload = convertSecondToTime((int) $object->lines[$i]->planned_workload, 'allhourmin');
  284. $showpricebeforepagebreak = 1;
  285. $pdf->startTransaction();
  286. // Label
  287. $pdf->SetXY($this->posxlabel, $curY);
  288. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  289. $pageposafter = $pdf->getPage();
  290. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  291. $pdf->rollbackTransaction(true);
  292. $pageposafter = $pageposbefore;
  293. //print $pageposafter.'-'.$pageposbefore;exit;
  294. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  295. // Label
  296. $pdf->SetXY($this->posxlabel, $curY);
  297. $posybefore = $pdf->GetY();
  298. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  299. $pageposafter = $pdf->getPage();
  300. $posyafter = $pdf->GetY();
  301. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  302. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  303. $pdf->AddPage('', '', true);
  304. if (!empty($tplidx)) {
  305. $pdf->useTemplate($tplidx);
  306. }
  307. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  308. $this->_pagehead($pdf, $object, 0, $outputlangs);
  309. }
  310. $pdf->setPage($pageposafter + 1);
  311. }
  312. } else {
  313. // We found a page break
  314. // Allows data in the first page if description is long enough to break in multiples pages
  315. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  316. $showpricebeforepagebreak = 1;
  317. } else {
  318. $showpricebeforepagebreak = 0;
  319. }
  320. $forcedesconsamepage = 1;
  321. if ($forcedesconsamepage) {
  322. $pdf->rollbackTransaction(true);
  323. $pageposafter = $pageposbefore;
  324. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  325. $pdf->AddPage('', '', true);
  326. if (!empty($tplidx)) {
  327. $pdf->useTemplate($tplidx);
  328. }
  329. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  330. $this->_pagehead($pdf, $object, 0, $outputlangs);
  331. }
  332. $pdf->setPage($pageposafter + 1);
  333. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  334. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  335. $pdf->SetTextColor(0, 0, 0);
  336. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  337. $curY = $tab_top_newpage + $heightoftitleline + 1;
  338. // Label
  339. $pdf->SetXY($this->posxlabel, $curY);
  340. $posybefore = $pdf->GetY();
  341. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  342. $pageposafter = $pdf->getPage();
  343. $posyafter = $pdf->GetY();
  344. }
  345. }
  346. //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak);
  347. } else // No pagebreak
  348. {
  349. $pdf->commitTransaction();
  350. }
  351. $posYAfterDescription = $pdf->GetY();
  352. $nexY = $pdf->GetY();
  353. $pageposafter = $pdf->getPage();
  354. $pdf->setPage($pageposbefore);
  355. $pdf->setTopMargin($this->marge_haute);
  356. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  357. // We suppose that a too long description is moved completely on next page
  358. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  359. //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak);
  360. $pdf->setPage($pageposafter);
  361. $curY = $tab_top_newpage + $heightoftitleline + 1;
  362. }
  363. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  364. // Ref of task
  365. $pdf->SetXY($this->posxref, $curY);
  366. $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
  367. // Workload
  368. $pdf->SetXY($this->posxworkload, $curY);
  369. $pdf->SetFont('', '', $default_font_size - 2); // We use a smaller font
  370. $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload : '', 0, 'R');
  371. // Progress
  372. $pdf->SetXY($this->posxprogress, $curY);
  373. $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0, 'R');
  374. $pdf->SetFont('', '', $default_font_size - 1); // We restore font
  375. // Date start and end
  376. $pdf->SetXY($this->posxdatestart, $curY);
  377. $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0, 'C');
  378. $pdf->SetXY($this->posxdateend, $curY);
  379. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0, 'C');
  380. // Add line
  381. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  382. $pdf->setPage($pageposafter);
  383. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  384. //$pdf->SetDrawColor(190,190,200);
  385. $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
  386. $pdf->SetLineStyle(array('dash'=>0));
  387. }
  388. $nexY += 2; // Add space between lines
  389. // Detect if some page were added automatically and output _tableau for past pages
  390. while ($pagenb < $pageposafter) {
  391. $pdf->setPage($pagenb);
  392. if ($pagenb == 1) {
  393. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  394. } else {
  395. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  396. }
  397. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  398. $pagenb++;
  399. $pdf->setPage($pagenb);
  400. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  401. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  402. $this->_pagehead($pdf, $object, 0, $outputlangs);
  403. }
  404. }
  405. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  406. if ($pagenb == 1) {
  407. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  408. } else {
  409. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  410. }
  411. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  412. // New page
  413. $pdf->AddPage();
  414. if (!empty($tplidx)) {
  415. $pdf->useTemplate($tplidx);
  416. }
  417. $pagenb++;
  418. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  419. $this->_pagehead($pdf, $object, 0, $outputlangs);
  420. }
  421. }
  422. }
  423. // Show square
  424. if ($pagenb == 1) {
  425. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  426. } else {
  427. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  428. }
  429. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  430. // Footer of the page
  431. $this->_pagefoot($pdf, $object, $outputlangs);
  432. if (method_exists($pdf, 'AliasNbPages')) {
  433. $pdf->AliasNbPages();
  434. }
  435. $pdf->Close();
  436. $pdf->Output($file, 'F');
  437. // Add pdfgeneration hook
  438. $hookmanager->initHooks(array('pdfgeneration'));
  439. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  440. global $action;
  441. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  442. if ($reshook < 0) {
  443. $this->error = $hookmanager->error;
  444. $this->errors = $hookmanager->errors;
  445. }
  446. if (!empty($conf->global->MAIN_UMASK)) {
  447. @chmod($file, octdec($conf->global->MAIN_UMASK));
  448. }
  449. $this->result = array('fullpath'=>$file);
  450. return 1; // No error
  451. } else {
  452. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  453. return 0;
  454. }
  455. } else {
  456. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR");
  457. return 0;
  458. }
  459. }
  460. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  461. /**
  462. * Show table for lines
  463. *
  464. * @param TCPDF $pdf Object PDF
  465. * @param string $tab_top Top position of table
  466. * @param string $tab_height Height of table (rectangle)
  467. * @param int $nexY Y
  468. * @param Translate $outputlangs Langs object
  469. * @param int $hidetop Hide top bar of array
  470. * @param int $hidebottom Hide bottom bar of array
  471. * @return void
  472. */
  473. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  474. {
  475. global $conf, $mysoc;
  476. $heightoftitleline = 10;
  477. $default_font_size = pdf_getPDFFontSize($outputlangs);
  478. $pdf->SetDrawColor(128, 128, 128);
  479. // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter
  480. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
  481. // Line takes a position y in 3rd parameter
  482. $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
  483. $pdf->SetTextColor(0, 0, 0);
  484. $pdf->SetFont('', '', $default_font_size);
  485. $pdf->SetXY($this->posxref, $tab_top + 1);
  486. $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities("Tasks"), '', 'L');
  487. $pdf->SetXY($this->posxlabel, $tab_top + 1);
  488. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
  489. $pdf->SetXY($this->posxworkload, $tab_top + 1);
  490. $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities("PlannedWorkloadShort"), 0, 'R');
  491. $pdf->SetXY($this->posxprogress, $tab_top + 1);
  492. $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, '%', 0, 'R');
  493. // Date start
  494. $pdf->SetXY($this->posxdatestart, $tab_top + 1);
  495. $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans("Start"), 0, 'C');
  496. // Date end
  497. $pdf->SetXY($this->posxdateend, $tab_top + 1);
  498. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans("End"), 0, 'C');
  499. }
  500. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  501. /**
  502. * Show top header of page.
  503. *
  504. * @param TCPDF $pdf Object PDF
  505. * @param Project $object Object to show
  506. * @param int $showaddress 0=no, 1=yes
  507. * @param Translate $outputlangs Object lang for output
  508. * @return void
  509. */
  510. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  511. {
  512. global $langs, $conf, $mysoc;
  513. $default_font_size = pdf_getPDFFontSize($outputlangs);
  514. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  515. $pdf->SetTextColor(0, 0, 60);
  516. $pdf->SetFont('', 'B', $default_font_size + 3);
  517. $posx = $this->page_largeur - $this->marge_droite - 100;
  518. $posy = $this->marge_haute;
  519. $pdf->SetXY($this->marge_gauche, $posy);
  520. // Logo
  521. $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  522. if ($mysoc->logo) {
  523. if (is_readable($logo)) {
  524. $height = pdf_getHeightForLogo($logo);
  525. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  526. } else {
  527. $pdf->SetTextColor(200, 0, 0);
  528. $pdf->SetFont('', 'B', $default_font_size - 2);
  529. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  530. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  531. }
  532. } else {
  533. $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  534. }
  535. $pdf->SetFont('', 'B', $default_font_size + 3);
  536. $pdf->SetXY($posx, $posy);
  537. $pdf->SetTextColor(0, 0, 60);
  538. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  539. $pdf->SetFont('', '', $default_font_size + 2);
  540. $posy += 6;
  541. $pdf->SetXY($posx, $posy);
  542. $pdf->SetTextColor(0, 0, 60);
  543. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : ".dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
  544. if ($object->date_end) {
  545. $posy += 6;
  546. $pdf->SetXY($posx, $posy);
  547. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : ".dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
  548. }
  549. if (is_object($object->thirdparty)) {
  550. $posy += 6;
  551. $pdf->SetXY($posx, $posy);
  552. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty")." : ".$object->thirdparty->getFullName($outputlangs), '', 'R');
  553. }
  554. $pdf->SetTextColor(0, 0, 60);
  555. // Add list of linked objects
  556. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  557. $object->fetchObjectLinked();
  558. foreach($object->linkedObjects as $objecttype => $objects)
  559. {
  560. //var_dump($objects);exit;
  561. if ($objecttype == 'commande')
  562. {
  563. $outputlangs->load('orders');
  564. $num=count($objects);
  565. for ($i=0;$i<$num;$i++)
  566. {
  567. $posy+=4;
  568. $pdf->SetXY($posx,$posy);
  569. $pdf->SetFont('','', $default_font_size - 1);
  570. $text=$objects[$i]->ref;
  571. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  572. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  573. }
  574. }
  575. }
  576. */
  577. }
  578. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  579. /**
  580. * Show footer of page. Need this->emetteur object
  581. *
  582. * @param TCPDF $pdf PDF
  583. * @param Project $object Object to show
  584. * @param Translate $outputlangs Object lang for output
  585. * @param int $hidefreetext 1=Hide free text
  586. * @return integer
  587. */
  588. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  589. {
  590. global $conf;
  591. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  592. return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  593. }
  594. }