diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php
index 0de3c54e1ba..59df993b686 100644
--- a/htdocs/commande/list.php
+++ b/htdocs/commande/list.php
@@ -361,19 +361,22 @@ if ($resql)
// stock order and stock order_supplier
$stock_order=0;
$stock_order_supplier=0;
- if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
- if (! empty($conf->commande->enabled)) {
+ if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
+ {
+ if (! empty($conf->commande->enabled))
+ {
if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
- $generic_product->load_stats_commande(0,'1,2',true);
+ $generic_product->load_stats_commande(0,'1,2');
$productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
} else {
$generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
}
$stock_order=$generic_product->stats_commande['qty'];
}
- if (! empty($conf->fournisseur->enabled)) {
+ if (! empty($conf->fournisseur->enabled))
+ {
if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
- $generic_product->load_stats_commande_fournisseur(0,'3',true);
+ $generic_product->load_stats_commande_fournisseur(0,'3');
$productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
} else {
$generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php
index c88886de649..9874f809673 100644
--- a/htdocs/fourn/commande/dispatch.php
+++ b/htdocs/fourn/commande/dispatch.php
@@ -387,11 +387,11 @@ if ($id > 0 || ! empty($ref))
print '
';
if (count($listwarehouses)>1)
{
- print $form->selectarray("entrepot".$suffix, $listwarehouses, '', 1, 0, 0, '', 0, 0, $disabled);
+ print $form->selectarray("entrepot".$suffix, $listwarehouses, GETPOST("entrepot".$suffix), 1, 0, 0, '', 0, 0, $disabled);
}
elseif (count($listwarehouses)==1)
{
- print $form->selectarray("entrepot".$suffix, $listwarehouses, '', 0, 0, 0, '', 0, 0, $disabled);
+ print $form->selectarray("entrepot".$suffix, $listwarehouses, GETPOST("entrepot".$suffix), 0, 0, 0, '', 0, 0, $disabled);
}
else
{
diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql
index 9e1ca7bb6f9..c0aeda5b671 100755
--- a/htdocs/install/mysql/migration/repair.sql
+++ b/htdocs/install/mysql/migration/repair.sql
@@ -212,5 +212,6 @@ update llx_facturedet set product_type = 1 where product_type = 2;
--update llx_commandedet as d set d.product_type = 1 where d.fk_product = 22 and d.product_type = 0;
--update llx_facturedet as d set d.product_type = 1 where d.fk_product = 22 and d.product_type = 0;
+delete from llx_commande_fournisseur_dispatch where fk_commandefourndet = 0 or fk_commandefourndet IS NULL;
diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index 0e3e7dd6c27..fdd6408accb 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -108,7 +108,7 @@ WarehouseForStockDecrease=The warehouse %s will be used for stock decreas
WarehouseForStockIncrease=The warehouse %s will be used for stock increase
ForThisWarehouse=For this warehouse
ReplenishmentStatusDesc=This is list of all product with a stock lower than desired stock (or lower than alert value if checkbox "alert only" is checked), and suggest you to create supplier orders to fill the difference.
-ReplenishmentOrdersDesc=This is list of all opened supplier orders
+ReplenishmentOrdersDesc=This is list of all opened supplier orders including predefined products. Only opened orders with predefined products, so that may affect stocks, are visible here.
Replenishments=Replenishments
NbOfProductBeforePeriod=Quantity of product %s in stock before selected period (< %s)
NbOfProductAfterPeriod=Quantity of product %s in stock after selected period (> %s)
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 0778046c431..e26f9102544 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3024,7 +3024,9 @@ class Product extends CommonObject
}
}
$this->db->free($result);
- $this->load_virtual_stock();
+
+ $this->load_virtual_stock(); // This also load stats_commande_fournisseur, ...
+
return 1;
}
else
@@ -3048,18 +3050,21 @@ class Product extends CommonObject
$stock_sending_client=0;
$stock_reception_fournisseur=0;
- if (! empty($conf->commande->enabled)) {
+ if (! empty($conf->commande->enabled))
+ {
$result=$this->load_stats_commande(0,'1,2');
if ($result < 0) dol_print_error($db,$this->error);
$stock_commande_client=$this->stats_commande['qty'];
}
- if (! empty($conf->expedition->enabled)) {
+ if (! empty($conf->expedition->enabled))
+ {
$result=$this->load_stats_sending(0,'1,2');
if ($result < 0) dol_print_error($db,$this->error);
$stock_sending_client=$this->stats_expedition['qty'];
}
- if (! empty($conf->fournisseur->enabled)) {
- $result=$this->load_stats_commande_fournisseur(0,'3,4');
+ if (! empty($conf->fournisseur->enabled))
+ {
+ $result=$this->load_stats_commande_fournisseur(0,'1,2,3,4');
if ($result < 0) dol_print_error($db,$this->error);
$stock_commande_fournisseur=$this->stats_commande_fournisseur['qty'];
diff --git a/htdocs/product/stock/lib/replenishment.lib.php b/htdocs/product/stock/lib/replenishment.lib.php
index 50a0d85e25c..1ef993c479d 100644
--- a/htdocs/product/stock/lib/replenishment.lib.php
+++ b/htdocs/product/stock/lib/replenishment.lib.php
@@ -25,56 +25,80 @@
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
/**
- * dispatched
+ * Check if there is still some dispatching of stock to do.
*
- * @param int $order_id Id of order
- * @return boolean
+ * @param int $order_id Id of order to check
+ * @return boolean True = There is some dispatching to do, False = All dispatching is done (may be we receive more) or is not required
*/
-function dispatched($order_id)
+function dolDispatchToDo($order_id)
{
global $db;
- $sql = 'SELECT fk_product, SUM(qty) FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch';
- $sql .= ' WHERE fk_commande = ' . $order_id . ' GROUP BY fk_product';
- $sql .= ' ORDER by fk_product';
- $resql = $db->query($sql);
+
$dispatched = array();
$ordered = array();
- if($resql && $db->num_rows($resql))
- {
- while($res = $db->fetch_object($resql))
- $dispatched[] = $res;
- }
- $sql = 'SELECT fk_product, SUM(qty) FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet';
- $sql .= ' WHERE fk_commande = ' . $order_id . ' GROUP BY fk_product';
- $sql .= ' ORDER by fk_product';
+
+ # Count nb of quantity dispatched per product
+ $sql = 'SELECT fk_product, SUM(qty) FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch';
+ $sql.= ' WHERE fk_commande = ' . $order_id;
+ $sql.= ' GROUP BY fk_product';
+ $sql.= ' ORDER by fk_product';
$resql = $db->query($sql);
- if($resql && $db->num_rows($resql)) {
- while($res = $db->fetch_object($resql))
- $ordered[] = $res;
+ if ($resql && $db->num_rows($resql))
+ {
+ while ($obj = $db->fetch_object($resql))
+ $dispatched[$obj->fk_product] = $obj;
}
- return $dispatched == $ordered;
+
+ # Count nb of quantity to dispatch per product
+ $sql = 'SELECT fk_product, SUM(qty) FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet';
+ $sql.= ' WHERE fk_commande = ' . $order_id;
+ $sql.= ' AND fk_product > 0';
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= ' AND product_type = 0';
+ $sql.= ' GROUP BY fk_product';
+ $sql.= ' ORDER by fk_product';
+ $resql = $db->query($sql);
+ if ($resql && $db->num_rows($resql))
+ {
+ while ($obj = $db->fetch_object($resql))
+ $ordered[$obj->fk_product] = $obj;
+ }
+
+ $todispatch=0;
+ foreach ($ordered as $key => $val)
+ {
+ if ($ordered[$key] > $dispatched[$key]) $todispatch++;
+ }
+
+ return ($todispatch ? true : false);
+ //return true;
}
/**
* dispatchedOrders
*
- * @return Ambigous
+ * @return string Array of id of orders wit all dispathing already done or not required
*/
function dispatchedOrders()
{
global $db;
+
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur';
$resql = $db->query($sql);
- $res = array();
- if ($resql && $db->num_rows($resql) > 0) {
- while ($obj = $db->fetch_object($resql)) {
- if (dispatched($obj->rowid)) {
- $res[] = $obj->rowid;
+ $resarray = array();
+ if ($resql && $db->num_rows($resql) > 0)
+ {
+ while ($obj = $db->fetch_object($resql))
+ {
+ if (! dolDispatchToDo($obj->rowid))
+ {
+ $resarray[] = $obj->rowid;
}
}
}
- if ($res) {
- $res = '(' . implode(',', $res) . ')';
+
+ if (count($resarray))
+ {
+ $res = '(' . implode(',', $resarray) . ')';
} else {
//hack to make sure ordered SQL request won't syntax error
$res = '(0)';
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index 35835709ab8..efb008df4ff 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -336,6 +336,17 @@ $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
$head[1][1] = $langs->trans("ReplenishmentOrders");
$head[1][2] = 'replenishorders';
+
+
+print ' |