150 global $conf, $hookmanager, $langs, $user;
152 if (!is_object($outputlangs)) {
153 $outputlangs = $langs;
157 $outputlangs->charset_output =
'ISO-8859-1';
161 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
163 if ($conf->project->multidir_output[
$object->entity]) {
167 $dir = $conf->project->multidir_output[
$object->entity];
168 if (!preg_match(
'/specimen/i', $objectref)) {
169 $dir .=
"/".$objectref;
171 $file = $dir.
"/".$objectref.
".pdf";
173 if (!file_exists($dir)) {
175 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
180 if (file_exists($dir)) {
182 if (!is_object($hookmanager)) {
183 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
186 $hookmanager->initHooks(array(
'pdfgeneration'));
187 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
189 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
194 $pdf->SetAutoPageBreak(1, 0);
196 $heightforinfotot = 40;
197 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
198 $heightforfooter = $this->marge_basse + 8;
200 $heightforfooter += 6;
203 if (class_exists(
'TCPDF')) {
204 $pdf->setPrintHeader(
false);
205 $pdf->setPrintFooter(
false);
210 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
211 $tplidx = $pdf->importPage(1);
215 $task =
new Task($this->db);
216 $tasksarray = $task->getTasksArray(0, 0,
$object->id);
219 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
223 $nblines = count(
$object->lines);
227 $pdf->SetDrawColor(128, 128, 128);
229 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
230 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
231 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
232 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
233 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
235 $pdf->SetCompression(
false);
239 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
243 if (!empty($tplidx)) {
244 $pdf->useTemplate($tplidx);
248 $pdf->SetFont(
'',
'', $default_font_size - 1);
249 $pdf->MultiCell(0, 3,
'');
250 $pdf->SetTextColor(0, 0, 0);
253 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
255 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
258 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
267 $pdf->SetFont(
'',
'', $default_font_size - 1);
268 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
269 $nexY = $pdf->GetY();
270 $height_note = $nexY - $tab_top;
273 $pdf->SetDrawColor(192, 192, 192);
274 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
276 $tab_height = $tab_height - $height_note;
277 $tab_top = $nexY + 6;
282 $heightoftitleline = 10;
283 $iniY = $tab_top + $heightoftitleline + 1;
284 $curY = $tab_top + $heightoftitleline + 1;
285 $nexY = $tab_top + $heightoftitleline + 1;
288 for ($i = 0; $i < $nblines; $i++) {
290 $pdf->SetFont(
'',
'', $default_font_size - 1);
291 $pdf->SetTextColor(0, 0, 0);
293 $pdf->setTopMargin($tab_top_newpage);
294 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
295 $pageposbefore = $pdf->getPage();
298 $ref =
$object->lines[$i]->ref;
299 $libelleline =
$object->lines[$i]->label;
300 $progress = (
$object->lines[$i]->progress ?
$object->lines[$i]->progress.
'%' :
'');
305 $showpricebeforepagebreak = 1;
307 $pdf->startTransaction();
309 $pdf->SetXY($this->posxlabel, $curY);
310 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
311 $pageposafter = $pdf->getPage();
312 if ($pageposafter > $pageposbefore) {
313 $pdf->rollbackTransaction(
true);
314 $pageposafter = $pageposbefore;
316 $pdf->setPageOrientation(
'', 1, $heightforfooter);
318 $pdf->SetXY($this->posxlabel, $curY);
319 $posybefore = $pdf->GetY();
320 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
321 $pageposafter = $pdf->getPage();
322 $posyafter = $pdf->GetY();
323 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
324 if ($i == ($nblines - 1)) {
325 $pdf->AddPage(
'',
'',
true);
326 if (!empty($tplidx)) {
327 $pdf->useTemplate($tplidx);
332 $pdf->setPage($pageposafter + 1);
339 $showpricebeforepagebreak = 1;
341 $showpricebeforepagebreak = 0;
344 $forcedesconsamepage = 1;
345 if ($forcedesconsamepage) {
346 $pdf->rollbackTransaction(
true);
347 $pageposafter = $pageposbefore;
348 $pdf->setPageOrientation(
'', 1, $heightforfooter);
350 $pdf->AddPage(
'',
'',
true);
351 if (!empty($tplidx)) {
352 $pdf->useTemplate($tplidx);
357 $pdf->setPage($pageposafter + 1);
358 $pdf->SetFont(
'',
'', $default_font_size - 1);
359 $pdf->MultiCell(0, 3,
'');
360 $pdf->SetTextColor(0, 0, 0);
362 $pdf->setPageOrientation(
'', 1, $heightforfooter);
363 $curY = $tab_top_newpage + $heightoftitleline + 1;
366 $pdf->SetXY($this->posxlabel, $curY);
367 $posybefore = $pdf->GetY();
368 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
369 $pageposafter = $pdf->getPage();
370 $posyafter = $pdf->GetY();
375 $pdf->commitTransaction();
377 $posYAfterDescription = $pdf->GetY();
379 $nexY = $pdf->GetY();
380 $pageposafter = $pdf->getPage();
381 $pdf->setPage($pageposbefore);
382 $pdf->setTopMargin($this->marge_haute);
383 $pdf->setPageOrientation(
'', 1, 0);
386 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
388 $pdf->setPage($pageposafter);
389 $curY = $tab_top_newpage + $heightoftitleline + 1;
392 $pdf->SetFont(
'',
'', $default_font_size - 1);
395 $pdf->SetXY($this->posxref, $curY);
396 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
398 $pdf->SetXY($this->posxworkload, $curY);
399 $pdf->SetFont(
'',
'', $default_font_size - 2);
400 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
402 $pdf->SetXY($this->posxprogress, $curY);
403 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
404 $pdf->SetFont(
'',
'', $default_font_size - 1);
407 $pdf->SetXY($this->posxdatestart, $curY);
408 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
409 $pdf->SetXY($this->posxdateend, $curY);
410 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
414 $pdf->setPage($pageposafter);
415 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
417 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
418 $pdf->SetLineStyle(array(
'dash' => 0));
424 while ($pagenb < $pageposafter) {
425 $pdf->setPage($pagenb);
427 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
429 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
433 $pdf->setPage($pagenb);
434 $pdf->setPageOrientation(
'', 1, 0);
438 if (!empty($tplidx)) {
439 $pdf->useTemplate($tplidx);
442 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
444 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
446 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
451 if (!empty($tplidx)) {
452 $pdf->useTemplate($tplidx);
463 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
465 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
467 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
471 if (method_exists($pdf,
'AliasNbPages')) {
472 $pdf->AliasNbPages();
477 $pdf->Output($file,
'F');
480 $hookmanager->initHooks(array(
'pdfgeneration'));
481 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
483 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
485 $this->error = $hookmanager->error;
486 $this->errors = $hookmanager->errors;
491 $this->result = array(
'fullpath' => $file);
495 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
499 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
517 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
519 global $conf, $mysoc;
521 $heightoftitleline = 10;
525 $pdf->SetDrawColor(128, 128, 128);
528 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
531 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
533 $pdf->SetTextColor(0, 0, 0);
534 $pdf->SetFont(
'',
'', $default_font_size);
536 $pdf->SetXY($this->posxref, $tab_top + 1);
537 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
539 $pdf->SetXY($this->posxlabel, $tab_top + 1);
540 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
542 $pdf->SetXY($this->posxworkload, $tab_top + 1);
543 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
545 $pdf->SetXY($this->posxprogress, $tab_top + 1);
546 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
549 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
550 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans(
"Start"), 0,
'C');
553 $pdf->SetXY($this->posxdateend, $tab_top + 1);
554 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans(
"End"), 0,
'C');
569 global $langs, $conf, $mysoc;
575 $pdf->SetTextColor(0, 0, 60);
576 $pdf->SetFont(
'',
'B', $default_font_size + 3);
578 $posx = $this->page_largeur - $this->marge_droite - 100;
579 $posy = $this->marge_haute;
581 $pdf->SetXY($this->marge_gauche, $posy);
584 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
586 if (is_readable($logo)) {
588 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
590 $pdf->SetTextColor(200, 0, 0);
591 $pdf->SetFont(
'',
'B', $default_font_size - 2);
592 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
593 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
596 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
599 $pdf->SetFont(
'',
'B', $default_font_size + 3);
600 $pdf->SetXY($posx, $posy);
601 $pdf->SetTextColor(0, 0, 60);
602 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
603 $pdf->SetFont(
'',
'', $default_font_size + 2);
606 $pdf->SetXY($posx, $posy);
607 $pdf->SetTextColor(0, 0, 60);
608 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
612 $pdf->SetXY($posx, $posy);
613 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
616 if (is_object(
$object->thirdparty)) {
618 $pdf->SetXY($posx, $posy);
619 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
622 $pdf->SetTextColor(0, 0, 60);