28require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
66 public $version =
'dolibarr';
76 global $langs, $mysoc;
79 $langs->loadLangs(array(
"main",
"companies"));
82 $this->
name =
"standard";
83 $this->
description = $langs->trans(
"DocumentModelStandardPDF");
88 $this->page_largeur = $formatarray[
'width'];
89 $this->page_hauteur = $formatarray[
'height'];
90 $this->format = array($this->page_largeur, $this->page_hauteur);
96 $this->option_logo = 1;
97 $this->option_multilang = 1;
98 $this->option_freetext = 0;
101 $this->emetteur = $mysoc;
102 if (!$this->emetteur->country_code) {
103 $this->emetteur->country_code = substr($langs->defaultlang, -2);
120 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
123 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
125 if (!is_object($outputlangs)) {
126 $outputlangs = $langs;
130 $outputlangs->charset_output =
'ISO-8859-1';
134 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
136 if (is_array(
$object->lines)) {
137 $nblines = count(
$object->lines);
142 if ($conf->product->dir_output) {
145 $dir = $conf->product->dir_output;
146 $file = $dir.
"/SPECIMEN.pdf";
149 $dir = $conf->product->dir_output.
"/".$objectref;
150 $file = $dir.
"/".$objectref.
".pdf";
154 $supplierprices = $productFournisseur->list_product_fournisseur_price(
$object->id);
155 $object->supplierprices = $supplierprices;
157 if (!file_exists($dir)) {
159 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
164 if (file_exists($dir)) {
166 if (!is_object($hookmanager)) {
167 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
170 $hookmanager->initHooks(array(
'pdfgeneration'));
171 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
173 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
178 $pdf->SetAutoPageBreak(1, 0);
180 $heightforinfotot = 40;
182 $heightforfooter = $this->marge_basse + 8;
184 $heightforfooter += 6;
187 if (class_exists(
'TCPDF')) {
188 $pdf->setPrintHeader(
false);
189 $pdf->setPrintFooter(
false);
194 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
195 $tplidx = $pdf->importPage(1);
200 $pdf->SetDrawColor(128, 128, 128);
202 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
203 $pdf->SetSubject($outputlangs->transnoentities(
"Product"));
204 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
205 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
206 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Product"));
208 $pdf->SetCompression(
false);
212 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
217 if (!empty($tplidx)) {
218 $pdf->useTemplate($tplidx);
222 $pdf->SetFont(
'',
'', $default_font_size - 1);
223 $pdf->MultiCell(0, 3,
'');
224 $pdf->SetTextColor(0, 0, 0);
228 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
230 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
233 $pdf->SetFont(
'',
'B', $default_font_size);
235 $nexY = $pdf->GetY();
248 foreach ($pdir as $midir) {
250 if ($conf->entity !=
$object->entity) {
251 $dir = $conf->product->multidir_output[
$object->entity].
'/'.$midir;
253 $dir = $conf->product->dir_output.
'/'.$midir;
255 foreach (
$object->liste_photos($dir, 1) as $key => $obj) {
257 if ($obj[
'photo_vignette']) {
258 $filename = $obj[
'photo_vignette'];
260 $filename = $obj[
'photo'];
263 $filename = $obj[
'photo'];
265 $realpath = $dir.$filename;
271 $imglinesize = array();
272 if (!empty($realpath) && $arephoto) {
274 $imgsizewidth = $imgsize[
'width'] + 20;
275 $imgsizeheight = $imgsize[
'height'] + 20;
277 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
278 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
279 $posyphoto = $tab_top - 1;
280 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight,
'',
'',
'', 2, 300);
281 $nexyafterphoto = $tab_top + $imgsizeheight;
285 $pdf->SetFont(
'',
'', $default_font_size);
287 $nexY = $pdf->GetY();
291 $outputlangs->load(
"other");
294 if (isset(
$object->weight_units)) {
295 $texttoshow .=
' '.measuring_units_string(
$object->weight_units,
'weight', 0, 0, $outputlangs);
297 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
298 $nexY = $pdf->GetY();
301 $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 :
'?');
303 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
304 $nexY = $pdf->GetY();
309 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
310 $nexY = $pdf->GetY();
315 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
316 $nexY = $pdf->GetY();
320 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
321 $tab_top = $nexyafterphoto;
326 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
333 $pdf->SetFont(
'',
'', $default_font_size - 1);
334 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
335 $nexY = $pdf->GetY();
336 $height_note = $nexY - $tab_top;
339 $pdf->SetDrawColor(192, 192, 192);
340 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
342 $tab_height -= $height_note;
343 $tab_top = $nexY + 6;
348 $iniY = $tab_top + 7;
349 $curY = $tab_top + 7;
350 $nexY = $tab_top + 7;
568 if (method_exists($pdf,
'AliasNbPages')) {
569 $pdf->AliasNbPages();
574 $pdf->Output($file,
'F');
577 $hookmanager->initHooks(array(
'pdfgeneration'));
578 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
580 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
582 $this->error = $hookmanager->error;
583 $this->errors = $hookmanager->errors;
588 $this->result = array(
'fullpath' => $file);
592 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
596 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PRODUCT_OUTPUTDIR");
615 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
625 $currency = !empty($currency) ? $currency : $conf->currency;
629 $pdf->SetTextColor(0, 0, 0);
630 $pdf->SetFont(
'',
'', $default_font_size - 2);
632 if (empty($hidetop)) {
633 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
634 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
635 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
639 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F', array(), explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
643 $pdf->SetDrawColor(128, 128, 128);
644 $pdf->SetFont(
'',
'', $default_font_size - 1);
647 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
649 if (empty($hidetop)) {
650 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
652 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
653 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
657 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
658 if (empty($hidetop)) {
659 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
660 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
664 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
665 if (empty($hidetop)) {
666 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
667 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
670 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
671 if (empty($hidetop)) {
672 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
673 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
677 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
678 if (empty($hidetop)) {
679 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
680 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
684 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
685 if (empty($hidetop)) {
686 if ($this->atleastonediscount) {
687 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
688 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
692 if ($this->atleastonediscount) {
693 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
695 if (empty($hidetop)) {
696 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
697 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHT"),
'',
'C');
717 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
722 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills",
"orders"));
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);
862 $pdf->SetTextColor(0, 0, 0);
879 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
880 return pdf_pagefoot($pdf, $outputlangs,
'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur,
$object, $showdetails, $hidefreetext);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Parent class to manage intervention document templates.
Class to manage predefined suppliers products.
Class to build documents using ODF templates generator.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.