25 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
26 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
58 public $update_main_doc_field;
69 public $phpmin = array(7, 0);
75 public $version =
'dolibarr';
100 public $marge_droite;
125 global $conf, $langs, $mysoc;
128 $langs->loadLangs(array(
"main",
"projects",
"companies"));
131 $this->
name =
"timespent";
132 $this->
description = $langs->trans(
"DocumentModelTimeSpent");
133 $this->update_main_doc_field = 1;
138 $this->page_largeur = $formatarray[
'width'];
139 $this->page_hauteur = $formatarray[
'height'];
140 $this->format = array($this->page_largeur, $this->page_hauteur);
146 $this->option_logo = 1;
147 $this->option_tva = 1;
150 $this->emetteur = $mysoc;
151 if (!$this->emetteur->country_code) {
152 $this->emetteur->country_code = substr($langs->defaultlang, -2);
156 $this->posxref = $this->marge_gauche + 1;
157 $this->posxlabel = $this->marge_gauche + 25;
158 $this->posxworkload = $this->marge_gauche + 100;
159 $this->posxtimespent = $this->marge_gauche + 120;
161 $this->posxuser = $this->marge_gauche + 147;
163 if ($this->page_largeur < 210) {
164 $this->posxref -= 20;
165 $this->posxlabel -= 20;
166 $this->posxtimespent -= 20;
168 $this->posxuser -= 20;
185 global $conf, $hookmanager, $langs, $user;
187 if (!is_object($outputlangs)) {
188 $outputlangs = $langs;
191 if (!empty($conf->global->MAIN_USE_FPDF)) {
192 $outputlangs->charset_output =
'ISO-8859-1';
196 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
198 if ($conf->project->dir_output) {
202 $dir = $conf->project->dir_output;
203 if (!preg_match(
'/specimen/i', $objectref)) {
204 $dir .=
"/".$objectref;
206 $file = $dir.
"/".$objectref.
".pdf";
208 if (!file_exists($dir)) {
210 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
215 if (file_exists($dir)) {
217 if (!is_object($hookmanager)) {
218 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
221 $hookmanager->initHooks(array(
'pdfgeneration'));
222 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
224 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
229 $pdf->SetAutoPageBreak(1, 0);
231 $heightforinfotot = 40;
232 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
233 $heightforfooter = $this->marge_basse + 8;
234 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
235 $heightforfooter += 6;
238 if (class_exists(
'TCPDF')) {
239 $pdf->setPrintHeader(
false);
240 $pdf->setPrintFooter(
false);
244 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
245 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
246 $tplidx = $pdf->importPage(1);
250 $task =
new Task($this->
db);
251 $tasksarray = $task->getTasksArray(0, 0, $object->id);
253 if (!$object->id > 0) {
254 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
257 $object->lines = $tasksarray;
258 $nblines = count($object->lines);
262 $pdf->SetDrawColor(128, 128, 128);
264 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
265 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
266 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
267 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
268 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
270 $pdf->SetCompression(
false);
273 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
277 if (!empty($tplidx)) {
278 $pdf->useTemplate($tplidx);
281 $this->
_pagehead($pdf, $object, 1, $outputlangs);
282 $pdf->SetFont(
'',
'', $default_font_size - 1);
283 $pdf->MultiCell(0, 3,
'');
284 $pdf->SetTextColor(0, 0, 0);
287 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
289 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
292 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
301 $pdf->SetFont(
'',
'', $default_font_size - 1);
302 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
303 $nexY = $pdf->GetY();
304 $height_note = $nexY - $tab_top;
307 $pdf->SetDrawColor(192, 192, 192);
308 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
310 $tab_height = $tab_height - $height_note;
311 $tab_top = $nexY + 6;
316 $heightoftitleline = 10;
317 $iniY = $tab_top + $heightoftitleline + 1;
318 $curY = $tab_top + $heightoftitleline + 1;
319 $nexY = $tab_top + $heightoftitleline + 1;
321 $tmpuser =
new User($this->
db);
326 for ($i = 0; $i < $nblines; $i++) {
328 $pdf->SetFont(
'',
'', $default_font_size - 1);
329 $pdf->SetTextColor(0, 0, 0);
331 $pdf->setTopMargin($tab_top_newpage);
332 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
333 $pageposbefore = $pdf->getPage();
336 $ref = $object->lines[$i]->ref;
337 $libelleline = $object->lines[$i]->label;
339 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
343 $showpricebeforepagebreak = 1;
345 $pdf->startTransaction();
347 $pdf->SetXY($this->posxlabel, $curY);
348 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
349 $pageposafter = $pdf->getPage();
350 if ($pageposafter > $pageposbefore) {
351 $pdf->rollbackTransaction(
true);
352 $pageposafter = $pageposbefore;
354 $pdf->setPageOrientation(
'', 1, $heightforfooter);
356 $pdf->SetXY($this->posxlabel, $curY);
357 $posybefore = $pdf->GetY();
358 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
359 $pageposafter = $pdf->getPage();
360 $posyafter = $pdf->GetY();
361 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
362 if ($i == ($nblines - 1)) {
363 $pdf->AddPage(
'',
'',
true);
364 if (!empty($tplidx)) {
365 $pdf->useTemplate($tplidx);
368 $this->
_pagehead($pdf, $object, 0, $outputlangs);
370 $pdf->setPage($pageposafter + 1);
376 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
377 $showpricebeforepagebreak = 1;
379 $showpricebeforepagebreak = 0;
382 $forcedesconsamepage = 1;
383 if ($forcedesconsamepage) {
384 $pdf->rollbackTransaction(
true);
385 $pageposafter = $pageposbefore;
386 $pdf->setPageOrientation(
'', 1, $heightforfooter);
388 $pdf->AddPage(
'',
'',
true);
389 if (!empty($tplidx)) {
390 $pdf->useTemplate($tplidx);
393 $this->
_pagehead($pdf, $object, 0, $outputlangs);
395 $pdf->setPage($pageposafter + 1);
396 $pdf->SetFont(
'',
'', $default_font_size - 1);
397 $pdf->MultiCell(0, 3,
'');
398 $pdf->SetTextColor(0, 0, 0);
400 $pdf->setPageOrientation(
'', 1, $heightforfooter);
401 $curY = $tab_top_newpage + $heightoftitleline + 1;
404 $pdf->SetXY($this->posxlabel, $curY);
405 $posybefore = $pdf->GetY();
406 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
407 $pageposafter = $pdf->getPage();
408 $posyafter = $pdf->GetY();
414 $pdf->commitTransaction();
416 $posYAfterDescription = $pdf->GetY();
418 $nexY = $pdf->GetY();
419 $pageposafter = $pdf->getPage();
420 $pdf->setPage($pageposbefore);
421 $pdf->setTopMargin($this->marge_haute);
422 $pdf->setPageOrientation(
'', 1, 0);
425 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
427 $pdf->setPage($pageposafter);
428 $curY = $tab_top_newpage + $heightoftitleline + 1;
431 $pdf->SetFont(
'',
'', $default_font_size - 1);
434 $pdf->SetXY($this->posxref, $curY);
435 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
437 $pdf->SetXY($this->posxtimespent, $curY);
438 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
451 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
452 $pdf->setPage($pageposafter);
453 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
455 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
456 $pdf->SetLineStyle(array(
'dash'=>0));
462 while ($pagenb < $pageposafter) {
463 $pdf->setPage($pagenb);
465 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
467 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
469 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
471 $pdf->setPage($pagenb);
472 $pdf->setPageOrientation(
'', 1, 0);
474 $this->
_pagehead($pdf, $object, 0, $outputlangs);
476 if (!empty($tplidx)) {
477 $pdf->useTemplate($tplidx);
480 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
482 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
484 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
486 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
489 if (!empty($tplidx)) {
490 $pdf->useTemplate($tplidx);
494 $this->
_pagehead($pdf, $object, 0, $outputlangs);
501 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
503 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
505 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
508 $this->
_pagefoot($pdf, $object, $outputlangs);
509 if (method_exists($pdf,
'AliasNbPages')) {
510 $pdf->AliasNbPages();
515 $pdf->Output($file,
'F');
518 $hookmanager->initHooks(array(
'pdfgeneration'));
519 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
521 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
523 $this->error = $hookmanager->error;
524 $this->errors = $hookmanager->errors;
527 if (!empty($conf->global->MAIN_UMASK)) {
528 @chmod($file, octdec($conf->global->MAIN_UMASK));
531 $this->result = array(
'fullpath'=>$file);
535 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
539 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
557 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
559 global $conf, $mysoc;
561 $heightoftitleline = 10;
565 $pdf->SetDrawColor(128, 128, 128);
568 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
571 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
573 $pdf->SetTextColor(0, 0, 0);
574 $pdf->SetFont(
'',
'', $default_font_size);
576 $pdf->SetXY($this->posxref, $tab_top + 1);
577 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
579 $pdf->SetXY($this->posxlabel, $tab_top + 1);
580 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
582 $pdf->SetXY($this->posxtimespent, $tab_top + 1);
583 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $outputlangs->transnoentities(
"TimeSpent"), 0,
'R');
588 $pdf->SetXY($this->posxuser, $tab_top + 1);
589 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3,
'', 0,
'C');
602 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
604 global $langs, $conf, $mysoc;
610 $pdf->SetTextColor(0, 0, 60);
611 $pdf->SetFont(
'',
'B', $default_font_size + 3);
613 $posx = $this->page_largeur - $this->marge_droite - 100;
614 $posy = $this->marge_haute;
616 $pdf->SetXY($this->marge_gauche, $posy);
619 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
621 if (is_readable($logo)) {
623 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
625 $pdf->SetTextColor(200, 0, 0);
626 $pdf->SetFont(
'',
'B', $default_font_size - 2);
627 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
628 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
631 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
634 $pdf->SetFont(
'',
'B', $default_font_size + 3);
635 $pdf->SetXY($posx, $posy);
636 $pdf->SetTextColor(0, 0, 60);
637 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
638 $pdf->SetFont(
'',
'', $default_font_size + 2);
641 $pdf->SetXY($posx, $posy);
642 $pdf->SetTextColor(0, 0, 60);
643 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
646 $pdf->SetXY($posx, $posy);
647 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
649 if (is_object($object->thirdparty)) {
651 $pdf->SetXY($posx, $posy);
652 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
655 $pdf->SetTextColor(0, 0, 60);
692 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
694 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
695 return pdf_pagefoot($pdf, $outputlangs,
'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
Parent class for projects models.
Class to manage Dolibarr users.
Class to manage generation of project document Timespent.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs)
Function to build pdf project onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
__construct($db)
Constructor.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.