diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index e4978191919..012e09b05ab 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -1924,7 +1924,7 @@ class CommandeFournisseur extends CommonOrder
}
}
- // TODO LDR01 Add option to accept only if ALL predefined products are received (same qty).
+ // TODO LDR01 Add a control test to accept only if ALL predefined products are received (same qty).
if (! $error && ! ($statut == 4 or $statut == 5 or $statut == 7))
@@ -2753,10 +2753,11 @@ class CommandeFournisseur extends CommonOrder
/**
* Calc status regarding dispatch stock
*
- * @param User $user User action
- * @return int <0 if KO, 0 if not applicable, >0 if OK
+ * @param User $user User action
+ * @param int $closeopenorder Close if received
+ * @return int <0 if KO, 0 if not applicable, >0 if OK
*/
- public function calcAndSetStatusDispatch(User $user)
+ public function calcAndSetStatusDispatch(User $user, $closeopenorder=1)
{
global $conf;
@@ -2794,18 +2795,30 @@ class CommandeFournisseur extends CommonOrder
if (count($diff_array)==0)
{
//No diff => mean everythings is received
- $ret=$this->setStatus($user,5);
- if ($ret<0) {
- $this->error=$object->error; $this->errors=$object->errors;
+ if ($closeopenorder)
+ {
+ $ret=$this->setStatus($user,5);
+ if ($ret<0) {
+ return -1;
+ }
+ return 5;
+ }
+ else
+ {
+ //Diff => received partially
+ $ret=$this->setStatus($user,4);
+ if ($ret<0) {
+ return -1;
+ }
+ return 4;
}
- return 5;
}
else
{
//Diff => received partially
$ret=$this->setStatus($user,4);
if ($ret<0) {
- $this->error=$object->error; $this->errors=$object->errors;
+ return -1;
}
return 4;
}
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index b7a465145b8..2e1f4db613c 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -831,7 +831,7 @@ if (empty($reshook))
{
$date_liv = dol_mktime(GETPOST('rehour'),GETPOST('remin'),GETPOST('resec'),GETPOST("remonth"),GETPOST("reday"),GETPOST("reyear"));
- $result = $object->Livraison($user, $date_liv, GETPOST("type"), GETPOST("comment"));
+ $result = $object->Livraison($user, $date_liv, GETPOST("type"), GETPOST("comment")); // GETPOST("type") is 'tot', 'par', 'nev', 'can'
if ($result > 0)
{
$langs->load("deliveries");
diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php
index 472c44d1031..5d3e0ebc47f 100644
--- a/htdocs/fourn/commande/dispatch.php
+++ b/htdocs/fourn/commande/dispatch.php
@@ -77,6 +77,8 @@ if ($id > 0 || ! empty($ref)) {
setEventMessages($commande->error, $commande->errors, 'errors');
}
}
+
+
/*
* Actions
*/
@@ -147,9 +149,11 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$db->begin();
$pos = 0;
- foreach ( $_POST as $key => $value ) {
+ foreach ($_POST as $key => $value)
+ {
// without batch module enabled
- if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
+ if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
+ {
$pos ++;
// $numline=$reg[2] + 1; // line of product
@@ -179,7 +183,8 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
}
// with batch module enabled
- if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
+ if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg))
+ {
$pos ++;
// eat-by date dispatch
@@ -224,7 +229,7 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
if (! $error) {
- $result = $commande->calcAndSetStatusDispatch($user);
+ $result = $commande->calcAndSetStatusDispatch($user, GETPOST('closeopenorder')?1:0);
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
$error ++;
@@ -543,15 +548,21 @@ if ($id > 0 || ! empty($ref)) {
print "\n";
print "
\n";
- if ($nbproduct) {
- print $langs->trans("Comment") . ' : ';
+ if ($nbproduct)
+ {
+ $checkboxlabel=$langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv($commande->statuts[5]));
+
+ print '