124 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
127 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
129 if (!is_object($outputlangs)) {
130 $outputlangs = $langs;
133 if (!empty($conf->global->MAIN_USE_FPDF)) {
134 $outputlangs->charset_output =
'ISO-8859-1';
138 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
140 if (is_array($object->lines)) {
141 $nblines = count($object->lines);
146 if ($conf->product->dir_output) {
148 if ($object->specimen) {
149 $dir = $conf->product->dir_output;
150 $file = $dir.
"/SPECIMEN.pdf";
153 $dir = $conf->product->dir_output.
"/".$objectref;
154 $file = $dir.
"/".$objectref.
".pdf";
158 $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
159 $object->supplierprices = $supplierprices;
161 if (!file_exists($dir)) {
163 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
168 if (file_exists($dir)) {
170 if (!is_object($hookmanager)) {
171 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
174 $hookmanager->initHooks(array(
'pdfgeneration'));
175 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
177 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
182 $pdf->SetAutoPageBreak(1, 0);
184 $heightforinfotot = 40;
185 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
186 $heightforfooter = $this->marge_basse + 8;
187 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
188 $heightforfooter += 6;
191 if (class_exists(
'TCPDF')) {
192 $pdf->setPrintHeader(
false);
193 $pdf->setPrintFooter(
false);
197 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
198 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
199 $tplidx = $pdf->importPage(1);
204 $pdf->SetDrawColor(128, 128, 128);
206 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
207 $pdf->SetSubject($outputlangs->transnoentities(
"Product"));
208 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
209 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
210 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Product"));
212 $pdf->SetCompression(
false);
215 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
220 if (!empty($tplidx)) {
221 $pdf->useTemplate($tplidx);
224 $this->
_pagehead($pdf, $object, 1, $outputlangs);
225 $pdf->SetFont(
'',
'', $default_font_size - 1);
226 $pdf->MultiCell(0, 3,
'');
227 $pdf->SetTextColor(0, 0, 0);
231 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
233 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
236 $pdf->SetFont(
'',
'B', $default_font_size);
237 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top,
dol_htmlentitiesbr($object->label), 0, 1);
238 $nexY = $pdf->GetY();
242 $pdir[0] =
get_exdir($object->id, 2, 0, 0, $object,
'product').$object->id.
"/photos/";
243 $pdir[1] =
get_exdir(0, 0, 0, 0, $object,
'product').dol_sanitizeFileName($object->ref).
'/';
245 $pdir[0] =
get_exdir(0, 0, 0, 0, $object,
'product');
246 $pdir[1] =
get_exdir($object->id, 2, 0, 0, $object,
'product').$object->id.
"/photos/";
250 foreach ($pdir as $midir) {
252 if ($conf->entity != $object->entity) {
253 $dir = $conf->product->multidir_output[$object->entity].
'/'.$midir;
255 $dir = $conf->product->dir_output.
'/'.$midir;
257 foreach ($object->liste_photos($dir, 1) as $key => $obj) {
259 if ($obj[
'photo_vignette']) {
260 $filename = $obj[
'photo_vignette'];
262 $filename = $obj[
'photo'];
265 $filename = $obj[
'photo'];
267 $realpath = $dir.$filename;
273 $imglinesize = array();
274 if (!empty($realpath) && $arephoto) {
276 $imgsizewidth = $imgsize[
'width'] + 20;
277 $imgsizeheight = $imgsize[
'height'] + 20;
279 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
280 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
281 $posyphoto = $tab_top - 1;
282 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight,
'',
'',
'', 2, 300);
283 $nexyafterphoto = $tab_top + $imgsizeheight;
287 $pdf->SetFont(
'',
'', $default_font_size);
288 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY,
dol_htmlentitiesbr($object->description), 0, 1);
289 $nexY = $pdf->GetY();
293 $outputlangs->load(
"other");
294 if ($object->weight) {
296 if (isset($object->weight_units)) {
297 $texttoshow .=
' '.measuring_units_string($object->weight_units,
'weight', 0, 0, $outputlangs);
299 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
300 $nexY = $pdf->GetY();
302 if ($object->length) {
303 $texttoshow = $langs->trans(
"Length") .
' x ' . $langs->trans(
"Width") .
' x ' . $langs->trans(
"Height") .
': ' . ($object->length !=
'' ? $object->length :
'?') .
' x ' . ($object->width !=
'' ? $object->width :
'?') .
' x ' . ($object->height !=
'' ? $object->height :
'?');
305 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
306 $nexY = $pdf->GetY();
308 if ($object->surface) {
311 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
312 $nexY = $pdf->GetY();
314 if ($object->volume) {
317 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
318 $nexY = $pdf->GetY();
322 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
323 $tab_top = $nexyafterphoto;
328 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
335 $pdf->SetFont(
'',
'', $default_font_size - 1);
336 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
337 $nexY = $pdf->GetY();
338 $height_note = $nexY - $tab_top;
341 $pdf->SetDrawColor(192, 192, 192);
342 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
344 $tab_height = $tab_height - $height_note;
345 $tab_top = $nexY + 6;
350 $iniY = $tab_top + 7;
351 $curY = $tab_top + 7;
352 $nexY = $tab_top + 7;
569 $this->
_pagefoot($pdf, $object, $outputlangs);
570 if (method_exists($pdf,
'AliasNbPages')) {
571 $pdf->AliasNbPages();
576 $pdf->Output($file,
'F');
579 $hookmanager->initHooks(array(
'pdfgeneration'));
580 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
582 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
584 $this->error = $hookmanager->error;
585 $this->errors = $hookmanager->errors;
590 $this->result = array(
'fullpath'=>$file);
594 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
598 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PRODUCT_OUTPUTDIR");
617 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
627 $currency = !empty($currency) ? $currency : $conf->currency;
631 $pdf->SetTextColor(0, 0, 0);
632 $pdf->SetFont(
'',
'', $default_font_size - 2);
634 if (empty($hidetop)) {
635 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
636 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
637 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
640 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
641 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
645 $pdf->SetDrawColor(128, 128, 128);
646 $pdf->SetFont(
'',
'', $default_font_size - 1);
649 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
651 if (empty($hidetop)) {
652 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
654 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
655 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
658 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
659 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
660 if (empty($hidetop)) {
661 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
662 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
666 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
667 if (empty($hidetop)) {
668 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
669 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
672 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
673 if (empty($hidetop)) {
674 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
675 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
678 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
679 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
680 if (empty($hidetop)) {
681 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
682 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
686 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
687 if (empty($hidetop)) {
688 if ($this->atleastonediscount) {
689 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
690 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
694 if ($this->atleastonediscount) {
695 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
697 if (empty($hidetop)) {
698 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
699 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHT"),
'',
'C');
714 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey =
"")
716 global $conf, $langs, $hookmanager;
719 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
722 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills",
"orders"));
726 if ($object->type == 1) {
727 $titlekey =
'ServiceSheet';
729 $titlekey =
'ProductSheet';
739 $pdf->SetTextColor(0, 0, 60);
740 $pdf->SetFont(
'',
'B', $default_font_size + 3);
744 $posy = $this->marge_haute;
745 $posx = $this->page_largeur - $this->marge_droite - 100;
747 $pdf->SetXY($this->marge_gauche, $posy);
751 if ($this->emetteur->logo) {
752 $logodir = $conf->mycompany->dir_output;
753 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
754 $logodir = $conf->mycompany->multidir_output[$object->entity];
757 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
759 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
761 if (is_readable($logo)) {
763 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
765 $pdf->SetTextColor(200, 0, 0);
766 $pdf->SetFont(
'',
'B', $default_font_size - 2);
767 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
768 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
771 $text = $this->emetteur->name;
772 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
777 $pdf->SetFont(
'',
'B', $default_font_size + 3);
778 $pdf->SetXY($posx, $posy);
779 $pdf->SetTextColor(0, 0, 60);
780 $title = $outputlangs->transnoentities($titlekey);
781 $pdf->MultiCell(100, 3, $title,
'',
'R');
783 $pdf->SetFont(
'',
'B', $default_font_size);
786 $pdf->SetXY($posx, $posy);
787 $pdf->SetTextColor(0, 0, 60);
788 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
791 $pdf->SetFont(
'',
'', $default_font_size - 1);
826 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
862 $pdf->SetTextColor(0, 0, 0);