146 global $conf, $hookmanager, $langs, $user;
148 if (!is_object($outputlangs)) {
149 $outputlangs = $langs;
153 $outputlangs->charset_output =
'ISO-8859-1';
157 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
159 if ($conf->project->multidir_output[
$object->entity]) {
163 $dir = $conf->project->multidir_output[
$object->entity];
164 if (!preg_match(
'/specimen/i', $objectref)) {
165 $dir .=
"/".$objectref;
167 $file = $dir.
"/".$objectref.
".pdf";
169 if (!file_exists($dir)) {
171 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
176 if (file_exists($dir)) {
178 if (!is_object($hookmanager)) {
179 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
182 $hookmanager->initHooks(array(
'pdfgeneration'));
183 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
185 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
190 $pdf->SetAutoPageBreak(1, 0);
192 $heightforinfotot = 40;
194 $heightforfooter = $this->marge_basse + 8;
196 $heightforfooter += 6;
199 if (class_exists(
'TCPDF')) {
200 $pdf->setPrintHeader(
false);
201 $pdf->setPrintFooter(
false);
206 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
207 $tplidx = $pdf->importPage(1);
211 $task =
new Task($this->db);
212 $tasksarray = $task->getTasksArray(0, 0,
$object->id);
215 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
219 $nblines = count(
$object->lines);
223 $pdf->SetDrawColor(128, 128, 128);
225 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
226 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
227 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
228 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
229 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
231 $pdf->SetCompression(
false);
235 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
239 if (!empty($tplidx)) {
240 $pdf->useTemplate($tplidx);
244 $pdf->SetFont(
'',
'', $default_font_size - 1);
245 $pdf->MultiCell(0, 3,
'');
246 $pdf->SetTextColor(0, 0, 0);
249 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
251 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
254 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
263 $pdf->SetFont(
'',
'', $default_font_size - 1);
264 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
265 $nexY = $pdf->GetY();
266 $height_note = $nexY - $tab_top;
269 $pdf->SetDrawColor(192, 192, 192);
270 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
272 $tab_height = $tab_height - $height_note;
273 $tab_top = $nexY + 6;
278 $heightoftitleline = 10;
279 $iniY = $tab_top + $heightoftitleline + 1;
280 $curY = $tab_top + $heightoftitleline + 1;
281 $nexY = $tab_top + $heightoftitleline + 1;
283 $tmpuser =
new User($this->db);
288 for ($i = 0; $i < $nblines; $i++) {
290 $pdf->SetFont(
'',
'', $default_font_size - 1);
291 $pdf->SetTextColor(0, 0, 0);
293 $pdf->setTopMargin($tab_top_newpage);
294 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
295 $pageposbefore = $pdf->getPage();
298 $ref =
$object->lines[$i]->ref;
299 $libelleline =
$object->lines[$i]->label;
305 $showpricebeforepagebreak = 1;
307 $pdf->startTransaction();
309 $pdf->SetXY($this->posxlabel, $curY);
310 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
311 $pageposafter = $pdf->getPage();
312 if ($pageposafter > $pageposbefore) {
313 $pdf->rollbackTransaction(
true);
314 $pageposafter = $pageposbefore;
316 $pdf->setPageOrientation(
'', 1, $heightforfooter);
318 $pdf->SetXY($this->posxlabel, $curY);
319 $posybefore = $pdf->GetY();
320 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
321 $pageposafter = $pdf->getPage();
322 $posyafter = $pdf->GetY();
323 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
324 if ($i == ($nblines - 1)) {
325 $pdf->AddPage(
'',
'',
true);
326 if (!empty($tplidx)) {
327 $pdf->useTemplate($tplidx);
332 $pdf->setPage($pageposafter + 1);
339 $showpricebeforepagebreak = 1;
341 $showpricebeforepagebreak = 0;
344 $forcedesconsamepage = 1;
345 if ($forcedesconsamepage) {
346 $pdf->rollbackTransaction(
true);
347 $pageposafter = $pageposbefore;
348 $pdf->setPageOrientation(
'', 1, $heightforfooter);
350 $pdf->AddPage(
'',
'',
true);
351 if (!empty($tplidx)) {
352 $pdf->useTemplate($tplidx);
357 $pdf->setPage($pageposafter + 1);
358 $pdf->SetFont(
'',
'', $default_font_size - 1);
359 $pdf->MultiCell(0, 3,
'');
360 $pdf->SetTextColor(0, 0, 0);
362 $pdf->setPageOrientation(
'', 1, $heightforfooter);
363 $curY = $tab_top_newpage + $heightoftitleline + 1;
366 $pdf->SetXY($this->posxlabel, $curY);
367 $posybefore = $pdf->GetY();
368 $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
369 $pageposafter = $pdf->getPage();
370 $posyafter = $pdf->GetY();
375 $pdf->commitTransaction();
377 $posYAfterDescription = $pdf->GetY();
379 $nexY = $pdf->GetY();
380 $pageposafter = $pdf->getPage();
381 $pdf->setPage($pageposbefore);
382 $pdf->setTopMargin($this->marge_haute);
383 $pdf->setPageOrientation(
'', 1, 0);
386 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
388 $pdf->setPage($pageposafter);
389 $curY = $tab_top_newpage + $heightoftitleline + 1;
392 $pdf->SetFont(
'',
'', $default_font_size - 1);
395 $pdf->SetXY($this->posxref, $curY);
396 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
398 $pdf->SetXY($this->posxtimespent, $curY);
399 $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration :
'', 0,
'R');
413 $pdf->setPage($pageposafter);
414 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
416 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
417 $pdf->SetLineStyle(array(
'dash' => 0));
423 while ($pagenb < $pageposafter) {
424 $pdf->setPage($pagenb);
426 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
428 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
432 $pdf->setPage($pagenb);
433 $pdf->setPageOrientation(
'', 1, 0);
437 if (!empty($tplidx)) {
438 $pdf->useTemplate($tplidx);
441 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
443 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
445 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
450 if (!empty($tplidx)) {
451 $pdf->useTemplate($tplidx);
462 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
464 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
466 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
470 if (method_exists($pdf,
'AliasNbPages')) {
471 $pdf->AliasNbPages();
476 $pdf->Output($file,
'F');
479 $hookmanager->initHooks(array(
'pdfgeneration'));
480 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
482 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
484 $this->error = $hookmanager->error;
485 $this->errors = $hookmanager->errors;
490 $this->result = array(
'fullpath' => $file);
494 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
498 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
563 global $langs, $conf, $mysoc;
569 $pdf->SetTextColor(0, 0, 60);
570 $pdf->SetFont(
'',
'B', $default_font_size + 3);
572 $posx = $this->page_largeur - $this->marge_droite - 100;
573 $posy = $this->marge_haute;
575 $pdf->SetXY($this->marge_gauche, $posy);
578 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
580 if (is_readable($logo)) {
582 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
584 $pdf->SetTextColor(200, 0, 0);
585 $pdf->SetFont(
'',
'B', $default_font_size - 2);
586 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
587 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
590 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
593 $pdf->SetFont(
'',
'B', $default_font_size + 3);
594 $pdf->SetXY($posx, $posy);
595 $pdf->SetTextColor(0, 0, 60);
596 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
597 $pdf->SetFont(
'',
'', $default_font_size + 2);
600 $pdf->SetXY($posx, $posy);
601 $pdf->SetTextColor(0, 0, 60);
602 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
605 $pdf->SetXY($posx, $posy);
606 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
608 if (is_object(
$object->thirdparty)) {
610 $pdf->SetXY($posx, $posy);
611 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
614 $pdf->SetTextColor(0, 0, 60);