137 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
142 if (!is_object($outputlangs)) {
143 $outputlangs = $langs;
147 $outputlangs->charset_output =
'ISO-8859-1';
151 $outputlangs->loadLangs(array(
"main",
"interventions",
"dict",
"companies",
"compta"));
158 if (
$conf->ficheinter->dir_output) {
163 $dir =
$conf->ficheinter->dir_output;
164 $file = $dir.
"/SPECIMEN.pdf";
167 $dir =
$conf->ficheinter->dir_output.
"/".$objectref;
168 $file = $dir.
"/".$objectref.
".pdf";
171 if (!file_exists($dir)) {
173 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
178 if (file_exists($dir)) {
180 if (!is_object($hookmanager)) {
181 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
184 $hookmanager->initHooks(array(
'pdfgeneration'));
185 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
187 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
194 $heightforinfotot = 40;
196 $heightforfooter = $this->marge_basse + 8;
198 $heightforfooter += 6;
200 $pdf->setAutoPageBreak(
true, 0);
202 if (class_exists(
'TCPDF')) {
203 $pdf->setPrintHeader(
false);
204 $pdf->setPrintFooter(
false);
209 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
210 $tplidx = $pdf->importPage(1);
215 $pdf->SetDrawColor(128, 128, 128);
217 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
218 $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
219 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
220 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
221 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
223 $pdf->SetCompression(
false);
227 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
231 if (!empty($tplidx)) {
232 $pdf->useTemplate($tplidx);
236 $pdf->SetFont(
'',
'', $default_font_size - 1);
237 $pdf->SetTextColor(0, 0, 0);
239 $tab_top = 80 + $this->marge_haute;
240 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
242 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
245 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
246 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
247 if (!empty($extranote)) {
253 $notetoshow =
make_substitutions((
string) $notetoshow, $substitutionarray, $outputlangs);
258 $pdf->SetFont(
'',
'', $default_font_size - 1);
259 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
260 $nexY = $pdf->GetY();
261 $height_note = $nexY - $tab_top;
264 $pdf->SetDrawColor(192, 192, 192);
265 $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');
267 $tab_height -= $height_note;
268 $tab_top = $nexY + 6;
277 $pdf->startTransaction();
278 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
279 $pdf->rollbackTransaction(
true);
281 $nexY = $tab_top + $this->tabTitleHeight;
284 $pageposbeforeprintlines = $pdf->getPage();
285 $pagenb = $pageposbeforeprintlines;
286 for ($i = 0; $i < $nblines; $i++) {
287 $objectligne =
$object->lines[$i];
291 $issubtotalline = (defined(
'SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
292 $sub_options = is_array($objectligne->extraparams) ? ($objectligne->extraparams[
"subtotal"] ?? array()) : array();
296 if ($issubtotalline && empty($objectligne->qty)) {
297 $objectligne->qty = (int) $objectligne->duration;
300 if (($curY + 6) > ($this->page_hauteur - $heightforfooter)
301 || (isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight))) {
303 if (!empty($tplidx)) {
304 $pdf->useTemplate($tplidx);
306 $pdf->setPage($pdf->getNumPages());
307 $nexY = $curY = $tab_top_newpage;
310 $pdf->SetFont(
'',
'', $default_font_size - 1);
311 $pdf->SetTextColor(0, 0, 0);
313 $pdf->setTopMargin($tab_top_newpage);
314 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
315 $pageposbefore = $pdf->getPage();
319 if ($issubtotalline) {
321 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
323 $pdf->startTransaction();
327 $pageposafter = $pdf->getPage();
328 if ($pageposafter > $pageposbefore) {
329 $pdf->rollbackTransaction(
true);
333 $pageposafter = $pdf->getPage();
334 $posyafter = $pdf->GetY();
335 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
336 if ($i == ($nblines - 1)) {
337 $pdf->AddPage(
'',
'',
true);
338 if (!empty($tplidx)) {
339 $pdf->useTemplate($tplidx);
341 $pdf->setPage($pageposafter + 1);
345 $pdf->commitTransaction();
350 $nexY = $pdf->GetY();
351 $pageposafter = $pdf->getPage();
353 $pdf->setPage($pageposbefore);
354 $pdf->setTopMargin($this->marge_haute);
355 $pdf->setPageOrientation(
'',
true, 0);
358 if ($pageposafter > $pageposbefore) {
359 $pdf->setPage($pageposafter);
360 $curY = $tab_top_newpage;
363 $pdf->SetFont(
'',
'', $default_font_size - 1);
371 if (!$issubtotalline) {
376 if ($this->
getColumnStatus(
'duration') && $objectligne->duration > 0) {
381 if (!empty($objectligne->array_options)) {
382 foreach ($objectligne->array_options as $extrafieldColKey => $extrafieldValue) {
397 'outputlangs' => $outputlangs,
398 'hidedetails' => $hidedetails
400 $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
404 $pdf->setPage($pageposafter);
405 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
406 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
407 $pdf->SetLineStyle(array(
'dash' => 0));
411 while ($pagenb < $pageposafter) {
412 $pdf->setPage($pagenb);
413 if ($pagenb == $pageposbeforeprintlines) {
414 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
416 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
420 $pdf->setPage($pagenb);
421 $pdf->setPageOrientation(
'',
true, 0);
425 if (!empty($tplidx)) {
426 $pdf->useTemplate($tplidx);
432 if ($pagenb == $pageposbeforeprintlines) {
433 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
434 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
436 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
437 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
447 if (method_exists($pdf,
'AliasNbPages')) {
448 $pdf->AliasNbPages();
452 $pdf->Output($file,
'F');
455 $hookmanager->initHooks(array(
'pdfgeneration'));
456 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
457 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
458 $this->warnings = $hookmanager->warnings;
460 $this->error = $hookmanager->error;
461 $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");
609 global
$conf, $langs;
614 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
618 $pdf->SetTextColor(0, 0, 60);
619 $pdf->SetFont(
'',
'B', $default_font_size + 3);
621 $posx = $this->page_largeur - $this->marge_droite - 100;
622 $posy = $this->marge_haute;
624 $pdf->SetXY($this->marge_gauche, $posy);
627 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
628 if ($this->emetteur->logo) {
629 if (is_readable($logo)) {
631 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
633 $pdf->SetTextColor(200, 0, 0);
634 $pdf->SetFont(
'',
'B', $default_font_size - 2);
635 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
636 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
639 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
642 $pdf->SetFont(
'',
'B', $default_font_size + 3);
643 $pdf->SetXY($posx, $posy);
644 $pdf->SetTextColor(0, 0, 60);
645 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"InterventionCard"),
'',
'R');
647 $pdf->SetFont(
'',
'B', $default_font_size + 2);
650 $pdf->SetXY($posx, $posy);
651 $pdf->SetTextColor(0, 0, 60);
652 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
655 $pdf->SetFont(
'',
'', $default_font_size);
658 $pdf->SetXY($posx, $posy);
659 $pdf->SetTextColor(0, 0, 60);
660 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
662 if (!empty(
$object->ref_client)) {
664 $pdf->SetXY($posx, $posy);
665 $pdf->SetTextColor(0, 0, 60);
666 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
671 $pdf->SetXY($posx, $posy);
672 $pdf->SetTextColor(0, 0, 60);
673 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
678 $carac_emetteur =
'';
679 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
680 if (count($arrayidcontact) > 0) {
681 $object->fetch_user($arrayidcontact[0]);
682 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
683 $carac_emetteur .= $labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs)).
"\n";
689 $posy = 32 + $this->marge_haute;
690 $posx = $this->marge_gauche;
692 $posx = $this->page_largeur - $this->marge_droite - 80;
698 $pdf->SetTextColor(0, 0, 0);
699 $pdf->SetFont(
'',
'', $default_font_size - 2);
700 $pdf->SetXY($posx, $posy);
701 $pdf->SetFillColor(230, 230, 230);
702 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
707 $pdf->SetXY($posx + 2, $posy + 3);
708 $pdf->SetTextColor(0, 0, 60);
709 $pdf->SetFont(
'',
'B', $default_font_size);
710 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
711 $posy = $pdf->getY();
715 $pdf->SetFont(
'',
'', $default_font_size - 1);
716 $pdf->SetXY($posx + 2, $posy);
717 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
721 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
722 if (count($arrayidcontact) > 0) {
724 $result =
$object->fetch_contact($arrayidcontact[0]);
728 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
729 $thirdparty =
$object->contact;
731 $thirdparty =
$object->thirdparty;
740 if ($this->page_largeur < 210) {
743 $posy = 32 + $this->marge_haute;
744 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
746 $posx = $this->marge_gauche;
751 $pdf->SetTextColor(0, 0, 0);
752 $pdf->SetFont(
'',
'', $default_font_size - 2);
753 $pdf->SetXY($posx + 2, $posy - 5);
754 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
755 $pdf->SetTextColor(0, 0, 0);
759 $pdf->SetXY($posx + 2, $posy + 3);
760 $pdf->SetFont(
'',
'B', $default_font_size);
761 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
763 $posy = $pdf->getY();
766 $pdf->SetFont(
'',
'', $default_font_size - 1);
767 $pdf->SetXY($posx + 2, $posy);
768 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
807 $this->defaultContentsFieldsStyle = array(
809 'padding' => array(1, 0.5, 1, 0.5),
813 $this->defaultTitlesFieldsStyle = array(
815 'padding' => array(0.5, 0, 0.5, 0),
819 $this->cols[
'position'] = array(
826 'padding' => array(0.5, 0.5, 0.5, 0.5),
830 'padding' => array(1, 0.5, 1, 1.5),
835 $this->cols[
'desc'] = array(
840 'textkey' =>
'Designation',
842 'padding' => array(0.5, 0.5, 0.5, 0.5),
846 'padding' => array(1, 0.5, 1, 1.5),
851 $this->cols[
'date'] = array(
858 'border-left' =>
true,
865 $this->cols[
'duration'] = array(
870 'textkey' =>
'Duration',
872 'border-left' =>
true,
886 'outputlangs' => $outputlangs,
887 'hidedetails' => $hidedetails,
888 'hidedesc' => $hidedesc,
889 'hideref' => $hideref
892 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
894 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
895 } elseif (empty($reshook)) {
897 $this->cols = array_replace($this->cols, $hookmanager->resArray);
899 $this->cols = $hookmanager->resArray;