149 global $conf, $hookmanager, $langs, $user;
151 if (!is_object($outputlangs)) {
152 $outputlangs = $langs;
156 $outputlangs->charset_output =
'ISO-8859-1';
160 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
162 if ($conf->project->multidir_output[$object->entity]) {
166 $dir = $conf->project->multidir_output[$object->entity];
167 if (!preg_match(
'/specimen/i', $objectref)) {
168 $dir .=
"/".$objectref;
170 $file = $dir.
"/".$objectref.
".pdf";
172 if (!file_exists($dir)) {
174 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
179 if (file_exists($dir)) {
181 if (!is_object($hookmanager)) {
182 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
185 $hookmanager->initHooks(array(
'pdfgeneration'));
186 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
188 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
193 $pdf->SetAutoPageBreak(1, 0);
195 $heightforinfotot = 40;
196 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
197 $heightforfooter = $this->marge_basse + 8;
199 $heightforfooter += 6;
202 if (class_exists(
'TCPDF')) {
203 $pdf->setPrintHeader(
false);
204 $pdf->setPrintFooter(
false);
209 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
210 $tplidx = $pdf->importPage(1);
214 $task =
new Task($this->db);
215 $tasksarray = $task->getTasksArray(0, 0, $object->id);
217 if (!$object->id > 0) {
218 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
221 $object->lines = $tasksarray;
222 $nblines = count($object->lines);
226 $pdf->SetDrawColor(128, 128, 128);
228 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
229 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
230 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
231 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
232 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
234 $pdf->SetCompression(
false);
237 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
241 if (!empty($tplidx)) {
242 $pdf->useTemplate($tplidx);
245 $this->
_pagehead($pdf, $object, 1, $outputlangs);
246 $pdf->SetFont(
'',
'', $default_font_size - 1);
247 $pdf->MultiCell(0, 3,
'');
248 $pdf->SetTextColor(0, 0, 0);
251 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
253 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
256 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
265 $pdf->SetFont(
'',
'', $default_font_size - 1);
266 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
267 $nexY = $pdf->GetY();
268 $height_note = $nexY - $tab_top;
271 $pdf->SetDrawColor(192, 192, 192);
272 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
274 $tab_height = $tab_height - $height_note;
275 $tab_top = $nexY + 6;
280 $heightoftitleline = 10;
281 $iniY = $tab_top + $heightoftitleline + 1;
282 $curY = $tab_top + $heightoftitleline + 1;
283 $nexY = $tab_top + $heightoftitleline + 1;
286 for ($i = 0; $i < $nblines; $i++) {
288 $pdf->SetFont(
'',
'', $default_font_size - 1);
289 $pdf->SetTextColor(0, 0, 0);
291 $pdf->setTopMargin($tab_top_newpage);
292 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
293 $pageposbefore = $pdf->getPage();
296 $ref = $object->lines[$i]->ref;
297 $libelleline = $object->lines[$i]->label;
298 $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.
'%' :
'');
299 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
301 $planned_workload =
convertSecondToTime((
int) $object->lines[$i]->planned_workload,
'allhourmin');
303 $showpricebeforepagebreak = 1;
305 $pdf->startTransaction();
307 $pdf->SetXY($this->posxlabel, $curY);
308 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
309 $pageposafter = $pdf->getPage();
310 if ($pageposafter > $pageposbefore) {
311 $pdf->rollbackTransaction(
true);
312 $pageposafter = $pageposbefore;
314 $pdf->setPageOrientation(
'', 1, $heightforfooter);
316 $pdf->SetXY($this->posxlabel, $curY);
317 $posybefore = $pdf->GetY();
318 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
319 $pageposafter = $pdf->getPage();
320 $posyafter = $pdf->GetY();
321 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
322 if ($i == ($nblines - 1)) {
323 $pdf->AddPage(
'',
'',
true);
324 if (!empty($tplidx)) {
325 $pdf->useTemplate($tplidx);
328 $this->
_pagehead($pdf, $object, 0, $outputlangs);
330 $pdf->setPage($pageposafter + 1);
337 $showpricebeforepagebreak = 1;
339 $showpricebeforepagebreak = 0;
342 $forcedesconsamepage = 1;
343 if ($forcedesconsamepage) {
344 $pdf->rollbackTransaction(
true);
345 $pageposafter = $pageposbefore;
346 $pdf->setPageOrientation(
'', 1, $heightforfooter);
348 $pdf->AddPage(
'',
'',
true);
349 if (!empty($tplidx)) {
350 $pdf->useTemplate($tplidx);
353 $this->
_pagehead($pdf, $object, 0, $outputlangs);
355 $pdf->setPage($pageposafter + 1);
356 $pdf->SetFont(
'',
'', $default_font_size - 1);
357 $pdf->MultiCell(0, 3,
'');
358 $pdf->SetTextColor(0, 0, 0);
360 $pdf->setPageOrientation(
'', 1, $heightforfooter);
361 $curY = $tab_top_newpage + $heightoftitleline + 1;
364 $pdf->SetXY($this->posxlabel, $curY);
365 $posybefore = $pdf->GetY();
366 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
367 $pageposafter = $pdf->getPage();
368 $posyafter = $pdf->GetY();
373 $pdf->commitTransaction();
375 $posYAfterDescription = $pdf->GetY();
377 $nexY = $pdf->GetY();
378 $pageposafter = $pdf->getPage();
379 $pdf->setPage($pageposbefore);
380 $pdf->setTopMargin($this->marge_haute);
381 $pdf->setPageOrientation(
'', 1, 0);
384 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
386 $pdf->setPage($pageposafter);
387 $curY = $tab_top_newpage + $heightoftitleline + 1;
390 $pdf->SetFont(
'',
'', $default_font_size - 1);
393 $pdf->SetXY($this->posxref, $curY);
394 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
396 $pdf->SetXY($this->posxworkload, $curY);
397 $pdf->SetFont(
'',
'', $default_font_size - 2);
398 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
400 $pdf->SetXY($this->posxprogress, $curY);
401 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
402 $pdf->SetFont(
'',
'', $default_font_size - 1);
405 $pdf->SetXY($this->posxdatestart, $curY);
406 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
407 $pdf->SetXY($this->posxdateend, $curY);
408 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
412 $pdf->setPage($pageposafter);
413 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
415 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
416 $pdf->SetLineStyle(array(
'dash'=>0));
422 while ($pagenb < $pageposafter) {
423 $pdf->setPage($pagenb);
425 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
427 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
429 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
431 $pdf->setPage($pagenb);
432 $pdf->setPageOrientation(
'', 1, 0);
434 $this->
_pagehead($pdf, $object, 0, $outputlangs);
436 if (!empty($tplidx)) {
437 $pdf->useTemplate($tplidx);
440 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
442 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
444 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
446 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
449 if (!empty($tplidx)) {
450 $pdf->useTemplate($tplidx);
454 $this->
_pagehead($pdf, $object, 0, $outputlangs);
461 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
463 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
465 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
468 $this->
_pagefoot($pdf, $object, $outputlangs);
469 if (method_exists($pdf,
'AliasNbPages')) {
470 $pdf->AliasNbPages();
475 $pdf->Output($file,
'F');
478 $hookmanager->initHooks(array(
'pdfgeneration'));
479 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
481 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
483 $this->error = $hookmanager->error;
484 $this->errors = $hookmanager->errors;
489 $this->result = array(
'fullpath'=>$file);
493 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
497 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
565 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
567 global $langs, $conf, $mysoc;
573 $pdf->SetTextColor(0, 0, 60);
574 $pdf->SetFont(
'',
'B', $default_font_size + 3);
576 $posx = $this->page_largeur - $this->marge_droite - 100;
577 $posy = $this->marge_haute;
579 $pdf->SetXY($this->marge_gauche, $posy);
582 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
584 if (is_readable($logo)) {
586 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
588 $pdf->SetTextColor(200, 0, 0);
589 $pdf->SetFont(
'',
'B', $default_font_size - 2);
590 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
591 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
594 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
597 $pdf->SetFont(
'',
'B', $default_font_size + 3);
598 $pdf->SetXY($posx, $posy);
599 $pdf->SetTextColor(0, 0, 60);
600 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
601 $pdf->SetFont(
'',
'', $default_font_size + 2);
604 $pdf->SetXY($posx, $posy);
605 $pdf->SetTextColor(0, 0, 60);
606 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
608 if ($object->date_end) {
610 $pdf->SetXY($posx, $posy);
611 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
614 if (is_object($object->thirdparty)) {
616 $pdf->SetXY($posx, $posy);
617 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
620 $pdf->SetTextColor(0, 0, 60);