142 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
147 if (!is_object($outputlangs)) {
148 $outputlangs = $langs;
152 $outputlangs->charset_output =
'ISO-8859-1';
156 $outputlangs->loadLangs(array(
"main",
"interventions",
"dict",
"companies",
"compta"));
163 if (
$conf->ficheinter->dir_output) {
168 $dir =
$conf->ficheinter->dir_output;
169 $file = $dir.
"/SPECIMEN.pdf";
172 $dir =
$conf->ficheinter->dir_output.
"/".$objectref;
173 $file = $dir.
"/".$objectref.
".pdf";
176 if (!file_exists($dir)) {
178 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
183 if (file_exists($dir)) {
185 if (!is_object($hookmanager)) {
186 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
189 $hookmanager->initHooks(array(
'pdfgeneration'));
190 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
192 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
199 $heightforinfotot = 40;
201 $heightforfooter = $this->marge_basse + 8;
203 $heightforfooter += 6;
205 $pdf->setAutoPageBreak(
true, 0);
207 if (class_exists(
'TCPDF')) {
208 $pdf->setPrintHeader(
false);
209 $pdf->setPrintFooter(
false);
214 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
215 $tplidx = $pdf->importPage(1);
220 $pdf->SetDrawColor(128, 128, 128);
222 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
223 $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
224 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
225 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
226 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
228 $pdf->SetCompression(
false);
232 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
236 if (!empty($tplidx)) {
237 $pdf->useTemplate($tplidx);
241 $pdf->SetFont(
'',
'', $default_font_size - 1);
242 $pdf->SetTextColor(0, 0, 0);
244 $tab_top = 80 + $this->marge_haute;
245 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
247 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
250 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
251 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
252 if (!empty($extranote)) {
258 $notetoshow =
make_substitutions((
string) $notetoshow, $substitutionarray, $outputlangs);
263 $pdf->SetFont(
'',
'', $default_font_size - 1);
264 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
265 $nexY = $pdf->GetY();
266 $height_note = $nexY - $tab_top;
269 $pdf->SetDrawColor(192, 192, 192);
270 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
272 $tab_height -= $height_note;
273 $tab_top = $nexY + 6;
282 $pdf->startTransaction();
283 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
284 $pdf->rollbackTransaction(
true);
286 $nexY = $tab_top + $this->tabTitleHeight;
289 $pageposbeforeprintlines = $pdf->getPage();
290 $pagenb = $pageposbeforeprintlines;
291 for ($i = 0; $i < $nblines; $i++) {
292 $objectligne =
$object->lines[$i];
296 $issubtotalline = (defined(
'SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
297 $sub_options = is_array($objectligne->extraparams) ? ($objectligne->extraparams[
"subtotal"] ?? array()) : array();
301 if ($issubtotalline && empty($objectligne->qty)) {
302 $objectligne->qty = (int) $objectligne->duration;
305 if (($curY + 6) > ($this->page_hauteur - $heightforfooter)
306 || (isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight))) {
308 if (!empty($tplidx)) {
309 $pdf->useTemplate($tplidx);
311 $pdf->setPage($pdf->getNumPages());
312 $nexY = $curY = $tab_top_newpage;
315 $pdf->SetFont(
'',
'', $default_font_size - 1);
316 $pdf->SetTextColor(0, 0, 0);
318 $pdf->setTopMargin($tab_top_newpage);
319 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
320 $pageposbefore = $pdf->getPage();
324 if ($issubtotalline) {
326 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
328 $pdf->startTransaction();
332 $pageposafter = $pdf->getPage();
333 if ($pageposafter > $pageposbefore) {
334 $pdf->rollbackTransaction(
true);
338 $pageposafter = $pdf->getPage();
339 $posyafter = $pdf->GetY();
340 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
341 if ($i == ($nblines - 1)) {
342 $pdf->AddPage(
'',
'',
true);
343 if (!empty($tplidx)) {
344 $pdf->useTemplate($tplidx);
346 $pdf->setPage($pageposafter + 1);
350 $pdf->commitTransaction();
355 $nexY = $pdf->GetY();
356 $pageposafter = $pdf->getPage();
358 $pdf->setPage($pageposbefore);
359 $pdf->setTopMargin($this->marge_haute);
360 $pdf->setPageOrientation(
'',
true, 0);
363 if ($pageposafter > $pageposbefore) {
364 $pdf->setPage($pageposafter);
365 $curY = $tab_top_newpage;
368 $pdf->SetFont(
'',
'', $default_font_size - 1);
376 if (!$issubtotalline) {
381 if ($this->
getColumnStatus(
'duration') && $objectligne->duration > 0) {
386 if (!empty($objectligne->array_options)) {
387 foreach ($objectligne->array_options as $extrafieldColKey => $extrafieldValue) {
402 'outputlangs' => $outputlangs,
403 'hidedetails' => $hidedetails
405 $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
409 $pdf->setPage($pageposafter);
410 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
411 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
412 $pdf->SetLineStyle(array(
'dash' => 0));
416 while ($pagenb < $pageposafter) {
417 $pdf->setPage($pagenb);
418 if ($pagenb == $pageposbeforeprintlines) {
419 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
421 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
425 $pdf->setPage($pagenb);
426 $pdf->setPageOrientation(
'',
true, 0);
430 if (!empty($tplidx)) {
431 $pdf->useTemplate($tplidx);
437 if ($pagenb == $pageposbeforeprintlines) {
438 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
439 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
441 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
442 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
452 if (method_exists($pdf,
'AliasNbPages')) {
453 $pdf->AliasNbPages();
457 $pdf->Output($file,
'F');
460 $hookmanager->initHooks(array(
'pdfgeneration'));
461 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
462 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
463 $this->warnings = $hookmanager->warnings;
465 $this->error = $hookmanager->error;
466 $this->errors = $hookmanager->errors;
473 $this->result = array(
'fullpath' => $file);
477 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
481 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
614 global
$conf, $langs;
619 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
623 $pdf->SetTextColor(0, 0, 60);
624 $pdf->SetFont(
'',
'B', $default_font_size + 3);
626 $posx = $this->page_largeur - $this->marge_droite - 100;
627 $posy = $this->marge_haute;
629 $pdf->SetXY($this->marge_gauche, $posy);
632 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
633 if ($this->emetteur->logo) {
634 if (is_readable($logo)) {
636 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
638 $pdf->SetTextColor(200, 0, 0);
639 $pdf->SetFont(
'',
'B', $default_font_size - 2);
640 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
641 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
644 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
647 $pdf->SetFont(
'',
'B', $default_font_size + 3);
648 $pdf->SetXY($posx, $posy);
649 $pdf->SetTextColor(0, 0, 60);
650 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"InterventionCard"),
'',
'R');
652 $pdf->SetFont(
'',
'B', $default_font_size + 2);
655 $pdf->SetXY($posx, $posy);
656 $pdf->SetTextColor(0, 0, 60);
657 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
660 $pdf->SetFont(
'',
'', $default_font_size);
663 $pdf->SetXY($posx, $posy);
664 $pdf->SetTextColor(0, 0, 60);
665 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
667 if (!empty(
$object->ref_client)) {
669 $pdf->SetXY($posx, $posy);
670 $pdf->SetTextColor(0, 0, 60);
671 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
676 $pdf->SetXY($posx, $posy);
677 $pdf->SetTextColor(0, 0, 60);
678 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
683 $carac_emetteur =
'';
684 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
685 if (count($arrayidcontact) > 0) {
686 $object->fetch_user($arrayidcontact[0]);
687 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
688 $carac_emetteur .= $labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs)).
"\n";
694 $posy = 32 + $this->marge_haute;
695 $posx = $this->marge_gauche;
697 $posx = $this->page_largeur - $this->marge_droite - 80;
703 $pdf->SetTextColor(0, 0, 0);
704 $pdf->SetFont(
'',
'', $default_font_size - 2);
705 $pdf->SetXY($posx, $posy);
706 $pdf->SetFillColor(230, 230, 230);
707 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
712 $pdf->SetXY($posx + 2, $posy + 3);
713 $pdf->SetTextColor(0, 0, 60);
714 $pdf->SetFont(
'',
'B', $default_font_size);
715 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
716 $posy = $pdf->getY();
720 $pdf->SetFont(
'',
'', $default_font_size - 1);
721 $pdf->SetXY($posx + 2, $posy);
722 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
726 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
727 if (count($arrayidcontact) > 0) {
729 $result =
$object->fetch_contact($arrayidcontact[0]);
733 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
734 $thirdparty =
$object->contact;
736 $thirdparty =
$object->thirdparty;
745 if ($this->page_largeur < 210) {
748 $posy = 32 + $this->marge_haute;
749 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
751 $posx = $this->marge_gauche;
756 $pdf->SetTextColor(0, 0, 0);
757 $pdf->SetFont(
'',
'', $default_font_size - 2);
758 $pdf->SetXY($posx + 2, $posy - 5);
759 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
760 $pdf->SetTextColor(0, 0, 0);
764 $pdf->SetXY($posx + 2, $posy + 3);
765 $pdf->SetFont(
'',
'B', $default_font_size);
766 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
768 $posy = $pdf->getY();
771 $pdf->SetFont(
'',
'', $default_font_size - 1);
772 $pdf->SetXY($posx + 2, $posy);
773 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
812 $this->defaultContentsFieldsStyle = array(
814 'padding' => array(1, 0.5, 1, 0.5),
818 $this->defaultTitlesFieldsStyle = array(
820 'padding' => array(0.5, 0, 0.5, 0),
824 $this->cols[
'position'] = array(
831 'padding' => array(0.5, 0.5, 0.5, 0.5),
835 'padding' => array(1, 0.5, 1, 1.5),
840 $this->cols[
'desc'] = array(
845 'textkey' =>
'Designation',
847 'padding' => array(0.5, 0.5, 0.5, 0.5),
851 'padding' => array(1, 0.5, 1, 1.5),
856 $this->cols[
'date'] = array(
863 'border-left' =>
true,
870 $this->cols[
'duration'] = array(
875 'textkey' =>
'Duration',
877 'border-left' =>
true,
891 'outputlangs' => $outputlangs,
892 'hidedetails' => $hidedetails,
893 'hidedesc' => $hidedesc,
894 'hideref' => $hideref
897 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
899 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
900 } elseif (empty($reshook)) {
902 $this->cols = array_replace($this->cols, $hookmanager->resArray);
904 $this->cols = $hookmanager->resArray;