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;
315 $tmpuser =
new User($this->db);
320 for ($i = 0; $i < $nblines; $i++) {
322 $pdf->SetFont(
'',
'', $default_font_size - 1);
323 $pdf->SetTextColor(0, 0, 0);
325 $pdf->setTopMargin($tab_top_newpage);
326 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
327 $pageposbefore = $pdf->getPage();
330 $ref = $object->lines[$i]->ref;
331 $libelleline = $object->lines[$i]->label;
333 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
337 $showpricebeforepagebreak = 1;
339 $pdf->startTransaction();
341 $pdf->SetXY($this->posxlabel, $curY);
342 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
343 $pageposafter = $pdf->getPage();
344 if ($pageposafter > $pageposbefore) {
345 $pdf->rollbackTransaction(
true);
346 $pageposafter = $pageposbefore;
348 $pdf->setPageOrientation(
'', 1, $heightforfooter);
350 $pdf->SetXY($this->posxlabel, $curY);
351 $posybefore = $pdf->GetY();
352 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
353 $pageposafter = $pdf->getPage();
354 $posyafter = $pdf->GetY();
355 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
356 if ($i == ($nblines - 1)) {
357 $pdf->AddPage(
'',
'',
true);
358 if (!empty($tplidx)) {
359 $pdf->useTemplate($tplidx);
362 $this->
_pagehead($pdf, $object, 0, $outputlangs);
364 $pdf->setPage($pageposafter + 1);
370 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
371 $showpricebeforepagebreak = 1;
373 $showpricebeforepagebreak = 0;
376 $forcedesconsamepage = 1;
377 if ($forcedesconsamepage) {
378 $pdf->rollbackTransaction(
true);
379 $pageposafter = $pageposbefore;
380 $pdf->setPageOrientation(
'', 1, $heightforfooter);
382 $pdf->AddPage(
'',
'',
true);
383 if (!empty($tplidx)) {
384 $pdf->useTemplate($tplidx);
387 $this->
_pagehead($pdf, $object, 0, $outputlangs);
389 $pdf->setPage($pageposafter + 1);
390 $pdf->SetFont(
'',
'', $default_font_size - 1);
391 $pdf->MultiCell(0, 3,
'');
392 $pdf->SetTextColor(0, 0, 0);
394 $pdf->setPageOrientation(
'', 1, $heightforfooter);
395 $curY = $tab_top_newpage + $heightoftitleline + 1;
398 $pdf->SetXY($this->posxlabel, $curY);
399 $posybefore = $pdf->GetY();
400 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
401 $pageposafter = $pdf->getPage();
402 $posyafter = $pdf->GetY();
408 $pdf->commitTransaction();
410 $posYAfterDescription = $pdf->GetY();
412 $nexY = $pdf->GetY();
413 $pageposafter = $pdf->getPage();
414 $pdf->setPage($pageposbefore);
415 $pdf->setTopMargin($this->marge_haute);
416 $pdf->setPageOrientation(
'', 1, 0);
419 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
421 $pdf->setPage($pageposafter);
422 $curY = $tab_top_newpage + $heightoftitleline + 1;
425 $pdf->SetFont(
'',
'', $default_font_size - 1);
428 $pdf->SetXY($this->posxref, $curY);
429 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
431 $pdf->SetXY($this->posxtimespent, $curY);
432 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
445 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
446 $pdf->setPage($pageposafter);
447 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
449 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
450 $pdf->SetLineStyle(array(
'dash'=>0));
456 while ($pagenb < $pageposafter) {
457 $pdf->setPage($pagenb);
459 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
461 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
463 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
465 $pdf->setPage($pagenb);
466 $pdf->setPageOrientation(
'', 1, 0);
468 $this->
_pagehead($pdf, $object, 0, $outputlangs);
470 if (!empty($tplidx)) {
471 $pdf->useTemplate($tplidx);
474 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
476 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
478 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
480 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
483 if (!empty($tplidx)) {
484 $pdf->useTemplate($tplidx);
488 $this->
_pagehead($pdf, $object, 0, $outputlangs);
495 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
497 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
499 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
502 $this->
_pagefoot($pdf, $object, $outputlangs);
503 if (method_exists($pdf,
'AliasNbPages')) {
504 $pdf->AliasNbPages();
509 $pdf->Output($file,
'F');
512 $hookmanager->initHooks(array(
'pdfgeneration'));
513 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
515 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
517 $this->error = $hookmanager->error;
518 $this->errors = $hookmanager->errors;
523 $this->result = array(
'fullpath'=>$file);
527 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
531 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
594 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
596 global $langs, $conf, $mysoc;
602 $pdf->SetTextColor(0, 0, 60);
603 $pdf->SetFont(
'',
'B', $default_font_size + 3);
605 $posx = $this->page_largeur - $this->marge_droite - 100;
606 $posy = $this->marge_haute;
608 $pdf->SetXY($this->marge_gauche, $posy);
611 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
613 if (is_readable($logo)) {
615 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
617 $pdf->SetTextColor(200, 0, 0);
618 $pdf->SetFont(
'',
'B', $default_font_size - 2);
619 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
620 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
623 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
626 $pdf->SetFont(
'',
'B', $default_font_size + 3);
627 $pdf->SetXY($posx, $posy);
628 $pdf->SetTextColor(0, 0, 60);
629 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
630 $pdf->SetFont(
'',
'', $default_font_size + 2);
633 $pdf->SetXY($posx, $posy);
634 $pdf->SetTextColor(0, 0, 60);
635 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
638 $pdf->SetXY($posx, $posy);
639 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
641 if (is_object($object->thirdparty)) {
643 $pdf->SetXY($posx, $posy);
644 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
647 $pdf->SetTextColor(0, 0, 60);