131 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
134 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
136 if (!is_object($outputlangs)) {
137 $outputlangs = $langs;
141 $outputlangs->charset_output =
'ISO-8859-1';
145 $outputlangs->loadLangs(array(
"main",
"interventions",
"dict",
"companies"));
152 if ($conf->ficheinter->dir_output) {
157 $dir = $conf->ficheinter->dir_output;
158 $file = $dir.
"/SPECIMEN.pdf";
161 $dir = $conf->ficheinter->dir_output.
"/".$objectref;
162 $file = $dir.
"/".$objectref.
".pdf";
165 if (!file_exists($dir)) {
167 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
172 if (file_exists($dir)) {
174 if (!is_object($hookmanager)) {
175 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
179 $hookmanager->initHooks(array(
'pdfgeneration'));
180 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
182 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
184 $nblines = count(
$object->lines);
189 $heightforinfotot = 50;
190 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
191 $heightforfooter = $this->marge_basse + 8;
193 $heightforfooter += 6;
195 $pdf->SetAutoPageBreak(1, 0);
197 if (class_exists(
'TCPDF')) {
198 $pdf->setPrintHeader(
false);
199 $pdf->setPrintFooter(
false);
204 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
205 $tplidx = $pdf->importPage(1);
210 $pdf->SetDrawColor(128, 128, 128);
212 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
213 $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
214 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
215 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
216 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
218 $pdf->SetCompression(
false);
222 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
226 if (!empty($tplidx)) {
227 $pdf->useTemplate($tplidx);
231 $pdf->SetFont(
'',
'', $default_font_size - 1);
232 $pdf->SetTextColor(0, 0, 0);
235 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
237 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
240 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
249 $pdf->SetFont(
'',
'', $default_font_size - 1);
250 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
251 $nexY = $pdf->GetY();
252 $height_note = $nexY - $tab_top;
255 $pdf->SetDrawColor(192, 192, 192);
256 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
258 $tab_height = $tab_height - $height_note;
259 $tab_top = $nexY + 6;
264 $iniY = $tab_top + 7;
265 $curY = $tab_top + 7;
266 $nexY = $tab_top + 7;
268 $pdf->SetXY($this->marge_gauche, $tab_top);
269 $pdf->MultiCell(190, 5, $outputlangs->transnoentities(
"Description"), 0,
'L', 0);
270 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
272 $pdf->SetFont(
'',
'', $default_font_size - 1);
274 $pdf->SetXY($this->marge_gauche, $tab_top + 5);
278 $text .= ($text ?
' - ' :
'').$langs->trans(
"Total").
": ".$totaltime;
283 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
284 $nexY = $pdf->GetY();
286 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
288 $nblines = count(
$object->lines);
291 for ($i = 0; $i < $nblines; $i++) {
292 $objectligne =
$object->lines[$i];
294 $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
295 if ($valide > 0 ||
$object->specimen) {
297 $pdf->SetFont(
'',
'', $default_font_size - 1);
298 $pdf->SetTextColor(0, 0, 0);
300 $pdf->setTopMargin($tab_top_newpage);
301 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
302 $pageposbefore = $pdf->getPage();
305 $curX = $this->posxdesc - 1;
309 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'dayhour',
false, $outputlangs,
true);
311 $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei,
'day',
false, $outputlangs,
true);
314 if ($objectligne->duration > 0) {
315 $txt .=
" - ".$outputlangs->transnoentities(
"Duration").
" : ".
convertSecondToTime($objectligne->duration);
317 $txt =
'<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).
'</strong>';
320 $pdf->startTransaction();
321 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1,
dol_concatdesc($txt, $desc), 0, 1, 0);
322 $pageposafter = $pdf->getPage();
323 if ($pageposafter > $pageposbefore) {
324 $pdf->rollbackTransaction(
true);
325 $pageposafter = $pageposbefore;
327 $pdf->setPageOrientation(
'', 1, $heightforfooter);
328 $pdf->writeHTMLCell(0, 0, $curX, $curY,
dol_concatdesc($txt, $desc), 0, 1, 0);
329 $pageposafter = $pdf->getPage();
330 $posyafter = $pdf->GetY();
332 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
333 if ($i == ($nblines - 1)) {
334 $pdf->AddPage(
'',
'',
true);
335 if (!empty($tplidx)) {
336 $pdf->useTemplate($tplidx);
341 $pdf->setPage($pageposafter + 1);
345 $pdf->commitTransaction();
348 $nexY = $pdf->GetY();
349 $pageposafter = $pdf->getPage();
350 $pdf->setPage($pageposbefore);
351 $pdf->setTopMargin($this->marge_haute);
352 $pdf->setPageOrientation(
'', 1, 0);
355 if ($pageposafter > $pageposbefore) {
356 $pdf->setPage($pageposafter);
357 $curY = $tab_top_newpage;
360 $pdf->SetFont(
'',
'', $default_font_size - 1);
363 while ($pagenb < $pageposafter) {
364 $pdf->setPage($pagenb);
366 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
368 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
372 $pdf->setPage($pagenb);
373 $pdf->setPageOrientation(
'', 1, 0);
377 if (!empty($tplidx)) {
378 $pdf->useTemplate($tplidx);
381 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
383 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object);
385 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object);
390 if (!empty($tplidx)) {
391 $pdf->useTemplate($tplidx);
403 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object);
404 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
406 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object);
407 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
411 if (method_exists($pdf,
'AliasNbPages')) {
412 $pdf->AliasNbPages();
416 $pdf->Output($file,
'F');
419 $hookmanager->initHooks(array(
'pdfgeneration'));
420 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
422 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
424 $this->error = $hookmanager->error;
425 $this->errors = $hookmanager->errors;
430 $this->result = array(
'fullpath' => $file);
434 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
438 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
528 global $conf, $langs;
533 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
538 $pdf->SetTextColor(0, 0, 60);
539 $pdf->SetFont(
'',
'B', $default_font_size + 3);
541 $posx = $this->page_largeur - $this->marge_droite - 100;
542 $posy = $this->marge_haute;
544 $pdf->SetXY($this->marge_gauche, $posy);
547 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
548 if ($this->emetteur->logo) {
549 if (is_readable($logo)) {
551 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
553 $pdf->SetTextColor(200, 0, 0);
554 $pdf->SetFont(
'',
'B', $default_font_size - 2);
555 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
556 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
559 $text = $this->emetteur->name;
560 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
563 $pdf->SetFont(
'',
'B', $default_font_size + 3);
564 $pdf->SetXY($posx, $posy);
565 $pdf->SetTextColor(0, 0, 60);
566 $title = $outputlangs->transnoentities(
"InterventionCard");
567 $pdf->MultiCell(100, 4, $title,
'',
'R');
569 $pdf->SetFont(
'',
'B', $default_font_size + 2);
572 $pdf->SetXY($posx, $posy);
573 $pdf->SetTextColor(0, 0, 60);
574 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
577 $pdf->SetFont(
'',
'', $default_font_size);
580 $pdf->SetXY($posx, $posy);
581 $pdf->SetTextColor(0, 0, 60);
582 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
584 if (!empty(
$object->ref_client)) {
586 $pdf->SetXY($posx, $posy);
587 $pdf->SetTextColor(0, 0, 60);
588 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") .
" : " .
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
594 $pdf->SetXY($posx, $posy);
595 $pdf->SetTextColor(0, 0, 60);
596 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
601 $carac_emetteur =
'';
603 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
604 if (count($arrayidcontact) > 0) {
605 $object->fetch_user($arrayidcontact[0]);
606 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
607 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
609 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
613 $carac_emetteur .=
"\n";
620 $posx = $this->marge_gauche;
622 $posx = $this->page_largeur - $this->marge_droite - 80;
628 $pdf->SetTextColor(0, 0, 0);
629 $pdf->SetFont(
'',
'', $default_font_size - 2);
630 $pdf->SetXY($posx, $posy - 5);
631 $pdf->SetXY($posx, $posy);
632 $pdf->SetFillColor(230, 230, 230);
633 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
638 $pdf->SetXY($posx + 2, $posy + 3);
639 $pdf->SetTextColor(0, 0, 60);
640 $pdf->SetFont(
'',
'B', $default_font_size);
641 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
642 $posy = $pdf->getY();
646 $pdf->SetFont(
'',
'', $default_font_size - 1);
647 $pdf->SetXY($posx + 2, $posy);
648 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
653 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
654 if (count($arrayidcontact) > 0) {
656 $result =
$object->fetch_contact($arrayidcontact[0]);
660 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
661 $thirdparty =
$object->contact;
663 $thirdparty =
$object->thirdparty;
672 if ($this->page_largeur < 210) {
676 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
678 $posx = $this->marge_gauche;
683 $pdf->SetTextColor(0, 0, 0);
684 $pdf->SetFont(
'',
'', $default_font_size - 2);
685 $pdf->SetXY($posx + 2, $posy - 5);
686 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
687 $pdf->SetTextColor(0, 0, 0);
691 $pdf->SetXY($posx + 2, $posy + 3);
692 $pdf->SetFont(
'',
'B', $default_font_size);
693 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
695 $posy = $pdf->getY();
698 $pdf->SetFont(
'',
'', $default_font_size - 1);
699 $pdf->SetXY($posx + 2, $posy);
700 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');