194 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
197 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
200 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
202 if (!is_object($outputlangs)) {
203 $outputlangs = $langs;
207 $outputlangs->charset_output =
'ISO-8859-1';
211 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
213 global $outputlangsbis;
214 $outputlangsbis =
null;
218 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
221 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
228 if (
$conf->recruitment->dir_output.
'/recruitmentjobposition') {
233 $dir =
$conf->recruitment->dir_output.
'/recruitmentjobposition';
234 $file = $dir.
"/SPECIMEN.pdf";
237 $dir =
$conf->recruitment->dir_output.
'/recruitmentjobposition/'.$objectref;
238 $file = $dir.
"/".$objectref.
".pdf";
240 if (!file_exists($dir)) {
242 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
247 if (file_exists($dir)) {
249 $hookmanager->initHooks(array(
'pdfgeneration'));
250 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
251 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
254 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
259 $pdf->SetAutoPageBreak(1, 0);
261 $heightforinfotot = 50;
263 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
265 if (class_exists(
'TCPDF')) {
266 $pdf->setPrintHeader(
false);
267 $pdf->setPrintFooter(
false);
273 $logodir =
$conf->mycompany->dir_output;
274 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
275 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
277 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
278 $tplidx = $pdf->importPage(1);
283 $pdf->SetDrawColor(128, 128, 128);
285 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
286 $pdf->SetSubject(
$object->label);
287 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
288 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
289 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".
$object->label.
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
291 $pdf->SetCompression(
false);
295 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
303 'Name' => $this->emetteur->name,
304 'Location' =>
getCountry($this->emetteur->country_code,
''),
305 'Reason' =>
'MYOBJECT',
306 'ContactInfo' => $this->emetteur->email
308 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
312 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
316 if (!empty($tplidx)) {
317 $pdf->useTemplate($tplidx);
321 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
322 $pdf->SetFont(
'',
'', $default_font_size - 1);
323 $pdf->MultiCell(0, 3,
'');
324 $pdf->SetTextColor(0, 0, 0);
326 $tab_top = 90 + $top_shift;
327 $tab_top_newpage = (!
getDolGlobalString(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
328 $tab_height = 130 - $top_shift;
329 $tab_height_newpage = 150;
331 $tab_height_newpage -= $top_shift;
334 $nexY = $tab_top - 1;
337 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
339 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
340 if (!empty($extranote)) {
344 $pagenb = $pdf->getPage();
348 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
349 $pageposbeforenote = $pagenb;
356 $pdf->startTransaction();
358 $pdf->SetFont(
'',
'', $default_font_size - 1);
359 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
361 $pageposafternote = $pdf->getPage();
362 $posyafter = $pdf->GetY();
364 if ($pageposafternote > $pageposbeforenote) {
365 $pdf->rollbackTransaction(
true);
368 while ($pagenb < $pageposafternote) {
371 if (!empty($tplidx)) {
372 $pdf->useTemplate($tplidx);
378 $pdf->setTopMargin($tab_top_newpage);
380 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
384 $pdf->setPage($pageposbeforenote);
385 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
386 $pdf->SetFont(
'',
'', $default_font_size - 1);
387 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
388 $pageposafternote = $pdf->getPage();
390 $posyafter = $pdf->GetY();
392 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
393 $pdf->AddPage(
'',
'',
true);
396 $pdf->setPage($pageposafternote);
397 $pdf->setTopMargin($tab_top_newpage);
399 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
405 $i = $pageposbeforenote;
406 while ($i < $pageposafternote) {
410 $pdf->SetDrawColor(128, 128, 128);
412 if ($i > $pageposbeforenote) {
413 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
414 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
416 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
417 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
421 $pdf->setPageOrientation(
'', 1, 0);
428 $pdf->setPage($pageposafternote);
429 if (!empty($tplidx)) {
430 $pdf->useTemplate($tplidx);
435 $height_note = $posyafter - $tab_top_newpage;
436 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
438 $pdf->commitTransaction();
439 $posyafter = $pdf->GetY();
440 $height_note = $posyafter - $tab_top;
441 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
443 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
445 $pdf->AddPage(
'',
'',
true);
448 $pdf->setPage($pageposafternote);
449 if (!empty($tplidx)) {
450 $pdf->useTemplate($tplidx);
456 $posyafter = $tab_top_newpage;
460 $tab_height -= $height_note;
461 $tab_top = $posyafter + 6;
470 $pdf->startTransaction();
471 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
472 $pdf->rollbackTransaction(
true);
474 $nexY = $tab_top + $this->tabTitleHeight;
477 $pageposbeforeprintlines = $pdf->getPage();
478 $pagenb = $pageposbeforeprintlines;
479 for ($i = 0; $i < $nblines; $i++) {
481 $pdf->SetFont(
'',
'', $default_font_size - 1);
482 $pdf->SetTextColor(0, 0, 0);
484 $pdf->setTopMargin($tab_top_newpage);
485 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
486 $pageposbefore = $pdf->getPage();
488 $showpricebeforepagebreak = 1;
492 $pdf->startTransaction();
495 $pageposafter = $pdf->getPage();
497 if ($pageposafter > $pageposbefore) {
498 $pdf->rollbackTransaction(
true);
499 $pdf->setPageOrientation(
'', 1, $heightforfooter);
503 $pageposafter = $pdf->getPage();
504 $posyafter = $pdf->GetY();
506 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
507 if ($i == ($nblines - 1)) {
508 $pdf->AddPage(
'',
'',
true);
509 if (!empty($tplidx)) {
510 $pdf->useTemplate($tplidx);
512 $pdf->setPage($pageposafter + 1);
518 $showpricebeforepagebreak = 1;
520 $showpricebeforepagebreak = 0;
524 $pdf->commitTransaction();
528 $nexY = $pdf->GetY();
529 $pageposafter = $pdf->getPage();
530 $pdf->setPage($pageposbefore);
531 $pdf->setTopMargin($this->marge_haute);
532 $pdf->setPageOrientation(
'', 1, 0);
535 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
536 $pdf->setPage($pageposafter);
537 $curY = $tab_top_newpage;
540 $pdf->SetFont(
'',
'', $default_font_size - 1);
548 'outputlangs' => $outputlangs,
549 'hidedetails' => $hidedetails
551 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
554 while ($pagenb < $pageposafter) {
555 $pdf->setPage($pagenb);
556 if ($pagenb == $pageposbeforeprintlines) {
557 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
559 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
563 $pdf->setPage($pagenb);
564 $pdf->setPageOrientation(
'', 1, 0);
568 if (!empty($tplidx)) {
569 $pdf->useTemplate($tplidx);
573 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
574 if ($pagenb == $pageposafter) {
575 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
577 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
582 if (!empty($tplidx)) {
583 $pdf->useTemplate($tplidx);
593 if ($pagenb == $pageposbeforeprintlines) {
594 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0,
$object->multicurrency_code, $outputlangsbis);
595 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
597 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code, $outputlangsbis);
598 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
617 if (method_exists($pdf,
'AliasNbPages')) {
618 $pdf->AliasNbPages();
623 $pdf->Output($file,
'F');
626 $hookmanager->initHooks(array(
'pdfgeneration'));
627 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
629 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
631 $this->error = $hookmanager->error;
632 $this->errors = $hookmanager->errors;
637 $this->result = array(
'fullpath' => $file);
641 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
645 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
727 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
732 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
739 if (
$object->status == $object::STATUS_DRAFT &&
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK')) {
740 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK'));
743 $pdf->SetTextColor(0, 0, 60);
744 $pdf->SetFont(
'',
'B', $default_font_size + 3);
748 $posy = $this->marge_haute;
749 $posx = $this->page_largeur - $this->marge_droite - $w;
751 $pdf->SetXY($this->marge_gauche, $posy);
755 if ($this->emetteur->logo) {
756 $logodir =
$conf->mycompany->dir_output;
757 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
758 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
761 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
763 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
765 if (is_readable($logo)) {
767 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
769 $pdf->SetTextColor(200, 0, 0);
770 $pdf->SetFont(
'',
'B', $default_font_size - 2);
771 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
772 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
775 $text = $this->emetteur->name;
776 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
780 $pdf->SetFont(
'',
'B', $default_font_size + 3);
781 $pdf->SetXY($posx, $posy);
782 $pdf->SetTextColor(0, 0, 60);
784 $pdf->MultiCell($w, 3, $title,
'',
'R');
786 $pdf->SetFont(
'',
'B', $default_font_size);
789 $pdf->SetXY($posx, $posy);
790 $pdf->SetTextColor(0, 0, 60);
791 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref);
792 if (
$object->status == $object::STATUS_DRAFT) {
793 $pdf->SetTextColor(128, 0, 0);
794 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
796 $pdf->MultiCell($w, 4, $textref,
'',
'R');
799 $pdf->SetFont(
'',
'', $default_font_size - 2);
803 $pdf->SetXY($posx, $posy);
804 $pdf->SetTextColor(0, 0, 60);
805 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
810 if (!empty(
$object->project->ref)) {
812 $pdf->SetXY($posx, $posy);
813 $pdf->SetTextColor(0, 0, 60);
814 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->projet->title),
'',
'R');
820 if (!empty(
$object->project->ref)) {
822 $pdf->SetXY($posx, $posy);
823 $pdf->SetTextColor(0, 0, 60);
824 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
830 if (!empty(
$object->project->ref)) {
831 $outputlangs->load(
"projects");
833 $pdf->SetXY($posx, $posy);
834 $pdf->SetTextColor(0, 0, 60);
835 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
840 $pdf->SetXY($posx, $posy);
841 $pdf->SetTextColor(0, 0, 60);
843 $title = $outputlangs->transnoentities(
"Date");
845 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
847 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_creation,
"day",
false, $outputlangs),
'',
'R');
849 if (
$object->thirdparty->code_client) {
851 $pdf->SetXY($posx, $posy);
852 $pdf->SetTextColor(0, 0, 60);
853 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
860 $current_y = $pdf->getY();
862 if ($current_y < $pdf->getY()) {
863 $top_shift = $pdf->getY() - $current_y;
873 $posx = $this->marge_gauche;
875 $posx = $this->page_largeur - $this->marge_droite - 80;
883 $pdf->SetTextColor(0, 0, 0);
884 $pdf->SetFont(
'',
'', $default_font_size - 2);
885 $pdf->SetXY($posx, $posy - 5);
886 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
887 $pdf->SetXY($posx, $posy);
888 $pdf->SetFillColor(230, 230, 230);
889 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
890 $pdf->SetTextColor(0, 0, 60);
893 $pdf->SetXY($posx + 2, $posy + 3);
894 $pdf->SetFont(
'',
'B', $default_font_size);
895 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
896 $posy = $pdf->getY();
899 $pdf->SetXY($posx + 2, $posy);
900 $pdf->SetFont(
'',
'', $default_font_size - 1);
901 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
905 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
906 if (count($arrayidcontact) > 0) {
908 $result =
$object->fetch_contact($arrayidcontact[0]);
953 $pdf->SetTextColor(0, 0, 0);