diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 7f091749660..f6575eb2140 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -1391,7 +1391,7 @@ class CommandeFournisseur extends CommonOrder
*/
function dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0)
{
- global $conf;
+ global $conf, $langs;
$error = 0;
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
@@ -1409,10 +1409,44 @@ class CommandeFournisseur extends CommonOrder
}
$dispatchstatus = 1;
- if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 if this option is on
+ if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 or 2 if this option is on
$now=dol_now();
+ // If a serial number is provided, we check that sellby and eatby match already existing serial
+ if ($batch)
+ {
+ $sql = "SELECT rowid, batch, eatby, sellby FROM ".MAIN_DB_PREFIX."product_batch WHERE batch = '".$this->db->escape($batch)."'";
+ dol_syslog(get_class($this)."::dispatchProduct scan serial to check if eatby and sellby match", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i=0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($obj->eatby != $eatby)
+ {
+ $this->error=$langs->trans("ThisSerialAlreadyExistWithDifferentDate", $batch, $obj->eatby);
+ return -1;
+ }
+ if ($obj->sellby != $sellby)
+ {
+ $this->error=$langs->trans("ThisSerialAlreadyExistWithDifferentDate", $batch, $obj->sellby);
+ return -1;
+ }
+ $i++;
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+
if (($this->statut == 3 || $this->statut == 4 || $this->statut == 5))
{
$this->db->begin();
@@ -1480,7 +1514,7 @@ class CommandeFournisseur extends CommonOrder
}
}
else
- {
+ {
$this->error='BadStatusForObject';
return -2;
}
diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php
index 429378ac291..b3d1c9b12dd 100644
--- a/htdocs/fourn/commande/dispatch.php
+++ b/htdocs/fourn/commande/dispatch.php
@@ -127,11 +127,15 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$db->begin();
+ $pos=0;
foreach($_POST as $key => $value)
{
if (preg_match('/^product_([0-9]+)$/i', $key, $reg)) // without batch module enabled
{
- $numline=$reg[1] + 1; // line of product
+ $pos++;
+
+ //$numline=$reg[1] + 1; // line of product
+ $numline=$pos;
$prod = "product_".$reg[1];
$qty = "qty_".$reg[1];
$ent = "entrepot_".$reg[1];
@@ -161,8 +165,11 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) // with batch module enabled
{
+ $pos++;
+
//eat-by date dispatch
- $numline=$reg[2] + 1; // line of product
+ //$numline=$reg[2] + 1; // line of product
+ $numline=$pos;
$prod = "product_".$reg[1]."_".$reg[2];
$qty = "qty_".$reg[1]."_".$reg[2];
$ent = "entrepot_".$reg[1]."_".$reg[2];
@@ -202,7 +209,6 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
}
}
-
}
if (! $notrigger && ! $error)
@@ -430,6 +436,20 @@ if ($id > 0 || ! empty($ref))
$nbproduct++;
$var=!$var;
+
+ // To show detail cref and description value, we must make calculation by cref
+ //print ($objp->cref?' ('.$objp->cref.')':'');
+ //if ($objp->description) print '
'.nl2br($objp->description);
+ if ((empty($conf->productbatch->enabled)) || $objp->tobatch==0)
+ {
+ $suffix='_'.$i;
+ } else {
+ $suffix='_0_'.$i;
+ }
+
+
+ print "\n";
+ print ''."\n";
print "