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';
45 public $phpmin = array(5, 6);
51 public $version =
'dolibarr';
66 global $conf, $langs, $mysoc;
69 $langs->loadLangs(array(
"main",
"projects",
"companies"));
72 $this->
name =
"baleine";
73 $this->
description = $langs->trans(
"DocumentModelBaleine");
78 $this->page_largeur = $formatarray[
'width'];
79 $this->page_hauteur = $formatarray[
'height'];
80 $this->format = array($this->page_largeur, $this->page_hauteur);
81 $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
82 $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
83 $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
84 $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
86 $this->option_logo = 1;
87 $this->option_tva = 1;
88 $this->option_codeproduitservice = 1;
91 $this->emetteur = $mysoc;
92 if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2);
95 $this->posxref = $this->marge_gauche + 1;
96 $this->posxlabel = $this->marge_gauche + 25;
97 $this->posxworkload = $this->marge_gauche + 117;
98 $this->posxprogress = $this->marge_gauche + 137;
99 $this->posxdatestart = $this->marge_gauche + 147;
100 $this->posxdateend = $this->marge_gauche + 169;
101 if ($this->page_largeur < 210)
103 $this->posxref -= 20;
104 $this->posxlabel -= 20;
105 $this->posxworkload -= 20;
106 $this->posxprogress -= 20;
107 $this->posxdatestart -= 20;
108 $this->posxdateend -= 20;
124 global $conf, $hookmanager, $langs, $user;
126 if (!is_object($outputlangs)) $outputlangs = $langs;
128 if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output =
'ISO-8859-1';
131 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
133 if ($conf->projet->dir_output)
138 $dir = $conf->projet->dir_output;
139 if (!preg_match(
'/specimen/i', $objectref)) $dir .=
"/".$objectref;
140 $file = $dir.
"/".$objectref.
".pdf";
142 if (!file_exists($dir))
146 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
151 if (file_exists($dir))
154 if (!is_object($hookmanager))
156 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
159 $hookmanager->initHooks(array(
'pdfgeneration'));
160 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
162 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
167 $pdf->SetAutoPageBreak(1, 0);
169 $heightforinfotot = 40;
170 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
171 $heightforfooter = $this->marge_basse + 8;
172 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6;
174 if (class_exists(
'TCPDF'))
176 $pdf->setPrintHeader(
false);
177 $pdf->setPrintFooter(
false);
181 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
183 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
184 $tplidx = $pdf->importPage(1);
188 $task =
new Task($this->
db);
189 $tasksarray = $task->getTasksArray(0, 0, $object->id);
191 if (!$object->id > 0)
193 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
196 $object->lines = $tasksarray;
197 $nblines = count($object->lines);
201 $pdf->SetDrawColor(128, 128, 128);
203 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
204 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
205 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
206 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
207 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
208 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
210 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
214 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
216 $this->
_pagehead($pdf, $object, 1, $outputlangs);
217 $pdf->SetFont(
'',
'', $default_font_size - 1);
218 $pdf->MultiCell(0, 3,
'');
219 $pdf->SetTextColor(0, 0, 0);
222 $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
224 $tab_height_newpage = 190;
227 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
237 $pdf->SetFont(
'',
'', $default_font_size - 1);
238 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
239 $nexY = $pdf->GetY();
240 $height_note = $nexY - $tab_top;
243 $pdf->SetDrawColor(192, 192, 192);
244 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
246 $tab_height = $tab_height - $height_note;
247 $tab_top = $nexY + 6;
252 $heightoftitleline = 10;
253 $iniY = $tab_top + $heightoftitleline + 1;
254 $curY = $tab_top + $heightoftitleline + 1;
255 $nexY = $tab_top + $heightoftitleline + 1;
258 for ($i = 0; $i < $nblines; $i++)
261 $pdf->SetFont(
'',
'', $default_font_size - 1);
262 $pdf->SetTextColor(0, 0, 0);
264 $pdf->setTopMargin($tab_top_newpage);
265 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
266 $pageposbefore = $pdf->getPage();
269 $ref = $object->lines[$i]->ref;
270 $libelleline = $object->lines[$i]->label;
271 $progress = ($object->lines[$i]->progress ? $object->lines[$i]->progress.
'%' :
'');
272 $datestart =
dol_print_date($object->lines[$i]->date_start,
'day');
274 $planned_workload =
convertSecondToTime((
int) $object->lines[$i]->planned_workload,
'allhourmin');
276 $showpricebeforepagebreak = 1;
278 $pdf->startTransaction();
280 $pdf->SetXY($this->posxlabel, $curY);
281 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
282 $pageposafter = $pdf->getPage();
283 if ($pageposafter > $pageposbefore)
285 $pdf->rollbackTransaction(
true);
286 $pageposafter = $pageposbefore;
288 $pdf->setPageOrientation(
'', 1, $heightforfooter);
290 $pdf->SetXY($this->posxlabel, $curY);
291 $posybefore = $pdf->GetY();
292 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
293 $pageposafter = $pdf->getPage();
294 $posyafter = $pdf->GetY();
295 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))
297 if ($i == ($nblines - 1))
299 $pdf->AddPage(
'',
'',
true);
300 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
301 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
302 $pdf->setPage($pageposafter + 1);
308 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
309 $showpricebeforepagebreak = 1;
310 else $showpricebeforepagebreak = 0;
312 $forcedesconsamepage = 1;
313 if ($forcedesconsamepage)
315 $pdf->rollbackTransaction(
true);
316 $pageposafter = $pageposbefore;
317 $pdf->setPageOrientation(
'', 1, $heightforfooter);
319 $pdf->AddPage(
'',
'',
true);
320 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
321 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
322 $pdf->setPage($pageposafter + 1);
323 $pdf->SetFont(
'',
'', $default_font_size - 1);
324 $pdf->MultiCell(0, 3,
'');
325 $pdf->SetTextColor(0, 0, 0);
327 $pdf->setPageOrientation(
'', 1, $heightforfooter);
328 $curY = $tab_top_newpage + $heightoftitleline + 1;
331 $pdf->SetXY($this->posxlabel, $curY);
332 $posybefore = $pdf->GetY();
333 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0,
'L');
334 $pageposafter = $pdf->getPage();
335 $posyafter = $pdf->GetY();
341 $pdf->commitTransaction();
343 $posYAfterDescription = $pdf->GetY();
345 $nexY = $pdf->GetY();
346 $pageposafter = $pdf->getPage();
347 $pdf->setPage($pageposbefore);
348 $pdf->setTopMargin($this->marge_haute);
349 $pdf->setPageOrientation(
'', 1, 0);
352 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
354 $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1;
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
360 $pdf->SetXY($this->posxref, $curY);
361 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0,
'L');
363 $pdf->SetXY($this->posxworkload, $curY);
364 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload ? $planned_workload :
'', 0,
'R');
366 $pdf->SetXY($this->posxprogress, $curY);
367 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0,
'R');
370 $pdf->SetXY($this->posxdatestart, $curY);
371 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0,
'C');
372 $pdf->SetXY($this->posxdateend, $curY);
373 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0,
'C');
376 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
378 $pdf->setPage($pageposafter);
379 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
381 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
382 $pdf->SetLineStyle(array(
'dash'=>0));
388 while ($pagenb < $pageposafter)
390 $pdf->setPage($pagenb);
393 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
395 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
397 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
399 $pdf->setPage($pagenb);
400 $pdf->setPageOrientation(
'', 1, 0);
401 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
403 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
407 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
409 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
411 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
414 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
416 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
422 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
423 else $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
424 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
427 $this->
_pagefoot($pdf, $object, $outputlangs);
428 if (method_exists($pdf,
'AliasNbPages')) $pdf->AliasNbPages();
432 $pdf->Output($file,
'F');
435 $hookmanager->initHooks(array(
'pdfgeneration'));
436 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
438 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
441 $this->error = $hookmanager->error;
442 $this->errors = $hookmanager->errors;
445 if (!empty($conf->global->MAIN_UMASK))
446 @chmod($file, octdec($conf->global->MAIN_UMASK));
448 $this->result = array(
'fullpath'=>$file);
452 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
456 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
474 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
476 global $conf, $mysoc;
478 $heightoftitleline = 10;
482 $pdf->SetDrawColor(128, 128, 128);
485 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
488 $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
490 $pdf->SetTextColor(0, 0, 0);
491 $pdf->SetFont(
'',
'', $default_font_size);
493 $pdf->SetXY($this->posxref, $tab_top + 1);
494 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities(
"Tasks"),
'',
'L');
496 $pdf->SetXY($this->posxlabel, $tab_top + 1);
497 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities(
"Description"), 0,
'L');
499 $pdf->SetXY($this->posxworkload, $tab_top + 1);
500 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities(
"PlannedWorkloadShort"), 0,
'R');
502 $pdf->SetXY($this->posxprogress, $tab_top + 1);
503 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3,
'%', 0,
'R');
506 $pdf->SetXY($this->posxdatestart, $tab_top + 1);
507 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans(
"Start"), 0,
'C');
510 $pdf->SetXY($this->posxdateend, $tab_top + 1);
511 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans(
"End"), 0,
'C');
524 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
526 global $langs, $conf, $mysoc;
532 $pdf->SetTextColor(0, 0, 60);
533 $pdf->SetFont(
'',
'B', $default_font_size + 3);
535 $posx = $this->page_largeur - $this->marge_droite - 100;
536 $posy = $this->marge_haute;
538 $pdf->SetXY($this->marge_gauche, $posy);
541 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
544 if (is_readable($logo))
547 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
549 $pdf->SetTextColor(200, 0, 0);
550 $pdf->SetFont(
'',
'B', $default_font_size - 2);
551 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
552 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
554 }
else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
556 $pdf->SetFont(
'',
'B', $default_font_size + 3);
557 $pdf->SetXY($posx, $posy);
558 $pdf->SetTextColor(0, 0, 60);
559 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
560 $pdf->SetFont(
'',
'', $default_font_size + 2);
563 $pdf->SetXY($posx, $posy);
564 $pdf->SetTextColor(0, 0, 60);
565 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
568 $pdf->SetXY($posx, $posy);
569 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
571 if (is_object($object->thirdparty))
574 $pdf->SetXY($posx, $posy);
575 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
578 $pdf->SetTextColor(0, 0, 60);
615 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
618 $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
619 return pdf_pagefoot($pdf, $outputlangs,
'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
write_file($object, $outputlangs)
Function to build pdf project onto disk.
__construct($db)
Constructor.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
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...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
Parent class for projects models.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Class to manage generation of project document Baleine.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
convertSecondToTime($iSecond, $format= 'all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
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...
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.