NEW #5801 More complete change to allow to disable supplier invoice
document generation
This commit is contained in:
parent
855ad3e166
commit
86d86f8442
@ -136,19 +136,23 @@ else if ($action == 'del')
|
|||||||
// Set default model
|
// Set default model
|
||||||
else if ($action == 'setdoc')
|
else if ($action == 'setdoc')
|
||||||
{
|
{
|
||||||
if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
|
if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
|
||||||
{
|
{
|
||||||
// La constante qui a ete lue en avant du nouveau set
|
// La constante qui a ete lue en avant du nouveau set
|
||||||
// on passe donc par une variable pour avoir un affichage coherent
|
// on passe donc par une variable pour avoir un affichage coherent
|
||||||
$conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
|
$conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On active le modele
|
// On active le modele
|
||||||
$ret = delDocumentModel($value, $type);
|
$ret = delDocumentModel($value, $type);
|
||||||
if ($ret > 0)
|
if ($ret > 0)
|
||||||
{
|
{
|
||||||
$ret = addDocumentModel($value, $type, $label, $scandir);
|
$ret = addDocumentModel($value, $type, $label, $scandir);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if ($action == 'unsetdoc')
|
||||||
|
{
|
||||||
|
dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'setmod')
|
if ($action == 'setmod')
|
||||||
@ -366,7 +370,7 @@ foreach ($dirmodels as $reldir)
|
|||||||
{
|
{
|
||||||
while (($file = readdir($handle))!==false)
|
while (($file = readdir($handle))!==false)
|
||||||
{
|
{
|
||||||
if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
|
if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
|
||||||
{
|
{
|
||||||
$name = substr($file, 4, dol_strlen($file) -16);
|
$name = substr($file, 4, dol_strlen($file) -16);
|
||||||
$classname = substr($file, 0, dol_strlen($file) -12);
|
$classname = substr($file, 0, dol_strlen($file) -12);
|
||||||
@ -383,7 +387,7 @@ foreach ($dirmodels as $reldir)
|
|||||||
require_once $dir.$file;
|
require_once $dir.$file;
|
||||||
$module = new $classname($db,$specimenthirdparty);
|
$module = new $classname($db,$specimenthirdparty);
|
||||||
if (method_exists($module,'info')) print $module->info($langs);
|
if (method_exists($module,'info')) print $module->info($langs);
|
||||||
else print $module->description;
|
else print $module->description;
|
||||||
|
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
@ -391,16 +395,17 @@ foreach ($dirmodels as $reldir)
|
|||||||
if (in_array($name, $def))
|
if (in_array($name, $def))
|
||||||
{
|
{
|
||||||
print '<td align="center">'."\n";
|
print '<td align="center">'."\n";
|
||||||
if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
|
//if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
|
||||||
{
|
//{
|
||||||
|
// Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
|
||||||
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">';
|
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">';
|
||||||
print img_picto($langs->trans("Enabled"),'switch_on');
|
print img_picto($langs->trans("Enabled"),'switch_on');
|
||||||
print '</a>';
|
print '</a>';
|
||||||
}
|
/*}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print img_picto($langs->trans("Enabled"),'switch_on');
|
print img_picto($langs->trans("Enabled"),'switch_on');
|
||||||
}
|
}*/
|
||||||
print "</td>";
|
print "</td>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -414,7 +419,9 @@ foreach ($dirmodels as $reldir)
|
|||||||
print '<td align="center">';
|
print '<td align="center">';
|
||||||
if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name")
|
if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name")
|
||||||
{
|
{
|
||||||
print img_picto($langs->trans("Default"),'on');
|
//print img_picto($langs->trans("Default"),'on');
|
||||||
|
// Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
|
||||||
|
print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1908,7 +1908,7 @@ class FactureFournisseur extends CommonInvoice
|
|||||||
* @param int $hidedetails Hide details of lines
|
* @param int $hidedetails Hide details of lines
|
||||||
* @param int $hidedesc Hide description
|
* @param int $hidedesc Hide description
|
||||||
* @param int $hideref Hide ref
|
* @param int $hideref Hide ref
|
||||||
* @return int 0 if KO, 1 if OK
|
* @return int <0 if KO, 0 if nothing done, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
|
public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
|
||||||
{
|
{
|
||||||
@ -1917,7 +1917,7 @@ class FactureFournisseur extends CommonInvoice
|
|||||||
$langs->load("suppliers");
|
$langs->load("suppliers");
|
||||||
|
|
||||||
// Set the model on the model name to use
|
// Set the model on the model name to use
|
||||||
if (! dol_strlen($modele))
|
if (empty($modele))
|
||||||
{
|
{
|
||||||
if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
|
if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
|
||||||
{
|
{
|
||||||
@ -1925,13 +1925,20 @@ class FactureFournisseur extends CommonInvoice
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$modele = 'canelle';
|
$modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($modele))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$modelpath = "core/modules/supplier_invoice/pdf/";
|
||||||
|
|
||||||
$modelpath = "core/modules/supplier_invoice/pdf/";
|
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
|
}
|
||||||
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -254,6 +254,24 @@ if (empty($reshook))
|
|||||||
if ($object->update($user) < 0) {
|
if ($object->update($user) < 0) {
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Define output language
|
||||||
|
$outputlangs = $langs;
|
||||||
|
$newlang = '';
|
||||||
|
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
|
||||||
|
$newlang = GETPOST('lang_id');
|
||||||
|
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
|
||||||
|
$newlang = $object->thirdparty->default_lang;
|
||||||
|
if (! empty($newlang)) {
|
||||||
|
$outputlangs = new Translate("", $conf);
|
||||||
|
$outputlangs->setDefaultLang($newlang);
|
||||||
|
}
|
||||||
|
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||||
|
$ret = $object->fetch($object->id); // Reload to get new records
|
||||||
|
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// payments conditions
|
// payments conditions
|
||||||
@ -559,7 +577,7 @@ if (empty($reshook))
|
|||||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||||
$outputlangs = $langs;
|
$outputlangs = $langs;
|
||||||
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
if ($result <= 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
dol_print_error($db,$object->error,$object->errors);
|
dol_print_error($db,$object->error,$object->errors);
|
||||||
exit;
|
exit;
|
||||||
@ -969,7 +987,7 @@ if (empty($reshook))
|
|||||||
$outputlangs->setDefaultLang($newlang);
|
$outputlangs->setDefaultLang($newlang);
|
||||||
}
|
}
|
||||||
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
if ($result <= 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
$action='';
|
$action='';
|
||||||
@ -2325,7 +2343,7 @@ else
|
|||||||
if (! $file || ! is_readable($file))
|
if (! $file || ! is_readable($file))
|
||||||
{
|
{
|
||||||
$result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
$result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
if ($result <= 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
dol_print_error($db,$object->error,$object->errors);
|
dol_print_error($db,$object->error,$object->errors);
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user