158 global $conf, $hookmanager, $langs, $user;
160 if (!is_object($outputlangs)) {
161 $outputlangs = $langs;
165 $outputlangs->charset_output =
'ISO-8859-1';
169 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
171 if ($conf->project->multidir_output[
$object->entity]) {
175 $dir = $conf->project->multidir_output[
$object->entity];
176 if (!preg_match(
'/specimen/i', $objectref)) {
177 $dir .=
"/".$objectref;
179 $file = $dir.
"/".$objectref.
".pdf";
181 if (!file_exists($dir)) {
183 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
188 if (file_exists($dir)) {
190 if (!is_object($hookmanager)) {
191 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
194 $hookmanager->initHooks(array(
'pdfgeneration'));
195 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
197 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
202 $pdf->SetAutoPageBreak(1, 0);
204 $heightforinfotot = 40;
206 $heightforfooter = $this->marge_basse + 8;
208 $heightforfooter += 6;
211 if (class_exists(
'TCPDF')) {
212 $pdf->setPrintHeader(
false);
213 $pdf->setPrintFooter(
false);
218 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
219 $tplidx = $pdf->importPage(1);
223 $task =
new Task($this->db);
224 $tasksarray = $task->getTasksArray(
null,
null,
$object->id);
227 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
231 $nblines = count(
$object->lines);
235 $pdf->SetDrawColor(128, 128, 128);
237 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
238 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
239 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
240 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
241 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
243 $pdf->SetCompression(
false);
247 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
251 if (!empty($tplidx)) {
252 $pdf->useTemplate($tplidx);
256 $pdf->SetFont(
'',
'', $default_font_size - 1);
257 $pdf->MultiCell(0, 3,
'');
258 $pdf->SetTextColor(0, 0, 0);
261 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
263 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
266 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
275 $pdf->SetFont(
'',
'', $default_font_size - 1);
276 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
277 $nexY = $pdf->GetY();
278 $height_note = $nexY - $tab_top;
281 $pdf->SetDrawColor(192, 192, 192);
282 $pdf->RoundedRect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
284 $tab_height -= $height_note;
285 $tab_top = $nexY + 6;
290 $heightoftitleline = 10;
291 $iniY = $tab_top + $heightoftitleline + 1;
292 $curY = $tab_top + $heightoftitleline + 1;
293 $nexY = $tab_top + $heightoftitleline + 1;
296 for ($i = 0; $i < $nblines; $i++) {
298 $pdf->SetFont(
'',
'', $default_font_size - 1);
299 $pdf->SetTextColor(0, 0, 0);
301 $pdf->setTopMargin($tab_top_newpage);
302 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
303 $pageposbefore = $pdf->getPage();
306 $ref =
$object->lines[$i]->ref;
307 $libelleline =
$object->lines[$i]->label;
308 $progress = (
$object->lines[$i]->progress ?
$object->lines[$i]->progress.
'%' :
'');
313 $showpricebeforepagebreak = 1;
315 $pdf->startTransaction();
317 $pdf->SetXY($this->posxlabel, $curY);
318 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
319 $pageposafter = $pdf->getPage();
320 if ($pageposafter > $pageposbefore) {
321 $pdf->rollbackTransaction(
true);
322 $pageposafter = $pageposbefore;
324 $pdf->setPageOrientation(
'', 1, $heightforfooter);
326 $pdf->SetXY($this->posxlabel, $curY);
327 $posybefore = $pdf->GetY();
328 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
329 $pageposafter = $pdf->getPage();
330 $posyafter = $pdf->GetY();
331 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
332 if ($i == ($nblines - 1)) {
333 $pdf->AddPage(
'',
'',
true);
334 if (!empty($tplidx)) {
335 $pdf->useTemplate($tplidx);
340 $pdf->setPage($pageposafter + 1);
347 $showpricebeforepagebreak = 1;
349 $showpricebeforepagebreak = 0;
352 $forcedesconsamepage = 1;
353 if ($forcedesconsamepage) {
354 $pdf->rollbackTransaction(
true);
355 $pageposafter = $pageposbefore;
356 $pdf->setPageOrientation(
'', 1, $heightforfooter);
358 $pdf->AddPage(
'',
'',
true);
359 if (!empty($tplidx)) {
360 $pdf->useTemplate($tplidx);
365 $pdf->setPage($pageposafter + 1);
366 $pdf->SetFont(
'',
'', $default_font_size - 1);
367 $pdf->MultiCell(0, 3,
'');
368 $pdf->SetTextColor(0, 0, 0);
370 $pdf->setPageOrientation(
'', 1, $heightforfooter);
371 $curY = $tab_top_newpage + $heightoftitleline + 1;
374 $pdf->SetXY($this->posxlabel, $curY);
375 $posybefore = $pdf->GetY();
376 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
377 $pageposafter = $pdf->getPage();
378 $posyafter = $pdf->GetY();
383 $pdf->commitTransaction();
385 $posYAfterDescription = $pdf->GetY();
387 $nexY = $pdf->GetY();
388 $pageposafter = $pdf->getPage();
389 $pdf->setPage($pageposbefore);
390 $pdf->setTopMargin($this->marge_haute);
391 $pdf->setPageOrientation(
'', 1, 0);
394 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
396 $pdf->setPage($pageposafter);
397 $curY = $tab_top_newpage + $heightoftitleline + 1;
400 $pdf->SetFont(
'',
'', $default_font_size - 1);
403 $pdf->SetXY($this->posxref, $curY);
404 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
406 $pdf->SetXY($this->posxworkload, $curY);
407 $pdf->SetFont(
'',
'', $default_font_size - 2);
408 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
410 $pdf->SetXY($this->posxprogress, $curY);
411 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
412 $pdf->SetFont(
'',
'', $default_font_size - 1);
415 $pdf->SetXY($this->posxdatestart, $curY);
416 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
417 $pdf->SetXY($this->posxdateend, $curY);
418 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
422 $pdf->setPage($pageposafter);
423 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
425 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
426 $pdf->SetLineStyle(array(
'dash' => 0));
432 while ($pagenb < $pageposafter) {
433 $pdf->setPage($pagenb);
435 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
437 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
441 $pdf->setPage($pagenb);
442 $pdf->setPageOrientation(
'', 1, 0);
446 if (!empty($tplidx)) {
447 $pdf->useTemplate($tplidx);
450 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
452 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
454 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
459 if (!empty($tplidx)) {
460 $pdf->useTemplate($tplidx);
471 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
473 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
475 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
479 if (method_exists($pdf,
'AliasNbPages')) {
480 $pdf->AliasNbPages();
485 $pdf->Output($file,
'F');
488 $hookmanager->initHooks(array(
'pdfgeneration'));
489 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
491 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
493 $this->error = $hookmanager->error;
494 $this->errors = $hookmanager->errors;
499 $this->result = array(
'fullpath' => $file);
503 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
507 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
525 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
527 global $conf, $mysoc;
529 $heightoftitleline = 10;
533 $pdf->SetDrawColor(128, 128, 128);
536 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius,
'1234',
'D');
539 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
541 $pdf->SetTextColor(0, 0, 0);
542 $pdf->SetFont(
'',
'', $default_font_size);
544 $pdf->SetXY($this->posxref, $tab_top + 1);
545 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
547 $pdf->SetXY($this->posxlabel, $tab_top + 1);
548 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
550 $pdf->SetXY($this->posxworkload, $tab_top + 1);
551 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
553 $pdf->SetXY($this->posxprogress, $tab_top + 1);
554 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
557 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
558 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans(
"Start"), 0,
'C');
561 $pdf->SetXY($this->posxdateend, $tab_top + 1);
562 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans(
"End"), 0,
'C');
577 global $langs, $conf, $mysoc;
583 $pdf->SetTextColor(0, 0, 60);
584 $pdf->SetFont(
'',
'B', $default_font_size + 3);
586 $posx = $this->page_largeur - $this->marge_droite - 100;
587 $posy = $this->marge_haute;
589 $pdf->SetXY($this->marge_gauche, $posy);
592 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
594 if (is_readable($logo)) {
596 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
598 $pdf->SetTextColor(200, 0, 0);
599 $pdf->SetFont(
'',
'B', $default_font_size - 2);
600 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
601 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
604 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
607 $pdf->SetFont(
'',
'B', $default_font_size + 3);
608 $pdf->SetXY($posx, $posy);
609 $pdf->SetTextColor(0, 0, 60);
610 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
611 $pdf->SetFont(
'',
'', $default_font_size + 2);
614 $pdf->SetXY($posx, $posy);
615 $pdf->SetTextColor(0, 0, 60);
616 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
620 $pdf->SetXY($posx, $posy);
621 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
624 if (is_object(
$object->thirdparty)) {
626 $pdf->SetXY($posx, $posy);
627 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
630 $pdf->SetTextColor(0, 0, 60);