144 global $conf, $hookmanager, $langs, $user;
146 if (!is_object($outputlangs)) {
147 $outputlangs = $langs;
151 $outputlangs->charset_output =
'ISO-8859-1';
155 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
157 if ($conf->project->multidir_output[$object->entity]) {
161 $dir = $conf->project->multidir_output[$object->entity];
162 if (!preg_match(
'/specimen/i', $objectref)) {
163 $dir .=
"/".$objectref;
165 $file = $dir.
"/".$objectref.
".pdf";
167 if (!file_exists($dir)) {
169 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
174 if (file_exists($dir)) {
176 if (!is_object($hookmanager)) {
177 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
180 $hookmanager->initHooks(array(
'pdfgeneration'));
181 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
183 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
188 $pdf->SetAutoPageBreak(1, 0);
190 $heightforinfotot = 40;
191 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
192 $heightforfooter = $this->marge_basse + 8;
194 $heightforfooter += 6;
197 if (class_exists(
'TCPDF')) {
198 $pdf->setPrintHeader(
false);
199 $pdf->setPrintFooter(
false);
204 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
205 $tplidx = $pdf->importPage(1);
209 $task =
new Task($this->db);
210 $tasksarray = $task->getTasksArray(0, 0, $object->id);
212 if (!$object->id > 0) {
213 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
216 $object->lines = $tasksarray;
217 $nblines = count($object->lines);
221 $pdf->SetDrawColor(128, 128, 128);
223 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
224 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
225 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
226 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
227 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
229 $pdf->SetCompression(
false);
232 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
236 if (!empty($tplidx)) {
237 $pdf->useTemplate($tplidx);
240 $this->
_pagehead($pdf, $object, 1, $outputlangs);
241 $pdf->SetFont(
'',
'', $default_font_size - 1);
242 $pdf->MultiCell(0, 3,
'');
243 $pdf->SetTextColor(0, 0, 0);
246 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
248 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
251 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
260 $pdf->SetFont(
'',
'', $default_font_size - 1);
261 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
262 $nexY = $pdf->GetY();
263 $height_note = $nexY - $tab_top;
266 $pdf->SetDrawColor(192, 192, 192);
267 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
269 $tab_height = $tab_height - $height_note;
270 $tab_top = $nexY + 6;
275 $heightoftitleline = 10;
276 $iniY = $tab_top + $heightoftitleline + 1;
277 $curY = $tab_top + $heightoftitleline + 1;
278 $nexY = $tab_top + $heightoftitleline + 1;
280 $tmpuser =
new User($this->db);
285 for ($i = 0; $i < $nblines; $i++) {
287 $pdf->SetFont(
'',
'', $default_font_size - 1);
288 $pdf->SetTextColor(0, 0, 0);
290 $pdf->setTopMargin($tab_top_newpage);
291 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
292 $pageposbefore = $pdf->getPage();
295 $ref = $object->lines[$i]->ref;
296 $libelleline = $object->lines[$i]->label;
298 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
302 $showpricebeforepagebreak = 1;
304 $pdf->startTransaction();
306 $pdf->SetXY($this->posxlabel, $curY);
307 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
308 $pageposafter = $pdf->getPage();
309 if ($pageposafter > $pageposbefore) {
310 $pdf->rollbackTransaction(
true);
311 $pageposafter = $pageposbefore;
313 $pdf->setPageOrientation(
'', 1, $heightforfooter);
315 $pdf->SetXY($this->posxlabel, $curY);
316 $posybefore = $pdf->GetY();
317 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
318 $pageposafter = $pdf->getPage();
319 $posyafter = $pdf->GetY();
320 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
321 if ($i == ($nblines - 1)) {
322 $pdf->AddPage(
'',
'',
true);
323 if (!empty($tplidx)) {
324 $pdf->useTemplate($tplidx);
327 $this->
_pagehead($pdf, $object, 0, $outputlangs);
329 $pdf->setPage($pageposafter + 1);
336 $showpricebeforepagebreak = 1;
338 $showpricebeforepagebreak = 0;
341 $forcedesconsamepage = 1;
342 if ($forcedesconsamepage) {
343 $pdf->rollbackTransaction(
true);
344 $pageposafter = $pageposbefore;
345 $pdf->setPageOrientation(
'', 1, $heightforfooter);
347 $pdf->AddPage(
'',
'',
true);
348 if (!empty($tplidx)) {
349 $pdf->useTemplate($tplidx);
352 $this->
_pagehead($pdf, $object, 0, $outputlangs);
354 $pdf->setPage($pageposafter + 1);
355 $pdf->SetFont(
'',
'', $default_font_size - 1);
356 $pdf->MultiCell(0, 3,
'');
357 $pdf->SetTextColor(0, 0, 0);
359 $pdf->setPageOrientation(
'', 1, $heightforfooter);
360 $curY = $tab_top_newpage + $heightoftitleline + 1;
363 $pdf->SetXY($this->posxlabel, $curY);
364 $posybefore = $pdf->GetY();
365 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
366 $pageposafter = $pdf->getPage();
367 $posyafter = $pdf->GetY();
372 $pdf->commitTransaction();
374 $posYAfterDescription = $pdf->GetY();
376 $nexY = $pdf->GetY();
377 $pageposafter = $pdf->getPage();
378 $pdf->setPage($pageposbefore);
379 $pdf->setTopMargin($this->marge_haute);
380 $pdf->setPageOrientation(
'', 1, 0);
383 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
385 $pdf->setPage($pageposafter);
386 $curY = $tab_top_newpage + $heightoftitleline + 1;
389 $pdf->SetFont(
'',
'', $default_font_size - 1);
392 $pdf->SetXY($this->posxref, $curY);
393 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
395 $pdf->SetXY($this->posxtimespent, $curY);
396 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
410 $pdf->setPage($pageposafter);
411 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
413 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
414 $pdf->SetLineStyle(array(
'dash'=>0));
420 while ($pagenb < $pageposafter) {
421 $pdf->setPage($pagenb);
423 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
425 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
427 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
429 $pdf->setPage($pagenb);
430 $pdf->setPageOrientation(
'', 1, 0);
432 $this->
_pagehead($pdf, $object, 0, $outputlangs);
434 if (!empty($tplidx)) {
435 $pdf->useTemplate($tplidx);
438 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
440 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
442 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
444 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
452 $this->
_pagehead($pdf, $object, 0, $outputlangs);
459 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
461 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
463 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
466 $this->
_pagefoot($pdf, $object, $outputlangs);
467 if (method_exists($pdf,
'AliasNbPages')) {
468 $pdf->AliasNbPages();
473 $pdf->Output($file,
'F');
476 $hookmanager->initHooks(array(
'pdfgeneration'));
477 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
479 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
481 $this->error = $hookmanager->error;
482 $this->errors = $hookmanager->errors;
487 $this->result = array(
'fullpath'=>$file);
491 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
495 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
558 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
560 global $langs, $conf, $mysoc;
566 $pdf->SetTextColor(0, 0, 60);
567 $pdf->SetFont(
'',
'B', $default_font_size + 3);
569 $posx = $this->page_largeur - $this->marge_droite - 100;
570 $posy = $this->marge_haute;
572 $pdf->SetXY($this->marge_gauche, $posy);
575 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
577 if (is_readable($logo)) {
579 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
581 $pdf->SetTextColor(200, 0, 0);
582 $pdf->SetFont(
'',
'B', $default_font_size - 2);
583 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
584 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
587 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
590 $pdf->SetFont(
'',
'B', $default_font_size + 3);
591 $pdf->SetXY($posx, $posy);
592 $pdf->SetTextColor(0, 0, 60);
593 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
594 $pdf->SetFont(
'',
'', $default_font_size + 2);
597 $pdf->SetXY($posx, $posy);
598 $pdf->SetTextColor(0, 0, 60);
599 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
602 $pdf->SetXY($posx, $posy);
603 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
605 if (is_object($object->thirdparty)) {
607 $pdf->SetXY($posx, $posy);
608 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
611 $pdf->SetTextColor(0, 0, 60);