26 require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
64 public $phpmin = array(7, 0);
70 public $version =
'dolibarr';
86 global $conf, $langs, $mysoc;
89 $langs->loadLangs(array(
"main",
"companies"));
92 $this->
name =
"standard";
93 $this->
description = $langs->trans(
"DocumentModelStandardPDF");
98 $this->page_largeur = $formatarray[
'width'];
99 $this->page_hauteur = $formatarray[
'height'];
100 $this->format = array($this->page_largeur, $this->page_hauteur);
106 $this->option_logo = 1;
107 $this->option_multilang = 1;
108 $this->option_freetext = 0;
111 $this->emetteur = $mysoc;
112 if (!$this->emetteur->country_code) {
113 $this->emetteur->country_code = substr($langs->defaultlang, -2);
130 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
133 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
135 if (!is_object($outputlangs)) {
136 $outputlangs = $langs;
139 if (!empty($conf->global->MAIN_USE_FPDF)) {
140 $outputlangs->charset_output =
'ISO-8859-1';
144 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
146 if (is_array($object->lines)) {
147 $nblines = count($object->lines);
152 if ($conf->product->dir_output) {
154 if ($object->specimen) {
155 $dir = $conf->product->dir_output;
156 $file = $dir.
"/SPECIMEN.pdf";
159 $dir = $conf->product->dir_output.
"/".$objectref;
160 $file = $dir.
"/".$objectref.
".pdf";
164 $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
165 $object->supplierprices = $supplierprices;
167 if (!file_exists($dir)) {
169 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
174 if (file_exists($dir)) {
176 if (!is_object($hookmanager)) {
177 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
180 $hookmanager->initHooks(array(
'pdfgeneration'));
181 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
183 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
188 $pdf->SetAutoPageBreak(1, 0);
190 $heightforinfotot = 40;
191 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
192 $heightforfooter = $this->marge_basse + 8;
193 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
194 $heightforfooter += 6;
197 if (class_exists(
'TCPDF')) {
198 $pdf->setPrintHeader(
false);
199 $pdf->setPrintFooter(
false);
203 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
204 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
205 $tplidx = $pdf->importPage(1);
210 $pdf->SetDrawColor(128, 128, 128);
212 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
213 $pdf->SetSubject($outputlangs->transnoentities(
"Product"));
214 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
215 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
216 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Product"));
218 $pdf->SetCompression(
false);
221 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
226 if (!empty($tplidx)) {
227 $pdf->useTemplate($tplidx);
230 $this->
_pagehead($pdf, $object, 1, $outputlangs);
231 $pdf->SetFont(
'',
'', $default_font_size - 1);
232 $pdf->MultiCell(0, 3,
'');
233 $pdf->SetTextColor(0, 0, 0);
237 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
239 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
242 $pdf->SetFont(
'',
'B', $default_font_size);
243 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top,
dol_htmlentitiesbr($object->label), 0, 1);
244 $nexY = $pdf->GetY();
248 $pdir[0] =
get_exdir($object->id, 2, 0, 0, $object,
'product').$object->id.
"/photos/";
249 $pdir[1] =
get_exdir(0, 0, 0, 0, $object,
'product').dol_sanitizeFileName($object->ref).
'/';
251 $pdir[0] =
get_exdir(0, 0, 0, 0, $object,
'product');
252 $pdir[1] =
get_exdir($object->id, 2, 0, 0, $object,
'product').$object->id.
"/photos/";
256 foreach ($pdir as $midir) {
258 if ($conf->entity != $object->entity) {
259 $dir = $conf->product->multidir_output[$object->entity].
'/'.$midir;
261 $dir = $conf->product->dir_output.
'/'.$midir;
263 foreach ($object->liste_photos($dir, 1) as $key => $obj) {
265 if ($obj[
'photo_vignette']) {
266 $filename = $obj[
'photo_vignette'];
268 $filename = $obj[
'photo'];
271 $filename = $obj[
'photo'];
273 $realpath = $dir.$filename;
279 $imglinesize = array();
280 if (!empty($realpath) && $arephoto) {
282 $imgsizewidth = $imgsize[
'width'] + 20;
283 $imgsizeheight = $imgsize[
'height'] + 20;
285 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
286 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
287 $posyphoto = $tab_top - 1;
288 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight,
'',
'',
'', 2, 300);
289 $nexyafterphoto = $tab_top + $imgsizeheight;
293 $pdf->SetFont(
'',
'', $default_font_size);
294 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY,
dol_htmlentitiesbr($object->description), 0, 1);
295 $nexY = $pdf->GetY();
299 $outputlangs->load(
"other");
300 if ($object->weight) {
302 if (isset($object->weight_units)) {
303 $texttoshow .=
' '.measuring_units_string($object->weight_units,
'weight', 0, 0, $outputlangs);
305 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
306 $nexY = $pdf->GetY();
308 if ($object->length) {
309 $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 :
'?');
311 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
312 $nexY = $pdf->GetY();
314 if ($object->surface) {
317 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
318 $nexY = $pdf->GetY();
320 if ($object->volume) {
323 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
324 $nexY = $pdf->GetY();
328 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
329 $tab_top = $nexyafterphoto;
334 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
341 $pdf->SetFont(
'',
'', $default_font_size - 1);
342 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
343 $nexY = $pdf->GetY();
344 $height_note = $nexY - $tab_top;
347 $pdf->SetDrawColor(192, 192, 192);
348 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
350 $tab_height = $tab_height - $height_note;
351 $tab_top = $nexY + 6;
356 $iniY = $tab_top + 7;
357 $curY = $tab_top + 7;
358 $nexY = $tab_top + 7;
565 $this->
_pagefoot($pdf, $object, $outputlangs);
566 if (method_exists($pdf,
'AliasNbPages')) {
567 $pdf->AliasNbPages();
572 $pdf->Output($file,
'F');
575 $hookmanager->initHooks(array(
'pdfgeneration'));
576 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
578 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
580 $this->error = $hookmanager->error;
581 $this->errors = $hookmanager->errors;
586 $this->result = array(
'fullpath'=>$file);
590 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
594 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PRODUCT_OUTPUTDIR");
613 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
623 $currency = !empty($currency) ? $currency : $conf->currency;
627 $pdf->SetTextColor(0, 0, 0);
628 $pdf->SetFont(
'',
'', $default_font_size - 2);
630 if (empty($hidetop)) {
631 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
632 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
633 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
636 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
637 $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));
641 $pdf->SetDrawColor(128, 128, 128);
642 $pdf->SetFont(
'',
'', $default_font_size - 1);
645 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
647 if (empty($hidetop)) {
648 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
650 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
651 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
654 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
655 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
656 if (empty($hidetop)) {
657 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
658 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
662 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
663 if (empty($hidetop)) {
664 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
665 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
668 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
669 if (empty($hidetop)) {
670 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
671 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
674 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
675 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
676 if (empty($hidetop)) {
677 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
678 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
682 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
683 if (empty($hidetop)) {
684 if ($this->atleastonediscount) {
685 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
686 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
690 if ($this->atleastonediscount) {
691 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
693 if (empty($hidetop)) {
694 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
695 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHT"),
'',
'C');
710 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey =
"")
712 global $conf, $langs, $hookmanager;
715 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
718 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills",
"orders"));
722 if ($object->type == 1) {
723 $titlekey =
'ServiceSheet';
725 $titlekey =
'ProductSheet';
735 $pdf->SetTextColor(0, 0, 60);
736 $pdf->SetFont(
'',
'B', $default_font_size + 3);
740 $posy = $this->marge_haute;
741 $posx = $this->page_largeur - $this->marge_droite - 100;
743 $pdf->SetXY($this->marge_gauche, $posy);
747 if ($this->emetteur->logo) {
748 $logodir = $conf->mycompany->dir_output;
749 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
750 $logodir = $conf->mycompany->multidir_output[$object->entity];
753 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
755 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
757 if (is_readable($logo)) {
759 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
761 $pdf->SetTextColor(200, 0, 0);
762 $pdf->SetFont(
'',
'B', $default_font_size - 2);
763 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
764 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
767 $text = $this->emetteur->name;
768 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
773 $pdf->SetFont(
'',
'B', $default_font_size + 3);
774 $pdf->SetXY($posx, $posy);
775 $pdf->SetTextColor(0, 0, 60);
776 $title = $outputlangs->transnoentities($titlekey);
777 $pdf->MultiCell(100, 3, $title,
'',
'R');
779 $pdf->SetFont(
'',
'B', $default_font_size);
782 $pdf->SetXY($posx, $posy);
783 $pdf->SetTextColor(0, 0, 60);
784 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
787 $pdf->SetFont(
'',
'', $default_font_size - 1);
822 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
858 $pdf->SetTextColor(0, 0, 0);
871 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
873 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
874 return pdf_pagefoot($pdf, $outputlangs,
'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);