31 require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
61 public $update_main_doc_field;
72 public $phpmin = array(7, 0);
78 public $version =
'dolibarr';
103 public $marge_droite;
134 global $conf, $langs, $mysoc;
137 $this->
name =
'strato';
138 $this->
description = $langs->trans(
"StandardContractsTemplate");
139 $this->update_main_doc_field = 1;
145 $this->page_largeur = $formatarray[
'width'];
146 $this->page_hauteur = $formatarray[
'height'];
147 $this->format = array($this->page_largeur, $this->page_hauteur);
153 $this->option_logo = 1;
154 $this->option_tva = 0;
155 $this->option_modereg = 0;
156 $this->option_condreg = 0;
157 $this->option_multilang = 0;
158 $this->option_draft_watermark = 1;
161 $this->emetteur = $mysoc;
162 if (empty($this->emetteur->country_code)) {
163 $this->emetteur->country_code = substr($langs->defaultlang, -2);
167 $this->posxdesc = $this->marge_gauche + 1;
182 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
185 global $user, $langs, $conf, $hookmanager, $mysoc;
187 if (!is_object($outputlangs)) {
188 $outputlangs = $langs;
191 if (!empty($conf->global->MAIN_USE_FPDF)) {
192 $outputlangs->charset_output =
'ISO-8859-1';
196 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"contracts"));
198 if ($conf->contrat->dir_output) {
199 $object->fetch_thirdparty();
202 if ($object->specimen) {
203 $dir = $conf->contrat->dir_output;
204 $file = $dir.
"/SPECIMEN.pdf";
207 $dir = $conf->contrat->multidir_output[$object->entity].
"/".$objectref;
208 $file = $dir.
"/".$objectref.
".pdf";
211 if (!file_exists($dir)) {
213 $this->error = $outputlangs->trans(
"ErrorCanNotCreateDir", $dir);
218 if (file_exists($dir)) {
220 if (!is_object($hookmanager)) {
221 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
224 $hookmanager->initHooks(array(
'pdfgeneration'));
225 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
227 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
231 $heightforinfotot = 50;
232 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
233 $heightforfooter = $this->marge_basse + 9;
234 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
235 $heightforfooter += 6;
237 $pdf->SetAutoPageBreak(1, 0);
239 if (class_exists(
'TCPDF')) {
240 $pdf->setPrintHeader(
false);
241 $pdf->setPrintFooter(
false);
245 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
246 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
247 $tplidx = $pdf->importPage(1);
252 $pdf->SetDrawColor(128, 128, 128);
254 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
255 $pdf->SetSubject($outputlangs->transnoentities(
"ContractCard"));
256 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
257 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
258 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"ContractCard").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
260 $pdf->SetCompression(
false);
263 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
267 if (!empty($tplidx)) {
268 $pdf->useTemplate($tplidx);
271 $this->
_pagehead($pdf, $object, 1, $outputlangs);
272 $pdf->SetFont(
'',
'', $default_font_size - 1);
273 $pdf->MultiCell(0, 3,
'');
274 $pdf->SetTextColor(0, 0, 0);
277 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
280 if (!empty($object->note_public)) {
283 $pdf->SetFont(
'',
'', $default_font_size - 1);
284 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($object->note_public), 0, 1);
285 $nexY = $pdf->GetY();
286 $height_note = $nexY - $tab_top;
289 $pdf->SetDrawColor(192, 192, 192);
290 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
292 $tab_top = $nexY + 6;
295 $iniY = $tab_top + 7;
296 $curY = $tab_top + 7;
297 $nexY = $tab_top + 2;
299 $pdf->SetXY($this->marge_gauche, $tab_top);
301 $pdf->MultiCell(0, 2,
'');
303 $nblines = count($object->lines);
306 for ($i = 0; $i < $nblines; $i++) {
307 $objectligne = $object->lines[$i];
309 $valide = $objectligne->id ? 1 : 0;
311 if ($valide > 0 || $object->specimen) {
312 $curX = $this->posxdesc - 1;
314 $pdf->SetFont(
'',
'', $default_font_size - 1);
315 $pdf->SetTextColor(0, 0, 0);
317 $pdf->setTopMargin($tab_top_newpage);
318 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
319 $pageposbefore = $pdf->getPage();
323 if (!empty($objectligne->date_start)) {
324 $datei =
dol_print_date((
int) $objectligne->date_start,
'day',
false, $outputlangs,
true);
326 $datei = $langs->trans(
"Unknown");
329 if (!empty($objectligne->date_end)) {
330 $durationi =
convertSecondToTime((
int) $objectligne->date_end - (
int) $objectligne->date_start,
'allwithouthour');
331 $datee =
dol_print_date($objectligne->date_end,
'day',
false, $outputlangs,
true);
333 $durationi = $langs->trans(
"Unknown");
334 $datee = $langs->trans(
"Unknown");
337 if (!empty($objectligne->date_start_real)) {
338 $daters =
dol_print_date((
int) $objectligne->date_start_real,
'day',
false, $outputlangs,
true);
340 $daters = $langs->trans(
"Unknown");
343 if (!empty($objectligne->date_end_real)) {
344 $datere =
dol_print_date((
int) $objectligne->date_end_real,
'day',
false, $outputlangs,
true);
346 $datere = $langs->trans(
"Unknown");
349 $txtpredefinedservice = $objectligne->product_ref;
350 if ($objectligne->product_label) {
351 $txtpredefinedservice .=
' - ';
352 $txtpredefinedservice .= $objectligne->product_label;
357 if (empty($conf->global->CONTRACT_HIDE_QTY_ON_PDF)) {
358 $txt .= $outputlangs->transnoentities(
"Quantity") .
' : <strong>' . $objectligne->qty .
'</strong>';
360 if (empty($conf->global->CONTRACT_HIDE_PRICE_ON_PDF)) {
361 $txt .=
' - ' . $outputlangs->transnoentities(
"UnitPrice") .
' : <strong>' .
price($objectligne->subprice) .
'</strong>';
363 if (empty($conf->global->CONTRACT_HIDE_PLANNED_DATE_ON_PDF)) {
365 $txt .= $outputlangs->transnoentities(
"DateStartPlannedShort").
" : <strong>".$datei.
"</strong> - ".$outputlangs->transnoentities(
"DateEndPlanned").
" : <strong>".$datee.
'</strong>';
367 if (empty($conf->global->CONTRACT_HIDE_REAL_DATE_ON_PDF)) {
369 $txt .= $outputlangs->transnoentities(
"DateStartRealShort").
" : <strong>".$daters.
'</strong>';
370 if (!empty($objectligne->date_end_real)) {
371 $txt .=
" - ".$outputlangs->transnoentities(
"DateEndRealShort").
" : '<strong>'".$datere.
'</strong>';
375 $pdf->startTransaction();
377 $pageposafter = $pdf->getPage();
378 if ($pageposafter > $pageposbefore) {
379 $pdf->rollbackTransaction(
true);
380 $pageposafter = $pageposbefore;
382 $pdf->setPageOrientation(
'', 1, $heightforfooter);
384 $pageposafter = $pdf->getPage();
385 $posyafter = $pdf->GetY();
386 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
387 if ($i == ($nblines - 1)) {
388 $pdf->AddPage(
'',
'',
true);
389 if (!empty($tplidx)) {
390 $pdf->useTemplate($tplidx);
393 $this->
_pagehead($pdf, $object, 0, $outputlangs);
395 $pdf->setPage($pageposafter + 1);
401 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
402 $showpricebeforepagebreak = 1;
404 $showpricebeforepagebreak = 0;
409 $pdf->commitTransaction();
412 $nexY = $pdf->GetY() + 2;
413 $pageposafter = $pdf->getPage();
415 $pdf->setPage($pageposbefore);
416 $pdf->setTopMargin($this->marge_haute);
417 $pdf->setPageOrientation(
'', 1, 0);
420 if ($pageposafter > $pageposbefore) {
421 $pdf->setPage($pageposafter);
422 $curY = $tab_top_newpage;
425 $pdf->SetFont(
'',
'', $default_font_size - 1);
428 while ($pagenb < $pageposafter) {
429 $pdf->setPage($pagenb);
431 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
433 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
435 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
437 $pdf->setPage($pagenb);
438 $pdf->setPageOrientation(
'', 1, 0);
439 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
440 $this->
_pagehead($pdf, $object, 0, $outputlangs);
442 if (!empty($tplidx)) {
443 $pdf->useTemplate($tplidx);
447 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
449 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
451 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
453 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
456 if (!empty($tplidx)) {
457 $pdf->useTemplate($tplidx);
467 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
468 $this->
tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
469 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
471 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
472 $this->
tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
473 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
476 $this->
_pagefoot($pdf, $object, $outputlangs);
477 if (method_exists($pdf,
'AliasNbPages')) {
478 $pdf->AliasNbPages();
483 $pdf->Output($file,
'F');
486 if (!is_object($hookmanager)) {
487 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
490 $hookmanager->initHooks(array(
'pdfgeneration'));
491 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
493 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
495 $this->error = $hookmanager->error;
496 $this->errors = $hookmanager->errors;
501 $this->result = array(
'fullpath'=>$file);
505 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
509 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"CONTRACT_OUTPUTDIR");
527 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
565 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 3);
576 protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
578 $pdf->SetDrawColor(128, 128, 128);
579 $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
580 $posy = $tab_top + $tab_height + 3 + 3;
582 $pdf->SetXY($this->marge_gauche, $posy);
583 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities(
"ContactNameAndSignature", $this->emetteur->name), 0,
'L', 0);
585 $pdf->SetXY($this->marge_gauche, $posy + 5);
586 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 20,
'', 1);
588 $pdf->SetXY($posmiddle + 5, $posy);
589 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities(
"ContactNameAndSignature", $this->recipient->name), 0,
'L', 0);
591 $pdf->SetXY($posmiddle + 5, $posy + 5);
592 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 20,
'', 1);
605 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
607 global $conf, $langs;
612 $outputlangs->loadLangs(array(
"main",
"dict",
"contract",
"companies"));
617 if ($object->statut == 0 && (!empty($conf->global->CONTRACT_DRAFT_WATERMARK))) {
618 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->CONTRACT_DRAFT_WATERMARK);
622 $pdf->SetTextColor(0, 0, 60);
623 $pdf->SetFont(
'',
'B', $default_font_size + 3);
625 $posx = $this->page_largeur - $this->marge_droite - 100;
626 $posy = $this->marge_haute;
628 $pdf->SetXY($this->marge_gauche, $posy);
631 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
632 if ($this->emetteur->logo) {
633 if (is_readable($logo)) {
635 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
637 $pdf->SetTextColor(200, 0, 0);
638 $pdf->SetFont(
'',
'B', $default_font_size - 2);
639 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
640 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
643 $text = $this->emetteur->name;
644 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
647 $pdf->SetFont(
'',
'B', $default_font_size + 3);
648 $pdf->SetXY($posx, $posy);
649 $pdf->SetTextColor(0, 0, 60);
650 $title = $outputlangs->transnoentities(
"ContractCard");
651 $pdf->MultiCell(100, 4, $title,
'',
'R');
653 $pdf->SetFont(
'',
'B', $default_font_size + 2);
656 $pdf->SetXY($posx, $posy);
657 $pdf->SetTextColor(0, 0, 60);
658 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
661 $pdf->SetFont(
'',
'', $default_font_size);
664 $pdf->SetXY($posx, $posy);
665 $pdf->SetTextColor(0, 0, 60);
666 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date_contrat,
"day",
false, $outputlangs,
true),
'',
'R');
668 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
670 $pdf->SetXY($posx, $posy);
671 $pdf->SetTextColor(0, 0, 60);
672 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
677 $carac_emetteur =
'';
679 $arrayidcontact = $object->getIdContact(
'internal',
'INTERREPFOLL');
680 if (count($arrayidcontact) > 0) {
681 $object->fetch_user($arrayidcontact[0]);
682 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$outputlangs->transnoentities(
"Name").
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
685 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
689 $posx = $this->marge_gauche;
690 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
691 $posx = $this->page_largeur - $this->marge_droite - 80;
696 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
697 $pdf->SetTextColor(0, 0, 0);
698 $pdf->SetFont(
'',
'', $default_font_size - 2);
699 $pdf->SetXY($posx, $posy - 5);
700 $pdf->SetXY($posx, $posy);
701 $pdf->SetFillColor(230, 230, 230);
702 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
706 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
707 $pdf->SetXY($posx + 2, $posy + 3);
708 $pdf->SetTextColor(0, 0, 60);
709 $pdf->SetFont(
'',
'B', $default_font_size);
710 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
711 $posy = $pdf->getY();
715 $pdf->SetFont(
'',
'', $default_font_size - 1);
716 $pdf->SetXY($posx + 2, $posy);
717 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
722 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
723 if (count($arrayidcontact) > 0) {
725 $result = $object->fetch_contact($arrayidcontact[0]);
728 $this->recipient = $object->thirdparty;
731 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
732 $thirdparty = $object->contact;
734 $thirdparty = $object->thirdparty;
739 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact :
''), $usecontact,
'target', $object);
743 if ($this->page_largeur < 210) {
747 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
748 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
749 $posx = $this->marge_gauche;
753 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
754 $pdf->SetTextColor(0, 0, 0);
755 $pdf->SetFont(
'',
'', $default_font_size - 2);
756 $pdf->SetXY($posx + 2, $posy - 5);
757 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
758 $pdf->SetTextColor(0, 0, 0);
762 $pdf->SetXY($posx + 2, $posy + 3);
763 $pdf->SetFont(
'',
'B', $default_font_size);
764 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0,
'L');
766 $posy = $pdf->getY();
769 $pdf->SetFont(
'',
'', $default_font_size - 1);
770 $pdf->SetXY($posx + 2, $posy);
771 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
785 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
787 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
788 return pdf_pagefoot($pdf, $outputlangs,
'CONTRACT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);