FIX - Error to générate product doc - NEW - Add photo on product doc

This commit is contained in:
Anthony Berton 2023-01-26 10:36:44 +01:00
parent d36acc63dd
commit 6aadb7b9cc

View File

@ -209,10 +209,10 @@ class pdf_standard extends ModelePDFProduct
$pdf->SetDrawColor(128, 128, 128);
$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
$pdf->SetSubject($outputlangs->transnoentities("Order"));
$pdf->SetSubject($outputlangs->transnoentities("Product"));
$pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Product"));
if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
$pdf->SetCompression(false);
}
@ -242,6 +242,53 @@ class pdf_standard extends ModelePDFProduct
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
$nexY = $pdf->GetY();
// Show photo
if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
$pdir[0] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/";
$pdir[1] = get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref).'/';
} else {
$pdir[0] = get_exdir(0, 0, 0, 0, $object, 'product'); // default
$pdir[1] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/"; // alternative
}
$arephoto = false;
foreach ($pdir as $midir) {
if (!$arephoto) {
if ($conf->entity != $object->entity) {
$dir = $conf->product->multidir_output[$object->entity].'/'.$midir; //Check repertories of current entities
} else {
$dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
}
foreach ($object->liste_photos($dir, 1) as $key => $obj) {
if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
if ($obj['photo_vignette']) {
$filename = $obj['photo_vignette'];
} else {
$filename = $obj['photo'];
}
} else {
$filename = $obj['photo'];
}
$realpath = $dir.$filename;
$arephoto = true;
}
}
}
// Define size of image if we need it
$imglinesize = array();
if (!empty($realpath) && $arephoto) {
$imgsize = pdf_getSizeForImage($realpath);
$imgsizewidth = $imgsize['width'] + 20;
$imgsizeheight = $imgsize['height'] + 20;
$midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
$posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
$posyphoto = $tab_top - 1;
$pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight, '', '', '', 2, 300); // Use 300 dpi
$nexyafterphoto = $tab_top + $imgsizeheight;
}
// Description
$pdf->SetFont('', '', $default_font_size);
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
$nexY = $pdf->GetY();
@ -276,30 +323,22 @@ class pdf_standard extends ModelePDFProduct
$nexY = $pdf->GetY();
}
$tab_top = 88;
if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
$tab_top = $nexyafterphoto;
}
// Show notes
// TODO There is no public note on product yet
$notetoshow = empty($object->note_public) ? '' : $object->note_public;
if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
// Get first sale rep
if (is_object($object->thirdparty)) {
$salereparray = $object->thirdparty->getSalesRepresentatives($user);
$salerepobj = new User($this->db);
$salerepobj->fetch($salereparray[0]['id']);
if (!empty($salerepobj->signature)) {
$notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
}
}
}
if ($notetoshow) {
$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
$notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
$tab_top = 88;
$pdf->SetFont('', '', $default_font_size - 1);
$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
$pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
$nexY = $pdf->GetY();
$height_note = $nexY - $tab_top;
@ -687,7 +726,7 @@ class pdf_standard extends ModelePDFProduct
pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
// Show Draft Watermark
if ($object->statut == 0 && getDolGlobalString('COMMANDE_DRAFT_WATERMARK')) {
if ($object->statut == 0 && getDolGlobalString('PRODUCT_DRAFT_WATERMARK')) {
pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
}