143 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
146 global $user, $langs,
$conf,
$mysoc, $db, $hookmanager;
148 if (!is_object($outputlangs)) {
149 $outputlangs = $langs;
153 $outputlangs->charset_output =
'ISO-8859-1';
157 $outputlangs->loadLangs(array(
"main",
"interventions",
"dict",
"companies",
"compta"));
164 if (
$conf->ficheinter->dir_output) {
169 $dir =
$conf->ficheinter->dir_output;
170 $file = $dir.
"/SPECIMEN.pdf";
173 $dir =
$conf->ficheinter->dir_output.
"/".$objectref;
174 $file = $dir.
"/".$objectref.
".pdf";
177 if (!file_exists($dir)) {
179 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
184 if (file_exists($dir)) {
186 if (!is_object($hookmanager)) {
187 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
191 $hookmanager->initHooks(array(
'pdfgeneration'));
192 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
194 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
196 $nblines = count(
$object->lines);
201 $heightforinfotot = 50;
203 $heightforfooter = $this->marge_basse + 8;
205 $heightforfooter += 6;
207 $pdf->setAutoPageBreak(
true, 0);
209 if (class_exists(
'TCPDF')) {
210 $pdf->setPrintHeader(
false);
211 $pdf->setPrintFooter(
false);
216 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
217 $tplidx = $pdf->importPage(1);
222 $pdf->SetDrawColor(128, 128, 128);
224 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
225 $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
226 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
227 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
228 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
230 $pdf->SetCompression(
false);
234 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
238 if (!empty($tplidx)) {
239 $pdf->useTemplate($tplidx);
243 $pdf->SetFont(
'',
'', $default_font_size - 1);
244 $pdf->SetTextColor(0, 0, 0);
246 $tab_top = 80 + $this->marge_haute;
247 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
249 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
252 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
259 $tab_top = 78 + $this->marge_haute;
261 $pdf->SetFont(
'',
'', $default_font_size - 1);
262 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
263 $nexY = $pdf->GetY();
264 $height_note = $nexY - $tab_top;
267 $pdf->SetDrawColor(192, 192, 192);
268 $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');
270 $tab_height -= $height_note;
271 $tab_top = $nexY + 6;
276 $iniY = $tab_top + 7;
277 $curY = $tab_top + 7;
278 $nexY = $tab_top + 7;
280 $pdf->SetXY($this->marge_gauche, $tab_top);
281 $pdf->MultiCell(190, 5, $outputlangs->transnoentities(
"Description"), 0,
'L',
false);
282 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
284 $pdf->SetFont(
'',
'', $default_font_size - 1);
286 $pdf->SetXY($this->marge_gauche, $tab_top + 5);
290 $text .= ($text ?
' - ' :
'').$langs->trans(
"Total").
": ".$totaltime;
295 $pdf->writeHTMLCell(180, 3, $this->posxdesc - 1, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
296 $nexY = $pdf->GetY();
298 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
300 $nblines = count(
$object->lines);
303 for ($i = 0; $i < $nblines; $i++) {
304 $objectligne =
$object->lines[$i];
306 $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
307 if ($valide > 0 ||
$object->specimen) {
309 $pdf->SetFont(
'',
'', $default_font_size - 1);
310 $pdf->SetTextColor(0, 0, 0);
312 $pdf->setTopMargin($tab_top_newpage);
313 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
314 $pageposbefore = $pdf->getPage();
317 $curX = $this->posxdesc - 1;
321 $issubtotalline = (defined(
'SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
322 $subtotalbgcolor =
null;
324 if ($issubtotalline) {
325 $outputlangs->load(
'subtotals');
326 $level = (int) $objectligne->duration;
327 $linetext = $objectligne->desc;
330 $linetext =
getDolGlobalString(
'SUBTOTAL_LINE_TEXT_DOES_NOT_INCLUDE_TITLE_TEXT') ? $outputlangs->transnoentities(
'SubTotal') : $outputlangs->transnoentities(
'SubtotalOf', $objectligne->desc);
332 $indent = str_repeat(
' ', max(0, abs($level) - 1) * 4);
334 $desc = $indent.($level != 0 ?
'<strong>' :
'').
dol_htmlentitiesbr($linetext, 1).($level != 0 ?
'</strong>' :
'');
341 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'dayhour',
false, $outputlangs,
true);
343 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'day',
false, $outputlangs,
true);
346 if ($objectligne->duration > 0) {
347 $txt .=
" - ".$outputlangs->transnoentities(
"Duration").
" : ".
convertSecondToTime($objectligne->duration);
349 $txt =
'<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).
'</strong>';
354 if ($issubtotalline && is_array($subtotalbgcolor)) {
355 $pdf->startTransaction();
356 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1,
false);
357 $subtotalh = $pdf->GetY() - $curY;
358 $subtotalpage = $pdf->getPage();
359 $pdf->rollbackTransaction(
true);
360 if ($subtotalpage == $pageposbefore) {
361 $pdf->SetFillColor($subtotalbgcolor[0], $subtotalbgcolor[1], $subtotalbgcolor[2]);
362 $pdf->Rect($this->marge_gauche, $curY + 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, max(2, $subtotalh),
'F');
364 $pdf->SetTextColor(255, 255, 255);
369 $pdf->startTransaction();
370 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1,
false);
371 $pageposafter = $pdf->getPage();
372 if ($pageposafter > $pageposbefore) {
373 $pdf->rollbackTransaction(
true);
374 $pageposafter = $pageposbefore;
376 $pdf->setPageOrientation(
'',
true, $heightforfooter);
377 $pdf->writeHTMLCell(0, 0, $curX, $curY,
dol_concatdesc($txt, $desc), 0, 1,
false);
378 $pageposafter = $pdf->getPage();
379 $posyafter = $pdf->GetY();
381 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
382 if ($i == ($nblines - 1)) {
383 $pdf->AddPage(
'',
'',
true);
384 if (!empty($tplidx)) {
385 $pdf->useTemplate($tplidx);
390 $pdf->setPage($pageposafter + 1);
394 $pdf->commitTransaction();
397 if ($issubtotalline) {
398 $pdf->SetTextColor(0, 0, 0);
401 $nexY = $pdf->GetY();
402 $pageposafter = $pdf->getPage();
403 $pdf->setPage($pageposbefore);
404 $pdf->setTopMargin($this->marge_haute);
405 $pdf->setPageOrientation(
'',
true, 0);
408 if ($pageposafter > $pageposbefore) {
409 $pdf->setPage($pageposafter);
410 $curY = $tab_top_newpage;
413 $pdf->SetFont(
'',
'', $default_font_size - 1);
416 while ($pagenb < $pageposafter) {
417 $pdf->setPage($pagenb);
419 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
421 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
425 $pdf->setPage($pagenb);
426 $pdf->setPageOrientation(
'',
true, 0);
430 if (!empty($tplidx)) {
431 $pdf->useTemplate($tplidx);
434 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
436 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
438 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
443 if (!empty($tplidx)) {
444 $pdf->useTemplate($tplidx);
456 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object);
457 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
459 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object);
460 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
464 if (method_exists($pdf,
'AliasNbPages')) {
465 $pdf->AliasNbPages();
469 $pdf->Output($file,
'F');
472 $hookmanager->initHooks(array(
'pdfgeneration'));
473 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
475 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
476 $this->warnings = $hookmanager->warnings;
478 $this->error = $hookmanager->error;
479 $this->errors = $hookmanager->errors;
486 $this->result = array(
'fullpath' => $file);
490 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
494 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
584 global
$conf, $langs;
589 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
594 $pdf->SetTextColor(0, 0, 60);
595 $pdf->SetFont(
'',
'B', $default_font_size + 3);
597 $posx = $this->page_largeur - $this->marge_droite - 100;
598 $posy = $this->marge_haute;
600 $pdf->SetXY($this->marge_gauche, $posy);
603 $logo =
$conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
604 if ($this->emetteur->logo) {
605 if (is_readable($logo)) {
607 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
609 $pdf->SetTextColor(200, 0, 0);
610 $pdf->SetFont(
'',
'B', $default_font_size - 2);
611 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
612 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
615 $text = $this->emetteur->name;
616 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
619 $pdf->SetFont(
'',
'B', $default_font_size + 3);
620 $pdf->SetXY($posx, $posy);
621 $pdf->SetTextColor(0, 0, 60);
622 $title = $outputlangs->transnoentities(
"InterventionCard");
623 $pdf->MultiCell(100, 4, $title,
'',
'R');
625 $pdf->SetFont(
'',
'B', $default_font_size + 2);
628 $pdf->SetXY($posx, $posy);
629 $pdf->SetTextColor(0, 0, 60);
630 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
633 $pdf->SetFont(
'',
'', $default_font_size);
636 $pdf->SetXY($posx, $posy);
637 $pdf->SetTextColor(0, 0, 60);
638 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
640 if (!empty(
$object->ref_client)) {
642 $pdf->SetXY($posx, $posy);
643 $pdf->SetTextColor(0, 0, 60);
644 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") .
" : " .
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
650 $pdf->SetXY($posx, $posy);
651 $pdf->SetTextColor(0, 0, 60);
652 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
657 $pdf->SetXY($posx, $posy);
658 $pdf->SetTextColor(0, 0, 60);
659 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
664 $carac_emetteur =
'';
666 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
667 if (count($arrayidcontact) > 0) {
668 $object->fetch_user($arrayidcontact[0]);
669 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
670 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
672 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
676 $carac_emetteur .=
"\n";
682 $posy = 32 + $this->marge_haute;
683 $posx = $this->marge_gauche;
685 $posx = $this->page_largeur - $this->marge_droite - 80;
691 $pdf->SetTextColor(0, 0, 0);
692 $pdf->SetFont(
'',
'', $default_font_size - 2);
693 $pdf->SetXY($posx, $posy - 5);
694 $pdf->SetXY($posx, $posy);
695 $pdf->SetFillColor(230, 230, 230);
696 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
701 $pdf->SetXY($posx + 2, $posy + 3);
702 $pdf->SetTextColor(0, 0, 60);
703 $pdf->SetFont(
'',
'B', $default_font_size);
704 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
705 $posy = $pdf->getY();
709 $pdf->SetFont(
'',
'', $default_font_size - 1);
710 $pdf->SetXY($posx + 2, $posy);
711 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
716 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
717 if (count($arrayidcontact) > 0) {
719 $result =
$object->fetch_contact($arrayidcontact[0]);
723 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
724 $thirdparty =
$object->contact;
726 $thirdparty =
$object->thirdparty;
735 if ($this->page_largeur < 210) {
738 $posy = 32 + $this->marge_haute;
739 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
741 $posx = $this->marge_gauche;
746 $pdf->SetTextColor(0, 0, 0);
747 $pdf->SetFont(
'',
'', $default_font_size - 2);
748 $pdf->SetXY($posx + 2, $posy - 5);
749 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
750 $pdf->SetTextColor(0, 0, 0);
754 $pdf->SetXY($posx + 2, $posy + 3);
755 $pdf->SetFont(
'',
'B', $default_font_size);
756 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
758 $posy = $pdf->getY();
761 $pdf->SetFont(
'',
'', $default_font_size - 1);
762 $pdf->SetXY($posx + 2, $posy);
763 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');