pdf_timespent.modules.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. * or see https://www.gnu.org/
  16. */
  17. /**
  18. * \file htdocs/core/modules/project/doc/pdf_timespent.modules.php
  19. * \ingroup project
  20. * \brief File of class to generate project document Baleine
  21. */
  22. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  23. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. /**
  30. * Class to manage generation of project document Timespent
  31. */
  32. class pdf_timespent extends ModelePDFProjects
  33. {
  34. /**
  35. * @var DoliDb Database handler
  36. */
  37. public $db;
  38. /**
  39. * @var string model name
  40. */
  41. public $name;
  42. /**
  43. * @var string model description (short text)
  44. */
  45. public $description;
  46. /**
  47. * @var int Save the name of generated file as the main doc when generating a doc with this template
  48. */
  49. public $update_main_doc_field;
  50. /**
  51. * @var string document type
  52. */
  53. public $type;
  54. /**
  55. * @var array Minimum version of PHP required by module.
  56. * e.g.: PHP ≥ 5.6 = array(5, 6)
  57. */
  58. public $phpmin = array(5, 6);
  59. /**
  60. * Dolibarr version of the loaded document
  61. * @var string
  62. */
  63. public $version = 'dolibarr';
  64. /**
  65. * @var int page_largeur
  66. */
  67. public $page_largeur;
  68. /**
  69. * @var int page_hauteur
  70. */
  71. public $page_hauteur;
  72. /**
  73. * @var array format
  74. */
  75. public $format;
  76. /**
  77. * @var int marge_gauche
  78. */
  79. public $marge_gauche;
  80. /**
  81. * @var int marge_droite
  82. */
  83. public $marge_droite;
  84. /**
  85. * @var int marge_haute
  86. */
  87. public $marge_haute;
  88. /**
  89. * @var int marge_basse
  90. */
  91. public $marge_basse;
  92. /**
  93. * Issuer
  94. * @var Societe Object that emits
  95. */
  96. public $emetteur;
  97. /**
  98. * Constructor
  99. *
  100. * @param DoliDB $db Database handler
  101. */
  102. public function __construct($db)
  103. {
  104. global $conf, $langs, $mysoc;
  105. // Translations
  106. $langs->loadLangs(array("main", "projects", "companies"));
  107. $this->db = $db;
  108. $this->name = "timespent";
  109. $this->description = $langs->trans("DocumentModelTimeSpent");
  110. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  111. // Page size for A4 format
  112. $this->type = 'pdf';
  113. $formatarray = pdf_getFormat();
  114. $this->page_largeur = $formatarray['width'];
  115. $this->page_hauteur = $formatarray['height'];
  116. $this->format = array($this->page_largeur, $this->page_hauteur);
  117. $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  118. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  119. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  120. $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
  121. $this->option_logo = 1; // Display logo FAC_PDF_LOGO
  122. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  123. // Get source company
  124. $this->emetteur = $mysoc;
  125. if (!$this->emetteur->country_code) {
  126. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  127. }
  128. // Define position of columns
  129. $this->posxref = $this->marge_gauche + 1;
  130. $this->posxlabel = $this->marge_gauche + 25;
  131. $this->posxworkload = $this->marge_gauche + 100;
  132. $this->posxtimespent = $this->marge_gauche + 120;
  133. //$this->posxprogress=$this->marge_gauche+140;
  134. $this->posxuser = $this->marge_gauche + 147;
  135. //$this->posxdateend = $this->marge_gauche + 169;
  136. if ($this->page_largeur < 210) { // To work with US executive format
  137. $this->posxref -= 20;
  138. $this->posxlabel -= 20;
  139. $this->posxtimespent -= 20;
  140. //$this->posxprogress-=20;
  141. $this->posxuser -= 20;
  142. //$this->posxdateend -= 20;
  143. }
  144. }
  145. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  146. /**
  147. * Function to build pdf project onto disk
  148. *
  149. * @param Project $object Object project a generer
  150. * @param Translate $outputlangs Lang output object
  151. * @return int 1 if OK, <=0 if KO
  152. */
  153. public function write_file($object, $outputlangs)
  154. {
  155. // phpcs:enable
  156. global $conf, $hookmanager, $langs, $user;
  157. if (!is_object($outputlangs)) {
  158. $outputlangs = $langs;
  159. }
  160. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  161. if (!empty($conf->global->MAIN_USE_FPDF)) {
  162. $outputlangs->charset_output = 'ISO-8859-1';
  163. }
  164. // Load traductions files required by page
  165. $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
  166. if ($conf->project->dir_output) {
  167. //$nblines = count($object->lines); // This is set later with array of tasks
  168. $objectref = dol_sanitizeFileName($object->ref);
  169. $dir = $conf->project->dir_output;
  170. if (!preg_match('/specimen/i', $objectref)) {
  171. $dir .= "/".$objectref;
  172. }
  173. $file = $dir."/".$objectref.".pdf";
  174. if (!file_exists($dir)) {
  175. if (dol_mkdir($dir) < 0) {
  176. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  177. return 0;
  178. }
  179. }
  180. if (file_exists($dir)) {
  181. // Add pdfgeneration hook
  182. if (!is_object($hookmanager)) {
  183. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  184. $hookmanager = new HookManager($this->db);
  185. }
  186. $hookmanager->initHooks(array('pdfgeneration'));
  187. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  188. global $action;
  189. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  190. // Create pdf instance
  191. $pdf = pdf_getInstance($this->format);
  192. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  193. $pdf->SetAutoPageBreak(1, 0);
  194. $heightforinfotot = 40; // Height reserved to output the info and total part
  195. $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
  196. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  197. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  198. $heightforfooter += 6;
  199. }
  200. if (class_exists('TCPDF')) {
  201. $pdf->setPrintHeader(false);
  202. $pdf->setPrintFooter(false);
  203. }
  204. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  205. // Set path to the background PDF File
  206. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  207. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  208. $tplidx = $pdf->importPage(1);
  209. }
  210. // Complete object by loading several other informations
  211. $task = new Task($this->db);
  212. $tasksarray = $task->getTasksArray(0, 0, $object->id);
  213. if (!$object->id > 0) { // Special case when used with object = specimen, we may return all lines
  214. $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
  215. }
  216. $object->lines = $tasksarray;
  217. $nblines = count($object->lines);
  218. $pdf->Open();
  219. $pagenb = 0;
  220. $pdf->SetDrawColor(128, 128, 128);
  221. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  222. $pdf->SetSubject($outputlangs->transnoentities("Project"));
  223. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  224. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  225. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
  226. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  227. $pdf->SetCompression(false);
  228. }
  229. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  230. // New page
  231. $pdf->AddPage();
  232. if (!empty($tplidx)) {
  233. $pdf->useTemplate($tplidx);
  234. }
  235. $pagenb++;
  236. $this->_pagehead($pdf, $object, 1, $outputlangs);
  237. $pdf->SetFont('', '', $default_font_size - 1);
  238. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  239. $pdf->SetTextColor(0, 0, 0);
  240. $tab_top = 50;
  241. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  242. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  243. // Show public note
  244. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  245. if ($notetoshow) {
  246. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  247. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  248. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  249. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  250. $tab_top -= 2;
  251. $pdf->SetFont('', '', $default_font_size - 1);
  252. $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($notetoshow), 0, 1);
  253. $nexY = $pdf->GetY();
  254. $height_note = $nexY - $tab_top;
  255. // Rect takes a length in 3rd parameter
  256. $pdf->SetDrawColor(192, 192, 192);
  257. $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
  258. $tab_height = $tab_height - $height_note;
  259. $tab_top = $nexY + 6;
  260. } else {
  261. $height_note = 0;
  262. }
  263. $heightoftitleline = 10;
  264. $iniY = $tab_top + $heightoftitleline + 1;
  265. $curY = $tab_top + $heightoftitleline + 1;
  266. $nexY = $tab_top + $heightoftitleline + 1;
  267. $tmpuser = new User($this->db);
  268. // TODO We should loop on record of times spent grouped by user instead of lines of tasks
  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. $duration = convertSecondToTime((int) $object->lines[$i]->duration, 'allhourmin');
  284. $showpricebeforepagebreak = 1;
  285. $pdf->startTransaction();
  286. // Label
  287. $pdf->SetXY($this->posxlabel, $curY);
  288. $pdf->MultiCell($this->posxtimespent - $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->posxtimespent - $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->posxtimespent - $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. // timespent
  368. $pdf->SetXY($this->posxtimespent, $curY);
  369. $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration : '', 0, 'R');
  370. // Progress
  371. //$pdf->SetXY($this->posxprogress, $curY);
  372. //$pdf->MultiCell($this->posxuser-$this->posxprogress, 3, $progress, 0, 'R');
  373. // User spending time
  374. /*var_dump($object->lines[$i]);exit;
  375. $tmpuser->fetch($object->lines[$i]->fk_user);
  376. $pdf->SetXY($this->posxuser, $curY);
  377. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, $tmpuser->getFullName($outputlangs, 0, -1, 20), 0, 'C');
  378. */
  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->posxtimespent - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
  491. $pdf->SetXY($this->posxtimespent, $tab_top + 1);
  492. $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $outputlangs->transnoentities("TimeSpent"), 0, 'R');
  493. //$pdf->SetXY($this->posxprogress, $tab_top+1);
  494. //$pdf->MultiCell($this->posxuser - $this->posxprogress, 3, '%', 0, 'R');
  495. $pdf->SetXY($this->posxuser, $tab_top + 1);
  496. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, '', 0, 'C');
  497. }
  498. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  499. /**
  500. * Show top header of page.
  501. *
  502. * @param TCPDF $pdf Object PDF
  503. * @param Project $object Object to show
  504. * @param int $showaddress 0=no, 1=yes
  505. * @param Translate $outputlangs Object lang for output
  506. * @return void
  507. */
  508. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  509. {
  510. global $langs, $conf, $mysoc;
  511. $default_font_size = pdf_getPDFFontSize($outputlangs);
  512. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  513. $pdf->SetTextColor(0, 0, 60);
  514. $pdf->SetFont('', 'B', $default_font_size + 3);
  515. $posx = $this->page_largeur - $this->marge_droite - 100;
  516. $posy = $this->marge_haute;
  517. $pdf->SetXY($this->marge_gauche, $posy);
  518. // Logo
  519. $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  520. if ($mysoc->logo) {
  521. if (is_readable($logo)) {
  522. $height = pdf_getHeightForLogo($logo);
  523. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  524. } else {
  525. $pdf->SetTextColor(200, 0, 0);
  526. $pdf->SetFont('', 'B', $default_font_size - 2);
  527. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  528. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  529. }
  530. } else {
  531. $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  532. }
  533. $pdf->SetFont('', 'B', $default_font_size + 3);
  534. $pdf->SetXY($posx, $posy);
  535. $pdf->SetTextColor(0, 0, 60);
  536. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  537. $pdf->SetFont('', '', $default_font_size + 2);
  538. $posy += 6;
  539. $pdf->SetXY($posx, $posy);
  540. $pdf->SetTextColor(0, 0, 60);
  541. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : ".dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
  542. $posy += 6;
  543. $pdf->SetXY($posx, $posy);
  544. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : ".dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
  545. if (is_object($object->thirdparty)) {
  546. $posy += 6;
  547. $pdf->SetXY($posx, $posy);
  548. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty")." : ".$object->thirdparty->getFullName($outputlangs), '', 'R');
  549. }
  550. $pdf->SetTextColor(0, 0, 60);
  551. // Add list of linked objects
  552. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  553. $object->fetchObjectLinked();
  554. foreach($object->linkedObjects as $objecttype => $objects)
  555. {
  556. //var_dump($objects);exit;
  557. if ($objecttype == 'commande')
  558. {
  559. $outputlangs->load('orders');
  560. $num=count($objects);
  561. for ($i=0;$i<$num;$i++)
  562. {
  563. $posy+=4;
  564. $pdf->SetXY($posx,$posy);
  565. $pdf->SetFont('','', $default_font_size - 1);
  566. $text=$objects[$i]->ref;
  567. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  568. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  569. }
  570. }
  571. }
  572. */
  573. }
  574. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  575. /**
  576. * Show footer of page. Need this->emetteur object
  577. *
  578. * @param TCPDF $pdf PDF
  579. * @param Project $object Object to show
  580. * @param Translate $outputlangs Object lang for output
  581. * @param int $hidefreetext 1=Hide free text
  582. * @return integer
  583. */
  584. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  585. {
  586. global $conf;
  587. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  588. return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  589. }
  590. }