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';
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;
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",
"sendings"));
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";
162 if (!file_exists($dir)) {
164 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
169 if (file_exists($dir)) {
171 if (!is_object($hookmanager)) {
172 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
175 $hookmanager->initHooks(array(
'pdfgeneration'));
176 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
178 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
183 $pdf->setAutoPageBreak(
true, 0);
185 $heightforinfotot = 40;
187 $heightforfooter = $this->marge_basse + 8;
189 $heightforfooter += 6;
192 if (class_exists(
'TCPDF')) {
193 $pdf->setPrintHeader(
false);
194 $pdf->setPrintFooter(
false);
199 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
200 $tplidx = $pdf->importPage(1);
205 $pdf->SetDrawColor(128, 128, 128);
207 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
208 $pdf->SetSubject($outputlangs->transnoentities(
"Product"));
209 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
210 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
211 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Product"));
213 $pdf->SetCompression(
false);
217 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
222 if (!empty($tplidx)) {
223 $pdf->useTemplate($tplidx);
227 $pdf->SetFont(
'',
'', $default_font_size - 1);
228 $pdf->MultiCell(0, 3,
'');
229 $pdf->SetTextColor(0, 0, 0);
233 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
235 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
238 $pdf->SetFont(
'',
'B', $default_font_size);
240 $nexY = $pdf->GetY();
253 foreach ($pdir as $midir) {
255 if ($conf->entity !=
$object->entity) {
256 $dir = $conf->product->multidir_output[
$object->entity ?? $conf->entity].
'/'.$midir;
258 $dir = $conf->product->dir_output.
'/'.$midir;
260 foreach (
$object->liste_photos($dir, 1) as $key => $obj) {
262 if ($obj[
'photo_vignette']) {
263 $filename = $obj[
'photo_vignette'];
265 $filename = $obj[
'photo'];
268 $filename = $obj[
'photo'];
270 $realpath = $dir.$filename;
276 $imglinesize = array();
277 $nexyafterphoto =
null;
278 if (!empty($realpath) && $arephoto) {
280 $imgsizewidth = $imgsize[
'width'] + 20;
281 $imgsizeheight = $imgsize[
'height'] + 20;
283 $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
284 $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
285 $posyphoto = $tab_top - 1;
286 $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight,
'',
'',
'', 2, 300);
287 $nexyafterphoto = $tab_top + $imgsizeheight;
291 $pdf->SetFont(
'',
'', $default_font_size);
293 $nexY = $pdf->GetY();
297 $outputlangs->load(
"other");
300 if (isset(
$object->weight_units)) {
301 $texttoshow .=
' '.measuring_units_string(
$object->weight_units,
'weight', 0, 0, $outputlangs);
303 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
304 $nexY = $pdf->GetY();
307 $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 :
'?');
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();
321 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
322 $nexY = $pdf->GetY();
326 if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
327 $tab_top = $nexyafterphoto;
332 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
339 $pdf->SetFont(
'',
'', $default_font_size - 1);
340 $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
341 $nexY = $pdf->GetY();
342 $height_note = $nexY - $tab_top;
345 $pdf->SetDrawColor(192, 192, 192);
346 $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');
348 $tab_height -= $height_note;
349 $tab_top = $nexY + 6;
354 $iniY = $tab_top + 7;
355 $curY = $tab_top + 7;
356 $nexY = $tab_top + 7;
574 if (method_exists($pdf,
'AliasNbPages')) {
575 $pdf->AliasNbPages();
580 $pdf->Output($file,
'F');
583 $hookmanager->initHooks(array(
'pdfgeneration'));
584 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
586 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
587 $this->warnings = $hookmanager->warnings;
589 $this->error = $hookmanager->error;
590 $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 ?? $conf->entity])) {
763 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->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);
869 $pdf->SetTextColor(0, 0, 0);
886 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
887 return pdf_pagefoot($pdf, $outputlangs,
'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur,
$object, $showdetails, $hidefreetext);
if(! $sortfield) if(! $sortorder) $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 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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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_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)
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=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.