143 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
146 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
148 if (!is_object($outputlangs)) {
149 $outputlangs = $langs;
153 $outputlangs->charset_output =
'ISO-8859-1';
157 $outputlangs->loadLangs(array(
"main",
"hrm"));
159 $nblines = count($object->lines);
161 if ($conf->hrm->dir_output) {
163 if ($object->specimen) {
165 $dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1].
'/evaluation';
166 $file = $dir.
"/SPECIMEN.pdf";
170 $dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1].
'/evaluation'.
"/".$objectref;
171 $file = $dir.
"/".$objectref.
".pdf";
174 if (!file_exists($dir)) {
176 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
181 if (file_exists($dir)) {
183 if (!is_object($hookmanager)) {
184 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
187 $hookmanager->initHooks(array(
'pdfgeneration'));
188 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
190 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
192 $nblines = count($object->lines);
197 $heightforinfotot = 0;
198 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
199 $heightforfooter = $this->marge_basse + 12;
201 $heightforfooter += 6;
204 $pdf->SetAutoPageBreak(1, 0);
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);
219 $pdf->SetDrawColor(128, 128, 128);
221 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
222 $pdf->SetSubject($outputlangs->transnoentities(
"Evaluation"));
223 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
224 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
225 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Evaluation"));
227 $pdf->SetCompression(
false);
230 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
234 if (!empty($tplidx)) {
235 $pdf->useTemplate($tplidx);
238 $this->
_pagehead($pdf, $object, 1, $outputlangs);
239 $pdf->SetFont(
'',
'', $default_font_size - 1);
240 $pdf->MultiCell(0, 3,
'');
241 $pdf->SetTextColor(0, 0, 0);
244 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 35 : 10);
246 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
249 if (!empty($object->note_public)) {
252 $pdf->SetFont(
'',
'B', $default_font_size);
253 $pdf->MultiCell(190, 4, $outputlangs->transnoentities(
"Notes") .
":", 0,
'L', 0,
'', 12, $tab_top);
255 $pdf->SetFont(
'',
'', $default_font_size - 1);
256 $pdf->writeHTMLCell(190, 3, $this->posxnotes + 1, $tab_top + 1,
dol_htmlentitiesbr($object->note_public), 0, 1);
257 $nexY = $pdf->GetY();
258 $height_note = $nexY - $tab_top;
261 $pdf->SetDrawColor(192, 192, 192);
262 $pdf->Rect($this->marge_gauche, $tab_top - 1 - 4, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1 + 6);
264 $tab_height = $tab_height - $height_note;
265 $tab_top = $nexY + 6;
270 $iniY = $tab_top + 7;
271 $initialY = $tab_top + 7;
272 $nexY = $tab_top + 7;
274 $pdf->setTopMargin($tab_top_newpage);
277 while ($i < $nblines) {
278 $pdf->SetFont(
'',
'', $default_font_size - 2);
279 $pdf->SetTextColor(0, 0, 0);
281 if (empty($showmorebeforepagebreak) && ($i !== ($nblines - 1))) {
282 $pdf->setPageOrientation(
'', 1, $heightforfooter);
284 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
287 $pdf->setTopMargin($tab_top_newpage);
289 $pageposbefore = $pdf->getPage();
291 $pdf->startTransaction();
293 $this->
printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
297 $pageposafter = $pdf->getPage();
298 if ($pageposafter > $pageposbefore) {
300 $pdf->rollbackTransaction(
true);
302 $pageposafter = $pageposbefore;
303 if (empty($showmorebeforepagebreak)) {
304 $pdf->AddPage(
'',
'',
true);
305 if (!empty($tplidx)) {
306 $pdf->useTemplate($tplidx);
309 $this->
_pagehead($pdf, $object, 0, $outputlangs);
311 $pdf->setPage($pageposafter + 1);
312 $showmorebeforepagebreak = 1;
313 $nexY = $tab_top_newpage;
314 $nexY += ($pdf->getFontSize() * 1.3);
315 $pdf->SetFont(
'',
'', $default_font_size - 2);
316 $pdf->SetTextColor(0, 0, 0);
318 $pdf->setTopMargin($tab_top_newpage);
321 $pdf->setPageOrientation(
'', 1, $heightforfooter);
322 $showmorebeforepagebreak = 0;
325 $this->
printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
326 $pageposafter = $pdf->getPage();
327 $posyafter = $pdf->GetY();
328 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
330 if ($i == ($nblines - 1)) {
332 $pdf->AddPage(
'',
'',
true);
333 if (!empty($tplidx)) {
334 $pdf->useTemplate($tplidx);
337 $this->
_pagehead($pdf, $object, 0, $outputlangs);
339 $pdf->setPage($pageposafter + 1);
345 $showmorebeforepagebreak = 1;
347 $showmorebeforepagebreak = 0;
351 $pdf->commitTransaction();
356 $nexY = $pdf->GetY();
357 $pdf->line($this->marge_gauche, $nexY + 2, $this->page_largeur - $this->marge_droite, $nexY + 2);
358 $pageposafter = $pdf->getPage();
359 $pdf->setPage($pageposbefore);
360 $pdf->setTopMargin($this->marge_haute);
361 $pdf->setPageOrientation(
'', 1, 0);
364 $nexY += ($pdf->getFontSize() * 1.3);
367 while ($pagenb < $pageposafter) {
368 $pdf->setPage($pagenb);
369 $pdf->setPageOrientation(
'', 1, 0);
371 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
373 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
375 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
377 $pdf->setPage($pagenb);
378 $pdf->setPageOrientation(
'', 1, 0);
380 $this->
_pagehead($pdf, $object, 0, $outputlangs);
382 if (!empty($tplidx)) {
383 $pdf->useTemplate($tplidx);
386 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
388 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
390 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
392 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
400 $this->
_pagehead($pdf, $object, 0, $outputlangs);
407 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
408 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
410 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
411 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
414 $pdf->SetFont(
'',
'', 10);
418 $this->
_pagefoot($pdf, $object, $outputlangs);
419 if (method_exists($pdf,
'AliasNbPages')) {
420 $pdf->AliasNbPages();
425 $pdf->Output($file,
'F');
428 $hookmanager->initHooks(array(
'pdfgeneration'));
429 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
431 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
433 $this->error = $hookmanager->error;
434 $this->errors = $hookmanager->errors;
439 $this->result = array(
'fullpath'=>$file);
443 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
447 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"HRM_OUTPUTDIR");
462 protected function printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails = 0)
465 $objectligne = $object->lines[$linenumber];
466 $pdf->SetFont(
'',
'', $default_font_size - 1);
467 $pdf->SetTextColor(0, 0, 0);
470 $pdf->SetXY($this->posxresult - 1, $curY);
472 if ($objectligne->rankorder > $objectligne->required_rank) {
474 $pdf->SetFillColor(0, 109, 91);
475 } elseif ($objectligne->rankorder == $objectligne->required_rank) {
477 $pdf->SetFillColor(159, 226, 191);
478 } elseif ($objectligne->rankorder < $objectligne->required_rank) {
480 $pdf->SetFillColor(205, 92, 92);
482 if ($objectligne->rankorder == 0 || $objectligne->required_rank == 0) {
484 $pdf->SetFillColor(255, 255, 255);
486 $result = (($objectligne->required_rank != 0 && $objectligne->rankorder != 0) ? $objectligne->rankorder .
"/" . $objectligne->required_rank :
"-");
487 $pdf->MultiCell($this->posxresult - 210 - 0.8 - 4, 4, $result, 0,
'C', 1);
491 $pdf->SetXY($this->posxrequiredrank, $curY);
492 $pdf->MultiCell($this->posxresult - $this->posxrequiredrank - 0.8, 4, (($objectligne->required_rank != 0 && $objectligne->rankorder != 0) ? $objectligne->required_rank :
"-"), 0,
'C');
495 $pdf->SetXY($this->posxrankemp, $curY);
496 $pdf->MultiCell($this->posxrequiredrank - $this->posxrankemp - 0.8, 4, (($objectligne->rankorder != 0) ? $objectligne->rankorder :
"-"), 0,
'C');
499 $skill =
new Skill($this->db);
500 $skill->fetch($objectligne->fk_skill);
501 $pdf->SetXY($this->posxskill, $curY);
502 $comment = $skill->label;
504 if (!empty($skill->description)) {
505 $comment .=
'<br>' . $outputlangs->trans(
"Description").
': '.$skill->description;
507 $pdf->writeHTMLCell($this->posxrankemp - $this->posxskill - 0.8, 4, $this->posxskill - 1, $curY, $comment, 0, 1);
512 $pdf->SetXY($this->posxpiece, $curY);
513 $pdf->writeHTMLCell($this->posxskill - $this->posxpiece - 0.8, 3, $this->posxpiece - 1, $curY, $linenumber + 1, 0, 1, 0, 0,
'C');
526 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
529 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
532 $outputlangs->loadLangs(array(
"main",
"trips",
"companies"));
537 $pdf->SetTextColor(0, 0, 60);
538 $pdf->SetFont(
'',
'B', $default_font_size + 3);
540 $posy = $this->marge_haute;
541 $posx = $this->page_largeur - $this->marge_droite - 100;
543 $pdf->SetXY($this->marge_gauche, $posy);
546 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
547 if ($this->emetteur->logo) {
548 if (is_readable($logo)) {
550 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
552 $pdf->SetTextColor(200, 0, 0);
553 $pdf->SetFont(
'',
'B', $default_font_size - 2);
554 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
555 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
558 $text = $this->emetteur->name;
559 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
562 $pdf->SetFont(
'',
'B', $default_font_size + 4);
563 $pdf->SetXY($posx, $posy);
564 $pdf->SetTextColor(0, 0, 60);
565 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 6, $outputlangs->transnoentities(
"Eval"), 0,
'R');
567 $pdf->SetFont(
'',
'', $default_font_size - 1);
571 $pdf->SetXY($posx, $posy);
572 $pdf->SetTextColor(0, 0, 60);
573 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities(
"Ref").
" : ".$object->ref,
'',
'R');
577 $pdf->SetXY($posx, $posy);
578 $pdf->SetTextColor(0, 0, 60);
579 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities(
"DateEval").
" : ".
dol_print_date($object->date_eval,
"day",
false, $outputlangs),
'',
'R');
584 $carac_emetteur =
'';
587 $employee =
new User($this->db);
588 $employee->fetch($object->fk_user);
589 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$outputlangs->transnoentities(
'Employee').
' : '.$outputlangs->convToOutputCharset(ucfirst($employee->firstname) .
' ' . strtoupper($employee->lastname));
593 $job->fetch($object->fk_job);
594 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$outputlangs->transnoentities(
'JobProfile').
' : '.$outputlangs->convToOutputCharset($job->label);
604 $posx = $this->marge_gauche;
615 $pdf->SetXY($posx, $posy);
616 $pdf->SetFillColor(224, 224, 224);
617 $pdf->MultiCell(190, $hautcadre,
"", 0,
'R', 1);
618 $pdf->SetTextColor(0, 0, 60);
621 $pdf->SetXY($posx + 2, $posy + 3);
622 $pdf->SetFont(
'',
'B', $default_font_size);
623 $pdf->MultiCell(190, 4, $outputlangs->convToOutputCharset($object->label), 0,
'L');
624 $pdf->SetXY($posx + 2, $posy + 8);
625 $pdf->SetFont(
'',
'', $default_font_size - 1);
626 $pdf->MultiCell(190, 4, $carac_emetteur, 0,
'L');
644 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
654 $pdf->SetDrawColor(128, 128, 128);
657 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
659 if (empty($hidetop)) {
660 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
663 $pdf->SetFont(
'',
'', 8);
666 if (empty($hidetop)) {
667 $pdf->SetXY($this->posxpiece - 1, $tab_top + 1);
668 $pdf->MultiCell($this->posxskill - $this->posxpiece - 0.8, 1,
'',
'',
'C');
672 $pdf->line($this->posxskill - 1, $tab_top, $this->posxskill - 1, $tab_top + $tab_height);
673 if (empty($hidetop)) {
674 $pdf->SetXY($this->posxskill - 1, $tab_top + 1);
675 $pdf->MultiCell($this->posxrankemp - $this->posxskill - 0.8, 1, $outputlangs->transnoentities(
"Skill"),
'',
'L');
680 $pdf->line($this->posxrankemp - 1, $tab_top, $this->posxrankemp - 1, $tab_top + $tab_height);
681 if (empty($hidetop)) {
682 $pdf->SetXY($this->posxrankemp - 0.8, $tab_top + 1);
683 $pdf->MultiCell($this->posxrequiredrank - $this->posxrankemp - 1, 2, $outputlangs->transnoentities(
"EmployeeRankShort"),
'',
'C');
688 $pdf->line($this->posxrequiredrank - 1, $tab_top, $this->posxrequiredrank - 1, $tab_top + $tab_height);
689 if (empty($hidetop)) {
690 $pdf->SetXY($this->posxrequiredrank - 0.8, $tab_top + 1);
691 $pdf->MultiCell($this->posxresult - $this->posxrequiredrank - 1, 2, $outputlangs->transnoentities(
"RequiredRankShort"),
'',
'C');
695 $pdf->line($this->posxresult - 1, $tab_top, $this->posxresult - 1, $tab_top + $tab_height);
696 if (empty($hidetop)) {
697 $pdf->SetXY($this->posxresult - 0.8, $tab_top + 1);
698 $pdf->MultiCell($this->postotalht - $this->posxresult - 1, 2, $outputlangs->transnoentities(
"Result"),
'',
'C');
701 $pdf->SetTextColor(0, 0, 0);