153 global $conf, $hookmanager, $langs, $user;
155 if (!is_object($outputlangs)) {
156 $outputlangs = $langs;
160 $outputlangs->charset_output =
'ISO-8859-1';
164 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
166 if ($conf->project->multidir_output[
$object->entity]) {
170 $dir = $conf->project->multidir_output[
$object->entity];
171 if (!preg_match(
'/specimen/i', $objectref)) {
172 $dir .=
"/".$objectref;
174 $file = $dir.
"/".$objectref.
".pdf";
176 if (!file_exists($dir)) {
178 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
183 if (file_exists($dir)) {
185 if (!is_object($hookmanager)) {
186 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
189 $hookmanager->initHooks(array(
'pdfgeneration'));
190 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
192 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
197 $pdf->SetAutoPageBreak(1, 0);
199 $heightforinfotot = 40;
201 $heightforfooter = $this->marge_basse + 8;
203 $heightforfooter += 6;
206 if (class_exists(
'TCPDF')) {
207 $pdf->setPrintHeader(
false);
208 $pdf->setPrintFooter(
false);
213 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
214 $tplidx = $pdf->importPage(1);
218 $task =
new Task($this->db);
219 $tasksarray = $task->getTasksArray(
null,
null,
$object->id);
222 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
226 $nblines = count(
$object->lines);
230 $pdf->SetDrawColor(128, 128, 128);
232 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
233 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
234 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
235 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
236 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
238 $pdf->SetCompression(
false);
242 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
246 if (!empty($tplidx)) {
247 $pdf->useTemplate($tplidx);
251 $pdf->SetFont(
'',
'', $default_font_size - 1);
252 $pdf->MultiCell(0, 3,
'');
253 $pdf->SetTextColor(0, 0, 0);
256 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
258 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
261 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
270 $pdf->SetFont(
'',
'', $default_font_size - 1);
271 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
272 $nexY = $pdf->GetY();
273 $height_note = $nexY - $tab_top;
276 $pdf->SetDrawColor(192, 192, 192);
277 $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');
279 $tab_height -= $height_note;
280 $tab_top = $nexY + 6;
285 $heightoftitleline = 10;
286 $iniY = $tab_top + $heightoftitleline + 1;
287 $curY = $tab_top + $heightoftitleline + 1;
288 $nexY = $tab_top + $heightoftitleline + 1;
290 $tmpuser =
new User($this->db);
295 for ($i = 0; $i < $nblines; $i++) {
297 $pdf->SetFont(
'',
'', $default_font_size - 1);
298 $pdf->SetTextColor(0, 0, 0);
300 $pdf->setTopMargin($tab_top_newpage);
301 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
302 $pageposbefore = $pdf->getPage();
305 $ref =
$object->lines[$i]->ref;
306 $libelleline =
$object->lines[$i]->label;
312 $showpricebeforepagebreak = 1;
314 $pdf->startTransaction();
316 $pdf->SetXY($this->posxlabel, $curY);
317 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
318 $pageposafter = $pdf->getPage();
319 if ($pageposafter > $pageposbefore) {
320 $pdf->rollbackTransaction(
true);
321 $pageposafter = $pageposbefore;
323 $pdf->setPageOrientation(
'', 1, $heightforfooter);
325 $pdf->SetXY($this->posxlabel, $curY);
326 $posybefore = $pdf->GetY();
327 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
328 $pageposafter = $pdf->getPage();
329 $posyafter = $pdf->GetY();
330 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
331 if ($i == ($nblines - 1)) {
332 $pdf->AddPage(
'',
'',
true);
333 if (!empty($tplidx)) {
334 $pdf->useTemplate($tplidx);
339 $pdf->setPage($pageposafter + 1);
346 $showpricebeforepagebreak = 1;
348 $showpricebeforepagebreak = 0;
351 $forcedesconsamepage = 1;
352 if ($forcedesconsamepage) {
353 $pdf->rollbackTransaction(
true);
354 $pageposafter = $pageposbefore;
355 $pdf->setPageOrientation(
'', 1, $heightforfooter);
357 $pdf->AddPage(
'',
'',
true);
358 if (!empty($tplidx)) {
359 $pdf->useTemplate($tplidx);
364 $pdf->setPage($pageposafter + 1);
365 $pdf->SetFont(
'',
'', $default_font_size - 1);
366 $pdf->MultiCell(0, 3,
'');
367 $pdf->SetTextColor(0, 0, 0);
369 $pdf->setPageOrientation(
'', 1, $heightforfooter);
370 $curY = $tab_top_newpage + $heightoftitleline + 1;
373 $pdf->SetXY($this->posxlabel, $curY);
374 $posybefore = $pdf->GetY();
375 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
376 $pageposafter = $pdf->getPage();
377 $posyafter = $pdf->GetY();
382 $pdf->commitTransaction();
384 $posYAfterDescription = $pdf->GetY();
386 $nexY = $pdf->GetY();
387 $pageposafter = $pdf->getPage();
388 $pdf->setPage($pageposbefore);
389 $pdf->setTopMargin($this->marge_haute);
390 $pdf->setPageOrientation(
'', 1, 0);
393 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
395 $pdf->setPage($pageposafter);
396 $curY = $tab_top_newpage + $heightoftitleline + 1;
399 $pdf->SetFont(
'',
'', $default_font_size - 1);
402 $pdf->SetXY($this->posxref, $curY);
403 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
405 $pdf->SetXY($this->posxtimespent, $curY);
406 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
420 $pdf->setPage($pageposafter);
421 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
423 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
424 $pdf->SetLineStyle(array(
'dash' => 0));
430 while ($pagenb < $pageposafter) {
431 $pdf->setPage($pagenb);
433 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
435 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
439 $pdf->setPage($pagenb);
440 $pdf->setPageOrientation(
'', 1, 0);
444 if (!empty($tplidx)) {
445 $pdf->useTemplate($tplidx);
448 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
450 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
452 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
457 if (!empty($tplidx)) {
458 $pdf->useTemplate($tplidx);
469 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
471 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
473 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
477 if (method_exists($pdf,
'AliasNbPages')) {
478 $pdf->AliasNbPages();
483 $pdf->Output($file,
'F');
486 $hookmanager->initHooks(array(
'pdfgeneration'));
487 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
489 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
491 $this->error = $hookmanager->error;
492 $this->errors = $hookmanager->errors;
497 $this->result = array(
'fullpath' => $file);
501 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
505 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
570 global $langs, $conf, $mysoc;
576 $pdf->SetTextColor(0, 0, 60);
577 $pdf->SetFont(
'',
'B', $default_font_size + 3);
579 $posx = $this->page_largeur - $this->marge_droite - 100;
580 $posy = $this->marge_haute;
582 $pdf->SetXY($this->marge_gauche, $posy);
585 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
587 if (is_readable($logo)) {
589 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
591 $pdf->SetTextColor(200, 0, 0);
592 $pdf->SetFont(
'',
'B', $default_font_size - 2);
593 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
594 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
597 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
600 $pdf->SetFont(
'',
'B', $default_font_size + 3);
601 $pdf->SetXY($posx, $posy);
602 $pdf->SetTextColor(0, 0, 60);
603 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
604 $pdf->SetFont(
'',
'', $default_font_size + 2);
607 $pdf->SetXY($posx, $posy);
608 $pdf->SetTextColor(0, 0, 60);
609 $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');
615 if (is_object(
$object->thirdparty)) {
617 $pdf->SetXY($posx, $posy);
618 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
621 $pdf->SetTextColor(0, 0, 60);