diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 78615fc2cf6..f1f5c8fb969 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -2469,7 +2469,7 @@ class FactureFournisseur extends CommonInvoice
{
$this->error=$obj->error;
//dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
- return false;
+ return -1;
}
}
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index a49bc2022fd..ba08e0db0d4 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -57,7 +57,7 @@ if (!empty($conf->variants->enabled)) {
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
-$langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks'));
+$langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks', 'admin'));
if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
$id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int'));
@@ -2329,11 +2329,9 @@ else
// Confirmation de la validation
if ($action == 'valid')
{
- // on verifie si l'objet est en numerotation provisoire
- $objectref = substr($object->ref, 1, 4);
- if ($objectref == 'PROV')
+ // We check if number is temporary number
+ if (preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) // empty should not happened, but when it occurs, the test save life
{
- $savdate = $object->date;
$numref = $object->getNextNumRef($societe);
}
else
@@ -2341,46 +2339,51 @@ else
$numref = $object->ref;
}
- $text = $langs->trans('ConfirmValidateBill', $numref);
- /*if (! empty($conf->notification->enabled))
- {
- require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
- $notify=new Notify($db);
- $text.='
';
- $text.=$notify->confirmMessage('BILL_SUPPLIER_VALIDATE',$object->socid, $object);
- }*/
- $formquestion = array();
-
- $qualified_for_stock_change = 0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
+ if ($numref < 0)
{
- $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ setEventMessages($object->error, $object->errors, 'errors');
+ $action = '';
}
else
{
- $qualified_for_stock_change = $object->hasProductsOrServices(1);
+
+ $text = $langs->trans('ConfirmValidateBill', $numref);
+ /*if (! empty($conf->notification->enabled))
+ {
+ require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
+ $notify=new Notify($db);
+ $text.='
';
+ $text.=$notify->confirmMessage('BILL_SUPPLIER_VALIDATE',$object->socid, $object);
+ }*/
+ $formquestion = array();
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
+ }
+
+ if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
+ $langs->load("stocks");
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ $formproduct = new FormProduct($db);
+ $warehouse = new Entrepot($db);
+ $warehouse_array = $warehouse->list_array();
+ if (count($warehouse_array) == 1) {
+ $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array));
+ $value = '';
+ } else {
+ $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease");
+ $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1);
+ }
+ $formquestion = array(
+ array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value)
+ );
+ }
+
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1);
}
-
- if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change)
- {
- $langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- $formproduct = new FormProduct($db);
- $warehouse = new Entrepot($db);
- $warehouse_array = $warehouse->list_array();
- if (count($warehouse_array) == 1) {
- $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array));
- $value = '';
- } else {
- $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease");
- $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1);
- }
- $formquestion = array(
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value)
- );
- }
-
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1);
}
// Confirmation edit (back to draft)