145 global $conf, $hookmanager, $langs, $user;
147 if (!is_object($outputlangs)) {
148 $outputlangs = $langs;
152 $outputlangs->charset_output =
'ISO-8859-1';
156 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
158 if ($conf->project->multidir_output[
$object->entity]) {
162 $dir = $conf->project->multidir_output[
$object->entity];
163 if (!preg_match(
'/specimen/i', $objectref)) {
164 $dir .=
"/".$objectref;
166 $file = $dir.
"/".$objectref.
".pdf";
168 if (!file_exists($dir)) {
170 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
175 if (file_exists($dir)) {
177 if (!is_object($hookmanager)) {
178 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
181 $hookmanager->initHooks(array(
'pdfgeneration'));
182 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
184 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
189 $pdf->SetAutoPageBreak(1, 0);
191 $heightforinfotot = 40;
192 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
193 $heightforfooter = $this->marge_basse + 8;
195 $heightforfooter += 6;
198 if (class_exists(
'TCPDF')) {
199 $pdf->setPrintHeader(
false);
200 $pdf->setPrintFooter(
false);
205 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
206 $tplidx = $pdf->importPage(1);
210 $task =
new Task($this->db);
211 $tasksarray = $task->getTasksArray(0, 0,
$object->id);
214 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
218 $nblines = count(
$object->lines);
222 $pdf->SetDrawColor(128, 128, 128);
224 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
225 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
226 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
227 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
228 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
230 $pdf->SetCompression(
false);
234 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
238 if (!empty($tplidx)) {
239 $pdf->useTemplate($tplidx);
243 $pdf->SetFont(
'',
'', $default_font_size - 1);
244 $pdf->MultiCell(0, 3,
'');
245 $pdf->SetTextColor(0, 0, 0);
248 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
250 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
253 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
262 $pdf->SetFont(
'',
'', $default_font_size - 1);
263 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
264 $nexY = $pdf->GetY();
265 $height_note = $nexY - $tab_top;
268 $pdf->SetDrawColor(192, 192, 192);
269 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
271 $tab_height = $tab_height - $height_note;
272 $tab_top = $nexY + 6;
277 $heightoftitleline = 10;
278 $iniY = $tab_top + $heightoftitleline + 1;
279 $curY = $tab_top + $heightoftitleline + 1;
280 $nexY = $tab_top + $heightoftitleline + 1;
282 $tmpuser =
new User($this->db);
287 for ($i = 0; $i < $nblines; $i++) {
289 $pdf->SetFont(
'',
'', $default_font_size - 1);
290 $pdf->SetTextColor(0, 0, 0);
292 $pdf->setTopMargin($tab_top_newpage);
293 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
294 $pageposbefore = $pdf->getPage();
297 $ref =
$object->lines[$i]->ref;
298 $libelleline =
$object->lines[$i]->label;
304 $showpricebeforepagebreak = 1;
306 $pdf->startTransaction();
308 $pdf->SetXY($this->posxlabel, $curY);
309 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
310 $pageposafter = $pdf->getPage();
311 if ($pageposafter > $pageposbefore) {
312 $pdf->rollbackTransaction(
true);
313 $pageposafter = $pageposbefore;
315 $pdf->setPageOrientation(
'', 1, $heightforfooter);
317 $pdf->SetXY($this->posxlabel, $curY);
318 $posybefore = $pdf->GetY();
319 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
320 $pageposafter = $pdf->getPage();
321 $posyafter = $pdf->GetY();
322 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
323 if ($i == ($nblines - 1)) {
324 $pdf->AddPage(
'',
'',
true);
325 if (!empty($tplidx)) {
326 $pdf->useTemplate($tplidx);
331 $pdf->setPage($pageposafter + 1);
338 $showpricebeforepagebreak = 1;
340 $showpricebeforepagebreak = 0;
343 $forcedesconsamepage = 1;
344 if ($forcedesconsamepage) {
345 $pdf->rollbackTransaction(
true);
346 $pageposafter = $pageposbefore;
347 $pdf->setPageOrientation(
'', 1, $heightforfooter);
349 $pdf->AddPage(
'',
'',
true);
350 if (!empty($tplidx)) {
351 $pdf->useTemplate($tplidx);
356 $pdf->setPage($pageposafter + 1);
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
358 $pdf->MultiCell(0, 3,
'');
359 $pdf->SetTextColor(0, 0, 0);
361 $pdf->setPageOrientation(
'', 1, $heightforfooter);
362 $curY = $tab_top_newpage + $heightoftitleline + 1;
365 $pdf->SetXY($this->posxlabel, $curY);
366 $posybefore = $pdf->GetY();
367 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
368 $pageposafter = $pdf->getPage();
369 $posyafter = $pdf->GetY();
374 $pdf->commitTransaction();
376 $posYAfterDescription = $pdf->GetY();
378 $nexY = $pdf->GetY();
379 $pageposafter = $pdf->getPage();
380 $pdf->setPage($pageposbefore);
381 $pdf->setTopMargin($this->marge_haute);
382 $pdf->setPageOrientation(
'', 1, 0);
385 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
387 $pdf->setPage($pageposafter);
388 $curY = $tab_top_newpage + $heightoftitleline + 1;
391 $pdf->SetFont(
'',
'', $default_font_size - 1);
394 $pdf->SetXY($this->posxref, $curY);
395 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
397 $pdf->SetXY($this->posxtimespent, $curY);
398 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
412 $pdf->setPage($pageposafter);
413 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
415 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
416 $pdf->SetLineStyle(array(
'dash' => 0));
422 while ($pagenb < $pageposafter) {
423 $pdf->setPage($pagenb);
425 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
427 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
431 $pdf->setPage($pagenb);
432 $pdf->setPageOrientation(
'', 1, 0);
436 if (!empty($tplidx)) {
437 $pdf->useTemplate($tplidx);
440 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
442 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
444 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
449 if (!empty($tplidx)) {
450 $pdf->useTemplate($tplidx);
461 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
463 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
465 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
469 if (method_exists($pdf,
'AliasNbPages')) {
470 $pdf->AliasNbPages();
475 $pdf->Output($file,
'F');
478 $hookmanager->initHooks(array(
'pdfgeneration'));
479 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
481 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
483 $this->error = $hookmanager->error;
484 $this->errors = $hookmanager->errors;
489 $this->result = array(
'fullpath' => $file);
493 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
497 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
562 global $langs, $conf, $mysoc;
568 $pdf->SetTextColor(0, 0, 60);
569 $pdf->SetFont(
'',
'B', $default_font_size + 3);
571 $posx = $this->page_largeur - $this->marge_droite - 100;
572 $posy = $this->marge_haute;
574 $pdf->SetXY($this->marge_gauche, $posy);
577 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
579 if (is_readable($logo)) {
581 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
583 $pdf->SetTextColor(200, 0, 0);
584 $pdf->SetFont(
'',
'B', $default_font_size - 2);
585 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
586 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
589 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
592 $pdf->SetFont(
'',
'B', $default_font_size + 3);
593 $pdf->SetXY($posx, $posy);
594 $pdf->SetTextColor(0, 0, 60);
595 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
596 $pdf->SetFont(
'',
'', $default_font_size + 2);
599 $pdf->SetXY($posx, $posy);
600 $pdf->SetTextColor(0, 0, 60);
601 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
604 $pdf->SetXY($posx, $posy);
605 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
607 if (is_object(
$object->thirdparty)) {
609 $pdf->SetXY($posx, $posy);
610 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
613 $pdf->SetTextColor(0, 0, 60);