29require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
67 public $version =
'dolibarr';
77 global $langs, $mysoc;
80 $langs->loadLangs(array(
"main",
"companies"));
83 $this->
name =
"standard";
84 $this->
description = $langs->trans(
"DocumentModelStandardPDF");
89 $this->page_largeur = $formatarray[
'width'];
90 $this->page_hauteur = $formatarray[
'height'];
91 $this->format = array($this->page_largeur, $this->page_hauteur);
96 $this->corner_radius =
getDolGlobalInt(
'MAIN_PDF_FRAME_CORNER_RADIUS', 0);
97 $this->option_logo = 1;
98 $this->option_multilang = 1;
99 $this->option_freetext = 0;
102 $this->posxdesc = $this->marge_gauche + 1;
104 if ($mysoc ===
null) {
110 $this->emetteur = $mysoc;
111 if (!$this->emetteur->country_code) {
112 $this->emetteur->country_code = substr($langs->defaultlang, -2);
129 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
132 global $user, $langs,
$conf, $mysoc, $db, $hookmanager;
134 if (!is_object($outputlangs)) {
135 $outputlangs = $langs;
139 $outputlangs->charset_output =
'ISO-8859-1';
143 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
145 if (is_array(
$object->lines)) {
146 $nblines = count(
$object->lines);
151 if (
$conf->product->dir_output) {
154 $dir =
$conf->product->dir_output;
155 $file = $dir.
"/SPECIMEN.pdf";
158 $dir =
$conf->product->dir_output.
"/".$objectref;
159 $file = $dir.
"/".$objectref.
".pdf";
163 $supplierprices = $productFournisseur->list_product_fournisseur_price(
$object->id);
164 $object->supplierprices = $supplierprices;
166 if (!file_exists($dir)) {
168 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
173 if (file_exists($dir)) {
175 if (!is_object($hookmanager)) {
176 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
179 $hookmanager->initHooks(array(
'pdfgeneration'));
180 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
182 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
187 $pdf->SetAutoPageBreak(1, 0);
189 $heightforinfotot = 40;
191 $heightforfooter = $this->marge_basse + 8;
193 $heightforfooter += 6;
196 if (class_exists(
'TCPDF')) {
197 $pdf->setPrintHeader(
false);
198 $pdf->setPrintFooter(
false);
203 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
204 $tplidx = $pdf->importPage(1);
209 $pdf->SetDrawColor(128, 128, 128);
211 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
212 $pdf->SetSubject($outputlangs->transnoentities(
"Product"));
213 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
214 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
215 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Product"));
217 $pdf->SetCompression(
false);
221 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
226 if (!empty($tplidx)) {
227 $pdf->useTemplate($tplidx);
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);
244 $nexY = $pdf->GetY();
257 foreach ($pdir as $midir) {
260 $dir =
$conf->product->multidir_output[
$object->entity].
'/'.$midir;
262 $dir =
$conf->product->dir_output.
'/'.$midir;
264 foreach (
$object->liste_photos($dir, 1) as $key => $obj) {
266 if ($obj[
'photo_vignette']) {
267 $filename = $obj[
'photo_vignette'];
269 $filename = $obj[
'photo'];
272 $filename = $obj[
'photo'];
274 $realpath = $dir.$filename;
280 $imglinesize = array();
281 if (!empty($realpath) && $arephoto) {
283 $imgsizewidth = $imgsize[
'width'] + 20;
284 $imgsizeheight = $imgsize[
'height'] + 20;
286 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
287 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
288 $posyphoto = $tab_top - 1;
289 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight,
'',
'',
'', 2, 300);
290 $nexyafterphoto = $tab_top + $imgsizeheight;
294 $pdf->SetFont(
'',
'', $default_font_size);
296 $nexY = $pdf->GetY();
300 $outputlangs->load(
"other");
303 if (isset(
$object->weight_units)) {
304 $texttoshow .=
' '.measuring_units_string(
$object->weight_units,
'weight', 0, 0, $outputlangs);
306 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
307 $nexY = $pdf->GetY();
310 $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 :
'?');
312 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
313 $nexY = $pdf->GetY();
318 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
319 $nexY = $pdf->GetY();
324 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
325 $nexY = $pdf->GetY();
329 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
330 $tab_top = $nexyafterphoto;
335 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
342 $pdf->SetFont(
'',
'', $default_font_size - 1);
343 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
344 $nexY = $pdf->GetY();
345 $height_note = $nexY - $tab_top;
348 $pdf->SetDrawColor(192, 192, 192);
349 $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');
351 $tab_height -= $height_note;
352 $tab_top = $nexY + 6;
357 $iniY = $tab_top + 7;
358 $curY = $tab_top + 7;
359 $nexY = $tab_top + 7;
577 if (method_exists($pdf,
'AliasNbPages')) {
578 $pdf->AliasNbPages();
583 $pdf->Output($file,
'F');
586 $hookmanager->initHooks(array(
'pdfgeneration'));
587 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
589 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
591 $this->error = $hookmanager->error;
592 $this->errors = $hookmanager->errors;
597 $this->result = array(
'fullpath' => $file);
601 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
605 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PRODUCT_OUTPUTDIR");
624 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
634 $currency = !empty($currency) ? $currency :
$conf->currency;
638 $pdf->SetTextColor(0, 0, 0);
639 $pdf->SetFont(
'',
'', $default_font_size - 2);
641 if (empty($hidetop)) {
642 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
643 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
644 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
648 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F', array(), explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
652 $pdf->SetDrawColor(128, 128, 128);
653 $pdf->SetFont(
'',
'', $default_font_size - 1);
656 $this->
printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
658 if (empty($hidetop)) {
659 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
661 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
662 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
666 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
667 if (empty($hidetop)) {
668 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
669 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
673 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
674 if (empty($hidetop)) {
675 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
676 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
679 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
680 if (empty($hidetop)) {
681 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
682 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
686 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
687 if (empty($hidetop)) {
688 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
689 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
693 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
694 if (empty($hidetop)) {
695 if ($this->atleastonediscount) {
696 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
697 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
701 if ($this->atleastonediscount) {
702 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
704 if (empty($hidetop)) {
705 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
706 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHT"),
'',
'C');
726 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
731 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills",
"orders"));
736 $titlekey =
'ServiceSheet';
738 $titlekey =
'ProductSheet';
748 $pdf->SetTextColor(0, 0, 60);
749 $pdf->SetFont(
'',
'B', $default_font_size + 3);
753 $posy = $this->marge_haute;
754 $posx = $this->page_largeur - $this->marge_droite - 100;
756 $pdf->SetXY($this->marge_gauche, $posy);
760 if ($this->emetteur->logo) {
761 $logodir =
$conf->mycompany->dir_output;
762 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
763 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
766 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
768 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
770 if (is_readable($logo)) {
772 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
774 $pdf->SetTextColor(200, 0, 0);
775 $pdf->SetFont(
'',
'B', $default_font_size - 2);
776 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
777 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
780 $text = $this->emetteur->name;
781 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
786 $pdf->SetFont(
'',
'B', $default_font_size + 3);
787 $pdf->SetXY($posx, $posy);
788 $pdf->SetTextColor(0, 0, 60);
789 $title = $outputlangs->transnoentities($titlekey);
790 $pdf->MultiCell(100, 3, $title,
'',
'R');
792 $pdf->SetFont(
'',
'B', $default_font_size);
795 $pdf->SetXY($posx, $posy);
796 $pdf->SetTextColor(0, 0, 60);
797 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
800 $pdf->SetFont(
'',
'', $default_font_size - 1);
871 $pdf->SetTextColor(0, 0, 0);
888 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
889 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
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the 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...
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
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($unitid, $measuring_style='', $unitscale='', $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.