pdf_baleine.modules.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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 = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  120. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  121. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  122. $this->marge_basse = getDolGlobalInt('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. // Get source company
  126. $this->emetteur = $mysoc;
  127. if (!$this->emetteur->country_code) {
  128. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  129. }
  130. // Define position of columns
  131. $this->posxref = $this->marge_gauche + 1;
  132. $this->posxlabel = $this->marge_gauche + 25;
  133. $this->posxworkload = $this->marge_gauche + 117;
  134. $this->posxprogress = $this->marge_gauche + 137;
  135. $this->posxdatestart = $this->marge_gauche + 147;
  136. $this->posxdateend = $this->marge_gauche + 169;
  137. if ($this->page_largeur < 210) { // To work with US executive format
  138. $this->posxref -= 20;
  139. $this->posxlabel -= 20;
  140. $this->posxworkload -= 20;
  141. $this->posxprogress -= 20;
  142. $this->posxdatestart -= 20;
  143. $this->posxdateend -= 20;
  144. }
  145. }
  146. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  147. /**
  148. * Function to build pdf project onto disk
  149. *
  150. * @param Project $object Object project a generer
  151. * @param Translate $outputlangs Lang output object
  152. * @return int 1 if OK, <=0 if KO
  153. */
  154. public function write_file($object, $outputlangs)
  155. {
  156. // phpcs:enable
  157. global $conf, $hookmanager, $langs, $user;
  158. if (!is_object($outputlangs)) {
  159. $outputlangs = $langs;
  160. }
  161. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  162. if (!empty($conf->global->MAIN_USE_FPDF)) {
  163. $outputlangs->charset_output = 'ISO-8859-1';
  164. }
  165. // Load traductions files required by page
  166. $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
  167. if ($conf->project->dir_output) {
  168. //$nblines = count($object->lines); // This is set later with array of tasks
  169. $objectref = dol_sanitizeFileName($object->ref);
  170. $dir = $conf->project->dir_output;
  171. if (!preg_match('/specimen/i', $objectref)) {
  172. $dir .= "/".$objectref;
  173. }
  174. $file = $dir."/".$objectref.".pdf";
  175. if (!file_exists($dir)) {
  176. if (dol_mkdir($dir) < 0) {
  177. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  178. return 0;
  179. }
  180. }
  181. if (file_exists($dir)) {
  182. // Add pdfgeneration hook
  183. if (!is_object($hookmanager)) {
  184. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  185. $hookmanager = new HookManager($this->db);
  186. }
  187. $hookmanager->initHooks(array('pdfgeneration'));
  188. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  189. global $action;
  190. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  191. // Create pdf instance
  192. $pdf = pdf_getInstance($this->format);
  193. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  194. $pdf->SetAutoPageBreak(1, 0);
  195. $heightforinfotot = 40; // Height reserved to output the info and total part
  196. $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
  197. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  198. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  199. $heightforfooter += 6;
  200. }
  201. if (class_exists('TCPDF')) {
  202. $pdf->setPrintHeader(false);
  203. $pdf->setPrintFooter(false);
  204. }
  205. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  206. // Set path to the background PDF File
  207. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  208. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  209. $tplidx = $pdf->importPage(1);
  210. }
  211. // Complete object by loading several other informations
  212. $task = new Task($this->db);
  213. $tasksarray = $task->getTasksArray(0, 0, $object->id);
  214. if (!$object->id > 0) { // Special case when used with object = specimen, we may return all lines
  215. $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
  216. }
  217. $object->lines = $tasksarray;
  218. $nblines = count($object->lines);
  219. $pdf->Open();
  220. $pagenb = 0;
  221. $pdf->SetDrawColor(128, 128, 128);
  222. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  223. $pdf->SetSubject($outputlangs->transnoentities("Project"));
  224. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  225. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  226. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
  227. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  228. $pdf->SetCompression(false);
  229. }
  230. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  231. // New page
  232. $pdf->AddPage();
  233. if (!empty($tplidx)) {
  234. $pdf->useTemplate($tplidx);
  235. }
  236. $pagenb++;
  237. $this->_pagehead($pdf, $object, 1, $outputlangs);
  238. $pdf->SetFont('', '', $default_font_size - 1);
  239. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  240. $pdf->SetTextColor(0, 0, 0);
  241. $tab_top = 50;
  242. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  243. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  244. // Show public note
  245. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  246. if ($notetoshow) {
  247. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  248. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  249. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  250. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  251. $tab_top -= 2;
  252. $pdf->SetFont('', '', $default_font_size - 1);
  253. $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($notetoshow), 0, 1);
  254. $nexY = $pdf->GetY();
  255. $height_note = $nexY - $tab_top;
  256. // Rect takes a length in 3rd parameter
  257. $pdf->SetDrawColor(192, 192, 192);
  258. $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
  259. $tab_height = $tab_height - $height_note;
  260. $tab_top = $nexY + 6;
  261. } else {
  262. $height_note = 0;
  263. }
  264. $heightoftitleline = 10;
  265. $iniY = $tab_top + $heightoftitleline + 1;
  266. $curY = $tab_top + $heightoftitleline + 1;
  267. $nexY = $tab_top + $heightoftitleline + 1;
  268. // Loop on each lines
  269. for ($i = 0; $i < $nblines; $i++) {
  270. $curY = $nexY;
  271. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  272. $pdf->SetTextColor(0, 0, 0);
  273. $pdf->setTopMargin($tab_top_newpage);
  274. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  275. $pageposbefore = $pdf->getPage();
  276. // Description of line
  277. $ref = $object->lines[$i]->ref;
  278. $libelleline = $object->lines[$i]->label;
  279. $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.'%' : '');
  280. $datestart = dol_print_date($object->lines[$i]->date_start, 'day');
  281. $dateend = dol_print_date($object->lines[$i]->date_end, 'day');
  282. $planned_workload = convertSecondToTime((int) $object->lines[$i]->planned_workload, 'allhourmin');
  283. $showpricebeforepagebreak = 1;
  284. $pdf->startTransaction();
  285. // Label
  286. $pdf->SetXY($this->posxlabel, $curY);
  287. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  288. $pageposafter = $pdf->getPage();
  289. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  290. $pdf->rollbackTransaction(true);
  291. $pageposafter = $pageposbefore;
  292. //print $pageposafter.'-'.$pageposbefore;exit;
  293. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  294. // Label
  295. $pdf->SetXY($this->posxlabel, $curY);
  296. $posybefore = $pdf->GetY();
  297. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  298. $pageposafter = $pdf->getPage();
  299. $posyafter = $pdf->GetY();
  300. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  301. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  302. $pdf->AddPage('', '', true);
  303. if (!empty($tplidx)) {
  304. $pdf->useTemplate($tplidx);
  305. }
  306. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  307. $this->_pagehead($pdf, $object, 0, $outputlangs);
  308. }
  309. $pdf->setPage($pageposafter + 1);
  310. }
  311. } else {
  312. // We found a page break
  313. // Allows data in the first page if description is long enough to break in multiples pages
  314. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  315. $showpricebeforepagebreak = 1;
  316. } else {
  317. $showpricebeforepagebreak = 0;
  318. }
  319. $forcedesconsamepage = 1;
  320. if ($forcedesconsamepage) {
  321. $pdf->rollbackTransaction(true);
  322. $pageposafter = $pageposbefore;
  323. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  324. $pdf->AddPage('', '', true);
  325. if (!empty($tplidx)) {
  326. $pdf->useTemplate($tplidx);
  327. }
  328. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  329. $this->_pagehead($pdf, $object, 0, $outputlangs);
  330. }
  331. $pdf->setPage($pageposafter + 1);
  332. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  333. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  334. $pdf->SetTextColor(0, 0, 0);
  335. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  336. $curY = $tab_top_newpage + $heightoftitleline + 1;
  337. // Label
  338. $pdf->SetXY($this->posxlabel, $curY);
  339. $posybefore = $pdf->GetY();
  340. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  341. $pageposafter = $pdf->getPage();
  342. $posyafter = $pdf->GetY();
  343. }
  344. }
  345. //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak);
  346. } else // No pagebreak
  347. {
  348. $pdf->commitTransaction();
  349. }
  350. $posYAfterDescription = $pdf->GetY();
  351. $nexY = $pdf->GetY();
  352. $pageposafter = $pdf->getPage();
  353. $pdf->setPage($pageposbefore);
  354. $pdf->setTopMargin($this->marge_haute);
  355. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  356. // We suppose that a too long description is moved completely on next page
  357. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  358. //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak);
  359. $pdf->setPage($pageposafter);
  360. $curY = $tab_top_newpage + $heightoftitleline + 1;
  361. }
  362. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  363. // Ref of task
  364. $pdf->SetXY($this->posxref, $curY);
  365. $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
  366. // Workload
  367. $pdf->SetXY($this->posxworkload, $curY);
  368. $pdf->SetFont('', '', $default_font_size - 2); // We use a smaller font
  369. $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload : '', 0, 'R');
  370. // Progress
  371. $pdf->SetXY($this->posxprogress, $curY);
  372. $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0, 'R');
  373. $pdf->SetFont('', '', $default_font_size - 1); // We restore font
  374. // Date start and end
  375. $pdf->SetXY($this->posxdatestart, $curY);
  376. $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0, 'C');
  377. $pdf->SetXY($this->posxdateend, $curY);
  378. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0, 'C');
  379. // Add line
  380. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  381. $pdf->setPage($pageposafter);
  382. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  383. //$pdf->SetDrawColor(190,190,200);
  384. $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
  385. $pdf->SetLineStyle(array('dash'=>0));
  386. }
  387. $nexY += 2; // Add space between lines
  388. // Detect if some page were added automatically and output _tableau for past pages
  389. while ($pagenb < $pageposafter) {
  390. $pdf->setPage($pagenb);
  391. if ($pagenb == 1) {
  392. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  393. } else {
  394. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  395. }
  396. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  397. $pagenb++;
  398. $pdf->setPage($pagenb);
  399. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  400. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  401. $this->_pagehead($pdf, $object, 0, $outputlangs);
  402. }
  403. if (!empty($tplidx)) {
  404. $pdf->useTemplate($tplidx);
  405. }
  406. }
  407. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  408. if ($pagenb == 1) {
  409. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  410. } else {
  411. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  412. }
  413. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  414. // New page
  415. $pdf->AddPage();
  416. if (!empty($tplidx)) {
  417. $pdf->useTemplate($tplidx);
  418. }
  419. $pagenb++;
  420. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  421. $this->_pagehead($pdf, $object, 0, $outputlangs);
  422. }
  423. }
  424. }
  425. // Show square
  426. if ($pagenb == 1) {
  427. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  428. } else {
  429. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  430. }
  431. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  432. // Footer of the page
  433. $this->_pagefoot($pdf, $object, $outputlangs);
  434. if (method_exists($pdf, 'AliasNbPages')) {
  435. $pdf->AliasNbPages();
  436. }
  437. $pdf->Close();
  438. $pdf->Output($file, 'F');
  439. // Add pdfgeneration hook
  440. $hookmanager->initHooks(array('pdfgeneration'));
  441. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  442. global $action;
  443. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  444. if ($reshook < 0) {
  445. $this->error = $hookmanager->error;
  446. $this->errors = $hookmanager->errors;
  447. }
  448. if (!empty($conf->global->MAIN_UMASK)) {
  449. @chmod($file, octdec($conf->global->MAIN_UMASK));
  450. }
  451. $this->result = array('fullpath'=>$file);
  452. return 1; // No error
  453. } else {
  454. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  455. return 0;
  456. }
  457. } else {
  458. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR");
  459. return 0;
  460. }
  461. }
  462. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  463. /**
  464. * Show table for lines
  465. *
  466. * @param TCPDF $pdf Object PDF
  467. * @param string $tab_top Top position of table
  468. * @param string $tab_height Height of table (rectangle)
  469. * @param int $nexY Y
  470. * @param Translate $outputlangs Langs object
  471. * @param int $hidetop Hide top bar of array
  472. * @param int $hidebottom Hide bottom bar of array
  473. * @return void
  474. */
  475. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  476. {
  477. global $conf, $mysoc;
  478. $heightoftitleline = 10;
  479. $default_font_size = pdf_getPDFFontSize($outputlangs);
  480. $pdf->SetDrawColor(128, 128, 128);
  481. // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter
  482. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
  483. // Line takes a position y in 3rd parameter
  484. $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
  485. $pdf->SetTextColor(0, 0, 0);
  486. $pdf->SetFont('', '', $default_font_size);
  487. $pdf->SetXY($this->posxref, $tab_top + 1);
  488. $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities("Tasks"), '', 'L');
  489. $pdf->SetXY($this->posxlabel, $tab_top + 1);
  490. $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
  491. $pdf->SetXY($this->posxworkload, $tab_top + 1);
  492. $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities("PlannedWorkloadShort"), 0, 'R');
  493. $pdf->SetXY($this->posxprogress, $tab_top + 1);
  494. $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, '%', 0, 'R');
  495. // Date start
  496. $pdf->SetXY($this->posxdatestart, $tab_top + 1);
  497. $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans("Start"), 0, 'C');
  498. // Date end
  499. $pdf->SetXY($this->posxdateend, $tab_top + 1);
  500. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans("End"), 0, 'C');
  501. }
  502. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  503. /**
  504. * Show top header of page.
  505. *
  506. * @param TCPDF $pdf Object PDF
  507. * @param Project $object Object to show
  508. * @param int $showaddress 0=no, 1=yes
  509. * @param Translate $outputlangs Object lang for output
  510. * @return void
  511. */
  512. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  513. {
  514. global $langs, $conf, $mysoc;
  515. $default_font_size = pdf_getPDFFontSize($outputlangs);
  516. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  517. $pdf->SetTextColor(0, 0, 60);
  518. $pdf->SetFont('', 'B', $default_font_size + 3);
  519. $posx = $this->page_largeur - $this->marge_droite - 100;
  520. $posy = $this->marge_haute;
  521. $pdf->SetXY($this->marge_gauche, $posy);
  522. // Logo
  523. $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  524. if ($mysoc->logo) {
  525. if (is_readable($logo)) {
  526. $height = pdf_getHeightForLogo($logo);
  527. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  528. } else {
  529. $pdf->SetTextColor(200, 0, 0);
  530. $pdf->SetFont('', 'B', $default_font_size - 2);
  531. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  532. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  533. }
  534. } else {
  535. $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  536. }
  537. $pdf->SetFont('', 'B', $default_font_size + 3);
  538. $pdf->SetXY($posx, $posy);
  539. $pdf->SetTextColor(0, 0, 60);
  540. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  541. $pdf->SetFont('', '', $default_font_size + 2);
  542. $posy += 6;
  543. $pdf->SetXY($posx, $posy);
  544. $pdf->SetTextColor(0, 0, 60);
  545. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : ".dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
  546. if ($object->date_end) {
  547. $posy += 6;
  548. $pdf->SetXY($posx, $posy);
  549. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : ".dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
  550. }
  551. if (is_object($object->thirdparty)) {
  552. $posy += 6;
  553. $pdf->SetXY($posx, $posy);
  554. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty")." : ".$object->thirdparty->getFullName($outputlangs), '', 'R');
  555. }
  556. $pdf->SetTextColor(0, 0, 60);
  557. // Add list of linked objects
  558. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  559. $object->fetchObjectLinked();
  560. foreach($object->linkedObjects as $objecttype => $objects)
  561. {
  562. //var_dump($objects);exit;
  563. if ($objecttype == 'commande')
  564. {
  565. $outputlangs->load('orders');
  566. $num=count($objects);
  567. for ($i=0;$i<$num;$i++)
  568. {
  569. $posy+=4;
  570. $pdf->SetXY($posx,$posy);
  571. $pdf->SetFont('','', $default_font_size - 1);
  572. $text=$objects[$i]->ref;
  573. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  574. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  575. }
  576. }
  577. }
  578. */
  579. }
  580. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  581. /**
  582. * Show footer of page. Need this->emetteur object
  583. *
  584. * @param TCPDF $pdf PDF
  585. * @param Project $object Object to show
  586. * @param Translate $outputlangs Object lang for output
  587. * @param int $hidefreetext 1=Hide free text
  588. * @return integer
  589. */
  590. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  591. {
  592. global $conf;
  593. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  594. return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  595. }
  596. }