WIP Attach document to expense report lines

This commit is contained in:
Laurent Destailleur 2019-03-24 20:33:00 +01:00
parent a950d8389e
commit 335af2f458

View File

@ -2115,6 +2115,7 @@ else
print '<td class="right">'.price($line->total_ttc).'</td>'; print '<td class="right">'.price($line->total_ttc).'</td>';
} }
// Column with preview
print '<td class="center">'; print '<td class="center">';
if ($line->fk_ecm_files > 0) if ($line->fk_ecm_files > 0)
{ {
@ -2141,7 +2142,50 @@ else
print '<img class="photo" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.'/'.$minifile).'" title="">'; print '<img class="photo" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.'/'.$minifile).'" title="">';
print '</a>'; print '</a>';
} }
else print '&nbsp;'; else
{
$modulepart='expensereport';
$thumbshown=0;
if (preg_match('/\.pdf$/i', $ecmfilesstatic->filename))
{
$filepdf = $conf->expensereport->dir_output.'/'.$relativepath.$ecmfilesstatic->filename;
$fileimage = $conf->expensereport->dir_output.'/'.$relativepath.$ecmfilesstatic->filename.'_preview.png';
$relativepathimage = $relativepath.$ecmfilesstatic->filename.'_preview.png';
$pdfexists = file_exists($filepdf);
if ($pdfexists)
{
// Conversion du PDF en image png si fichier png non existant
if (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf)))
{
if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experience trouble with pdf thumb generation and imagick, you can disable here.
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
if ($ret < 0) $error++;
}
}
}
if ($pdfexists && ! $error)
{
$heightforphotref=70;
if (! empty($conf->dol_optimize_smallscreen)) $heightforphotref=60;
// If the preview file is found
if (file_exists($fileimage))
{
$thumbshown=1;
print '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">';
}
}
}
if (! $thumbshown)
{
print img_mime($ecmfilesstatic->filename);
}
}
} }
} }
print '</td>'; print '</td>';
@ -2378,8 +2422,6 @@ else
else else
{ {
$modulepart='expensereport'; $modulepart='expensereport';
//$conf->global->MAIN_DISABLE_PDF_THUMBS=1;
print '<a href=""><div class="photoref">'; print '<a href=""><div class="photoref">';
$thumbshown=0; $thumbshown=0;
if (preg_match('/\.pdf$/i', $file['name'])) if (preg_match('/\.pdf$/i', $file['name']))