Skip to content
Snippets Groups Projects
Commit 6a1446f4 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Add option MAIN_GENERATE_DOCUMENT_WITH_PICTURE

parent a1e76636
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ For users: ...@@ -27,6 +27,7 @@ For users:
- New: Add new graphical boxes (customer invoices and orders per month). - New: Add new graphical boxes (customer invoices and orders per month).
- New: [ task #286 ] Enhance rounding function of prices to allow round of sum instead of sum of rounding. - New: [ task #286 ] Enhance rounding function of prices to allow round of sum instead of sum of rounding.
- New: Can add an event automatically when a projet is create. - New: Can add an event automatically when a projet is create.
- New: Add option MAIN_GENERATE_DOCUMENT_WITH_PICTURE.
- Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). - Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error).
For translators: For translators:
......
...@@ -396,6 +396,9 @@ class Conf ...@@ -396,6 +396,9 @@ class Conf
if (! isset($this->global->MAIN_MAX_DECIMALS_TOT)) $this->global->MAIN_MAX_DECIMALS_TOT=2; if (! isset($this->global->MAIN_MAX_DECIMALS_TOT)) $this->global->MAIN_MAX_DECIMALS_TOT=2;
if (! isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) $this->global->MAIN_MAX_DECIMALS_SHOWN=8; if (! isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) $this->global->MAIN_MAX_DECIMALS_SHOWN=8;
// Default pdf use dash between lines
if (! isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) $this->global->MAIN_PDF_DASH_BETWEEN_LINES=1;
// Default max file size for upload // Default max file size for upload
$this->maxfilesize = (empty($this->global->MAIN_UPLOAD_DOC) ? 0 : $this->global->MAIN_UPLOAD_DOC * 1024); $this->maxfilesize = (empty($this->global->MAIN_UPLOAD_DOC) ? 0 : $this->global->MAIN_UPLOAD_DOC * 1024);
......
...@@ -199,8 +199,8 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') ...@@ -199,8 +199,8 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P')
{ {
$this->SetXY($x,$y); $this->SetXY($x,$y);
$val=str_replace('<br>',"\n",$html); $val=str_replace('<br>',"\n",$html);
$val=dol_string_nohtmltag($val,false,'ISO-8859-1'); //$val=dol_string_nohtmltag($val,false,'ISO-8859-1');
//print 'eee'.$val;exit; $val=dol_string_nohtmltag($val,false,'UTF-8');
$this->MultiCell($w,$h,$val,$border,$align,$fill); $this->MultiCell($w,$h,$val,$border,$align,$fill);
} }
} }
...@@ -1554,25 +1554,29 @@ function pdf_getLinkedObjects($object,$outputlangs) ...@@ -1554,25 +1554,29 @@ function pdf_getLinkedObjects($object,$outputlangs)
} }
/** /**
* Return dimensions to use for images onto PDF * Return dimensions to use for images onto PDF checking that width and height are not higher than
* maximum (16x32 by default).
* *
* @param string $realpath Full path to photo file to use * @param string $realpath Full path to photo file to use
* @return array Height/Width to use to output image (in pixel) * @return array Height and width to use to output image (in pdf user unit, so mm)
*/ */
function pdf_getHeightForImage($realpath) function pdf_getSizeForImage($realpath)
{ {
$maxheight=12; $maxwidth=16; global $conf;
$maxwidth=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?16:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
$maxheight=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT)?32:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
$tmp=dol_getImageSize($realpath); $tmp=dol_getImageSize($realpath);
if ($tmp['height']) if ($tmp['height'])
{ {
$width=(int) round($maxheight*$tmp['width']/$tmp['height']); $width=(int) round($maxheight*$tmp['width']/$tmp['height']); // I try to use maxheight
if ($width > $maxwidth) if ($width > $maxwidth) // Pb with maxheight, so i use maxwidth
{ {
$height=(int) round($height*$maxwidth/$width);
$width=$maxwidth; $width=$maxwidth;
$height=(int) round($maxwidth*$tmp['height']/$tmp['width']);
} }
else else // No pb with maxheight
{ {
$height=$maxheight; $height=$maxheight;
} }
......
...@@ -272,15 +272,76 @@ class pdf_azur extends ModelePDFPropales ...@@ -272,15 +272,76 @@ class pdf_azur extends ModelePDFPropales
$pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
// Define size of image if we need it
$imglinesize=array(); $realpath='';
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITH_PICTURE))
{
if ($object->lines[$i]->fk_product)
{
$objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product);
$pdir = get_exdir($object->lines[$i]->fk_product,2) . $object->lines[$i]->fk_product ."/photos/";
$dir = $conf->product->dir_output.'/'.$pdir;
$realpath='';
if ($object->ref == 'SPECIMEN' && $i == 1)
{
$realpath = DOL_DOCUMENT_ROOT.'/theme/common/nophoto.jpg';
}
else
{
foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
{
if ($obj['photo_vignette'])
{
$filename='thumbs/'.$obj['photo_vignette'];
}
else
{
$filename=$obj['photo'];
}
$realpath = $dir.$filename;
break;
}
}
if (!empty($realpath)) $imglinesize=pdf_getSizeForImage($realpath);
}
}
$pdf->setTopMargin($tab_top_newpage); $pdf->setTopMargin($tab_top_newpage);
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
$pageposbefore=$pdf->getPage(); $pageposbefore=$pdf->getPage();
$showpricebeforepagebreak=1;
$posYAfterImage=0;
$posYAfterDescription=0;
// We start with Photo of product line
if (($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo to high, we moved completely on new page
{
$pdf->AddPage('','',true);
if (! empty($tplidx)) $pdf->useTemplate($tplidx);
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
$pdf->setPage($pagenb+1);
$curY = $tab_top_newpage;
$showpricebeforepagebreak=0;
}
if (isset($imglinesize['width']) && isset($imglinesize['height']))
{
$curX = $this->posxpicture-1;
$pdf->Image($realpath, $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'],'','','',2, 300); // Use 300 dpi
// $pdf->Image does not increase value return by getY, so we save it manually
$posYAfterImage=$curY+$imglinesize['height'];
}
// Description of product line // Description of product line
$curX = $this->posxdesc-1; $curX = $this->posxdesc-1;
$showpricebeforepagebreak=1;
$pdf->startTransaction(); $pdf->startTransaction();
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITH_PICTURE)) if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITH_PICTURE))
{ {
...@@ -329,6 +390,7 @@ class pdf_azur extends ModelePDFPropales ...@@ -329,6 +390,7 @@ class pdf_azur extends ModelePDFPropales
{ {
$pdf->commitTransaction(); $pdf->commitTransaction();
} }
$posYAfterDescription=$pdf->GetY();
$nexY = $pdf->GetY(); $nexY = $pdf->GetY();
$pageposafter=$pdf->getPage(); $pageposafter=$pdf->getPage();
...@@ -336,67 +398,13 @@ class pdf_azur extends ModelePDFPropales ...@@ -336,67 +398,13 @@ class pdf_azur extends ModelePDFPropales
$pdf->setTopMargin($this->marge_haute); $pdf->setTopMargin($this->marge_haute);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
// We suppose that a too long description is moved completely on next page // We suppose that a too long description or photo were moved completely on next page
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter); $curY = $tab_top_newpage; $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
} }
$pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
// Photo
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITH_PICTURE))
{
$curX = $this->posxpicture-1;
if ($object->lines[$i]->fk_product)
{
$objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product);
$pdir = get_exdir($object->lines[$i]->fk_product,2) . $object->lines[$i]->fk_product ."/photos/";
$dir = $conf->product->dir_output.'/'.$pdir;
$realpath='';
if ($object->ref == 'SPECIMEN')
{
$realpath = DOL_DOCUMENT_ROOT.'/theme/common/nophoto.jpg';
}
else
{
foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
{
if ($obj['photo_vignette'])
{
$filename='thumbs/'.$obj['photo_vignette'];
}
else
{
$filename=$obj['photo'];
}
$realpath = $dir.$filename;
break;
}
}
if (!empty($realpath))
{
//$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$tmp=pdf_getHeightForImage($realpath);
//var_dump(constant('PDF_IMAGE_SCALE_RATIO'));var_dump($pdf->getImageScale());var_dump($tmp['width']);var_dump($pdf->pixelsToUnits($tmp['width']));exit;
// measures 1/72 of an inch, i.e. approximately 0.0139 inch or 25.4/72 = 0.3528 mm
var_dump($this->page_largeur);exit;
//var_dump(tmp['height']);exit;
$pdf->Line($this->posxtva,10,$this->posxtva+0.5,10);
$pdf->Image($realpath, $this->posxtva, 10, $tmp['width'], $tmp['height'],'','','',2,0); // Use 300 dpi
$pdf->Line($this->posxtva+$pdf->pixelsToUnits($tmp['width']),10,$this->posxtva+$pdf->pixelsToUnits($tmp['width'])+0.5,10);
$pdf->Image($realpath, $curX + ($this->posxtva-$this->posxpicture-($pdf->pixelsToUnits($tmp['width'])))/2, $curY-1, $tmp['width'], $tmp['height'],'','','',2, 300); // Use 300 dpi
//$nexY += 7; // +7 for height = 12
$nexY += round($pdf->pixelsToUnits($tmp['height']));
//var_dump($nexY);exit;
}
}
}
// VAT Rate // VAT Rate
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
{ {
...@@ -459,6 +467,8 @@ class pdf_azur extends ModelePDFPropales ...@@ -459,6 +467,8 @@ class pdf_azur extends ModelePDFPropales
if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=''; if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]='';
$this->tva[$vatrate] += $tvaligne; $this->tva[$vatrate] += $tvaligne;
if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
// Add line // Add line
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
{ {
...@@ -1063,7 +1073,7 @@ class pdf_azur extends ModelePDFPropales ...@@ -1063,7 +1073,7 @@ class pdf_azur extends ModelePDFPropales
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre); $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230'; //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $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)); if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 6, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
} }
$pdf->SetDrawColor(128,128,128); $pdf->SetDrawColor(128,128,128);
...@@ -1074,7 +1084,7 @@ class pdf_azur extends ModelePDFPropales ...@@ -1074,7 +1084,7 @@ class pdf_azur extends ModelePDFPropales
if (empty($hidetop)) if (empty($hidetop))
{ {
$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6); // line prend une position y en 2eme param et 4eme param
$pdf->SetXY($this->posxdesc-1, $tab_top+1); $pdf->SetXY($this->posxdesc-1, $tab_top+1);
$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L'); $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
...@@ -1085,8 +1095,8 @@ class pdf_azur extends ModelePDFPropales ...@@ -1085,8 +1095,8 @@ class pdf_azur extends ModelePDFPropales
$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height); $pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
if (empty($hidetop)) if (empty($hidetop))
{ {
$pdf->SetXY($this->posxpicture-1, $tab_top+1); //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C'); //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment