138 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
141 global $user, $langs, $conf,
$mysoc, $db, $hookmanager;
143 if (!is_object($outputlangs)) {
144 $outputlangs = $langs;
148 $outputlangs->charset_output =
'ISO-8859-1';
152 $outputlangs->loadLangs(array(
"main",
"interventions",
"dict",
"companies",
"compta"));
159 if ($conf->ficheinter->dir_output) {
164 $dir = $conf->ficheinter->dir_output;
165 $file = $dir.
"/SPECIMEN.pdf";
168 $dir = $conf->ficheinter->dir_output.
"/".$objectref;
169 $file = $dir.
"/".$objectref.
".pdf";
172 if (!file_exists($dir)) {
174 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
179 if (file_exists($dir)) {
181 if (!is_object($hookmanager)) {
182 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
186 $hookmanager->initHooks(array(
'pdfgeneration'));
187 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
189 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
191 $nblines = count(
$object->lines);
196 $heightforinfotot = 50;
198 $heightforfooter = $this->marge_basse + 8;
200 $heightforfooter += 6;
202 $pdf->setAutoPageBreak(
true, 0);
204 if (class_exists(
'TCPDF')) {
205 $pdf->setPrintHeader(
false);
206 $pdf->setPrintFooter(
false);
211 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
212 $tplidx = $pdf->importPage(1);
217 $pdf->SetDrawColor(128, 128, 128);
219 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
220 $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
221 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
222 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
223 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
225 $pdf->SetCompression(
false);
229 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
233 if (!empty($tplidx)) {
234 $pdf->useTemplate($tplidx);
238 $pdf->SetFont(
'',
'', $default_font_size - 1);
239 $pdf->SetTextColor(0, 0, 0);
242 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
244 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
247 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
256 $pdf->SetFont(
'',
'', $default_font_size - 1);
257 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
258 $nexY = $pdf->GetY();
259 $height_note = $nexY - $tab_top;
262 $pdf->SetDrawColor(192, 192, 192);
263 $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');
265 $tab_height -= $height_note;
266 $tab_top = $nexY + 6;
271 $iniY = $tab_top + 7;
272 $curY = $tab_top + 7;
273 $nexY = $tab_top + 7;
275 $pdf->SetXY($this->marge_gauche, $tab_top);
276 $pdf->MultiCell(190, 5, $outputlangs->transnoentities(
"Description"), 0,
'L',
false);
277 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
279 $pdf->SetFont(
'',
'', $default_font_size - 1);
281 $pdf->SetXY($this->marge_gauche, $tab_top + 5);
285 $text .= ($text ?
' - ' :
'').$langs->trans(
"Total").
": ".$totaltime;
290 $pdf->writeHTMLCell(180, 3, $this->posxdesc - 1, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
291 $nexY = $pdf->GetY();
293 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
295 $nblines = count(
$object->lines);
298 for ($i = 0; $i < $nblines; $i++) {
299 $objectligne =
$object->lines[$i];
301 $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
302 if ($valide > 0 ||
$object->specimen) {
304 $pdf->SetFont(
'',
'', $default_font_size - 1);
305 $pdf->SetTextColor(0, 0, 0);
307 $pdf->setTopMargin($tab_top_newpage);
308 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
309 $pageposbefore = $pdf->getPage();
312 $curX = $this->posxdesc - 1;
316 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'dayhour',
false, $outputlangs,
true);
318 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'day',
false, $outputlangs,
true);
321 if ($objectligne->duration > 0) {
322 $txt .=
" - ".$outputlangs->transnoentities(
"Duration").
" : ".
convertSecondToTime($objectligne->duration);
324 $txt =
'<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).
'</strong>';
327 $pdf->startTransaction();
328 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1,
false);
329 $pageposafter = $pdf->getPage();
330 if ($pageposafter > $pageposbefore) {
331 $pdf->rollbackTransaction(
true);
332 $pageposafter = $pageposbefore;
334 $pdf->setPageOrientation(
'',
true, $heightforfooter);
335 $pdf->writeHTMLCell(0, 0, $curX, $curY,
dol_concatdesc($txt, $desc), 0, 1,
false);
336 $pageposafter = $pdf->getPage();
337 $posyafter = $pdf->GetY();
339 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
340 if ($i == ($nblines - 1)) {
341 $pdf->AddPage(
'',
'',
true);
342 if (!empty($tplidx)) {
343 $pdf->useTemplate($tplidx);
348 $pdf->setPage($pageposafter + 1);
352 $pdf->commitTransaction();
355 $nexY = $pdf->GetY();
356 $pageposafter = $pdf->getPage();
357 $pdf->setPage($pageposbefore);
358 $pdf->setTopMargin($this->marge_haute);
359 $pdf->setPageOrientation(
'',
true, 0);
362 if ($pageposafter > $pageposbefore) {
363 $pdf->setPage($pageposafter);
364 $curY = $tab_top_newpage;
367 $pdf->SetFont(
'',
'', $default_font_size - 1);
370 while ($pagenb < $pageposafter) {
371 $pdf->setPage($pagenb);
373 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
375 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
379 $pdf->setPage($pagenb);
380 $pdf->setPageOrientation(
'',
true, 0);
384 if (!empty($tplidx)) {
385 $pdf->useTemplate($tplidx);
388 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
390 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
392 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
397 if (!empty($tplidx)) {
398 $pdf->useTemplate($tplidx);
410 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object);
411 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
413 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object);
414 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
418 if (method_exists($pdf,
'AliasNbPages')) {
419 $pdf->AliasNbPages();
423 $pdf->Output($file,
'F');
426 $hookmanager->initHooks(array(
'pdfgeneration'));
427 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
429 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
430 $this->warnings = $hookmanager->warnings;
432 $this->error = $hookmanager->error;
433 $this->errors = $hookmanager->errors;
440 $this->result = array(
'fullpath' => $file);
444 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
448 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
538 global $conf, $langs;
543 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
548 $pdf->SetTextColor(0, 0, 60);
549 $pdf->SetFont(
'',
'B', $default_font_size + 3);
551 $posx = $this->page_largeur - $this->marge_droite - 100;
552 $posy = $this->marge_haute;
554 $pdf->SetXY($this->marge_gauche, $posy);
557 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
558 if ($this->emetteur->logo) {
559 if (is_readable($logo)) {
561 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
563 $pdf->SetTextColor(200, 0, 0);
564 $pdf->SetFont(
'',
'B', $default_font_size - 2);
565 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
566 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
569 $text = $this->emetteur->name;
570 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
573 $pdf->SetFont(
'',
'B', $default_font_size + 3);
574 $pdf->SetXY($posx, $posy);
575 $pdf->SetTextColor(0, 0, 60);
576 $title = $outputlangs->transnoentities(
"InterventionCard");
577 $pdf->MultiCell(100, 4, $title,
'',
'R');
579 $pdf->SetFont(
'',
'B', $default_font_size + 2);
582 $pdf->SetXY($posx, $posy);
583 $pdf->SetTextColor(0, 0, 60);
584 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
587 $pdf->SetFont(
'',
'', $default_font_size);
590 $pdf->SetXY($posx, $posy);
591 $pdf->SetTextColor(0, 0, 60);
592 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
594 if (!empty(
$object->ref_client)) {
596 $pdf->SetXY($posx, $posy);
597 $pdf->SetTextColor(0, 0, 60);
598 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") .
" : " .
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
604 $pdf->SetXY($posx, $posy);
605 $pdf->SetTextColor(0, 0, 60);
606 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
611 $pdf->SetXY($posx, $posy);
612 $pdf->SetTextColor(0, 0, 60);
613 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
618 $carac_emetteur =
'';
620 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
621 if (count($arrayidcontact) > 0) {
622 $object->fetch_user($arrayidcontact[0]);
623 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
624 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
626 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
630 $carac_emetteur .=
"\n";
637 $posx = $this->marge_gauche;
639 $posx = $this->page_largeur - $this->marge_droite - 80;
645 $pdf->SetTextColor(0, 0, 0);
646 $pdf->SetFont(
'',
'', $default_font_size - 2);
647 $pdf->SetXY($posx, $posy - 5);
648 $pdf->SetXY($posx, $posy);
649 $pdf->SetFillColor(230, 230, 230);
650 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
655 $pdf->SetXY($posx + 2, $posy + 3);
656 $pdf->SetTextColor(0, 0, 60);
657 $pdf->SetFont(
'',
'B', $default_font_size);
658 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
659 $posy = $pdf->getY();
663 $pdf->SetFont(
'',
'', $default_font_size - 1);
664 $pdf->SetXY($posx + 2, $posy);
665 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
670 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
671 if (count($arrayidcontact) > 0) {
673 $result =
$object->fetch_contact($arrayidcontact[0]);
677 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
678 $thirdparty =
$object->contact;
680 $thirdparty =
$object->thirdparty;
689 if ($this->page_largeur < 210) {
693 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
695 $posx = $this->marge_gauche;
700 $pdf->SetTextColor(0, 0, 0);
701 $pdf->SetFont(
'',
'', $default_font_size - 2);
702 $pdf->SetXY($posx + 2, $posy - 5);
703 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
704 $pdf->SetTextColor(0, 0, 0);
708 $pdf->SetXY($posx + 2, $posy + 3);
709 $pdf->SetFont(
'',
'B', $default_font_size);
710 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
712 $posy = $pdf->getY();
715 $pdf->SetFont(
'',
'', $default_font_size - 1);
716 $pdf->SetXY($posx + 2, $posy);
717 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');