179 global $conf, $hookmanager, $langs, $user;
181 if (!is_object($outputlangs)) {
182 $outputlangs = $langs;
185 if (!empty($conf->global->MAIN_USE_FPDF)) {
186 $outputlangs->charset_output =
'ISO-8859-1';
190 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
192 if ($conf->project->multidir_output[$object->entity]) {
196 $dir = $conf->project->multidir_output[$object->entity];
197 if (!preg_match(
'/specimen/i', $objectref)) {
198 $dir .=
"/".$objectref;
200 $file = $dir.
"/".$objectref.
".pdf";
202 if (!file_exists($dir)) {
204 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
209 if (file_exists($dir)) {
211 if (!is_object($hookmanager)) {
212 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
215 $hookmanager->initHooks(array(
'pdfgeneration'));
216 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
218 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
223 $pdf->SetAutoPageBreak(1, 0);
225 $heightforinfotot = 40;
226 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
227 $heightforfooter = $this->marge_basse + 8;
228 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
229 $heightforfooter += 6;
232 if (class_exists(
'TCPDF')) {
233 $pdf->setPrintHeader(
false);
234 $pdf->setPrintFooter(
false);
238 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
239 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
240 $tplidx = $pdf->importPage(1);
244 $task =
new Task($this->db);
245 $tasksarray = $task->getTasksArray(0, 0, $object->id);
247 if (!$object->id > 0) {
248 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
251 $object->lines = $tasksarray;
252 $nblines = count($object->lines);
256 $pdf->SetDrawColor(128, 128, 128);
258 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
259 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
260 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
261 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
262 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
264 $pdf->SetCompression(
false);
267 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
271 if (!empty($tplidx)) {
272 $pdf->useTemplate($tplidx);
275 $this->
_pagehead($pdf, $object, 1, $outputlangs);
276 $pdf->SetFont(
'',
'', $default_font_size - 1);
277 $pdf->MultiCell(0, 3,
'');
278 $pdf->SetTextColor(0, 0, 0);
281 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
283 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
286 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
295 $pdf->SetFont(
'',
'', $default_font_size - 1);
296 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
297 $nexY = $pdf->GetY();
298 $height_note = $nexY - $tab_top;
301 $pdf->SetDrawColor(192, 192, 192);
302 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
304 $tab_height = $tab_height - $height_note;
305 $tab_top = $nexY + 6;
310 $heightoftitleline = 10;
311 $iniY = $tab_top + $heightoftitleline + 1;
312 $curY = $tab_top + $heightoftitleline + 1;
313 $nexY = $tab_top + $heightoftitleline + 1;
316 for ($i = 0; $i < $nblines; $i++) {
318 $pdf->SetFont(
'',
'', $default_font_size - 1);
319 $pdf->SetTextColor(0, 0, 0);
321 $pdf->setTopMargin($tab_top_newpage);
322 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
323 $pageposbefore = $pdf->getPage();
326 $ref = $object->lines[$i]->ref;
327 $libelleline = $object->lines[$i]->label;
328 $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.
'%' :
'');
329 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
331 $planned_workload =
convertSecondToTime((
int) $object->lines[$i]->planned_workload,
'allhourmin');
333 $showpricebeforepagebreak = 1;
335 $pdf->startTransaction();
337 $pdf->SetXY($this->posxlabel, $curY);
338 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
339 $pageposafter = $pdf->getPage();
340 if ($pageposafter > $pageposbefore) {
341 $pdf->rollbackTransaction(
true);
342 $pageposafter = $pageposbefore;
344 $pdf->setPageOrientation(
'', 1, $heightforfooter);
346 $pdf->SetXY($this->posxlabel, $curY);
347 $posybefore = $pdf->GetY();
348 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
349 $pageposafter = $pdf->getPage();
350 $posyafter = $pdf->GetY();
351 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
352 if ($i == ($nblines - 1)) {
353 $pdf->AddPage(
'',
'',
true);
354 if (!empty($tplidx)) {
355 $pdf->useTemplate($tplidx);
358 $this->
_pagehead($pdf, $object, 0, $outputlangs);
360 $pdf->setPage($pageposafter + 1);
366 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
367 $showpricebeforepagebreak = 1;
369 $showpricebeforepagebreak = 0;
372 $forcedesconsamepage = 1;
373 if ($forcedesconsamepage) {
374 $pdf->rollbackTransaction(
true);
375 $pageposafter = $pageposbefore;
376 $pdf->setPageOrientation(
'', 1, $heightforfooter);
378 $pdf->AddPage(
'',
'',
true);
379 if (!empty($tplidx)) {
380 $pdf->useTemplate($tplidx);
383 $this->
_pagehead($pdf, $object, 0, $outputlangs);
385 $pdf->setPage($pageposafter + 1);
386 $pdf->SetFont(
'',
'', $default_font_size - 1);
387 $pdf->MultiCell(0, 3,
'');
388 $pdf->SetTextColor(0, 0, 0);
390 $pdf->setPageOrientation(
'', 1, $heightforfooter);
391 $curY = $tab_top_newpage + $heightoftitleline + 1;
394 $pdf->SetXY($this->posxlabel, $curY);
395 $posybefore = $pdf->GetY();
396 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
397 $pageposafter = $pdf->getPage();
398 $posyafter = $pdf->GetY();
404 $pdf->commitTransaction();
406 $posYAfterDescription = $pdf->GetY();
408 $nexY = $pdf->GetY();
409 $pageposafter = $pdf->getPage();
410 $pdf->setPage($pageposbefore);
411 $pdf->setTopMargin($this->marge_haute);
412 $pdf->setPageOrientation(
'', 1, 0);
415 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
417 $pdf->setPage($pageposafter);
418 $curY = $tab_top_newpage + $heightoftitleline + 1;
421 $pdf->SetFont(
'',
'', $default_font_size - 1);
424 $pdf->SetXY($this->posxref, $curY);
425 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
427 $pdf->SetXY($this->posxworkload, $curY);
428 $pdf->SetFont(
'',
'', $default_font_size - 2);
429 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
431 $pdf->SetXY($this->posxprogress, $curY);
432 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
433 $pdf->SetFont(
'',
'', $default_font_size - 1);
436 $pdf->SetXY($this->posxdatestart, $curY);
437 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
438 $pdf->SetXY($this->posxdateend, $curY);
439 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
442 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
443 $pdf->setPage($pageposafter);
444 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
446 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
447 $pdf->SetLineStyle(array(
'dash'=>0));
453 while ($pagenb < $pageposafter) {
454 $pdf->setPage($pagenb);
456 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
458 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
460 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
462 $pdf->setPage($pagenb);
463 $pdf->setPageOrientation(
'', 1, 0);
465 $this->
_pagehead($pdf, $object, 0, $outputlangs);
467 if (!empty($tplidx)) {
468 $pdf->useTemplate($tplidx);
471 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
473 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
475 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
477 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
480 if (!empty($tplidx)) {
481 $pdf->useTemplate($tplidx);
485 $this->
_pagehead($pdf, $object, 0, $outputlangs);
492 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
494 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
496 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
499 $this->
_pagefoot($pdf, $object, $outputlangs);
500 if (method_exists($pdf,
'AliasNbPages')) {
501 $pdf->AliasNbPages();
506 $pdf->Output($file,
'F');
509 $hookmanager->initHooks(array(
'pdfgeneration'));
510 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
512 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
514 $this->error = $hookmanager->error;
515 $this->errors = $hookmanager->errors;
520 $this->result = array(
'fullpath'=>$file);
524 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
528 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
596 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
598 global $langs, $conf, $mysoc;
604 $pdf->SetTextColor(0, 0, 60);
605 $pdf->SetFont(
'',
'B', $default_font_size + 3);
607 $posx = $this->page_largeur - $this->marge_droite - 100;
608 $posy = $this->marge_haute;
610 $pdf->SetXY($this->marge_gauche, $posy);
613 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
615 if (is_readable($logo)) {
617 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
619 $pdf->SetTextColor(200, 0, 0);
620 $pdf->SetFont(
'',
'B', $default_font_size - 2);
621 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
622 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
625 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
628 $pdf->SetFont(
'',
'B', $default_font_size + 3);
629 $pdf->SetXY($posx, $posy);
630 $pdf->SetTextColor(0, 0, 60);
631 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
632 $pdf->SetFont(
'',
'', $default_font_size + 2);
635 $pdf->SetXY($posx, $posy);
636 $pdf->SetTextColor(0, 0, 60);
637 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
639 if ($object->date_end) {
641 $pdf->SetXY($posx, $posy);
642 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
645 if (is_object($object->thirdparty)) {
647 $pdf->SetXY($posx, $posy);
648 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
651 $pdf->SetTextColor(0, 0, 60);