pdf_timespent.modules.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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 = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  118. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  119. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  120. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->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. $this->option_codeproduitservice = 1; // Display product-service code
  124. // Get source company
  125. $this->emetteur = $mysoc;
  126. if (!$this->emetteur->country_code) {
  127. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  128. }
  129. // Define position of columns
  130. $this->posxref = $this->marge_gauche + 1;
  131. $this->posxlabel = $this->marge_gauche + 25;
  132. $this->posxworkload = $this->marge_gauche + 100;
  133. $this->posxtimespent = $this->marge_gauche + 120;
  134. //$this->posxprogress=$this->marge_gauche+140;
  135. $this->posxuser = $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->posxtimespent -= 20;
  141. //$this->posxprogress-=20;
  142. $this->posxuser -= 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->projet->dir_output) {
  168. //$nblines = count($object->lines); // This is set later with array of tasks
  169. $objectref = dol_sanitizeFileName($object->ref);
  170. $dir = $conf->projet->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. $tmpuser = new User($this->db);
  269. // TODO We should loop on record of times spent grouped by user instead of lines of tasks
  270. // Loop on each lines
  271. for ($i = 0; $i < $nblines; $i++) {
  272. $curY = $nexY;
  273. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  274. $pdf->SetTextColor(0, 0, 0);
  275. $pdf->setTopMargin($tab_top_newpage);
  276. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  277. $pageposbefore = $pdf->getPage();
  278. // Description of line
  279. $ref = $object->lines[$i]->ref;
  280. $libelleline = $object->lines[$i]->label;
  281. //$progress=($object->lines[$i]->progress?$object->lines[$i]->progress.'%':'');
  282. $datestart = dol_print_date($object->lines[$i]->date_start, 'day');
  283. $dateend = dol_print_date($object->lines[$i]->date_end, 'day');
  284. $duration = convertSecondToTime((int) $object->lines[$i]->duration, 'allhourmin');
  285. $showpricebeforepagebreak = 1;
  286. $pdf->startTransaction();
  287. // Label
  288. $pdf->SetXY($this->posxlabel, $curY);
  289. $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  290. $pageposafter = $pdf->getPage();
  291. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  292. $pdf->rollbackTransaction(true);
  293. $pageposafter = $pageposbefore;
  294. //print $pageposafter.'-'.$pageposbefore;exit;
  295. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  296. // Label
  297. $pdf->SetXY($this->posxlabel, $curY);
  298. $posybefore = $pdf->GetY();
  299. $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  300. $pageposafter = $pdf->getPage();
  301. $posyafter = $pdf->GetY();
  302. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  303. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  304. $pdf->AddPage('', '', true);
  305. if (!empty($tplidx)) {
  306. $pdf->useTemplate($tplidx);
  307. }
  308. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  309. $this->_pagehead($pdf, $object, 0, $outputlangs);
  310. }
  311. $pdf->setPage($pageposafter + 1);
  312. }
  313. } else {
  314. // We found a page break
  315. // Allows data in the first page if description is long enough to break in multiples pages
  316. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  317. $showpricebeforepagebreak = 1;
  318. } else {
  319. $showpricebeforepagebreak = 0;
  320. }
  321. $forcedesconsamepage = 1;
  322. if ($forcedesconsamepage) {
  323. $pdf->rollbackTransaction(true);
  324. $pageposafter = $pageposbefore;
  325. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  326. $pdf->AddPage('', '', true);
  327. if (!empty($tplidx)) {
  328. $pdf->useTemplate($tplidx);
  329. }
  330. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  331. $this->_pagehead($pdf, $object, 0, $outputlangs);
  332. }
  333. $pdf->setPage($pageposafter + 1);
  334. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  335. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  336. $pdf->SetTextColor(0, 0, 0);
  337. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  338. $curY = $tab_top_newpage + $heightoftitleline + 1;
  339. // Label
  340. $pdf->SetXY($this->posxlabel, $curY);
  341. $posybefore = $pdf->GetY();
  342. $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  343. $pageposafter = $pdf->getPage();
  344. $posyafter = $pdf->GetY();
  345. }
  346. }
  347. //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak);
  348. } else // No pagebreak
  349. {
  350. $pdf->commitTransaction();
  351. }
  352. $posYAfterDescription = $pdf->GetY();
  353. $nexY = $pdf->GetY();
  354. $pageposafter = $pdf->getPage();
  355. $pdf->setPage($pageposbefore);
  356. $pdf->setTopMargin($this->marge_haute);
  357. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  358. // We suppose that a too long description is moved completely on next page
  359. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  360. //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak);
  361. $pdf->setPage($pageposafter);
  362. $curY = $tab_top_newpage + $heightoftitleline + 1;
  363. }
  364. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  365. // Ref of task
  366. $pdf->SetXY($this->posxref, $curY);
  367. $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
  368. // timespent
  369. $pdf->SetXY($this->posxtimespent, $curY);
  370. $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration : '', 0, 'R');
  371. // Progress
  372. //$pdf->SetXY($this->posxprogress, $curY);
  373. //$pdf->MultiCell($this->posxuser-$this->posxprogress, 3, $progress, 0, 'R');
  374. // User spending time
  375. /*var_dump($object->lines[$i]);exit;
  376. $tmpuser->fetch($object->lines[$i]->fk_user);
  377. $pdf->SetXY($this->posxuser, $curY);
  378. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, $tmpuser->getFullName($outputlangs, 0, -1, 20), 0, 'C');
  379. */
  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->posxtimespent - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
  489. $pdf->SetXY($this->posxtimespent, $tab_top + 1);
  490. $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $outputlangs->transnoentities("TimeSpent"), 0, 'R');
  491. //$pdf->SetXY($this->posxprogress, $tab_top+1);
  492. //$pdf->MultiCell($this->posxuser - $this->posxprogress, 3, '%', 0, 'R');
  493. $pdf->SetXY($this->posxuser, $tab_top + 1);
  494. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, '', 0, 'C');
  495. }
  496. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  497. /**
  498. * Show top header of page.
  499. *
  500. * @param TCPDF $pdf Object PDF
  501. * @param Project $object Object to show
  502. * @param int $showaddress 0=no, 1=yes
  503. * @param Translate $outputlangs Object lang for output
  504. * @return void
  505. */
  506. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  507. {
  508. global $langs, $conf, $mysoc;
  509. $default_font_size = pdf_getPDFFontSize($outputlangs);
  510. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  511. $pdf->SetTextColor(0, 0, 60);
  512. $pdf->SetFont('', 'B', $default_font_size + 3);
  513. $posx = $this->page_largeur - $this->marge_droite - 100;
  514. $posy = $this->marge_haute;
  515. $pdf->SetXY($this->marge_gauche, $posy);
  516. // Logo
  517. $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  518. if ($mysoc->logo) {
  519. if (is_readable($logo)) {
  520. $height = pdf_getHeightForLogo($logo);
  521. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  522. } else {
  523. $pdf->SetTextColor(200, 0, 0);
  524. $pdf->SetFont('', 'B', $default_font_size - 2);
  525. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  526. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  527. }
  528. } else {
  529. $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  530. }
  531. $pdf->SetFont('', 'B', $default_font_size + 3);
  532. $pdf->SetXY($posx, $posy);
  533. $pdf->SetTextColor(0, 0, 60);
  534. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  535. $pdf->SetFont('', '', $default_font_size + 2);
  536. $posy += 6;
  537. $pdf->SetXY($posx, $posy);
  538. $pdf->SetTextColor(0, 0, 60);
  539. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : ".dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
  540. $posy += 6;
  541. $pdf->SetXY($posx, $posy);
  542. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : ".dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
  543. if (is_object($object->thirdparty)) {
  544. $posy += 6;
  545. $pdf->SetXY($posx, $posy);
  546. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty")." : ".$object->thirdparty->getFullName($outputlangs), '', 'R');
  547. }
  548. $pdf->SetTextColor(0, 0, 60);
  549. // Add list of linked objects
  550. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  551. $object->fetchObjectLinked();
  552. foreach($object->linkedObjects as $objecttype => $objects)
  553. {
  554. //var_dump($objects);exit;
  555. if ($objecttype == 'commande')
  556. {
  557. $outputlangs->load('orders');
  558. $num=count($objects);
  559. for ($i=0;$i<$num;$i++)
  560. {
  561. $posy+=4;
  562. $pdf->SetXY($posx,$posy);
  563. $pdf->SetFont('','', $default_font_size - 1);
  564. $text=$objects[$i]->ref;
  565. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  566. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  567. }
  568. }
  569. }
  570. */
  571. }
  572. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  573. /**
  574. * Show footer of page. Need this->emetteur object
  575. *
  576. * @param TCPDF $pdf PDF
  577. * @param Project $object Object to show
  578. * @param Translate $outputlangs Object lang for output
  579. * @param int $hidefreetext 1=Hide free text
  580. * @return integer
  581. */
  582. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  583. {
  584. global $conf;
  585. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  586. return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  587. }
  588. }