FIX generation of document for supplie rinvoice

This commit is contained in:
Laurent Destailleur 2019-01-30 14:07:50 +01:00
parent f955f3f4ee
commit 340412ed00
2 changed files with 20 additions and 4 deletions

View File

@ -43,6 +43,8 @@ accessforbidden();
$type=GETPOST('type', 'alpha');
$value=GETPOST('value', 'alpha');
$action=GETPOST('action', 'alpha');
$label = GETPOST('label', 'alpha');
$scandir = GETPOST('scan_dir','alpha');
$specimenthirdparty=new Societe($db);

View File

@ -48,12 +48,15 @@ if ($action == 'presend')
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
//
// Special case
if ($object->element == 'invoice_supplier')
{
$fileparams = dol_most_recent_file($diroutput . '/' . get_exdir($object->id,2,0,0,$object,$object->element).$ref, preg_quote($ref,'/').'([^\-])+');
}
else
{
$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
}
$file = $fileparams['fullname'];
}
@ -86,7 +89,10 @@ if ($action == 'presend')
}
// Build document if it not exists
if (! in_array($object->element, array('societe', 'user', 'member')))
$forcebuilddoc=true;
if (in_array($object->element, array('societe', 'user', 'member'))) $forcebuilddoc=false;
if ($object->element == 'invoice_supplier' && empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) $forcebuilddoc=false;
if ($forcebuilddoc) // If there is no default value for supplier invoice, we do not generate file, even if modelpdf was set by a manual generation
{
if ((! $file || ! is_readable($file)) && method_exists($object, 'generateDocument'))
{
@ -95,7 +101,15 @@ if ($action == 'presend')
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
if ($object->element == 'invoice_supplier')
{
$fileparams = dol_most_recent_file($diroutput . '/' . get_exdir($object->id,2,0,0,$object,$object->element).$ref, preg_quote($ref,'/').'([^\-])+');
}
else
{
$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
}
$file = $fileparams['fullname'];
}
}