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';
44 public $phpmin = array(5, 6);
50 public $version =
'dolibarr';
65 global $conf, $langs, $mysoc;
68 $langs->loadLangs(array(
"main",
"projects",
"companies"));
71 $this->
name =
"timespent";
72 $this->
description = $langs->trans(
"DocumentModelTimeSpent");
77 $this->page_largeur = $formatarray[
'width'];
78 $this->page_hauteur = $formatarray[
'height'];
79 $this->format = array($this->page_largeur, $this->page_hauteur);
80 $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
81 $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
82 $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
83 $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
85 $this->option_logo = 1;
86 $this->option_tva = 1;
87 $this->option_codeproduitservice = 1;
90 $this->emetteur = $mysoc;
91 if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2);
94 $this->posxref = $this->marge_gauche + 1;
95 $this->posxlabel = $this->marge_gauche + 25;
96 $this->posxworkload = $this->marge_gauche + 100;
97 $this->posxtimespent = $this->marge_gauche + 120;
99 $this->posxuser = $this->marge_gauche + 147;
101 if ($this->page_largeur < 210)
103 $this->posxref -= 20;
104 $this->posxlabel -= 20;
105 $this->posxtimespent -= 20;
107 $this->posxuser -= 20;
124 global $conf, $hookmanager, $langs, $user;
126 if (!is_object($outputlangs)) $outputlangs = $langs;
128 if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output =
'ISO-8859-1';
131 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
133 if ($conf->projet->dir_output)
138 $dir = $conf->projet->dir_output;
139 if (!preg_match(
'/specimen/i', $objectref)) $dir .=
"/".$objectref;
140 $file = $dir.
"/".$objectref.
".pdf";
142 if (!file_exists($dir))
146 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
151 if (file_exists($dir))
154 if (!is_object($hookmanager))
156 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
159 $hookmanager->initHooks(array(
'pdfgeneration'));
160 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
162 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
167 $pdf->SetAutoPageBreak(1, 0);
169 $heightforinfotot = 40;
170 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
171 $heightforfooter = $this->marge_basse + 8;
172 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6;
174 if (class_exists(
'TCPDF'))
176 $pdf->setPrintHeader(
false);
177 $pdf->setPrintFooter(
false);
181 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
183 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
184 $tplidx = $pdf->importPage(1);
188 $task =
new Task($this->
db);
189 $tasksarray = $task->getTasksArray(0, 0, $object->id);
191 if (!$object->id > 0)
193 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
196 $object->lines = $tasksarray;
197 $nblines = count($object->lines);
201 $pdf->SetDrawColor(128, 128, 128);
203 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
204 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
205 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
206 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
207 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
208 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
210 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
214 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
216 $this->
_pagehead($pdf, $object, 1, $outputlangs);
217 $pdf->SetFont(
'',
'', $default_font_size - 1);
218 $pdf->MultiCell(0, 3,
'');
219 $pdf->SetTextColor(0, 0, 0);
222 $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
224 $tab_height_newpage = 190;
227 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
237 $pdf->SetFont(
'',
'', $default_font_size - 1);
238 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
239 $nexY = $pdf->GetY();
240 $height_note = $nexY - $tab_top;
243 $pdf->SetDrawColor(192, 192, 192);
244 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
246 $tab_height = $tab_height - $height_note;
247 $tab_top = $nexY + 6;
252 $heightoftitleline = 10;
253 $iniY = $tab_top + $heightoftitleline + 1;
254 $curY = $tab_top + $heightoftitleline + 1;
255 $nexY = $tab_top + $heightoftitleline + 1;
257 $tmpuser =
new User($this->
db);
262 for ($i = 0; $i < $nblines; $i++)
265 $pdf->SetFont(
'',
'', $default_font_size - 1);
266 $pdf->SetTextColor(0, 0, 0);
268 $pdf->setTopMargin($tab_top_newpage);
269 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
270 $pageposbefore = $pdf->getPage();
273 $ref = $object->lines[$i]->ref;
274 $libelleline = $object->lines[$i]->label;
276 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
280 $showpricebeforepagebreak = 1;
282 $pdf->startTransaction();
284 $pdf->SetXY($this->posxlabel, $curY);
285 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
286 $pageposafter = $pdf->getPage();
287 if ($pageposafter > $pageposbefore)
289 $pdf->rollbackTransaction(
true);
290 $pageposafter = $pageposbefore;
292 $pdf->setPageOrientation(
'', 1, $heightforfooter);
294 $pdf->SetXY($this->posxlabel, $curY);
295 $posybefore = $pdf->GetY();
296 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
297 $pageposafter = $pdf->getPage();
298 $posyafter = $pdf->GetY();
299 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))
301 if ($i == ($nblines - 1))
303 $pdf->AddPage(
'',
'',
true);
304 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
305 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
306 $pdf->setPage($pageposafter + 1);
312 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
313 $showpricebeforepagebreak = 1;
314 else $showpricebeforepagebreak = 0;
316 $forcedesconsamepage = 1;
317 if ($forcedesconsamepage)
319 $pdf->rollbackTransaction(
true);
320 $pageposafter = $pageposbefore;
321 $pdf->setPageOrientation(
'', 1, $heightforfooter);
323 $pdf->AddPage(
'',
'',
true);
324 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
325 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
326 $pdf->setPage($pageposafter + 1);
327 $pdf->SetFont(
'',
'', $default_font_size - 1);
328 $pdf->MultiCell(0, 3,
'');
329 $pdf->SetTextColor(0, 0, 0);
331 $pdf->setPageOrientation(
'', 1, $heightforfooter);
332 $curY = $tab_top_newpage + $heightoftitleline + 1;
335 $pdf->SetXY($this->posxlabel, $curY);
336 $posybefore = $pdf->GetY();
337 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
338 $pageposafter = $pdf->getPage();
339 $posyafter = $pdf->GetY();
345 $pdf->commitTransaction();
347 $posYAfterDescription = $pdf->GetY();
349 $nexY = $pdf->GetY();
350 $pageposafter = $pdf->getPage();
351 $pdf->setPage($pageposbefore);
352 $pdf->setTopMargin($this->marge_haute);
353 $pdf->setPageOrientation(
'', 1, 0);
356 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
358 $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1;
361 $pdf->SetFont(
'',
'', $default_font_size - 1);
364 $pdf->SetXY($this->posxref, $curY);
365 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
367 $pdf->SetXY($this->posxtimespent, $curY);
368 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
381 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
383 $pdf->setPage($pageposafter);
384 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
386 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
387 $pdf->SetLineStyle(array(
'dash'=>0));
393 while ($pagenb < $pageposafter)
395 $pdf->setPage($pagenb);
398 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
400 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
402 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
404 $pdf->setPage($pagenb);
405 $pdf->setPageOrientation(
'', 1, 0);
406 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
408 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
412 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
414 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
416 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
419 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
421 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
427 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
428 else $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
429 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
432 $this->
_pagefoot($pdf, $object, $outputlangs);
433 if (method_exists($pdf,
'AliasNbPages')) $pdf->AliasNbPages();
437 $pdf->Output($file,
'F');
440 $hookmanager->initHooks(array(
'pdfgeneration'));
441 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
443 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
446 $this->error = $hookmanager->error;
447 $this->errors = $hookmanager->errors;
450 if (!empty($conf->global->MAIN_UMASK))
451 @chmod($file, octdec($conf->global->MAIN_UMASK));
453 $this->result = array(
'fullpath'=>$file);
457 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
461 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
479 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
481 global $conf, $mysoc;
483 $heightoftitleline = 10;
487 $pdf->SetDrawColor(128, 128, 128);
490 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
493 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
495 $pdf->SetTextColor(0, 0, 0);
496 $pdf->SetFont(
'',
'', $default_font_size);
498 $pdf->SetXY($this->posxref, $tab_top + 1);
499 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
501 $pdf->SetXY($this->posxlabel, $tab_top + 1);
502 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
504 $pdf->SetXY($this->posxtimespent, $tab_top + 1);
505 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $outputlangs->transnoentities(
"TimeSpent"), 0,
'R');
510 $pdf->SetXY($this->posxuser, $tab_top + 1);
511 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3,
'', 0,
'C');
524 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
526 global $langs, $conf, $mysoc;
532 $pdf->SetTextColor(0, 0, 60);
533 $pdf->SetFont(
'',
'B', $default_font_size + 3);
535 $posx = $this->page_largeur - $this->marge_droite - 100;
536 $posy = $this->marge_haute;
538 $pdf->SetXY($this->marge_gauche, $posy);
541 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
544 if (is_readable($logo))
547 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
549 $pdf->SetTextColor(200, 0, 0);
550 $pdf->SetFont(
'',
'B', $default_font_size - 2);
551 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
552 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
554 }
else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
556 $pdf->SetFont(
'',
'B', $default_font_size + 3);
557 $pdf->SetXY($posx, $posy);
558 $pdf->SetTextColor(0, 0, 60);
559 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
560 $pdf->SetFont(
'',
'', $default_font_size + 2);
563 $pdf->SetXY($posx, $posy);
564 $pdf->SetTextColor(0, 0, 60);
565 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
568 $pdf->SetXY($posx, $posy);
569 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
571 if (is_object($object->thirdparty))
574 $pdf->SetXY($posx, $posy);
575 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
578 $pdf->SetTextColor(0, 0, 60);
615 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
618 $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
619 return pdf_pagefoot($pdf, $outputlangs,
'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Class to manage Dolibarr users.
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...
Class to manage generation of project document Timespent.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
__construct($db)
Constructor.
Parent class for projects models.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
write_file($object, $outputlangs)
Function to build pdf project onto disk.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
convertSecondToTime($iSecond, $format= 'all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
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...