153 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
156 global
$conf, $hookmanager, $langs, $user;
158 if (!is_object($outputlangs)) {
159 $outputlangs = $langs;
163 $outputlangs->charset_output =
'ISO-8859-1';
167 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
174 if (!preg_match(
'/specimen/i', $objectref)) {
175 $dir .=
"/".$objectref;
177 $file = $dir.
"/".$objectref.
".pdf";
179 if (!file_exists($dir)) {
181 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
186 if (file_exists($dir)) {
188 if (!is_object($hookmanager)) {
189 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
192 $hookmanager->initHooks(array(
'pdfgeneration'));
193 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
195 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
200 $pdf->setAutoPageBreak(
true, 0);
202 $heightforinfotot = 40;
204 $heightforfooter = $this->marge_basse + 8;
206 $heightforfooter += 6;
209 if (class_exists(
'TCPDF')) {
210 $pdf->setPrintHeader(
false);
211 $pdf->setPrintFooter(
false);
216 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
217 $tplidx = $pdf->importPage(1);
221 $task =
new Task($this->db);
222 $tasksarray = $task->getTasksArray(
null,
null,
$object->id);
225 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
229 $nblines = count(
$object->lines);
233 $pdf->SetDrawColor(128, 128, 128);
235 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
236 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
237 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
238 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
239 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
241 $pdf->SetCompression(
false);
245 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
249 if (!empty($tplidx)) {
250 $pdf->useTemplate($tplidx);
254 $pdf->SetFont(
'',
'', $default_font_size - 1);
255 $pdf->MultiCell(0, 3,
'');
256 $pdf->SetTextColor(0, 0, 0);
259 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
261 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
264 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
273 $pdf->SetFont(
'',
'', $default_font_size - 1);
274 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
275 $nexY = $pdf->GetY();
276 $height_note = $nexY - $tab_top;
279 $pdf->SetDrawColor(192, 192, 192);
280 $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');
282 $tab_height -= $height_note;
283 $tab_top = $nexY + 6;
288 $heightoftitleline = 10;
289 $iniY = $tab_top + $heightoftitleline + 1;
290 $curY = $tab_top + $heightoftitleline + 1;
291 $nexY = $tab_top + $heightoftitleline + 1;
293 $tmpuser =
new User($this->db);
298 for ($i = 0; $i < $nblines; $i++) {
300 $pdf->SetFont(
'',
'', $default_font_size - 1);
301 $pdf->SetTextColor(0, 0, 0);
303 $pdf->setTopMargin($tab_top_newpage);
304 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
305 $pageposbefore = $pdf->getPage();
308 $ref =
$object->lines[$i]->ref;
309 $libelleline =
$object->lines[$i]->label;
315 $showpricebeforepagebreak = 1;
317 $pdf->startTransaction();
319 $pdf->SetXY($this->posxlabel, $curY);
320 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
321 $pageposafter = $pdf->getPage();
322 if ($pageposafter > $pageposbefore) {
323 $pdf->rollbackTransaction(
true);
324 $pageposafter = $pageposbefore;
326 $pdf->setPageOrientation(
'',
true, $heightforfooter);
328 $pdf->SetXY($this->posxlabel, $curY);
329 $posybefore = $pdf->GetY();
330 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
331 $pageposafter = $pdf->getPage();
332 $posyafter = $pdf->GetY();
333 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
334 if ($i == ($nblines - 1)) {
335 $pdf->AddPage(
'',
'',
true);
336 if (!empty($tplidx)) {
337 $pdf->useTemplate($tplidx);
342 $pdf->setPage($pageposafter + 1);
349 $showpricebeforepagebreak = 1;
351 $showpricebeforepagebreak = 0;
354 $forcedesconsamepage = 1;
355 if ($forcedesconsamepage) {
356 $pdf->rollbackTransaction(
true);
357 $pageposafter = $pageposbefore;
358 $pdf->setPageOrientation(
'',
true, $heightforfooter);
360 $pdf->AddPage(
'',
'',
true);
361 if (!empty($tplidx)) {
362 $pdf->useTemplate($tplidx);
367 $pdf->setPage($pageposafter + 1);
368 $pdf->SetFont(
'',
'', $default_font_size - 1);
369 $pdf->MultiCell(0, 3,
'');
370 $pdf->SetTextColor(0, 0, 0);
372 $pdf->setPageOrientation(
'',
true, $heightforfooter);
373 $curY = $tab_top_newpage + $heightoftitleline + 1;
376 $pdf->SetXY($this->posxlabel, $curY);
377 $posybefore = $pdf->GetY();
378 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
379 $pageposafter = $pdf->getPage();
380 $posyafter = $pdf->GetY();
385 $pdf->commitTransaction();
387 $posYAfterDescription = $pdf->GetY();
389 $nexY = $pdf->GetY();
390 $pageposafter = $pdf->getPage();
391 $pdf->setPage($pageposbefore);
392 $pdf->setTopMargin($this->marge_haute);
393 $pdf->setPageOrientation(
'',
true, 0);
396 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
398 $pdf->setPage($pageposafter);
399 $curY = $tab_top_newpage + $heightoftitleline + 1;
402 $pdf->SetFont(
'',
'', $default_font_size - 1);
405 $pdf->SetXY($this->posxref, $curY);
406 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
408 $pdf->SetXY($this->posxtimespent, $curY);
409 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
423 $pdf->setPage($pageposafter);
424 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
426 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
427 $pdf->SetLineStyle(array(
'dash' => 0));
433 while ($pagenb < $pageposafter) {
434 $pdf->setPage($pagenb);
436 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
438 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
442 $pdf->setPage($pagenb);
443 $pdf->setPageOrientation(
'',
true, 0);
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
451 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
453 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
455 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
472 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
474 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
476 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
480 if (method_exists($pdf,
'AliasNbPages')) {
481 $pdf->AliasNbPages();
486 $pdf->Output($file,
'F');
489 $hookmanager->initHooks(array(
'pdfgeneration'));
490 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
492 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
493 $this->warnings = $hookmanager->warnings;
495 $this->error = $hookmanager->error;
496 $this->errors = $hookmanager->errors;
503 $this->result = array(
'fullpath' => $file);
507 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
511 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
580 $pdf->SetTextColor(0, 0, 60);
581 $pdf->SetFont(
'',
'B', $default_font_size + 3);
583 $posx = $this->page_largeur - $this->marge_droite - 100;
584 $posy = $this->marge_haute;
586 $pdf->SetXY($this->marge_gauche, $posy);
589 $logo =
$conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
591 if (is_readable($logo)) {
593 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
595 $pdf->SetTextColor(200, 0, 0);
596 $pdf->SetFont(
'',
'B', $default_font_size - 2);
597 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
598 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
601 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
604 $pdf->SetFont(
'',
'B', $default_font_size + 3);
605 $pdf->SetXY($posx, $posy);
606 $pdf->SetTextColor(0, 0, 60);
607 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
608 $pdf->SetFont(
'',
'', $default_font_size + 2);
611 $pdf->SetXY($posx, $posy);
612 $pdf->SetTextColor(0, 0, 60);
613 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
616 $pdf->SetXY($posx, $posy);
617 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
619 if (is_object(
$object->thirdparty)) {
621 $pdf->SetXY($posx, $posy);
622 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
625 $pdf->SetTextColor(0, 0, 60);