195 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
198 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
201 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
203 if (!is_object($outputlangs)) {
204 $outputlangs = $langs;
208 $outputlangs->charset_output =
'ISO-8859-1';
212 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
214 global $outputlangsbis;
215 $outputlangsbis =
null;
219 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
222 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
229 if (
$conf->recruitment->dir_output.
'/recruitmentjobposition') {
234 $dir =
$conf->recruitment->dir_output.
'/recruitmentjobposition';
235 $file = $dir.
"/SPECIMEN.pdf";
238 $dir =
$conf->recruitment->dir_output.
'/recruitmentjobposition/'.$objectref;
239 $file = $dir.
"/".$objectref.
".pdf";
241 if (!file_exists($dir)) {
243 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
248 if (file_exists($dir)) {
250 $hookmanager->initHooks(array(
'pdfgeneration'));
251 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
252 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
255 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
260 $pdf->setAutoPageBreak(
true, 0);
262 $heightforinfotot = 50;
264 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
266 if (class_exists(
'TCPDF')) {
267 $pdf->setPrintHeader(
false);
268 $pdf->setPrintFooter(
false);
274 $logodir =
$conf->mycompany->dir_output;
275 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
276 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
278 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
279 $tplidx = $pdf->importPage(1);
284 $pdf->SetDrawColor(128, 128, 128);
286 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
287 $pdf->SetSubject(
$object->label);
288 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
289 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
290 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".
$object->label.
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
292 $pdf->SetCompression(
false);
296 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
304 'Name' => $this->emetteur->name,
305 'Location' =>
getCountry($this->emetteur->country_code,
''),
306 'Reason' =>
'MYOBJECT',
307 'ContactInfo' => $this->emetteur->email
309 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
313 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
317 if (!empty($tplidx)) {
318 $pdf->useTemplate($tplidx);
322 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
323 $pdf->SetFont(
'',
'', $default_font_size - 1);
324 $pdf->MultiCell(0, 3,
'');
325 $pdf->SetTextColor(0, 0, 0);
327 $tab_top = 90 + $top_shift;
328 $tab_top_newpage = (!
getDolGlobalString(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
329 $tab_height = 130 - $top_shift;
330 $tab_height_newpage = 150;
332 $tab_height_newpage -= $top_shift;
335 $nexY = $tab_top - 1;
338 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
340 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
341 if (!empty($extranote)) {
345 $pagenb = $pdf->getPage();
349 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
350 $pageposbeforenote = $pagenb;
357 $pdf->startTransaction();
359 $pdf->SetFont(
'',
'', $default_font_size - 1);
360 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
362 $pageposafternote = $pdf->getPage();
363 $posyafter = $pdf->GetY();
365 if ($pageposafternote > $pageposbeforenote) {
366 $pdf->rollbackTransaction(
true);
369 while ($pagenb < $pageposafternote) {
372 if (!empty($tplidx)) {
373 $pdf->useTemplate($tplidx);
379 $pdf->setTopMargin($tab_top_newpage);
381 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
385 $pdf->setPage($pageposbeforenote);
386 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
387 $pdf->SetFont(
'',
'', $default_font_size - 1);
388 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
389 $pageposafternote = $pdf->getPage();
391 $posyafter = $pdf->GetY();
393 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
394 $pdf->AddPage(
'',
'',
true);
397 $pdf->setPage($pageposafternote);
398 $pdf->setTopMargin($tab_top_newpage);
400 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
406 $i = $pageposbeforenote;
407 while ($i < $pageposafternote) {
411 $pdf->SetDrawColor(128, 128, 128);
413 if ($i > $pageposbeforenote) {
414 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
415 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
417 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
418 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
422 $pdf->setPageOrientation(
'',
true, 0);
429 $pdf->setPage($pageposafternote);
430 if (!empty($tplidx)) {
431 $pdf->useTemplate($tplidx);
436 $height_note = $posyafter - $tab_top_newpage;
437 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
439 $pdf->commitTransaction();
440 $posyafter = $pdf->GetY();
441 $height_note = $posyafter - $tab_top;
442 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
444 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
446 $pdf->AddPage(
'',
'',
true);
449 $pdf->setPage($pageposafternote);
450 if (!empty($tplidx)) {
451 $pdf->useTemplate($tplidx);
457 $posyafter = $tab_top_newpage;
461 $tab_height -= $height_note;
462 $tab_top = $posyafter + 6;
471 $pdf->startTransaction();
472 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
473 $pdf->rollbackTransaction(
true);
475 $nexY = $tab_top + $this->tabTitleHeight;
478 $pageposbeforeprintlines = $pdf->getPage();
479 $pagenb = $pageposbeforeprintlines;
480 for ($i = 0; $i < $nblines; $i++) {
482 $pdf->SetFont(
'',
'', $default_font_size - 1);
483 $pdf->SetTextColor(0, 0, 0);
485 $pdf->setTopMargin($tab_top_newpage);
486 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
487 $pageposbefore = $pdf->getPage();
489 $showpricebeforepagebreak = 1;
493 $pdf->startTransaction();
496 $pageposafter = $pdf->getPage();
498 if ($pageposafter > $pageposbefore) {
499 $pdf->rollbackTransaction(
true);
500 $pdf->setPageOrientation(
'',
true, $heightforfooter);
504 $pageposafter = $pdf->getPage();
505 $posyafter = $pdf->GetY();
507 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
508 if ($i == ($nblines - 1)) {
509 $pdf->AddPage(
'',
'',
true);
510 if (!empty($tplidx)) {
511 $pdf->useTemplate($tplidx);
513 $pdf->setPage($pageposafter + 1);
519 $showpricebeforepagebreak = 1;
521 $showpricebeforepagebreak = 0;
525 $pdf->commitTransaction();
529 $nexY = $pdf->GetY();
530 $pageposafter = $pdf->getPage();
531 $pdf->setPage($pageposbefore);
532 $pdf->setTopMargin($this->marge_haute);
533 $pdf->setPageOrientation(
'',
true, 0);
536 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
537 $pdf->setPage($pageposafter);
538 $curY = $tab_top_newpage;
541 $pdf->SetFont(
'',
'', $default_font_size - 1);
549 'outputlangs' => $outputlangs,
550 'hidedetails' => $hidedetails
552 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
555 while ($pagenb < $pageposafter) {
556 $pdf->setPage($pagenb);
557 if ($pagenb == $pageposbeforeprintlines) {
558 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
560 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
564 $pdf->setPage($pagenb);
565 $pdf->setPageOrientation(
'',
true, 0);
569 if (!empty($tplidx)) {
570 $pdf->useTemplate($tplidx);
574 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
575 if ($pagenb == $pageposafter) {
576 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
578 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code, $outputlangsbis);
583 if (!empty($tplidx)) {
584 $pdf->useTemplate($tplidx);
594 if ($pagenb == $pageposbeforeprintlines) {
595 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0,
$object->multicurrency_code, $outputlangsbis);
596 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
598 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code, $outputlangsbis);
599 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
618 if (method_exists($pdf,
'AliasNbPages')) {
619 $pdf->AliasNbPages();
624 $pdf->Output($file,
'F');
627 $hookmanager->initHooks(array(
'pdfgeneration'));
628 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
630 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
632 $this->error = $hookmanager->error;
633 $this->errors = $hookmanager->errors;
638 $this->result = array(
'fullpath' => $file);
642 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
646 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
728 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
733 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
740 if (
$object->status == $object::STATUS_DRAFT &&
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK')) {
741 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK'));
744 $pdf->SetTextColor(0, 0, 60);
745 $pdf->SetFont(
'',
'B', $default_font_size + 3);
749 $posy = $this->marge_haute;
750 $posx = $this->page_largeur - $this->marge_droite - $w;
752 $pdf->SetXY($this->marge_gauche, $posy);
756 if ($this->emetteur->logo) {
757 $logodir =
$conf->mycompany->dir_output;
758 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
759 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
762 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
764 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
766 if (is_readable($logo)) {
768 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
770 $pdf->SetTextColor(200, 0, 0);
771 $pdf->SetFont(
'',
'B', $default_font_size - 2);
772 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
773 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
776 $text = $this->emetteur->name;
777 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
781 $pdf->SetFont(
'',
'B', $default_font_size + 3);
782 $pdf->SetXY($posx, $posy);
783 $pdf->SetTextColor(0, 0, 60);
785 $pdf->MultiCell($w, 3, $title,
'',
'R');
787 $pdf->SetFont(
'',
'B', $default_font_size);
790 $pdf->SetXY($posx, $posy);
791 $pdf->SetTextColor(0, 0, 60);
792 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref);
793 if (
$object->status == $object::STATUS_DRAFT) {
794 $pdf->SetTextColor(128, 0, 0);
795 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
797 $pdf->MultiCell($w, 4, $textref,
'',
'R');
800 $pdf->SetFont(
'',
'', $default_font_size - 2);
804 $pdf->SetXY($posx, $posy);
805 $pdf->SetTextColor(0, 0, 60);
806 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
811 if (!empty(
$object->project->ref)) {
813 $pdf->SetXY($posx, $posy);
814 $pdf->SetTextColor(0, 0, 60);
815 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->projet->title),
'',
'R');
821 if (!empty(
$object->project->ref)) {
823 $pdf->SetXY($posx, $posy);
824 $pdf->SetTextColor(0, 0, 60);
825 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
831 if (!empty(
$object->project->ref)) {
832 $outputlangs->load(
"projects");
834 $pdf->SetXY($posx, $posy);
835 $pdf->SetTextColor(0, 0, 60);
836 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
841 $pdf->SetXY($posx, $posy);
842 $pdf->SetTextColor(0, 0, 60);
844 $title = $outputlangs->transnoentities(
"Date");
846 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
848 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_creation,
"day",
false, $outputlangs),
'',
'R');
850 if (
$object->thirdparty->code_client) {
852 $pdf->SetXY($posx, $posy);
853 $pdf->SetTextColor(0, 0, 60);
854 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
861 $current_y = $pdf->getY();
863 if ($current_y < $pdf->getY()) {
864 $top_shift = $pdf->getY() - $current_y;
874 $posx = $this->marge_gauche;
876 $posx = $this->page_largeur - $this->marge_droite - 80;
884 $pdf->SetTextColor(0, 0, 0);
885 $pdf->SetFont(
'',
'', $default_font_size - 2);
886 $pdf->SetXY($posx, $posy - 5);
887 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
888 $pdf->SetXY($posx, $posy);
889 $pdf->SetFillColor(230, 230, 230);
890 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R',
true);
891 $pdf->SetTextColor(0, 0, 60);
894 $pdf->SetXY($posx + 2, $posy + 3);
895 $pdf->SetFont(
'',
'B', $default_font_size);
896 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
897 $posy = $pdf->getY();
900 $pdf->SetXY($posx + 2, $posy);
901 $pdf->SetFont(
'',
'', $default_font_size - 1);
902 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
906 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
907 if (count($arrayidcontact) > 0) {
909 $result =
$object->fetch_contact($arrayidcontact[0]);
954 $pdf->SetTextColor(0, 0, 0);