150 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
153 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
155 if (!is_object($outputlangs)) {
156 $outputlangs = $langs;
160 $outputlangs->charset_output =
'ISO-8859-1';
164 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"contracts",
"compta"));
171 global $outputlangsbis;
172 $outputlangsbis =
null;
176 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"contracts",
"compta"));
179 $nblines = count(
$object->lines);
181 if (
$conf->contract->multidir_output[
$conf->entity]) {
187 $file = $dir.
"/SPECIMEN.pdf";
191 $file = $dir.
"/".$objectref.
".pdf";
194 if (!file_exists($dir)) {
196 $this->error = $langs->transnoentitiesnoconv(
"ErrorCanNotCreateDir", $dir);
201 if (file_exists($dir)) {
203 if (!is_object($hookmanager)) {
204 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
207 $hookmanager->initHooks(array(
'pdfgeneration'));
208 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
210 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
213 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
218 $pdf->SetAutoPageBreak(1, 0);
220 $heightforinfotot = 50;
222 $heightforfooter = $this->marge_basse + 9;
224 $heightforfooter += 6;
227 if (class_exists(
'TCPDF')) {
228 $pdf->setPrintHeader(
false);
229 $pdf->setPrintFooter(
false);
234 $logodir =
$conf->mycompany->dir_output;
235 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
236 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
238 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
239 $tplidx = $pdf->importPage(1);
244 $pdf->SetDrawColor(128, 128, 128);
246 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
247 $pdf->SetSubject($outputlangs->transnoentities(
"Contract"));
248 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
249 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
250 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Contract").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
252 $pdf->SetCompression(
false);
256 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
260 if (!empty($tplidx)) {
261 $pdf->useTemplate($tplidx);
264 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
265 $pdf->SetFont(
'',
'', $default_font_size - 1);
266 $pdf->MultiCell(0, 3,
'');
267 $pdf->SetTextColor(0, 0, 0);
270 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
273 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
276 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
277 if (!empty($extranote)) {
281 if (!empty($notetoshow)) {
289 $pdf->SetFont(
'',
'', $default_font_size - 1);
290 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
291 $nexY = $pdf->GetY();
292 $height_note = $nexY - $tab_top;
295 $pdf->SetDrawColor(192, 192, 192);
296 $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');
298 $tab_top = $nexY + 6;
301 $iniY = $tab_top + 7;
302 $curY = $tab_top + 7;
303 $nexY = $tab_top + 2;
305 $pdf->SetXY($this->marge_gauche, $tab_top);
307 $pdf->MultiCell(0, 2,
'');
309 $nblines = count(
$object->lines);
312 for ($i = 0; $i < $nblines; $i++) {
313 $objectligne =
$object->lines[$i];
315 $valide = $objectligne->id ? 1 : 0;
317 if ($valide > 0 ||
$object->specimen) {
318 $curX = $this->posxdesc - 1;
320 $pdf->SetFont(
'',
'', $default_font_size - 1);
321 $pdf->SetTextColor(0, 0, 0);
323 $pdf->setTopMargin($tab_top_newpage);
324 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
325 $pageposbefore = $pdf->getPage();
329 if (!empty($objectligne->date_start)) {
330 $datei =
dol_print_date((
int) $objectligne->date_start,
'day',
false, $outputlangs,
true);
332 $datei = $langs->trans(
"Unknown");
335 if (!empty($objectligne->date_end)) {
336 $durationi =
convertSecondToTime((
int) $objectligne->date_end - (
int) $objectligne->date_start,
'allwithouthour');
337 $datee =
dol_print_date($objectligne->date_end,
'day',
false, $outputlangs,
true);
339 $durationi = $langs->trans(
"Unknown");
340 $datee = $langs->trans(
"Unknown");
343 if (!empty($objectligne->date_start_real)) {
344 $daters =
dol_print_date((
int) $objectligne->date_start_real,
'day',
false, $outputlangs,
true);
346 $daters = $langs->trans(
"Unknown");
349 if (!empty($objectligne->date_end_real)) {
350 $datere =
dol_print_date((
int) $objectligne->date_end_real,
'day',
false, $outputlangs,
true);
352 $datere = $langs->trans(
"Unknown");
355 $txtpredefinedservice = $objectligne->product_ref;
356 if ($objectligne->product_label) {
357 $txtpredefinedservice .=
' - ';
358 $txtpredefinedservice .= $objectligne->product_label;
364 $txt .= $outputlangs->transnoentities(
"Quantity") .
' : <strong>' . $objectligne->qty .
'</strong>';
367 $txt .=
' - ' . $outputlangs->transnoentities(
"UnitPrice") .
' : <strong>' .
price($objectligne->subprice) .
'</strong>';
371 $txt .= $outputlangs->transnoentities(
"DateStartPlannedShort").
" : <strong>".$datei.
"</strong> - ".$outputlangs->transnoentities(
"DateEndPlanned").
" : <strong>".$datee.
'</strong>';
375 $txt .= $outputlangs->transnoentities(
"DateStartRealShort").
" : <strong>".$daters.
'</strong>';
376 if (!empty($objectligne->date_end_real)) {
377 $txt .=
" - ".$outputlangs->transnoentities(
"DateEndRealShort").
" : <strong>".$datere.
'</strong>';
381 $pdf->startTransaction();
383 $pageposafter = $pdf->getPage();
384 if ($pageposafter > $pageposbefore) {
385 $pdf->rollbackTransaction(
true);
386 $pageposafter = $pageposbefore;
388 $pdf->setPageOrientation(
'', 1, $heightforfooter);
390 $pageposafter = $pdf->getPage();
391 $posyafter = $pdf->GetY();
392 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
393 if ($i == ($nblines - 1)) {
394 $pdf->AddPage(
'',
'',
true);
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
401 $pdf->setPage($pageposafter + 1);
408 $showpricebeforepagebreak = 1;
410 $showpricebeforepagebreak = 0;
414 $pdf->commitTransaction();
416 $posYAfterDescription = $pdf->GetY();
418 $nexY = $pdf->GetY() + 2;
419 $pageposafter = $pdf->getPage();
421 $pdf->setPage($pageposbefore);
422 $pdf->setTopMargin($this->marge_haute);
423 $pdf->setPageOrientation(
'', 1, 0);
426 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
427 $pdf->setPage($pageposafter);
428 $curY = $tab_top_newpage;
431 $pdf->SetFont(
'',
'', $default_font_size - 1);
434 while ($pagenb < $pageposafter) {
435 $pdf->setPage($pagenb);
437 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
439 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
443 $pdf->setPage($pagenb);
444 $pdf->setPageOrientation(
'', 1, 0);
448 if (!empty($tplidx)) {
449 $pdf->useTemplate($tplidx);
453 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
455 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
457 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
473 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
474 $this->
tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
475 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
477 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
478 $this->
tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
479 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
483 if (method_exists($pdf,
'AliasNbPages')) {
484 $pdf->AliasNbPages();
489 $pdf->Output($file,
'F');
492 $hookmanager->initHooks(array(
'pdfgeneration'));
493 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
495 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
497 $this->error = $hookmanager->error;
498 $this->errors = $hookmanager->errors;
503 $this->result = array(
'fullpath' => $file);
507 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
511 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"CONTRACT_OUTPUTDIR");
615 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"Contract")
623 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
628 $outputlangs->loadLangs(array(
"main",
"dict",
"contract",
"companies"));
634 $pdf->SetTextColor(0, 0, 60);
635 $pdf->SetFont(
'',
'B', $default_font_size + 3);
639 $posy = $this->marge_haute;
640 $posx = $this->page_largeur - $this->marge_droite - $w;
642 $pdf->SetXY($this->marge_gauche, $posy);
646 if ($this->emetteur->logo) {
647 $logodir =
$conf->mycompany->dir_output;
652 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
654 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
656 if (is_readable($logo)) {
658 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
660 $pdf->SetTextColor(200, 0, 0);
661 $pdf->SetFont(
'',
'B', $default_font_size - 2);
662 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
663 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
666 $text = $this->emetteur->name;
667 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
671 $pdf->SetFont(
'',
'B', $default_font_size + 3);
672 $pdf->SetXY($posx, $posy);
673 $pdf->SetTextColor(0, 0, 60);
674 $title = $outputlangs->transnoentities($titlekey);
675 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
676 if (
$object->status == $object::STATUS_DRAFT) {
677 $pdf->SetTextColor(128, 0, 0);
678 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
680 $pdf->MultiCell($w, 3, $title,
'',
'R');
682 $pdf->SetFont(
'',
'B', $default_font_size);
692 $pdf->SetFont(
'',
'', $default_font_size - 1);
695 $pdf->SetXY($posx, $posy);
696 $pdf->SetTextColor(0, 0, 60);
697 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date_contrat,
"day",
false, $outputlangs,
true),
'',
'R');
701 $pdf->SetXY($posx, $posy);
702 $pdf->SetTextColor(0, 0, 60);
703 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
708 $pdf->SetXY($posx, $posy);
709 $pdf->SetTextColor(0, 0, 60);
710 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
715 $carac_emetteur =
'';
717 $arrayidcontact =
$object->getIdContact(
'internal',
'INTERREPFOLL');
718 if (count($arrayidcontact) > 0) {
719 $object->fetch_user($arrayidcontact[0]);
720 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
721 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
723 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
727 $carac_emetteur .=
"\n";
734 $posx = $this->marge_gauche;
736 $posx = $this->page_largeur - $this->marge_droite - 80;
742 $pdf->SetTextColor(0, 0, 0);
743 $pdf->SetFont(
'',
'', $default_font_size - 2);
744 $pdf->SetXY($posx, $posy - 5);
745 $pdf->SetXY($posx, $posy);
746 $pdf->SetFillColor(230, 230, 230);
747 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
748 $pdf->SetTextColor(0, 0, 60);
753 $pdf->SetXY($posx + 2, $posy + 3);
754 $pdf->SetTextColor(0, 0, 60);
755 $pdf->SetFont(
'',
'B', $default_font_size);
756 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
757 $posy = $pdf->getY();
761 $pdf->SetXY($posx + 2, $posy);
762 $pdf->SetFont(
'',
'', $default_font_size - 1);
763 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
768 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
769 if (count($arrayidcontact) > 0) {
771 $result =
$object->fetch_contact($arrayidcontact[0]);
774 $this->recipient =
$object->thirdparty;
777 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id) && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
778 $thirdparty =
$object->contact;
780 $thirdparty =
$object->thirdparty;
790 if ($this->page_largeur < 210) {
795 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
797 $posx = $this->marge_gauche;
802 $pdf->SetTextColor(0, 0, 0);
803 $pdf->SetFont(
'',
'', $default_font_size - 2);
804 $pdf->SetXY($posx + 2, $posy - 5);
805 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
806 $pdf->SetTextColor(0, 0, 0);
810 $pdf->SetXY($posx + 2, $posy + 3);
811 $pdf->SetFont(
'',
'B', $default_font_size);
812 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, $ltrdirection);
814 $posy = $pdf->getY();
817 $pdf->SetFont(
'',
'', $default_font_size - 1);
818 $pdf->SetXY($posx + 2, $posy);
820 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
823 $pdf->SetTextColor(0, 0, 0);