diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index 5f6b45cff1e..368128e8f02 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -95,3 +95,4 @@ ReplenishmentOrders=Replenishment orders
UseVirtualStock=Use virtual stock instead of physical stock
RuleForStockReplenishment=Rule for stocks replenishment
SelectProduct=Select at least one product
+AlertOnly= Alerts only
diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang
index 98aca2b2803..d0084e82fef 100644
--- a/htdocs/langs/fr_FR/stocks.lang
+++ b/htdocs/langs/fr_FR/stocks.lang
@@ -95,3 +95,4 @@ ReplenishmentOrders=Commandes de réapprovisionnement
UseVirtualStock=Utiliser le stock théorique à la place du stock physique
RuleForStockReplenishment=Règle de gestion du réapprovisionnement des stocks
SelectProduct=Sélectionnez au moins un produit
+AlertOnly = Alertes seulement
diff --git a/htdocs/product/stock/lib/replenishment.lib.php b/htdocs/product/stock/lib/replenishment.lib.php
index ef2cbb26c57..09c39e7661d 100644
--- a/htdocs/product/stock/lib/replenishment.lib.php
+++ b/htdocs/product/stock/lib/replenishment.lib.php
@@ -117,7 +117,7 @@ function ordered($product_id)
} else {
$error = $db->lasterror();
dol_print_error($db);
- dol_syslog('replenish.php: ' . $error, LOG_ERROR);
+ dol_syslog('replenish.php: ' . $error, LOG_ERR);
return $langs->trans('error');
}
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index 6b442f763f7..fbb6edf3bae 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -47,6 +47,7 @@ $snom = GETPOST('snom', 'alpha');
$sall = GETPOST('sall', 'alpha');
$type = GETPOST('type','int');
$tobuy = GETPOST('tobuy', 'int');
+$salert = GETPOST('salert', 'alpha');
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
@@ -66,9 +67,16 @@ $offset = $limit * $page ;
* Actions
*/
+if (isset($_POST['button_removefilter']) || isset($_POST['valid'])) {
+ $sref = '';
+ $snom = '';
+ $sal = '';
+ $salert = '';
+}
+
//orders creation
//FIXME: could go in the lib
-if ($action == 'order') {
+if ($action == 'order' && isset($_POST['valid'])) {
$linecount = GETPOST('linecount', 'int');
$box = 0;
unset($_POST['linecount']);
@@ -105,7 +113,7 @@ if ($action == 'order') {
} else {
$error=$db->lasterror();
dol_print_error($db);
- dol_syslog('replenish.php: '.$error, LOG_ERROR);
+ dol_syslog('replenish.php: '.$error, LOG_ERR);
}
$db->free($resql);
unset($_POST['fourn' . $i]);
@@ -152,7 +160,7 @@ $title = $langs->trans('Status');
$sql = 'SELECT p.rowid, p.ref, p.label, p.price';
$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type';
$sql .= ', p.tms as datem, p.duration, p.tobuy, p.seuil_stock_alerte,';
-$sql .= ' SUM(s.reel) as stock_physique';
+$sql .= ' SUM(COALESCE(s.reel, 0)) as stock_physique';
$sql .= ', p.desiredstock';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf';
@@ -175,10 +183,18 @@ if (dol_strlen($type)) {
}
}
if ($sref) {
- $sql .= ' AND p.ref LIKE "%' . $sref . '%"';
+ //natural search
+ $scrit = explode(' ', $sref);
+ foreach ($scrit as $crit) {
+ $sql .= ' AND p.ref LIKE "%' . $crit . '%"';
+ }
}
if ($snom) {
- $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"';
+ //natural search
+ $scrit = explode(' ', $snom);
+ foreach ($scrit as $crit) {
+ $sql .= ' AND p.label LIKE "%' . $db->escape($crit) . '%"';
+ }
}
$sql .= ' AND p.tobuy = 1';
@@ -190,8 +206,12 @@ $sql .= ' GROUP BY p.rowid, p.ref, p.label, p.price';
$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$sql .= ', p.duration, p.tobuy, p.seuil_stock_alerte';
$sql .= ', p.desiredstock';
-$sql .= ' HAVING (p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL)';
+$sql .= ' HAVING p.desiredstock > SUM(COALESCE(s.reel, 0))';
$sql .= ' AND p.desiredstock > 0';
+if ($salert == 'on') {
+ $sql .= ' AND SUM(COALESCE(s.reel, 0)) < p.seuil_stock_alerte AND p.seuil_stock_alerte is not NULL';
+ $alertchecked = 'checked="checked"';
+}
$sql .= $db->order($sortfield,$sortorder);
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
@@ -199,11 +219,6 @@ $resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- if ($num == 1 && ($sall or $snom or $sref)) {
- $objp = $db->fetch_object($resql);
- header('Location: ../fiche.php?id=' . $objp->rowid);
- exit;
- }
$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|';
$helpurl .= 'ES:Módulo_Stocks';
@@ -216,9 +231,10 @@ if ($resql) {
$head[1][1] = $langs->trans("ReplenishmentOrders");
$head[1][2] = 'replenishorders';
dol_fiche_head($head, 'replenish', $langs->trans('Replenishment'), 0, 'stock');
- if ($sref || $snom || $sall || GETPOST('search', 'alpha')) {
+ if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) {
$filters = '&sref=' . $sref . '&snom=' . $snom;
- $filters .= '&sall=' . $sall;
+ $filters .= '&sall=' . $sall;
+ $filters .= '&salert=' . $salert;
print_barre_liste($texte,
$page,
'replenish.php',
@@ -231,7 +247,8 @@ if ($resql) {
} else {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id;
- $filters .= (isset($type)?'&type=' . $type:'');
+ $filters .= (isset($type)?'&type=' . $type:'');
+ $filters .= '&salert=' . $salert;
print_barre_liste($texte,
$page,
'replenish.php',
@@ -253,7 +270,7 @@ if ($resql) {
'
';
$param = (isset($type)? '&type=' . $type : '');
- $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom;
+ $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert;
$param .= '&sref=' . $sref;
// Lignes des titres
@@ -356,13 +373,15 @@ if ($resql) {
'';
}
echo '| | ',
- ' | ',
+ '' . $langs->trans('AlertOnly') . ' | ',
' | ',
' | ',
' | ',
'',
'theme . '/img/search.png" alt="' . $langs->trans("Search") . '">',
+ '',
' | ',
'';
@@ -396,9 +415,6 @@ if ($resql) {
$prod->type = $objp->fk_product_type;
$ordered = ordered($prod->id);
- if (!$objp->stock_physique) {
- $objp->stock_physique = 0;
- }
if ($conf->global->USE_VIRTUAL_STOCK) {
//compute virtual stock
$prod->fetch($prod->id);
@@ -487,14 +503,15 @@ if ($resql) {
'',
'',
'';
if ($num > $conf->liste_limit) {
- if ($sref || $snom || $sall || GETPOST('search', 'alpha')) {
+ if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) {
$filters = '&sref=' . $sref . '&snom=' . $snom;
- $filters .= '&sall=' . $sall;
+ $filters .= '&sall=' . $sall;
+ $filters .= '&salert=' . $salert;
print_barre_liste('',
$page,
'replenish.php',
@@ -509,7 +526,8 @@ if ($resql) {
} else {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id;
- $filters .= (isset($type)? '&type=' . $type : '');
+ $filters .= (isset($type)? '&type=' . $type : '');
+ $filters .= '&salert=' . $salert;
print_barre_liste('',
$page,
'replenish.php',
diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php
index ed76755cfc0..c7be26c4861 100644
--- a/htdocs/product/stock/replenishorders.php
+++ b/htdocs/product/stock/replenishorders.php
@@ -103,10 +103,17 @@ if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id;
}
if ($sref) {
- $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"';
+ //natural search
+ $scrit = explode(' ', $sref);
+ foreach ($scrit as $crit) {
+ $sql .= ' AND cf.ref LIKE "%' . $db->escape($crit) . '%"';
+ }
}
if ($snom) {
- $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"';
+ $scrit = explode(' ', $snom);
+ foreach ($scrit as $crit) {
+ $sql .= ' AND s.nom LIKE "%' . $db->escape($crit) . '%"';
+ }
}
if ($suser) {
$sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"';