189 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
192 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
195 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
197 if (!is_object($outputlangs)) {
198 $outputlangs = $langs;
202 $outputlangs->charset_output =
'ISO-8859-1';
206 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
209 global $outputlangsbis;
210 $outputlangsbis =
new Translate(
'', $conf);
212 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
215 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
222 if ($conf->recruitment->dir_output.
'/recruitmentjobposition') {
227 $dir = $conf->recruitment->dir_output.
'/recruitmentjobposition';
228 $file = $dir.
"/SPECIMEN.pdf";
231 $dir = $conf->recruitment->dir_output.
'/recruitmentjobposition/'.$objectref;
232 $file = $dir.
"/".$objectref.
".pdf";
234 if (!file_exists($dir)) {
236 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
241 if (file_exists($dir)) {
243 $hookmanager->initHooks(array(
'pdfgeneration'));
244 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
245 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
248 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
253 $pdf->SetAutoPageBreak(1, 0);
255 $heightforinfotot = 50;
256 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
257 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
259 if (class_exists(
'TCPDF')) {
260 $pdf->setPrintHeader(
false);
261 $pdf->setPrintFooter(
false);
267 $logodir = $conf->mycompany->dir_output;
268 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
269 $logodir = $conf->mycompany->multidir_output[
$object->entity];
271 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
272 $tplidx = $pdf->importPage(1);
277 $pdf->SetDrawColor(128, 128, 128);
279 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
280 $pdf->SetSubject(
$object->label);
281 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
282 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
283 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".
$object->label.
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
285 $pdf->SetCompression(
false);
289 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
297 'Name' => $this->emetteur->name,
298 'Location' =>
getCountry($this->emetteur->country_code, 0),
299 'Reason' =>
'MYOBJECT',
300 'ContactInfo' => $this->emetteur->email
302 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
306 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
310 if (!empty($tplidx)) {
311 $pdf->useTemplate($tplidx);
315 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
316 $pdf->SetFont(
'',
'', $default_font_size - 1);
317 $pdf->MultiCell(0, 3,
'');
318 $pdf->SetTextColor(0, 0, 0);
320 $tab_top = 90 + $top_shift;
321 $tab_top_newpage = (!
getDolGlobalString(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
322 $tab_height = 130 - $top_shift;
323 $tab_height_newpage = 150;
325 $tab_height_newpage -= $top_shift;
328 $nexY = $tab_top - 1;
331 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
333 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
334 if (!empty($extranote)) {
338 $pagenb = $pdf->getPage();
342 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
343 $pageposbeforenote = $pagenb;
350 $pdf->startTransaction();
352 $pdf->SetFont(
'',
'', $default_font_size - 1);
353 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
355 $pageposafternote = $pdf->getPage();
356 $posyafter = $pdf->GetY();
358 if ($pageposafternote > $pageposbeforenote) {
359 $pdf->rollbackTransaction(
true);
362 while ($pagenb < $pageposafternote) {
365 if (!empty($tplidx)) {
366 $pdf->useTemplate($tplidx);
372 $pdf->setTopMargin($tab_top_newpage);
374 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
378 $pdf->setPage($pageposbeforenote);
379 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
380 $pdf->SetFont(
'',
'', $default_font_size - 1);
381 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
382 $pageposafternote = $pdf->getPage();
384 $posyafter = $pdf->GetY();
386 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
387 $pdf->AddPage(
'',
'',
true);
390 $pdf->setPage($pageposafternote);
391 $pdf->setTopMargin($tab_top_newpage);
393 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
399 $i = $pageposbeforenote;
400 while ($i < $pageposafternote) {
404 $pdf->SetDrawColor(128, 128, 128);
406 if ($i > $pageposbeforenote) {
407 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
408 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
410 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
411 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
415 $pdf->setPageOrientation(
'', 1, 0);
422 $pdf->setPage($pageposafternote);
423 if (!empty($tplidx)) {
424 $pdf->useTemplate($tplidx);
429 $height_note = $posyafter - $tab_top_newpage;
430 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
432 $pdf->commitTransaction();
433 $posyafter = $pdf->GetY();
434 $height_note = $posyafter - $tab_top;
435 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
437 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
439 $pdf->AddPage(
'',
'',
true);
442 $pdf->setPage($pageposafternote);
443 if (!empty($tplidx)) {
444 $pdf->useTemplate($tplidx);
450 $posyafter = $tab_top_newpage;
454 $tab_height = $tab_height - $height_note;
455 $tab_top = $posyafter + 6;
464 $pdf->startTransaction();
465 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
466 $pdf->rollbackTransaction(
true);
468 $nexY = $tab_top + $this->tabTitleHeight;
471 $pageposbeforeprintlines = $pdf->getPage();
472 $pagenb = $pageposbeforeprintlines;
473 for ($i = 0; $i < $nblines; $i++) {
475 $pdf->SetFont(
'',
'', $default_font_size - 1);
476 $pdf->SetTextColor(0, 0, 0);
478 $pdf->setTopMargin($tab_top_newpage);
479 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
480 $pageposbefore = $pdf->getPage();
482 $showpricebeforepagebreak = 1;
486 $pdf->startTransaction();
489 $pageposafter = $pdf->getPage();
491 if ($pageposafter > $pageposbefore) {
492 $pdf->rollbackTransaction(
true);
493 $pdf->setPageOrientation(
'', 1, $heightforfooter);
497 $pageposafter = $pdf->getPage();
498 $posyafter = $pdf->GetY();
500 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
501 if ($i == ($nblines - 1)) {
502 $pdf->AddPage(
'',
'',
true);
503 if (!empty($tplidx)) {
504 $pdf->useTemplate($tplidx);
506 $pdf->setPage($pageposafter + 1);
512 $showpricebeforepagebreak = 1;
514 $showpricebeforepagebreak = 0;
518 $pdf->commitTransaction();
522 $nexY = $pdf->GetY();
523 $pageposafter = $pdf->getPage();
524 $pdf->setPage($pageposbefore);
525 $pdf->setTopMargin($this->marge_haute);
526 $pdf->setPageOrientation(
'', 1, 0);
529 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
530 $pdf->setPage($pageposafter);
531 $curY = $tab_top_newpage;
534 $pdf->SetFont(
'',
'', $default_font_size - 1);
542 'outputlangs' => $outputlangs,
543 'hidedetails' => $hidedetails
545 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
548 while ($pagenb < $pageposafter) {
549 $pdf->setPage($pagenb);
550 if ($pagenb == $pageposbeforeprintlines) {
551 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
553 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
557 $pdf->setPage($pagenb);
558 $pdf->setPageOrientation(
'', 1, 0);
562 if (!empty($tplidx)) {
563 $pdf->useTemplate($tplidx);
567 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
568 if ($pagenb == $pageposafter) {
569 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
571 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
576 if (!empty($tplidx)) {
577 $pdf->useTemplate($tplidx);
587 if ($pagenb == $pageposbeforeprintlines) {
588 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0,
$object->multicurrency_code, $outputlangsbis);
589 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
591 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code, $outputlangsbis);
592 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
611 if (method_exists($pdf,
'AliasNbPages')) {
612 $pdf->AliasNbPages();
617 $pdf->Output($file,
'F');
620 $hookmanager->initHooks(array(
'pdfgeneration'));
621 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
623 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
625 $this->error = $hookmanager->error;
626 $this->errors = $hookmanager->errors;
631 $this->result = array(
'fullpath' => $file);
635 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
639 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
721 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
726 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
733 if (
$object->status == $object::STATUS_DRAFT &&
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK')) {
734 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK'));
737 $pdf->SetTextColor(0, 0, 60);
738 $pdf->SetFont(
'',
'B', $default_font_size + 3);
742 $posy = $this->marge_haute;
743 $posx = $this->page_largeur - $this->marge_droite - $w;
745 $pdf->SetXY($this->marge_gauche, $posy);
749 if ($this->emetteur->logo) {
750 $logodir = $conf->mycompany->dir_output;
751 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
752 $logodir = $conf->mycompany->multidir_output[
$object->entity];
755 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
757 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
759 if (is_readable($logo)) {
761 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
763 $pdf->SetTextColor(200, 0, 0);
764 $pdf->SetFont(
'',
'B', $default_font_size - 2);
765 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
766 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
769 $text = $this->emetteur->name;
770 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
774 $pdf->SetFont(
'',
'B', $default_font_size + 3);
775 $pdf->SetXY($posx, $posy);
776 $pdf->SetTextColor(0, 0, 60);
778 $pdf->MultiCell($w, 3, $title,
'',
'R');
780 $pdf->SetFont(
'',
'B', $default_font_size);
783 $pdf->SetXY($posx, $posy);
784 $pdf->SetTextColor(0, 0, 60);
785 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref);
786 if (
$object->status == $object::STATUS_DRAFT) {
787 $pdf->SetTextColor(128, 0, 0);
788 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
790 $pdf->MultiCell($w, 4, $textref,
'',
'R');
793 $pdf->SetFont(
'',
'', $default_font_size - 2);
797 $pdf->SetXY($posx, $posy);
798 $pdf->SetTextColor(0, 0, 60);
799 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
804 if (!empty(
$object->project->ref)) {
806 $pdf->SetXY($posx, $posy);
807 $pdf->SetTextColor(0, 0, 60);
808 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->projet->title),
'',
'R');
814 if (!empty(
$object->project->ref)) {
816 $pdf->SetXY($posx, $posy);
817 $pdf->SetTextColor(0, 0, 60);
818 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
824 if (!empty(
$object->project->ref)) {
825 $outputlangs->load(
"projects");
827 $pdf->SetXY($posx, $posy);
828 $pdf->SetTextColor(0, 0, 60);
829 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
834 $pdf->SetXY($posx, $posy);
835 $pdf->SetTextColor(0, 0, 60);
837 $title = $outputlangs->transnoentities(
"Date");
839 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
841 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_creation,
"day",
false, $outputlangs),
'',
'R');
843 if (
$object->thirdparty->code_client) {
845 $pdf->SetXY($posx, $posy);
846 $pdf->SetTextColor(0, 0, 60);
847 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
854 $current_y = $pdf->getY();
856 if ($current_y < $pdf->getY()) {
857 $top_shift = $pdf->getY() - $current_y;
867 $posx = $this->marge_gauche;
869 $posx = $this->page_largeur - $this->marge_droite - 80;
877 $pdf->SetTextColor(0, 0, 0);
878 $pdf->SetFont(
'',
'', $default_font_size - 2);
879 $pdf->SetXY($posx, $posy - 5);
880 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
881 $pdf->SetXY($posx, $posy);
882 $pdf->SetFillColor(230, 230, 230);
883 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
884 $pdf->SetTextColor(0, 0, 60);
887 $pdf->SetXY($posx + 2, $posy + 3);
888 $pdf->SetFont(
'',
'B', $default_font_size);
889 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
890 $posy = $pdf->getY();
893 $pdf->SetXY($posx + 2, $posy);
894 $pdf->SetFont(
'',
'', $default_font_size - 1);
895 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
899 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
900 if (count($arrayidcontact) > 0) {
902 $result =
$object->fetch_contact($arrayidcontact[0]);
947 $pdf->SetTextColor(0, 0, 0);