149 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
152 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
154 if (!is_object($outputlangs)) {
155 $outputlangs = $langs;
159 $outputlangs->charset_output =
'ISO-8859-1';
163 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"contracts",
"compta"));
170 global $outputlangsbis;
171 $outputlangsbis =
null;
175 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"contracts",
"compta"));
178 $nblines = count(
$object->lines);
180 if (
$conf->contract->multidir_output[
$conf->entity]) {
186 $file = $dir.
"/SPECIMEN.pdf";
190 $file = $dir.
"/".$objectref.
".pdf";
193 if (!file_exists($dir)) {
195 $this->error = $langs->transnoentitiesnoconv(
"ErrorCanNotCreateDir", $dir);
200 if (file_exists($dir)) {
202 if (!is_object($hookmanager)) {
203 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
206 $hookmanager->initHooks(array(
'pdfgeneration'));
207 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
209 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
212 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
217 $pdf->SetAutoPageBreak(1, 0);
219 $heightforinfotot = 50;
221 $heightforfooter = $this->marge_basse + 9;
223 $heightforfooter += 6;
226 if (class_exists(
'TCPDF')) {
227 $pdf->setPrintHeader(
false);
228 $pdf->setPrintFooter(
false);
233 $logodir =
$conf->mycompany->dir_output;
234 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
235 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
237 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
238 $tplidx = $pdf->importPage(1);
243 $pdf->SetDrawColor(128, 128, 128);
245 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
246 $pdf->SetSubject($outputlangs->transnoentities(
"Contract"));
247 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
248 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
249 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Contract").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
251 $pdf->SetCompression(
false);
255 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
259 if (!empty($tplidx)) {
260 $pdf->useTemplate($tplidx);
263 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
264 $pdf->SetFont(
'',
'', $default_font_size - 1);
265 $pdf->MultiCell(0, 3,
'');
266 $pdf->SetTextColor(0, 0, 0);
269 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
272 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
275 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
276 if (!empty($extranote)) {
280 if (!empty($notetoshow)) {
288 $pdf->SetFont(
'',
'', $default_font_size - 1);
289 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
290 $nexY = $pdf->GetY();
291 $height_note = $nexY - $tab_top;
294 $pdf->SetDrawColor(192, 192, 192);
295 $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');
297 $tab_top = $nexY + 6;
300 $iniY = $tab_top + 7;
301 $curY = $tab_top + 7;
302 $nexY = $tab_top + 2;
304 $pdf->SetXY($this->marge_gauche, $tab_top);
306 $pdf->MultiCell(0, 2,
'');
308 $nblines = count(
$object->lines);
311 for ($i = 0; $i < $nblines; $i++) {
312 $objectligne =
$object->lines[$i];
314 $valide = $objectligne->id ? 1 : 0;
316 if ($valide > 0 ||
$object->specimen) {
317 $curX = $this->posxdesc - 1;
319 $pdf->SetFont(
'',
'', $default_font_size - 1);
320 $pdf->SetTextColor(0, 0, 0);
322 $pdf->setTopMargin($tab_top_newpage);
323 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
324 $pageposbefore = $pdf->getPage();
328 if (!empty($objectligne->date_start)) {
329 $datei =
dol_print_date((
int) $objectligne->date_start,
'day',
false, $outputlangs,
true);
331 $datei = $langs->trans(
"Unknown");
334 if (!empty($objectligne->date_end)) {
335 $durationi =
convertSecondToTime((
int) $objectligne->date_end - (
int) $objectligne->date_start,
'allwithouthour');
336 $datee =
dol_print_date($objectligne->date_end,
'day',
false, $outputlangs,
true);
338 $durationi = $langs->trans(
"Unknown");
339 $datee = $langs->trans(
"Unknown");
342 if (!empty($objectligne->date_start_real)) {
343 $daters =
dol_print_date((
int) $objectligne->date_start_real,
'day',
false, $outputlangs,
true);
345 $daters = $langs->trans(
"Unknown");
348 if (!empty($objectligne->date_end_real)) {
349 $datere =
dol_print_date((
int) $objectligne->date_end_real,
'day',
false, $outputlangs,
true);
351 $datere = $langs->trans(
"Unknown");
354 $txtpredefinedservice = $objectligne->product_ref;
355 if ($objectligne->product_label) {
356 $txtpredefinedservice .=
' - ';
357 $txtpredefinedservice .= $objectligne->product_label;
363 $txt .= $outputlangs->transnoentities(
"Quantity") .
' : <strong>' . $objectligne->qty .
'</strong>';
366 $txt .=
' - ' . $outputlangs->transnoentities(
"UnitPrice") .
' : <strong>' .
price($objectligne->subprice) .
'</strong>';
370 $txt .= $outputlangs->transnoentities(
"DateStartPlannedShort").
" : <strong>".$datei.
"</strong> - ".$outputlangs->transnoentities(
"DateEndPlanned").
" : <strong>".$datee.
'</strong>';
374 $txt .= $outputlangs->transnoentities(
"DateStartRealShort").
" : <strong>".$daters.
'</strong>';
375 if (!empty($objectligne->date_end_real)) {
376 $txt .=
" - ".$outputlangs->transnoentities(
"DateEndRealShort").
" : <strong>".$datere.
'</strong>';
380 $pdf->startTransaction();
382 $pageposafter = $pdf->getPage();
383 if ($pageposafter > $pageposbefore) {
384 $pdf->rollbackTransaction(
true);
385 $pageposafter = $pageposbefore;
387 $pdf->setPageOrientation(
'', 1, $heightforfooter);
389 $pageposafter = $pdf->getPage();
390 $posyafter = $pdf->GetY();
391 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
392 if ($i == ($nblines - 1)) {
393 $pdf->AddPage(
'',
'',
true);
394 if (!empty($tplidx)) {
395 $pdf->useTemplate($tplidx);
400 $pdf->setPage($pageposafter + 1);
407 $showpricebeforepagebreak = 1;
409 $showpricebeforepagebreak = 0;
413 $pdf->commitTransaction();
415 $posYAfterDescription = $pdf->GetY();
417 $nexY = $pdf->GetY() + 2;
418 $pageposafter = $pdf->getPage();
420 $pdf->setPage($pageposbefore);
421 $pdf->setTopMargin($this->marge_haute);
422 $pdf->setPageOrientation(
'', 1, 0);
425 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
426 $pdf->setPage($pageposafter);
427 $curY = $tab_top_newpage;
430 $pdf->SetFont(
'',
'', $default_font_size - 1);
433 while ($pagenb < $pageposafter) {
434 $pdf->setPage($pagenb);
436 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
438 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
442 $pdf->setPage($pagenb);
443 $pdf->setPageOrientation(
'', 1, 0);
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
452 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
454 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
456 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
461 if (!empty($tplidx)) {
462 $pdf->useTemplate($tplidx);
472 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
473 $this->
tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
474 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
476 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
477 $this->
tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
478 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
482 if (method_exists($pdf,
'AliasNbPages')) {
483 $pdf->AliasNbPages();
488 $pdf->Output($file,
'F');
491 $hookmanager->initHooks(array(
'pdfgeneration'));
492 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
494 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
496 $this->error = $hookmanager->error;
497 $this->errors = $hookmanager->errors;
502 $this->result = array(
'fullpath' => $file);
506 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
510 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"CONTRACT_OUTPUTDIR");
614 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"Contract")
622 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
627 $outputlangs->loadLangs(array(
"main",
"dict",
"contract",
"companies"));
633 $pdf->SetTextColor(0, 0, 60);
634 $pdf->SetFont(
'',
'B', $default_font_size + 3);
638 $posy = $this->marge_haute;
639 $posx = $this->page_largeur - $this->marge_droite - $w;
641 $pdf->SetXY($this->marge_gauche, $posy);
645 if ($this->emetteur->logo) {
646 $logodir =
$conf->mycompany->dir_output;
651 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
653 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
655 if (is_readable($logo)) {
657 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
659 $pdf->SetTextColor(200, 0, 0);
660 $pdf->SetFont(
'',
'B', $default_font_size - 2);
661 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
662 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
665 $text = $this->emetteur->name;
666 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
670 $pdf->SetFont(
'',
'B', $default_font_size + 3);
671 $pdf->SetXY($posx, $posy);
672 $pdf->SetTextColor(0, 0, 60);
673 $title = $outputlangs->transnoentities($titlekey);
674 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
675 if (
$object->status == $object::STATUS_DRAFT) {
676 $pdf->SetTextColor(128, 0, 0);
677 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
679 $pdf->MultiCell($w, 3, $title,
'',
'R');
681 $pdf->SetFont(
'',
'B', $default_font_size);
691 $pdf->SetFont(
'',
'', $default_font_size - 1);
694 $pdf->SetXY($posx, $posy);
695 $pdf->SetTextColor(0, 0, 60);
696 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_contrat,
"day",
false, $outputlangs,
true),
'',
'R');
700 $pdf->SetXY($posx, $posy);
701 $pdf->SetTextColor(0, 0, 60);
702 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
707 $pdf->SetXY($posx, $posy);
708 $pdf->SetTextColor(0, 0, 60);
709 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
714 $carac_emetteur =
'';
716 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
717 if (count($arrayidcontact) > 0) {
718 $object->fetch_user($arrayidcontact[0]);
719 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
720 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
722 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
726 $carac_emetteur .=
"\n";
733 $posx = $this->marge_gauche;
735 $posx = $this->page_largeur - $this->marge_droite - 80;
741 $pdf->SetTextColor(0, 0, 0);
742 $pdf->SetFont(
'',
'', $default_font_size - 2);
743 $pdf->SetXY($posx, $posy - 5);
744 $pdf->SetXY($posx, $posy);
745 $pdf->SetFillColor(230, 230, 230);
746 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
747 $pdf->SetTextColor(0, 0, 60);
752 $pdf->SetXY($posx + 2, $posy + 3);
753 $pdf->SetTextColor(0, 0, 60);
754 $pdf->SetFont(
'',
'B', $default_font_size);
755 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
756 $posy = $pdf->getY();
760 $pdf->SetXY($posx + 2, $posy);
761 $pdf->SetFont(
'',
'', $default_font_size - 1);
762 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
767 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
768 if (count($arrayidcontact) > 0) {
770 $result =
$object->fetch_contact($arrayidcontact[0]);
773 $this->recipient =
$object->thirdparty;
776 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id) && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
777 $thirdparty =
$object->contact;
779 $thirdparty =
$object->thirdparty;
789 if ($this->page_largeur < 210) {
794 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
796 $posx = $this->marge_gauche;
801 $pdf->SetTextColor(0, 0, 0);
802 $pdf->SetFont(
'',
'', $default_font_size - 2);
803 $pdf->SetXY($posx + 2, $posy - 5);
804 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
805 $pdf->SetTextColor(0, 0, 0);
809 $pdf->SetXY($posx + 2, $posy + 3);
810 $pdf->SetFont(
'',
'B', $default_font_size);
811 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, $ltrdirection);
813 $posy = $pdf->getY();
816 $pdf->SetFont(
'',
'', $default_font_size - 1);
817 $pdf->SetXY($posx + 2, $posy);
819 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
822 $pdf->SetTextColor(0, 0, 0);