152 global $conf, $hookmanager, $langs, $user;
154 if (!is_object($outputlangs)) {
155 $outputlangs = $langs;
159 $outputlangs->charset_output =
'ISO-8859-1';
163 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
165 if ($conf->project->multidir_output[
$object->entity]) {
169 $dir = $conf->project->multidir_output[
$object->entity];
170 if (!preg_match(
'/specimen/i', $objectref)) {
171 $dir .=
"/".$objectref;
173 $file = $dir.
"/".$objectref.
".pdf";
175 if (!file_exists($dir)) {
177 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
182 if (file_exists($dir)) {
184 if (!is_object($hookmanager)) {
185 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
188 $hookmanager->initHooks(array(
'pdfgeneration'));
189 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
191 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
196 $pdf->SetAutoPageBreak(1, 0);
198 $heightforinfotot = 40;
200 $heightforfooter = $this->marge_basse + 8;
202 $heightforfooter += 6;
205 if (class_exists(
'TCPDF')) {
206 $pdf->setPrintHeader(
false);
207 $pdf->setPrintFooter(
false);
212 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
213 $tplidx = $pdf->importPage(1);
217 $task =
new Task($this->db);
218 $tasksarray = $task->getTasksArray(0, 0,
$object->id);
221 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
225 $nblines = count(
$object->lines);
229 $pdf->SetDrawColor(128, 128, 128);
231 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
232 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
233 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
234 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
235 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
237 $pdf->SetCompression(
false);
241 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
245 if (!empty($tplidx)) {
246 $pdf->useTemplate($tplidx);
250 $pdf->SetFont(
'',
'', $default_font_size - 1);
251 $pdf->MultiCell(0, 3,
'');
252 $pdf->SetTextColor(0, 0, 0);
255 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
257 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
260 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
269 $pdf->SetFont(
'',
'', $default_font_size - 1);
270 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
271 $nexY = $pdf->GetY();
272 $height_note = $nexY - $tab_top;
275 $pdf->SetDrawColor(192, 192, 192);
276 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
278 $tab_height -= $height_note;
279 $tab_top = $nexY + 6;
284 $heightoftitleline = 10;
285 $iniY = $tab_top + $heightoftitleline + 1;
286 $curY = $tab_top + $heightoftitleline + 1;
287 $nexY = $tab_top + $heightoftitleline + 1;
290 for ($i = 0; $i < $nblines; $i++) {
292 $pdf->SetFont(
'',
'', $default_font_size - 1);
293 $pdf->SetTextColor(0, 0, 0);
295 $pdf->setTopMargin($tab_top_newpage);
296 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
297 $pageposbefore = $pdf->getPage();
300 $ref =
$object->lines[$i]->ref;
301 $libelleline =
$object->lines[$i]->label;
302 $progress = (
$object->lines[$i]->progress ?
$object->lines[$i]->progress.
'%' :
'');
307 $showpricebeforepagebreak = 1;
309 $pdf->startTransaction();
311 $pdf->SetXY($this->posxlabel, $curY);
312 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
313 $pageposafter = $pdf->getPage();
314 if ($pageposafter > $pageposbefore) {
315 $pdf->rollbackTransaction(
true);
316 $pageposafter = $pageposbefore;
318 $pdf->setPageOrientation(
'', 1, $heightforfooter);
320 $pdf->SetXY($this->posxlabel, $curY);
321 $posybefore = $pdf->GetY();
322 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
323 $pageposafter = $pdf->getPage();
324 $posyafter = $pdf->GetY();
325 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
326 if ($i == ($nblines - 1)) {
327 $pdf->AddPage(
'',
'',
true);
328 if (!empty($tplidx)) {
329 $pdf->useTemplate($tplidx);
334 $pdf->setPage($pageposafter + 1);
341 $showpricebeforepagebreak = 1;
343 $showpricebeforepagebreak = 0;
346 $forcedesconsamepage = 1;
347 if ($forcedesconsamepage) {
348 $pdf->rollbackTransaction(
true);
349 $pageposafter = $pageposbefore;
350 $pdf->setPageOrientation(
'', 1, $heightforfooter);
352 $pdf->AddPage(
'',
'',
true);
353 if (!empty($tplidx)) {
354 $pdf->useTemplate($tplidx);
359 $pdf->setPage($pageposafter + 1);
360 $pdf->SetFont(
'',
'', $default_font_size - 1);
361 $pdf->MultiCell(0, 3,
'');
362 $pdf->SetTextColor(0, 0, 0);
364 $pdf->setPageOrientation(
'', 1, $heightforfooter);
365 $curY = $tab_top_newpage + $heightoftitleline + 1;
368 $pdf->SetXY($this->posxlabel, $curY);
369 $posybefore = $pdf->GetY();
370 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
371 $pageposafter = $pdf->getPage();
372 $posyafter = $pdf->GetY();
377 $pdf->commitTransaction();
379 $posYAfterDescription = $pdf->GetY();
381 $nexY = $pdf->GetY();
382 $pageposafter = $pdf->getPage();
383 $pdf->setPage($pageposbefore);
384 $pdf->setTopMargin($this->marge_haute);
385 $pdf->setPageOrientation(
'', 1, 0);
388 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
390 $pdf->setPage($pageposafter);
391 $curY = $tab_top_newpage + $heightoftitleline + 1;
394 $pdf->SetFont(
'',
'', $default_font_size - 1);
397 $pdf->SetXY($this->posxref, $curY);
398 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
400 $pdf->SetXY($this->posxworkload, $curY);
401 $pdf->SetFont(
'',
'', $default_font_size - 2);
402 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
404 $pdf->SetXY($this->posxprogress, $curY);
405 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
406 $pdf->SetFont(
'',
'', $default_font_size - 1);
409 $pdf->SetXY($this->posxdatestart, $curY);
410 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
411 $pdf->SetXY($this->posxdateend, $curY);
412 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
416 $pdf->setPage($pageposafter);
417 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
419 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
420 $pdf->SetLineStyle(array(
'dash' => 0));
426 while ($pagenb < $pageposafter) {
427 $pdf->setPage($pagenb);
429 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
431 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
435 $pdf->setPage($pagenb);
436 $pdf->setPageOrientation(
'', 1, 0);
440 if (!empty($tplidx)) {
441 $pdf->useTemplate($tplidx);
444 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
446 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
448 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
453 if (!empty($tplidx)) {
454 $pdf->useTemplate($tplidx);
465 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
467 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
469 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
473 if (method_exists($pdf,
'AliasNbPages')) {
474 $pdf->AliasNbPages();
479 $pdf->Output($file,
'F');
482 $hookmanager->initHooks(array(
'pdfgeneration'));
483 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
485 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
487 $this->error = $hookmanager->error;
488 $this->errors = $hookmanager->errors;
493 $this->result = array(
'fullpath' => $file);
497 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
501 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
519 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
521 global $conf, $mysoc;
523 $heightoftitleline = 10;
527 $pdf->SetDrawColor(128, 128, 128);
530 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
533 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
535 $pdf->SetTextColor(0, 0, 0);
536 $pdf->SetFont(
'',
'', $default_font_size);
538 $pdf->SetXY($this->posxref, $tab_top + 1);
539 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
541 $pdf->SetXY($this->posxlabel, $tab_top + 1);
542 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
544 $pdf->SetXY($this->posxworkload, $tab_top + 1);
545 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
547 $pdf->SetXY($this->posxprogress, $tab_top + 1);
548 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
551 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
552 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans(
"Start"), 0,
'C');
555 $pdf->SetXY($this->posxdateend, $tab_top + 1);
556 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans(
"End"), 0,
'C');
571 global $langs, $conf, $mysoc;
577 $pdf->SetTextColor(0, 0, 60);
578 $pdf->SetFont(
'',
'B', $default_font_size + 3);
580 $posx = $this->page_largeur - $this->marge_droite - 100;
581 $posy = $this->marge_haute;
583 $pdf->SetXY($this->marge_gauche, $posy);
586 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
588 if (is_readable($logo)) {
590 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
592 $pdf->SetTextColor(200, 0, 0);
593 $pdf->SetFont(
'',
'B', $default_font_size - 2);
594 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
595 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
598 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
601 $pdf->SetFont(
'',
'B', $default_font_size + 3);
602 $pdf->SetXY($posx, $posy);
603 $pdf->SetTextColor(0, 0, 60);
604 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
605 $pdf->SetFont(
'',
'', $default_font_size + 2);
608 $pdf->SetXY($posx, $posy);
609 $pdf->SetTextColor(0, 0, 60);
610 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
614 $pdf->SetXY($posx, $posy);
615 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
618 if (is_object(
$object->thirdparty)) {
620 $pdf->SetXY($posx, $posy);
621 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
624 $pdf->SetTextColor(0, 0, 60);