169 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
172 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
174 if (!is_object($outputlangs)) {
175 $outputlangs = $langs;
178 if (!empty($conf->global->MAIN_USE_FPDF)) {
179 $outputlangs->charset_output =
'ISO-8859-1';
183 $outputlangs->loadLangs(array(
"main",
"interventions",
"dict",
"companies"));
186 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FICHINTER_DRAFT_WATERMARK))) {
187 $this->watermark = $conf->global->FICHINTER_DRAFT_WATERMARK;
190 if ($conf->ficheinter->dir_output) {
191 $object->fetch_thirdparty();
194 if ($object->specimen) {
195 $dir = $conf->ficheinter->dir_output;
196 $file = $dir.
"/SPECIMEN.pdf";
199 $dir = $conf->ficheinter->dir_output.
"/".$objectref;
200 $file = $dir.
"/".$objectref.
".pdf";
203 if (!file_exists($dir)) {
205 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
210 if (file_exists($dir)) {
212 if (!is_object($hookmanager)) {
213 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
217 $hookmanager->initHooks(array(
'pdfgeneration'));
218 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
220 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
222 $nblines = count($object->lines);
227 $heightforinfotot = 50;
228 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
229 $heightforfooter = $this->marge_basse + 8;
230 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
231 $heightforfooter += 6;
233 $pdf->SetAutoPageBreak(1, 0);
235 if (class_exists(
'TCPDF')) {
236 $pdf->setPrintHeader(
false);
237 $pdf->setPrintFooter(
false);
241 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
242 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
243 $tplidx = $pdf->importPage(1);
248 $pdf->SetDrawColor(128, 128, 128);
250 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
251 $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
252 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
253 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
254 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
256 $pdf->SetCompression(
false);
259 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
263 if (!empty($tplidx)) {
264 $pdf->useTemplate($tplidx);
267 $this->
_pagehead($pdf, $object, 1, $outputlangs);
268 $pdf->SetFont(
'',
'', $default_font_size - 1);
269 $pdf->SetTextColor(0, 0, 0);
272 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
274 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
277 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
286 $pdf->SetFont(
'',
'', $default_font_size - 1);
287 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
288 $nexY = $pdf->GetY();
289 $height_note = $nexY - $tab_top;
292 $pdf->SetDrawColor(192, 192, 192);
293 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
295 $tab_height = $tab_height - $height_note;
296 $tab_top = $nexY + 6;
301 $iniY = $tab_top + 7;
302 $curY = $tab_top + 7;
303 $nexY = $tab_top + 7;
305 $pdf->SetXY($this->marge_gauche, $tab_top);
306 $pdf->MultiCell(190, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 0);
307 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
309 $pdf->SetFont(
'',
'', $default_font_size - 1);
311 $pdf->SetXY($this->marge_gauche, $tab_top + 5);
312 $text = $object->description;
313 if ($object->duration > 0) {
314 $totaltime =
convertSecondToTime($object->duration,
'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
315 $text .= ($text ?
' - ' :
'').$langs->trans(
"Total").
": ".$totaltime;
320 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
321 $nexY = $pdf->GetY();
323 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
325 $nblines = count($object->lines);
328 for ($i = 0; $i < $nblines; $i++) {
329 $objectligne = $object->lines[$i];
331 $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
332 if ($valide > 0 || $object->specimen) {
334 $pdf->SetFont(
'',
'', $default_font_size - 1);
335 $pdf->SetTextColor(0, 0, 0);
337 $pdf->setTopMargin($tab_top_newpage);
338 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
339 $pageposbefore = $pdf->getPage();
342 $curX = $this->posxdesc - 1;
345 if (empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
346 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'dayhour',
false, $outputlangs,
true);
348 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'day',
false, $outputlangs,
true);
351 if ($objectligne->duration > 0) {
352 $txt .=
" - ".$outputlangs->transnoentities(
"Duration").
" : ".
convertSecondToTime($objectligne->duration);
354 $txt =
'<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).
'</strong>';
357 $pdf->startTransaction();
358 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1, 0);
359 $pageposafter = $pdf->getPage();
360 if ($pageposafter > $pageposbefore) {
361 $pdf->rollbackTransaction(
true);
362 $pageposafter = $pageposbefore;
364 $pdf->setPageOrientation(
'', 1, $heightforfooter);
365 $pdf->writeHTMLCell(0, 0, $curX, $curY,
dol_concatdesc($txt, $desc), 0, 1, 0);
366 $pageposafter = $pdf->getPage();
367 $posyafter = $pdf->GetY();
369 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
370 if ($i == ($nblines - 1)) {
371 $pdf->AddPage(
'',
'',
true);
372 if (!empty($tplidx)) {
373 $pdf->useTemplate($tplidx);
376 $this->
_pagehead($pdf, $object, 0, $outputlangs);
378 $pdf->setPage($pageposafter + 1);
383 $pdf->commitTransaction();
386 $nexY = $pdf->GetY();
387 $pageposafter = $pdf->getPage();
388 $pdf->setPage($pageposbefore);
389 $pdf->setTopMargin($this->marge_haute);
390 $pdf->setPageOrientation(
'', 1, 0);
393 if ($pageposafter > $pageposbefore) {
394 $pdf->setPage($pageposafter);
395 $curY = $tab_top_newpage;
398 $pdf->SetFont(
'',
'', $default_font_size - 1);
401 while ($pagenb < $pageposafter) {
402 $pdf->setPage($pagenb);
404 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
406 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
408 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
410 $pdf->setPage($pagenb);
411 $pdf->setPageOrientation(
'', 1, 0);
413 $this->
_pagehead($pdf, $object, 0, $outputlangs);
415 if (!empty($tplidx)) {
416 $pdf->useTemplate($tplidx);
419 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
421 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
423 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
425 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
428 if (!empty($tplidx)) {
429 $pdf->useTemplate($tplidx);
433 $this->
_pagehead($pdf, $object, 0, $outputlangs);
441 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object);
442 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
444 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object);
445 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
448 $this->
_pagefoot($pdf, $object, $outputlangs);
449 if (method_exists($pdf,
'AliasNbPages')) {
450 $pdf->AliasNbPages();
454 $pdf->Output($file,
'F');
457 $hookmanager->initHooks(array(
'pdfgeneration'));
458 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
460 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
462 $this->error = $hookmanager->error;
463 $this->errors = $hookmanager->errors;
468 $this->result = array(
'fullpath'=>$file);
472 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
476 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
564 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
566 global $conf, $langs;
570 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
575 $pdf->SetTextColor(0, 0, 60);
576 $pdf->SetFont(
'',
'B', $default_font_size + 3);
578 $posx = $this->page_largeur - $this->marge_droite - 100;
579 $posy = $this->marge_haute;
581 $pdf->SetXY($this->marge_gauche, $posy);
584 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
585 if ($this->emetteur->logo) {
586 if (is_readable($logo)) {
588 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
590 $pdf->SetTextColor(200, 0, 0);
591 $pdf->SetFont(
'',
'B', $default_font_size - 2);
592 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
593 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
596 $text = $this->emetteur->name;
597 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
600 $pdf->SetFont(
'',
'B', $default_font_size + 3);
601 $pdf->SetXY($posx, $posy);
602 $pdf->SetTextColor(0, 0, 60);
603 $title = $outputlangs->transnoentities(
"InterventionCard");
604 $pdf->MultiCell(100, 4, $title,
'',
'R');
606 $pdf->SetFont(
'',
'B', $default_font_size + 2);
609 $pdf->SetXY($posx, $posy);
610 $pdf->SetTextColor(0, 0, 60);
611 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
614 $pdf->SetFont(
'',
'', $default_font_size);
617 $pdf->SetXY($posx, $posy);
618 $pdf->SetTextColor(0, 0, 60);
619 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
621 if (!empty($object->ref_client)) {
623 $pdf->SetXY($posx, $posy);
624 $pdf->SetTextColor(0, 0, 60);
625 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") .
" : " .
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
629 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
631 $pdf->SetXY($posx, $posy);
632 $pdf->SetTextColor(0, 0, 60);
633 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
638 $carac_emetteur =
'';
640 $arrayidcontact = $object->getIdContact(
'internal',
'INTERREPFOLL');
641 if (count($arrayidcontact) > 0) {
642 $object->fetch_user($arrayidcontact[0]);
643 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
644 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
646 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
648 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
650 $carac_emetteur .=
"\n";
653 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
657 $posx = $this->marge_gauche;
658 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
659 $posx = $this->page_largeur - $this->marge_droite - 80;
664 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
665 $pdf->SetTextColor(0, 0, 0);
666 $pdf->SetFont(
'',
'', $default_font_size - 2);
667 $pdf->SetXY($posx, $posy - 5);
668 $pdf->SetXY($posx, $posy);
669 $pdf->SetFillColor(230, 230, 230);
670 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
674 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
675 $pdf->SetXY($posx + 2, $posy + 3);
676 $pdf->SetTextColor(0, 0, 60);
677 $pdf->SetFont(
'',
'B', $default_font_size);
678 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
679 $posy = $pdf->getY();
683 $pdf->SetFont(
'',
'', $default_font_size - 1);
684 $pdf->SetXY($posx + 2, $posy);
685 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
690 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
691 if (count($arrayidcontact) > 0) {
693 $result = $object->fetch_contact($arrayidcontact[0]);
697 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
698 $thirdparty = $object->contact;
700 $thirdparty = $object->thirdparty;
705 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact :
''), $usecontact,
'target', $object);
709 if ($this->page_largeur < 210) {
713 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
714 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
715 $posx = $this->marge_gauche;
719 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
720 $pdf->SetTextColor(0, 0, 0);
721 $pdf->SetFont(
'',
'', $default_font_size - 2);
722 $pdf->SetXY($posx + 2, $posy - 5);
723 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
724 $pdf->SetTextColor(0, 0, 0);
728 $pdf->SetXY($posx + 2, $posy + 3);
729 $pdf->SetFont(
'',
'B', $default_font_size);
730 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
732 $posy = $pdf->getY();
735 $pdf->SetFont(
'',
'', $default_font_size - 1);
736 $pdf->SetXY($posx + 2, $posy);
737 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');