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->getAnonymisableFullName($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);
241 $tab_top = 80 + $this->marge_haute;
242 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
244 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
247 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
254 $tab_top = 78 + $this->marge_haute;
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 $issubtotalline = (defined(
'SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
317 $subtotalbgcolor =
null;
319 if ($issubtotalline) {
320 $outputlangs->load(
'subtotals');
321 $level = (int) $objectligne->duration;
322 $linetext = $objectligne->desc;
325 $linetext =
getDolGlobalString(
'SUBTOTAL_LINE_TEXT_DOES_NOT_INCLUDE_TITLE_TEXT') ? $outputlangs->transnoentities(
'SubTotal') : $outputlangs->transnoentities(
'SubtotalOf', $objectligne->desc);
327 $indent = str_repeat(
' ', max(0, abs($level) - 1) * 4);
329 $desc = $indent.($level != 0 ?
'<strong>' :
'').
dol_htmlentitiesbr($linetext, 1).($level != 0 ?
'</strong>' :
'');
336 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'dayhour',
false, $outputlangs,
true);
338 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'day',
false, $outputlangs,
true);
341 if ($objectligne->duration > 0) {
342 $txt .=
" - ".$outputlangs->transnoentities(
"Duration").
" : ".
convertSecondToTime($objectligne->duration);
344 $txt =
'<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).
'</strong>';
349 if ($issubtotalline && is_array($subtotalbgcolor)) {
350 $pdf->startTransaction();
351 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1,
false);
352 $subtotalh = $pdf->GetY() - $curY;
353 $subtotalpage = $pdf->getPage();
354 $pdf->rollbackTransaction(
true);
355 if ($subtotalpage == $pageposbefore) {
356 $pdf->SetFillColor($subtotalbgcolor[0], $subtotalbgcolor[1], $subtotalbgcolor[2]);
357 $pdf->Rect($this->marge_gauche, $curY + 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, max(2, $subtotalh),
'F');
359 $pdf->SetTextColor(255, 255, 255);
364 $pdf->startTransaction();
365 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1,
false);
366 $pageposafter = $pdf->getPage();
367 if ($pageposafter > $pageposbefore) {
368 $pdf->rollbackTransaction(
true);
369 $pageposafter = $pageposbefore;
371 $pdf->setPageOrientation(
'',
true, $heightforfooter);
372 $pdf->writeHTMLCell(0, 0, $curX, $curY,
dol_concatdesc($txt, $desc), 0, 1,
false);
373 $pageposafter = $pdf->getPage();
374 $posyafter = $pdf->GetY();
376 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
377 if ($i == ($nblines - 1)) {
378 $pdf->AddPage(
'',
'',
true);
379 if (!empty($tplidx)) {
380 $pdf->useTemplate($tplidx);
385 $pdf->setPage($pageposafter + 1);
389 $pdf->commitTransaction();
392 if ($issubtotalline) {
393 $pdf->SetTextColor(0, 0, 0);
396 $nexY = $pdf->GetY();
397 $pageposafter = $pdf->getPage();
398 $pdf->setPage($pageposbefore);
399 $pdf->setTopMargin($this->marge_haute);
400 $pdf->setPageOrientation(
'',
true, 0);
403 if ($pageposafter > $pageposbefore) {
404 $pdf->setPage($pageposafter);
405 $curY = $tab_top_newpage;
408 $pdf->SetFont(
'',
'', $default_font_size - 1);
411 while ($pagenb < $pageposafter) {
412 $pdf->setPage($pagenb);
414 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
416 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
420 $pdf->setPage($pagenb);
421 $pdf->setPageOrientation(
'',
true, 0);
425 if (!empty($tplidx)) {
426 $pdf->useTemplate($tplidx);
429 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
431 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
433 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
438 if (!empty($tplidx)) {
439 $pdf->useTemplate($tplidx);
451 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object);
452 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
454 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object);
455 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
459 if (method_exists($pdf,
'AliasNbPages')) {
460 $pdf->AliasNbPages();
464 $pdf->Output($file,
'F');
467 $hookmanager->initHooks(array(
'pdfgeneration'));
468 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
470 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
471 $this->warnings = $hookmanager->warnings;
473 $this->error = $hookmanager->error;
474 $this->errors = $hookmanager->errors;
481 $this->result = array(
'fullpath' => $file);
485 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
489 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
579 global
$conf, $langs;
584 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
589 $pdf->SetTextColor(0, 0, 60);
590 $pdf->SetFont(
'',
'B', $default_font_size + 3);
592 $posx = $this->page_largeur - $this->marge_droite - 100;
593 $posy = $this->marge_haute;
595 $pdf->SetXY($this->marge_gauche, $posy);
598 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
599 if ($this->emetteur->logo) {
600 if (is_readable($logo)) {
602 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
604 $pdf->SetTextColor(200, 0, 0);
605 $pdf->SetFont(
'',
'B', $default_font_size - 2);
606 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
607 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
610 $text = $this->emetteur->name;
611 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
614 $pdf->SetFont(
'',
'B', $default_font_size + 3);
615 $pdf->SetXY($posx, $posy);
616 $pdf->SetTextColor(0, 0, 60);
617 $title = $outputlangs->transnoentities(
"InterventionCard");
618 $pdf->MultiCell(100, 4, $title,
'',
'R');
620 $pdf->SetFont(
'',
'B', $default_font_size + 2);
623 $pdf->SetXY($posx, $posy);
624 $pdf->SetTextColor(0, 0, 60);
625 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
628 $pdf->SetFont(
'',
'', $default_font_size);
631 $pdf->SetXY($posx, $posy);
632 $pdf->SetTextColor(0, 0, 60);
633 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
635 if (!empty(
$object->ref_client)) {
637 $pdf->SetXY($posx, $posy);
638 $pdf->SetTextColor(0, 0, 60);
639 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") .
" : " .
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
645 $pdf->SetXY($posx, $posy);
646 $pdf->SetTextColor(0, 0, 60);
647 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
652 $pdf->SetXY($posx, $posy);
653 $pdf->SetTextColor(0, 0, 60);
654 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
659 $carac_emetteur =
'';
661 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
662 if (count($arrayidcontact) > 0) {
663 $object->fetch_user($arrayidcontact[0]);
664 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
665 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
667 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
671 $carac_emetteur .=
"\n";
677 $posy = 32 + $this->marge_haute;
678 $posx = $this->marge_gauche;
680 $posx = $this->page_largeur - $this->marge_droite - 80;
686 $pdf->SetTextColor(0, 0, 0);
687 $pdf->SetFont(
'',
'', $default_font_size - 2);
688 $pdf->SetXY($posx, $posy - 5);
689 $pdf->SetXY($posx, $posy);
690 $pdf->SetFillColor(230, 230, 230);
691 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
696 $pdf->SetXY($posx + 2, $posy + 3);
697 $pdf->SetTextColor(0, 0, 60);
698 $pdf->SetFont(
'',
'B', $default_font_size);
699 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
700 $posy = $pdf->getY();
704 $pdf->SetFont(
'',
'', $default_font_size - 1);
705 $pdf->SetXY($posx + 2, $posy);
706 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
711 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
712 if (count($arrayidcontact) > 0) {
714 $result =
$object->fetch_contact($arrayidcontact[0]);
718 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
719 $thirdparty =
$object->contact;
721 $thirdparty =
$object->thirdparty;
730 if ($this->page_largeur < 210) {
733 $posy = 32 + $this->marge_haute;
734 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
736 $posx = $this->marge_gauche;
741 $pdf->SetTextColor(0, 0, 0);
742 $pdf->SetFont(
'',
'', $default_font_size - 2);
743 $pdf->SetXY($posx + 2, $posy - 5);
744 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
745 $pdf->SetTextColor(0, 0, 0);
749 $pdf->SetXY($posx + 2, $posy + 3);
750 $pdf->SetFont(
'',
'B', $default_font_size);
751 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
753 $posy = $pdf->getY();
756 $pdf->SetFont(
'',
'', $default_font_size - 1);
757 $pdf->SetXY($posx + 2, $posy);
758 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');