diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php index 6fa692f47fc..540cd4a4b98 100644 --- a/htdocs/admin/supplier_invoice.php +++ b/htdocs/admin/supplier_invoice.php @@ -136,19 +136,23 @@ else if ($action == 'del') // Set default model else if ($action == 'setdoc') { - 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 - // on passe donc par une variable pour avoir un affichage coherent - $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; - } + 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 + // on passe donc par une variable pour avoir un affichage coherent + $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; + } - // On active le modele - $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $ret = addDocumentModel($value, $type, $label, $scandir); - } + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } +} +else if ($action == 'unsetdoc') +{ + dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity); } if ($action == 'setmod') @@ -366,7 +370,7 @@ foreach ($dirmodels as $reldir) { 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); $classname = substr($file, 0, dol_strlen($file) -12); @@ -383,7 +387,7 @@ foreach ($dirmodels as $reldir) require_once $dir.$file; $module = new $classname($db,$specimenthirdparty); if (method_exists($module,'info')) print $module->info($langs); - else print $module->description; + else print $module->description; print "\n"; @@ -391,16 +395,17 @@ foreach ($dirmodels as $reldir) if (in_array($name, $def)) { print ''."\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 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">'; print img_picto($langs->trans("Enabled"),'switch_on'); print ''; - } + /*} else { print img_picto($langs->trans("Enabled"),'switch_on'); - } + }*/ print ""; } else @@ -414,7 +419,9 @@ foreach ($dirmodels as $reldir) print ''; 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 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"),'on').''; } else { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 792e6e106aa..2ff460b7c78 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1908,7 +1908,7 @@ class FactureFournisseur extends CommonInvoice * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @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) { @@ -1917,7 +1917,7 @@ class FactureFournisseur extends CommonInvoice $langs->load("suppliers"); // Set the model on the model name to use - if (! dol_strlen($modele)) + if (empty($modele)) { if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) { @@ -1925,13 +1925,20 @@ class FactureFournisseur extends CommonInvoice } 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); + } } /** diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index b3fc5995031..2e0ef64f96f 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -254,6 +254,24 @@ if (empty($reshook)) if ($object->update($user) < 0) { 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 @@ -559,7 +577,7 @@ if (empty($reshook)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) + if ($result < 0) { dol_print_error($db,$object->error,$object->errors); exit; @@ -969,7 +987,7 @@ if (empty($reshook)) $outputlangs->setDefaultLang($newlang); } $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action=''; @@ -2325,7 +2343,7 @@ else if (! $file || ! is_readable($file)) { $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); exit;