26 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
27 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
59 public $update_main_doc_field;
70 public $phpmin = array(7, 0);
76 public $version =
'dolibarr';
101 public $marge_droite;
126 global $conf, $langs, $mysoc;
129 $langs->loadLangs(array(
"main",
"projects",
"companies"));
132 $this->
name =
"baleine";
133 $this->
description = $langs->trans(
"DocumentModelBaleine");
134 $this->update_main_doc_field = 1;
139 $this->page_largeur = $formatarray[
'width'];
140 $this->page_hauteur = $formatarray[
'height'];
141 $this->format = array($this->page_largeur, $this->page_hauteur);
147 $this->option_logo = 1;
148 $this->option_tva = 1;
151 $this->emetteur = $mysoc;
152 if (!$this->emetteur->country_code) {
153 $this->emetteur->country_code = substr($langs->defaultlang, -2);
157 $this->posxref = $this->marge_gauche + 1;
158 $this->posxlabel = $this->marge_gauche + 25;
159 $this->posxworkload = $this->marge_gauche + 117;
160 $this->posxprogress = $this->marge_gauche + 137;
161 $this->posxdatestart = $this->marge_gauche + 147;
162 $this->posxdateend = $this->marge_gauche + 169;
163 if ($this->page_largeur < 210) {
164 $this->posxref -= 20;
165 $this->posxlabel -= 20;
166 $this->posxworkload -= 20;
167 $this->posxprogress -= 20;
168 $this->posxdatestart -= 20;
169 $this->posxdateend -= 20;
185 global $conf, $hookmanager, $langs, $user;
187 if (!is_object($outputlangs)) {
188 $outputlangs = $langs;
191 if (!empty($conf->global->MAIN_USE_FPDF)) {
192 $outputlangs->charset_output =
'ISO-8859-1';
196 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
198 if ($conf->project->dir_output) {
202 $dir = $conf->project->dir_output;
203 if (!preg_match(
'/specimen/i', $objectref)) {
204 $dir .=
"/".$objectref;
206 $file = $dir.
"/".$objectref.
".pdf";
208 if (!file_exists($dir)) {
210 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
215 if (file_exists($dir)) {
217 if (!is_object($hookmanager)) {
218 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
221 $hookmanager->initHooks(array(
'pdfgeneration'));
222 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
224 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
229 $pdf->SetAutoPageBreak(1, 0);
231 $heightforinfotot = 40;
232 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
233 $heightforfooter = $this->marge_basse + 8;
234 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
235 $heightforfooter += 6;
238 if (class_exists(
'TCPDF')) {
239 $pdf->setPrintHeader(
false);
240 $pdf->setPrintFooter(
false);
244 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
245 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
246 $tplidx = $pdf->importPage(1);
250 $task =
new Task($this->
db);
251 $tasksarray = $task->getTasksArray(0, 0, $object->id);
253 if (!$object->id > 0) {
254 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
257 $object->lines = $tasksarray;
258 $nblines = count($object->lines);
262 $pdf->SetDrawColor(128, 128, 128);
264 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
265 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
266 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
267 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
268 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
270 $pdf->SetCompression(
false);
273 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
277 if (!empty($tplidx)) {
278 $pdf->useTemplate($tplidx);
281 $this->
_pagehead($pdf, $object, 1, $outputlangs);
282 $pdf->SetFont(
'',
'', $default_font_size - 1);
283 $pdf->MultiCell(0, 3,
'');
284 $pdf->SetTextColor(0, 0, 0);
287 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
289 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
292 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
301 $pdf->SetFont(
'',
'', $default_font_size - 1);
302 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
303 $nexY = $pdf->GetY();
304 $height_note = $nexY - $tab_top;
307 $pdf->SetDrawColor(192, 192, 192);
308 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
310 $tab_height = $tab_height - $height_note;
311 $tab_top = $nexY + 6;
316 $heightoftitleline = 10;
317 $iniY = $tab_top + $heightoftitleline + 1;
318 $curY = $tab_top + $heightoftitleline + 1;
319 $nexY = $tab_top + $heightoftitleline + 1;
322 for ($i = 0; $i < $nblines; $i++) {
324 $pdf->SetFont(
'',
'', $default_font_size - 1);
325 $pdf->SetTextColor(0, 0, 0);
327 $pdf->setTopMargin($tab_top_newpage);
328 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
329 $pageposbefore = $pdf->getPage();
332 $ref = $object->lines[$i]->ref;
333 $libelleline = $object->lines[$i]->label;
334 $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.
'%' :
'');
335 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
337 $planned_workload =
convertSecondToTime((
int) $object->lines[$i]->planned_workload,
'allhourmin');
339 $showpricebeforepagebreak = 1;
341 $pdf->startTransaction();
343 $pdf->SetXY($this->posxlabel, $curY);
344 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
345 $pageposafter = $pdf->getPage();
346 if ($pageposafter > $pageposbefore) {
347 $pdf->rollbackTransaction(
true);
348 $pageposafter = $pageposbefore;
350 $pdf->setPageOrientation(
'', 1, $heightforfooter);
352 $pdf->SetXY($this->posxlabel, $curY);
353 $posybefore = $pdf->GetY();
354 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
355 $pageposafter = $pdf->getPage();
356 $posyafter = $pdf->GetY();
357 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
358 if ($i == ($nblines - 1)) {
359 $pdf->AddPage(
'',
'',
true);
360 if (!empty($tplidx)) {
361 $pdf->useTemplate($tplidx);
364 $this->
_pagehead($pdf, $object, 0, $outputlangs);
366 $pdf->setPage($pageposafter + 1);
372 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
373 $showpricebeforepagebreak = 1;
375 $showpricebeforepagebreak = 0;
378 $forcedesconsamepage = 1;
379 if ($forcedesconsamepage) {
380 $pdf->rollbackTransaction(
true);
381 $pageposafter = $pageposbefore;
382 $pdf->setPageOrientation(
'', 1, $heightforfooter);
384 $pdf->AddPage(
'',
'',
true);
385 if (!empty($tplidx)) {
386 $pdf->useTemplate($tplidx);
389 $this->
_pagehead($pdf, $object, 0, $outputlangs);
391 $pdf->setPage($pageposafter + 1);
392 $pdf->SetFont(
'',
'', $default_font_size - 1);
393 $pdf->MultiCell(0, 3,
'');
394 $pdf->SetTextColor(0, 0, 0);
396 $pdf->setPageOrientation(
'', 1, $heightforfooter);
397 $curY = $tab_top_newpage + $heightoftitleline + 1;
400 $pdf->SetXY($this->posxlabel, $curY);
401 $posybefore = $pdf->GetY();
402 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
403 $pageposafter = $pdf->getPage();
404 $posyafter = $pdf->GetY();
410 $pdf->commitTransaction();
412 $posYAfterDescription = $pdf->GetY();
414 $nexY = $pdf->GetY();
415 $pageposafter = $pdf->getPage();
416 $pdf->setPage($pageposbefore);
417 $pdf->setTopMargin($this->marge_haute);
418 $pdf->setPageOrientation(
'', 1, 0);
421 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
423 $pdf->setPage($pageposafter);
424 $curY = $tab_top_newpage + $heightoftitleline + 1;
427 $pdf->SetFont(
'',
'', $default_font_size - 1);
430 $pdf->SetXY($this->posxref, $curY);
431 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
433 $pdf->SetXY($this->posxworkload, $curY);
434 $pdf->SetFont(
'',
'', $default_font_size - 2);
435 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
437 $pdf->SetXY($this->posxprogress, $curY);
438 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
439 $pdf->SetFont(
'',
'', $default_font_size - 1);
442 $pdf->SetXY($this->posxdatestart, $curY);
443 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
444 $pdf->SetXY($this->posxdateend, $curY);
445 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
448 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
449 $pdf->setPage($pageposafter);
450 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
452 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
453 $pdf->SetLineStyle(array(
'dash'=>0));
459 while ($pagenb < $pageposafter) {
460 $pdf->setPage($pagenb);
462 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
464 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
466 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
468 $pdf->setPage($pagenb);
469 $pdf->setPageOrientation(
'', 1, 0);
471 $this->
_pagehead($pdf, $object, 0, $outputlangs);
473 if (!empty($tplidx)) {
474 $pdf->useTemplate($tplidx);
477 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
479 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
481 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
483 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
486 if (!empty($tplidx)) {
487 $pdf->useTemplate($tplidx);
491 $this->
_pagehead($pdf, $object, 0, $outputlangs);
498 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
500 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
502 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
505 $this->
_pagefoot($pdf, $object, $outputlangs);
506 if (method_exists($pdf,
'AliasNbPages')) {
507 $pdf->AliasNbPages();
512 $pdf->Output($file,
'F');
515 $hookmanager->initHooks(array(
'pdfgeneration'));
516 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
518 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
520 $this->error = $hookmanager->error;
521 $this->errors = $hookmanager->errors;
524 if (!empty($conf->global->MAIN_UMASK)) {
525 @chmod($file, octdec($conf->global->MAIN_UMASK));
528 $this->result = array(
'fullpath'=>$file);
532 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
536 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
554 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
556 global $conf, $mysoc;
558 $heightoftitleline = 10;
562 $pdf->SetDrawColor(128, 128, 128);
565 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
568 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
570 $pdf->SetTextColor(0, 0, 0);
571 $pdf->SetFont(
'',
'', $default_font_size);
573 $pdf->SetXY($this->posxref, $tab_top + 1);
574 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
576 $pdf->SetXY($this->posxlabel, $tab_top + 1);
577 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
579 $pdf->SetXY($this->posxworkload, $tab_top + 1);
580 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
582 $pdf->SetXY($this->posxprogress, $tab_top + 1);
583 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
586 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
587 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans(
"Start"), 0,
'C');
590 $pdf->SetXY($this->posxdateend, $tab_top + 1);
591 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans(
"End"), 0,
'C');
604 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
606 global $langs, $conf, $mysoc;
612 $pdf->SetTextColor(0, 0, 60);
613 $pdf->SetFont(
'',
'B', $default_font_size + 3);
615 $posx = $this->page_largeur - $this->marge_droite - 100;
616 $posy = $this->marge_haute;
618 $pdf->SetXY($this->marge_gauche, $posy);
621 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
623 if (is_readable($logo)) {
625 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
627 $pdf->SetTextColor(200, 0, 0);
628 $pdf->SetFont(
'',
'B', $default_font_size - 2);
629 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
630 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
633 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
636 $pdf->SetFont(
'',
'B', $default_font_size + 3);
637 $pdf->SetXY($posx, $posy);
638 $pdf->SetTextColor(0, 0, 60);
639 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
640 $pdf->SetFont(
'',
'', $default_font_size + 2);
643 $pdf->SetXY($posx, $posy);
644 $pdf->SetTextColor(0, 0, 60);
645 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
647 if ($object->date_end) {
649 $pdf->SetXY($posx, $posy);
650 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
653 if (is_object($object->thirdparty)) {
655 $pdf->SetXY($posx, $posy);
656 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
659 $pdf->SetTextColor(0, 0, 60);
696 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
698 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
699 return pdf_pagefoot($pdf, $outputlangs,
'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
Parent class for projects models.
Class to manage generation of project document Baleine.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
__construct($db)
Constructor.
write_file($object, $outputlangs)
Function to build pdf project onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.