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(1, 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', 0);
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, 10, $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(
'', 1, $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, 0);
329 $pageposafter = $pdf->getPage();
330 if ($pageposafter > $pageposbefore) {
331 $pdf->rollbackTransaction(
true);
332 $pageposafter = $pageposbefore;
334 $pdf->setPageOrientation(
'', 1, $heightforfooter);
335 $pdf->writeHTMLCell(0, 0, $curX, $curY,
dol_concatdesc($txt, $desc), 0, 1, 0);
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(
'', 1, 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(
'', 1, 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);
431 $this->error = $hookmanager->error;
432 $this->errors = $hookmanager->errors;
437 $this->result = array(
'fullpath' => $file);
441 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
445 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"FICHEINTER_OUTPUTDIR");
535 global $conf, $langs;
540 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"interventions"));
545 $pdf->SetTextColor(0, 0, 60);
546 $pdf->SetFont(
'',
'B', $default_font_size + 3);
548 $posx = $this->page_largeur - $this->marge_droite - 100;
549 $posy = $this->marge_haute;
551 $pdf->SetXY($this->marge_gauche, $posy);
554 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
555 if ($this->emetteur->logo) {
556 if (is_readable($logo)) {
558 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
560 $pdf->SetTextColor(200, 0, 0);
561 $pdf->SetFont(
'',
'B', $default_font_size - 2);
562 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
563 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
566 $text = $this->emetteur->name;
567 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
570 $pdf->SetFont(
'',
'B', $default_font_size + 3);
571 $pdf->SetXY($posx, $posy);
572 $pdf->SetTextColor(0, 0, 60);
573 $title = $outputlangs->transnoentities(
"InterventionCard");
574 $pdf->MultiCell(100, 4, $title,
'',
'R');
576 $pdf->SetFont(
'',
'B', $default_font_size + 2);
579 $pdf->SetXY($posx, $posy);
580 $pdf->SetTextColor(0, 0, 60);
581 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
584 $pdf->SetFont(
'',
'', $default_font_size);
587 $pdf->SetXY($posx, $posy);
588 $pdf->SetTextColor(0, 0, 60);
589 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->datec,
"day",
false, $outputlangs,
true),
'',
'R');
591 if (!empty(
$object->ref_client)) {
593 $pdf->SetXY($posx, $posy);
594 $pdf->SetTextColor(0, 0, 60);
595 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") .
" : " .
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
601 $pdf->SetXY($posx, $posy);
602 $pdf->SetTextColor(0, 0, 60);
603 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
608 $pdf->SetXY($posx, $posy);
609 $pdf->SetTextColor(0, 0, 60);
610 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
615 $carac_emetteur =
'';
617 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
618 if (count($arrayidcontact) > 0) {
619 $object->fetch_user($arrayidcontact[0]);
620 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
621 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
623 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
627 $carac_emetteur .=
"\n";
634 $posx = $this->marge_gauche;
636 $posx = $this->page_largeur - $this->marge_droite - 80;
642 $pdf->SetTextColor(0, 0, 0);
643 $pdf->SetFont(
'',
'', $default_font_size - 2);
644 $pdf->SetXY($posx, $posy - 5);
645 $pdf->SetXY($posx, $posy);
646 $pdf->SetFillColor(230, 230, 230);
647 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
652 $pdf->SetXY($posx + 2, $posy + 3);
653 $pdf->SetTextColor(0, 0, 60);
654 $pdf->SetFont(
'',
'B', $default_font_size);
655 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
656 $posy = $pdf->getY();
660 $pdf->SetFont(
'',
'', $default_font_size - 1);
661 $pdf->SetXY($posx + 2, $posy);
662 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
667 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
668 if (count($arrayidcontact) > 0) {
670 $result =
$object->fetch_contact($arrayidcontact[0]);
674 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
675 $thirdparty =
$object->contact;
677 $thirdparty =
$object->thirdparty;
686 if ($this->page_largeur < 210) {
690 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
692 $posx = $this->marge_gauche;
697 $pdf->SetTextColor(0, 0, 0);
698 $pdf->SetFont(
'',
'', $default_font_size - 2);
699 $pdf->SetXY($posx + 2, $posy - 5);
700 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
701 $pdf->SetTextColor(0, 0, 0);
705 $pdf->SetXY($posx + 2, $posy + 3);
706 $pdf->SetFont(
'',
'B', $default_font_size);
707 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
709 $posy = $pdf->getY();
712 $pdf->SetFont(
'',
'', $default_font_size - 1);
713 $pdf->SetXY($posx + 2, $posy);
714 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');