118 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
121 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
123 if (!is_object($outputlangs)) {
124 $outputlangs = $langs;
128 $outputlangs->charset_output =
'ISO-8859-1';
132 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
134 if (is_array($object->lines)) {
135 $nblines = count($object->lines);
140 if ($conf->product->dir_output) {
142 if ($object->specimen) {
143 $dir = $conf->product->dir_output;
144 $file = $dir.
"/SPECIMEN.pdf";
147 $dir = $conf->product->dir_output.
"/".$objectref;
148 $file = $dir.
"/".$objectref.
".pdf";
152 $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
153 $object->supplierprices = $supplierprices;
155 if (!file_exists($dir)) {
157 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
162 if (file_exists($dir)) {
164 if (!is_object($hookmanager)) {
165 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
168 $hookmanager->initHooks(array(
'pdfgeneration'));
169 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
171 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
176 $pdf->SetAutoPageBreak(1, 0);
178 $heightforinfotot = 40;
179 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
180 $heightforfooter = $this->marge_basse + 8;
182 $heightforfooter += 6;
185 if (class_exists(
'TCPDF')) {
186 $pdf->setPrintHeader(
false);
187 $pdf->setPrintFooter(
false);
192 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
193 $tplidx = $pdf->importPage(1);
198 $pdf->SetDrawColor(128, 128, 128);
200 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
201 $pdf->SetSubject($outputlangs->transnoentities(
"Product"));
202 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
203 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
204 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Product"));
206 $pdf->SetCompression(
false);
209 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
214 if (!empty($tplidx)) {
215 $pdf->useTemplate($tplidx);
218 $this->
_pagehead($pdf, $object, 1, $outputlangs);
219 $pdf->SetFont(
'',
'', $default_font_size - 1);
220 $pdf->MultiCell(0, 3,
'');
221 $pdf->SetTextColor(0, 0, 0);
225 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
227 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
230 $pdf->SetFont(
'',
'B', $default_font_size);
231 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top,
dol_htmlentitiesbr($object->label), 0, 1);
232 $nexY = $pdf->GetY();
236 $pdir[0] =
get_exdir($object->id, 2, 0, 0, $object,
'product').$object->id.
"/photos/";
237 $pdir[1] =
get_exdir(0, 0, 0, 0, $object,
'product').dol_sanitizeFileName($object->ref).
'/';
239 $pdir[0] =
get_exdir(0, 0, 0, 0, $object,
'product');
240 $pdir[1] =
get_exdir($object->id, 2, 0, 0, $object,
'product').$object->id.
"/photos/";
244 foreach ($pdir as $midir) {
246 if ($conf->entity != $object->entity) {
247 $dir = $conf->product->multidir_output[$object->entity].
'/'.$midir;
249 $dir = $conf->product->dir_output.
'/'.$midir;
251 foreach ($object->liste_photos($dir, 1) as $key => $obj) {
253 if ($obj[
'photo_vignette']) {
254 $filename = $obj[
'photo_vignette'];
256 $filename = $obj[
'photo'];
259 $filename = $obj[
'photo'];
261 $realpath = $dir.$filename;
267 $imglinesize = array();
268 if (!empty($realpath) && $arephoto) {
270 $imgsizewidth = $imgsize[
'width'] + 20;
271 $imgsizeheight = $imgsize[
'height'] + 20;
273 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
274 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
275 $posyphoto = $tab_top - 1;
276 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight,
'',
'',
'', 2, 300);
277 $nexyafterphoto = $tab_top + $imgsizeheight;
281 $pdf->SetFont(
'',
'', $default_font_size);
282 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY,
dol_htmlentitiesbr($object->description), 0, 1);
283 $nexY = $pdf->GetY();
287 $outputlangs->load(
"other");
288 if ($object->weight) {
290 if (isset($object->weight_units)) {
291 $texttoshow .=
' '.measuring_units_string($object->weight_units,
'weight', 0, 0, $outputlangs);
293 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
294 $nexY = $pdf->GetY();
296 if ($object->length) {
297 $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 :
'?');
299 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
300 $nexY = $pdf->GetY();
302 if ($object->surface) {
305 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
306 $nexY = $pdf->GetY();
308 if ($object->volume) {
311 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
312 $nexY = $pdf->GetY();
316 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
317 $tab_top = $nexyafterphoto;
322 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
329 $pdf->SetFont(
'',
'', $default_font_size - 1);
330 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
331 $nexY = $pdf->GetY();
332 $height_note = $nexY - $tab_top;
335 $pdf->SetDrawColor(192, 192, 192);
336 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
338 $tab_height = $tab_height - $height_note;
339 $tab_top = $nexY + 6;
344 $iniY = $tab_top + 7;
345 $curY = $tab_top + 7;
346 $nexY = $tab_top + 7;
563 $this->
_pagefoot($pdf, $object, $outputlangs);
564 if (method_exists($pdf,
'AliasNbPages')) {
565 $pdf->AliasNbPages();
570 $pdf->Output($file,
'F');
573 $hookmanager->initHooks(array(
'pdfgeneration'));
574 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
576 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
578 $this->error = $hookmanager->error;
579 $this->errors = $hookmanager->errors;
584 $this->result = array(
'fullpath'=>$file);
588 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
592 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PRODUCT_OUTPUTDIR");
611 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
621 $currency = !empty($currency) ? $currency : $conf->currency;
625 $pdf->SetTextColor(0, 0, 0);
626 $pdf->SetFont(
'',
'', $default_font_size - 2);
628 if (empty($hidetop)) {
629 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
630 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
631 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
635 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
639 $pdf->SetDrawColor(128, 128, 128);
640 $pdf->SetFont(
'',
'', $default_font_size - 1);
643 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
645 if (empty($hidetop)) {
646 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
648 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
649 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
653 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
654 if (empty($hidetop)) {
655 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
656 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
660 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
661 if (empty($hidetop)) {
662 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
663 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
666 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
667 if (empty($hidetop)) {
668 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
669 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
673 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
674 if (empty($hidetop)) {
675 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
676 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
680 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
681 if (empty($hidetop)) {
682 if ($this->atleastonediscount) {
683 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
684 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
688 if ($this->atleastonediscount) {
689 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
691 if (empty($hidetop)) {
692 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
693 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHT"),
'',
'C');
708 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey =
"")
710 global $conf, $langs, $hookmanager;
713 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
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);