26 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
27 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
59 public $update_main_doc_field;
70 public $phpmin = array(7, 0);
76 public $version =
'dolibarr';
101 public $marge_droite;
126 global $conf, $langs, $mysoc;
129 $langs->loadLangs(array(
"main",
"projects",
"companies"));
132 $this->
name =
"baleine";
133 $this->
description = $langs->trans(
"DocumentModelBaleine");
134 $this->update_main_doc_field = 1;
139 $this->page_largeur = $formatarray[
'width'];
140 $this->page_hauteur = $formatarray[
'height'];
141 $this->format = array($this->page_largeur, $this->page_hauteur);
147 $this->option_logo = 1;
148 $this->option_tva = 1;
151 $this->emetteur = $mysoc;
152 if (!$this->emetteur->country_code) {
153 $this->emetteur->country_code = substr($langs->defaultlang, -2);
157 $this->posxref = $this->marge_gauche + 1;
158 $this->posxlabel = $this->marge_gauche + 25;
159 $this->posxworkload = $this->marge_gauche + 117;
160 $this->posxprogress = $this->marge_gauche + 137;
161 $this->posxdatestart = $this->marge_gauche + 147;
162 $this->posxdateend = $this->marge_gauche + 169;
163 if ($this->page_largeur < 210) {
164 $this->posxref -= 20;
165 $this->posxlabel -= 20;
166 $this->posxworkload -= 20;
167 $this->posxprogress -= 20;
168 $this->posxdatestart -= 20;
169 $this->posxdateend -= 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;
322 for ($i = 0; $i < $nblines; $i++) {
324 $pdf->SetFont(
'',
'', $default_font_size - 1);
325 $pdf->SetTextColor(0, 0, 0);
327 $pdf->setTopMargin($tab_top_newpage);
328 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
329 $pageposbefore = $pdf->getPage();
332 $ref = $object->lines[$i]->ref;
333 $libelleline = $object->lines[$i]->label;
334 $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.
'%' :
'');
335 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
337 $planned_workload =
convertSecondToTime((
int) $object->lines[$i]->planned_workload,
'allhourmin');
339 $showpricebeforepagebreak = 1;
341 $pdf->startTransaction();
343 $pdf->SetXY($this->posxlabel, $curY);
344 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
345 $pageposafter = $pdf->getPage();
346 if ($pageposafter > $pageposbefore) {
347 $pdf->rollbackTransaction(
true);
348 $pageposafter = $pageposbefore;
350 $pdf->setPageOrientation(
'', 1, $heightforfooter);
352 $pdf->SetXY($this->posxlabel, $curY);
353 $posybefore = $pdf->GetY();
354 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
355 $pageposafter = $pdf->getPage();
356 $posyafter = $pdf->GetY();
357 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
358 if ($i == ($nblines - 1)) {
359 $pdf->AddPage(
'',
'',
true);
360 if (!empty($tplidx)) {
361 $pdf->useTemplate($tplidx);
364 $this->
_pagehead($pdf, $object, 0, $outputlangs);
366 $pdf->setPage($pageposafter + 1);
372 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
373 $showpricebeforepagebreak = 1;
375 $showpricebeforepagebreak = 0;
378 $forcedesconsamepage = 1;
379 if ($forcedesconsamepage) {
380 $pdf->rollbackTransaction(
true);
381 $pageposafter = $pageposbefore;
382 $pdf->setPageOrientation(
'', 1, $heightforfooter);
384 $pdf->AddPage(
'',
'',
true);
385 if (!empty($tplidx)) {
386 $pdf->useTemplate($tplidx);
389 $this->
_pagehead($pdf, $object, 0, $outputlangs);
391 $pdf->setPage($pageposafter + 1);
392 $pdf->SetFont(
'',
'', $default_font_size - 1);
393 $pdf->MultiCell(0, 3,
'');
394 $pdf->SetTextColor(0, 0, 0);
396 $pdf->setPageOrientation(
'', 1, $heightforfooter);
397 $curY = $tab_top_newpage + $heightoftitleline + 1;
400 $pdf->SetXY($this->posxlabel, $curY);
401 $posybefore = $pdf->GetY();
402 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
403 $pageposafter = $pdf->getPage();
404 $posyafter = $pdf->GetY();
410 $pdf->commitTransaction();
412 $posYAfterDescription = $pdf->GetY();
414 $nexY = $pdf->GetY();
415 $pageposafter = $pdf->getPage();
416 $pdf->setPage($pageposbefore);
417 $pdf->setTopMargin($this->marge_haute);
418 $pdf->setPageOrientation(
'', 1, 0);
421 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
423 $pdf->setPage($pageposafter);
424 $curY = $tab_top_newpage + $heightoftitleline + 1;
427 $pdf->SetFont(
'',
'', $default_font_size - 1);
430 $pdf->SetXY($this->posxref, $curY);
431 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
433 $pdf->SetXY($this->posxworkload, $curY);
434 $pdf->SetFont(
'',
'', $default_font_size - 2);
435 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
437 $pdf->SetXY($this->posxprogress, $curY);
438 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
439 $pdf->SetFont(
'',
'', $default_font_size - 1);
442 $pdf->SetXY($this->posxdatestart, $curY);
443 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
444 $pdf->SetXY($this->posxdateend, $curY);
445 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
448 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
449 $pdf->setPage($pageposafter);
450 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
452 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
453 $pdf->SetLineStyle(array(
'dash'=>0));
459 while ($pagenb < $pageposafter) {
460 $pdf->setPage($pagenb);
462 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
464 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
466 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
468 $pdf->setPage($pagenb);
469 $pdf->setPageOrientation(
'', 1, 0);
471 $this->
_pagehead($pdf, $object, 0, $outputlangs);
473 if (!empty($tplidx)) {
474 $pdf->useTemplate($tplidx);
477 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
479 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
481 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
483 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
486 if (!empty($tplidx)) {
487 $pdf->useTemplate($tplidx);
491 $this->
_pagehead($pdf, $object, 0, $outputlangs);
498 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
500 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
502 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
505 $this->
_pagefoot($pdf, $object, $outputlangs);
506 if (method_exists($pdf,
'AliasNbPages')) {
507 $pdf->AliasNbPages();
512 $pdf->Output($file,
'F');
515 $hookmanager->initHooks(array(
'pdfgeneration'));
516 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
518 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
520 $this->error = $hookmanager->error;
521 $this->errors = $hookmanager->errors;
526 $this->result = array(
'fullpath'=>$file);
530 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
534 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
552 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
554 global $conf, $mysoc;
556 $heightoftitleline = 10;
560 $pdf->SetDrawColor(128, 128, 128);
563 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
566 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
568 $pdf->SetTextColor(0, 0, 0);
569 $pdf->SetFont(
'',
'', $default_font_size);
571 $pdf->SetXY($this->posxref, $tab_top + 1);
572 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
574 $pdf->SetXY($this->posxlabel, $tab_top + 1);
575 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
577 $pdf->SetXY($this->posxworkload, $tab_top + 1);
578 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
580 $pdf->SetXY($this->posxprogress, $tab_top + 1);
581 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
584 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
585 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans(
"Start"), 0,
'C');
588 $pdf->SetXY($this->posxdateend, $tab_top + 1);
589 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans(
"End"), 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');
645 if ($object->date_end) {
647 $pdf->SetXY($posx, $posy);
648 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
651 if (is_object($object->thirdparty)) {
653 $pdf->SetXY($posx, $posy);
654 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
657 $pdf->SetTextColor(0, 0, 60);
694 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
696 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
697 return pdf_pagefoot($pdf, $outputlangs,
'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);