158 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
161 global
$conf, $hookmanager, $langs, $user;
163 if (!is_object($outputlangs)) {
164 $outputlangs = $langs;
168 $outputlangs->charset_output =
'ISO-8859-1';
172 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
179 if (!preg_match(
'/specimen/i', $objectref)) {
180 $dir .=
"/".$objectref;
182 $file = $dir.
"/".$objectref.
".pdf";
184 if (!file_exists($dir)) {
186 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
191 if (file_exists($dir)) {
193 if (!is_object($hookmanager)) {
194 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
197 $hookmanager->initHooks(array(
'pdfgeneration'));
198 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
200 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
205 $pdf->setAutoPageBreak(
true, 0);
207 $heightforinfotot = 40;
209 $heightforfooter = $this->marge_basse + 8;
211 $heightforfooter += 6;
214 if (class_exists(
'TCPDF')) {
215 $pdf->setPrintHeader(
false);
216 $pdf->setPrintFooter(
false);
221 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
222 $tplidx = $pdf->importPage(1);
226 $task =
new Task($this->db);
227 $tasksarray = $task->getTasksArray(
null,
null,
$object->id);
230 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
234 $nblines = count(
$object->lines);
238 $pdf->SetDrawColor(128, 128, 128);
240 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
241 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
242 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
243 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
244 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
246 $pdf->SetCompression(
false);
250 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
254 if (!empty($tplidx)) {
255 $pdf->useTemplate($tplidx);
259 $pdf->SetFont(
'',
'', $default_font_size - 1);
260 $pdf->MultiCell(0, 3,
'');
261 $pdf->SetTextColor(0, 0, 0);
264 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
266 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
269 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
278 $pdf->SetFont(
'',
'', $default_font_size - 1);
279 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
280 $nexY = $pdf->GetY();
281 $height_note = $nexY - $tab_top;
284 $pdf->SetDrawColor(192, 192, 192);
285 $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');
287 $tab_height -= $height_note;
288 $tab_top = $nexY + 6;
293 $heightoftitleline = 10;
294 $iniY = $tab_top + $heightoftitleline + 1;
295 $curY = $tab_top + $heightoftitleline + 1;
296 $nexY = $tab_top + $heightoftitleline + 1;
299 for ($i = 0; $i < $nblines; $i++) {
301 $pdf->SetFont(
'',
'', $default_font_size - 1);
302 $pdf->SetTextColor(0, 0, 0);
304 $pdf->setTopMargin($tab_top_newpage);
305 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
306 $pageposbefore = $pdf->getPage();
309 $ref =
$object->lines[$i]->ref;
310 $libelleline =
$object->lines[$i]->label;
311 $progress = (
$object->lines[$i]->progress ?
$object->lines[$i]->progress.
'%' :
'');
316 $showpricebeforepagebreak = 1;
318 $pdf->startTransaction();
320 $pdf->SetXY($this->posxlabel, $curY);
321 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
322 $pageposafter = $pdf->getPage();
323 if ($pageposafter > $pageposbefore) {
324 $pdf->rollbackTransaction(
true);
325 $pageposafter = $pageposbefore;
327 $pdf->setPageOrientation(
'',
true, $heightforfooter);
329 $pdf->SetXY($this->posxlabel, $curY);
330 $posybefore = $pdf->GetY();
331 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
332 $pageposafter = $pdf->getPage();
333 $posyafter = $pdf->GetY();
334 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
335 if ($i == ($nblines - 1)) {
336 $pdf->AddPage(
'',
'',
true);
337 if (!empty($tplidx)) {
338 $pdf->useTemplate($tplidx);
343 $pdf->setPage($pageposafter + 1);
350 $showpricebeforepagebreak = 1;
352 $showpricebeforepagebreak = 0;
355 $forcedesconsamepage = 1;
356 if ($forcedesconsamepage) {
357 $pdf->rollbackTransaction(
true);
358 $pageposafter = $pageposbefore;
359 $pdf->setPageOrientation(
'',
true, $heightforfooter);
361 $pdf->AddPage(
'',
'',
true);
362 if (!empty($tplidx)) {
363 $pdf->useTemplate($tplidx);
368 $pdf->setPage($pageposafter + 1);
369 $pdf->SetFont(
'',
'', $default_font_size - 1);
370 $pdf->MultiCell(0, 3,
'');
371 $pdf->SetTextColor(0, 0, 0);
373 $pdf->setPageOrientation(
'',
true, $heightforfooter);
374 $curY = $tab_top_newpage + $heightoftitleline + 1;
377 $pdf->SetXY($this->posxlabel, $curY);
378 $posybefore = $pdf->GetY();
379 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
380 $pageposafter = $pdf->getPage();
381 $posyafter = $pdf->GetY();
386 $pdf->commitTransaction();
388 $posYAfterDescription = $pdf->GetY();
390 $nexY = $pdf->GetY();
391 $pageposafter = $pdf->getPage();
392 $pdf->setPage($pageposbefore);
393 $pdf->setTopMargin($this->marge_haute);
394 $pdf->setPageOrientation(
'',
true, 0);
397 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
399 $pdf->setPage($pageposafter);
400 $curY = $tab_top_newpage + $heightoftitleline + 1;
403 $pdf->SetFont(
'',
'', $default_font_size - 1);
406 $pdf->SetXY($this->posxref, $curY);
407 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
409 $pdf->SetXY($this->posxworkload, $curY);
410 $pdf->SetFont(
'',
'', $default_font_size - 2);
411 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
413 $pdf->SetXY($this->posxprogress, $curY);
414 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
415 $pdf->SetFont(
'',
'', $default_font_size - 1);
418 $pdf->SetXY($this->posxdatestart, $curY);
419 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
420 $pdf->SetXY($this->posxdateend, $curY);
421 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
425 $pdf->setPage($pageposafter);
426 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
428 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
429 $pdf->SetLineStyle(array(
'dash' => 0));
435 while ($pagenb < $pageposafter) {
436 $pdf->setPage($pagenb);
438 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
440 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
444 $pdf->setPage($pagenb);
445 $pdf->setPageOrientation(
'',
true, 0);
449 if (!empty($tplidx)) {
450 $pdf->useTemplate($tplidx);
453 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
455 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
457 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
474 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
476 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
478 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
482 if (method_exists($pdf,
'AliasNbPages')) {
483 $pdf->AliasNbPages();
488 $pdf->Output($file,
'F');
491 $hookmanager->initHooks(array(
'pdfgeneration'));
492 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
494 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
495 $this->warnings = $hookmanager->warnings;
497 $this->error = $hookmanager->error;
498 $this->errors = $hookmanager->errors;
505 $this->result = array(
'fullpath' => $file);
509 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
513 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
531 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
533 $heightoftitleline = 10;
537 $pdf->SetDrawColor(128, 128, 128);
540 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius,
'1234',
'D');
543 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
545 $pdf->SetTextColor(0, 0, 0);
546 $pdf->SetFont(
'',
'', $default_font_size);
548 $pdf->SetXY($this->posxref, $tab_top + 1);
549 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
551 $pdf->SetXY($this->posxlabel, $tab_top + 1);
552 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
554 $pdf->SetFont(
'',
'', $default_font_size - 1);
556 $pdf->SetXY($this->posxworkload, $tab_top + 1);
557 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
559 $pdf->SetXY($this->posxprogress, $tab_top + 1);
560 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
563 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
564 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->transnoentities(
"DateStart"), 0,
'C');
567 $pdf->SetXY($this->posxdateend, $tab_top + 1);
568 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->transnoentities(
"DateEnd"), 0,
'C');
589 $pdf->SetTextColor(0, 0, 60);
590 $pdf->SetFont(
'',
'B', $default_font_size + 3);
592 $posx = $this->page_largeur - $this->marge_droite - 100;
593 $posy = $this->marge_haute;
595 $pdf->SetXY($this->marge_gauche, $posy);
598 $logo =
$conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
600 if (is_readable($logo)) {
602 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
604 $pdf->SetTextColor(200, 0, 0);
605 $pdf->SetFont(
'',
'B', $default_font_size - 2);
606 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
607 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
610 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
613 $pdf->SetFont(
'',
'B', $default_font_size + 3);
614 $pdf->SetXY($posx, $posy);
615 $pdf->SetTextColor(0, 0, 60);
616 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
617 $pdf->SetFont(
'',
'', $default_font_size + 2);
620 $pdf->SetXY($posx, $posy);
621 $pdf->SetTextColor(0, 0, 60);
622 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
626 $pdf->SetXY($posx, $posy);
627 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
630 if (is_object(
$object->thirdparty)) {
632 $pdf->SetXY($posx, $posy);
633 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
636 $pdf->SetTextColor(0, 0, 60);