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"));
214 global $outputlangsbis;
217 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
220 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
227 if (
$conf->recruitment->dir_output.
'/recruitmentjobposition') {
232 $dir =
$conf->recruitment->dir_output.
'/recruitmentjobposition';
233 $file = $dir.
"/SPECIMEN.pdf";
236 $dir =
$conf->recruitment->dir_output.
'/recruitmentjobposition/'.$objectref;
237 $file = $dir.
"/".$objectref.
".pdf";
239 if (!file_exists($dir)) {
241 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
246 if (file_exists($dir)) {
248 $hookmanager->initHooks(array(
'pdfgeneration'));
249 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
250 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
253 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
258 $pdf->SetAutoPageBreak(1, 0);
260 $heightforinfotot = 50;
262 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
264 if (class_exists(
'TCPDF')) {
265 $pdf->setPrintHeader(
false);
266 $pdf->setPrintFooter(
false);
272 $logodir =
$conf->mycompany->dir_output;
273 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
274 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
276 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
277 $tplidx = $pdf->importPage(1);
282 $pdf->SetDrawColor(128, 128, 128);
284 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
285 $pdf->SetSubject(
$object->label);
286 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
287 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
288 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".
$object->label.
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
290 $pdf->SetCompression(
false);
294 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
302 'Name' => $this->emetteur->name,
303 'Location' =>
getCountry($this->emetteur->country_code,
''),
304 'Reason' =>
'MYOBJECT',
305 'ContactInfo' => $this->emetteur->email
307 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
311 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
315 if (!empty($tplidx)) {
316 $pdf->useTemplate($tplidx);
320 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
321 $pdf->SetFont(
'',
'', $default_font_size - 1);
322 $pdf->MultiCell(0, 3,
'');
323 $pdf->SetTextColor(0, 0, 0);
325 $tab_top = 90 + $top_shift;
326 $tab_top_newpage = (!
getDolGlobalString(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
327 $tab_height = 130 - $top_shift;
328 $tab_height_newpage = 150;
330 $tab_height_newpage -= $top_shift;
333 $nexY = $tab_top - 1;
336 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
338 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
339 if (!empty($extranote)) {
343 $pagenb = $pdf->getPage();
347 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
348 $pageposbeforenote = $pagenb;
355 $pdf->startTransaction();
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
358 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
360 $pageposafternote = $pdf->getPage();
361 $posyafter = $pdf->GetY();
363 if ($pageposafternote > $pageposbeforenote) {
364 $pdf->rollbackTransaction(
true);
367 while ($pagenb < $pageposafternote) {
370 if (!empty($tplidx)) {
371 $pdf->useTemplate($tplidx);
377 $pdf->setTopMargin($tab_top_newpage);
379 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
383 $pdf->setPage($pageposbeforenote);
384 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
385 $pdf->SetFont(
'',
'', $default_font_size - 1);
386 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
387 $pageposafternote = $pdf->getPage();
389 $posyafter = $pdf->GetY();
391 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
392 $pdf->AddPage(
'',
'',
true);
395 $pdf->setPage($pageposafternote);
396 $pdf->setTopMargin($tab_top_newpage);
398 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
404 $i = $pageposbeforenote;
405 while ($i < $pageposafternote) {
409 $pdf->SetDrawColor(128, 128, 128);
411 if ($i > $pageposbeforenote) {
412 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
413 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
415 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
416 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
420 $pdf->setPageOrientation(
'', 1, 0);
427 $pdf->setPage($pageposafternote);
428 if (!empty($tplidx)) {
429 $pdf->useTemplate($tplidx);
434 $height_note = $posyafter - $tab_top_newpage;
435 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
437 $pdf->commitTransaction();
438 $posyafter = $pdf->GetY();
439 $height_note = $posyafter - $tab_top;
440 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
442 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
444 $pdf->AddPage(
'',
'',
true);
447 $pdf->setPage($pageposafternote);
448 if (!empty($tplidx)) {
449 $pdf->useTemplate($tplidx);
455 $posyafter = $tab_top_newpage;
459 $tab_height -= $height_note;
460 $tab_top = $posyafter + 6;
469 $pdf->startTransaction();
470 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
471 $pdf->rollbackTransaction(
true);
473 $nexY = $tab_top + $this->tabTitleHeight;
476 $pageposbeforeprintlines = $pdf->getPage();
477 $pagenb = $pageposbeforeprintlines;
478 for ($i = 0; $i < $nblines; $i++) {
480 $pdf->SetFont(
'',
'', $default_font_size - 1);
481 $pdf->SetTextColor(0, 0, 0);
483 $pdf->setTopMargin($tab_top_newpage);
484 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
485 $pageposbefore = $pdf->getPage();
487 $showpricebeforepagebreak = 1;
491 $pdf->startTransaction();
494 $pageposafter = $pdf->getPage();
496 if ($pageposafter > $pageposbefore) {
497 $pdf->rollbackTransaction(
true);
498 $pdf->setPageOrientation(
'', 1, $heightforfooter);
502 $pageposafter = $pdf->getPage();
503 $posyafter = $pdf->GetY();
505 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
506 if ($i == ($nblines - 1)) {
507 $pdf->AddPage(
'',
'',
true);
508 if (!empty($tplidx)) {
509 $pdf->useTemplate($tplidx);
511 $pdf->setPage($pageposafter + 1);
517 $showpricebeforepagebreak = 1;
519 $showpricebeforepagebreak = 0;
523 $pdf->commitTransaction();
527 $nexY = $pdf->GetY();
528 $pageposafter = $pdf->getPage();
529 $pdf->setPage($pageposbefore);
530 $pdf->setTopMargin($this->marge_haute);
531 $pdf->setPageOrientation(
'', 1, 0);
534 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
535 $pdf->setPage($pageposafter);
536 $curY = $tab_top_newpage;
539 $pdf->SetFont(
'',
'', $default_font_size - 1);
547 'outputlangs' => $outputlangs,
548 'hidedetails' => $hidedetails
550 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
553 while ($pagenb < $pageposafter) {
554 $pdf->setPage($pagenb);
555 if ($pagenb == $pageposbeforeprintlines) {
556 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
558 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
562 $pdf->setPage($pagenb);
563 $pdf->setPageOrientation(
'', 1, 0);
567 if (!empty($tplidx)) {
568 $pdf->useTemplate($tplidx);
572 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
573 if ($pagenb == $pageposafter) {
574 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
576 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
581 if (!empty($tplidx)) {
582 $pdf->useTemplate($tplidx);
592 if ($pagenb == $pageposbeforeprintlines) {
593 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0,
$object->multicurrency_code, $outputlangsbis);
594 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
596 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code, $outputlangsbis);
597 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
616 if (method_exists($pdf,
'AliasNbPages')) {
617 $pdf->AliasNbPages();
622 $pdf->Output($file,
'F');
625 $hookmanager->initHooks(array(
'pdfgeneration'));
626 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
628 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
630 $this->error = $hookmanager->error;
631 $this->errors = $hookmanager->errors;
636 $this->result = array(
'fullpath' => $file);
640 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
644 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
726 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
731 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
738 if (
$object->status == $object::STATUS_DRAFT &&
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK')) {
739 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK'));
742 $pdf->SetTextColor(0, 0, 60);
743 $pdf->SetFont(
'',
'B', $default_font_size + 3);
747 $posy = $this->marge_haute;
748 $posx = $this->page_largeur - $this->marge_droite - $w;
750 $pdf->SetXY($this->marge_gauche, $posy);
754 if ($this->emetteur->logo) {
755 $logodir =
$conf->mycompany->dir_output;
756 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
757 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
760 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
762 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
764 if (is_readable($logo)) {
766 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
768 $pdf->SetTextColor(200, 0, 0);
769 $pdf->SetFont(
'',
'B', $default_font_size - 2);
770 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
771 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
774 $text = $this->emetteur->name;
775 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
779 $pdf->SetFont(
'',
'B', $default_font_size + 3);
780 $pdf->SetXY($posx, $posy);
781 $pdf->SetTextColor(0, 0, 60);
783 $pdf->MultiCell($w, 3, $title,
'',
'R');
785 $pdf->SetFont(
'',
'B', $default_font_size);
788 $pdf->SetXY($posx, $posy);
789 $pdf->SetTextColor(0, 0, 60);
790 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref);
791 if (
$object->status == $object::STATUS_DRAFT) {
792 $pdf->SetTextColor(128, 0, 0);
793 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
795 $pdf->MultiCell($w, 4, $textref,
'',
'R');
798 $pdf->SetFont(
'',
'', $default_font_size - 2);
802 $pdf->SetXY($posx, $posy);
803 $pdf->SetTextColor(0, 0, 60);
804 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
809 if (!empty(
$object->project->ref)) {
811 $pdf->SetXY($posx, $posy);
812 $pdf->SetTextColor(0, 0, 60);
813 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->projet->title),
'',
'R');
819 if (!empty(
$object->project->ref)) {
821 $pdf->SetXY($posx, $posy);
822 $pdf->SetTextColor(0, 0, 60);
823 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
829 if (!empty(
$object->project->ref)) {
830 $outputlangs->load(
"projects");
832 $pdf->SetXY($posx, $posy);
833 $pdf->SetTextColor(0, 0, 60);
834 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
839 $pdf->SetXY($posx, $posy);
840 $pdf->SetTextColor(0, 0, 60);
842 $title = $outputlangs->transnoentities(
"Date");
844 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
846 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_creation,
"day",
false, $outputlangs),
'',
'R');
848 if (
$object->thirdparty->code_client) {
850 $pdf->SetXY($posx, $posy);
851 $pdf->SetTextColor(0, 0, 60);
852 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
859 $current_y = $pdf->getY();
861 if ($current_y < $pdf->getY()) {
862 $top_shift = $pdf->getY() - $current_y;
872 $posx = $this->marge_gauche;
874 $posx = $this->page_largeur - $this->marge_droite - 80;
882 $pdf->SetTextColor(0, 0, 0);
883 $pdf->SetFont(
'',
'', $default_font_size - 2);
884 $pdf->SetXY($posx, $posy - 5);
885 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
886 $pdf->SetXY($posx, $posy);
887 $pdf->SetFillColor(230, 230, 230);
888 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
889 $pdf->SetTextColor(0, 0, 60);
892 $pdf->SetXY($posx + 2, $posy + 3);
893 $pdf->SetFont(
'',
'B', $default_font_size);
894 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
895 $posy = $pdf->getY();
898 $pdf->SetXY($posx + 2, $posy);
899 $pdf->SetFont(
'',
'', $default_font_size - 1);
900 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
904 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
905 if (count($arrayidcontact) > 0) {
907 $result =
$object->fetch_contact($arrayidcontact[0]);
952 $pdf->SetTextColor(0, 0, 0);