From 6a51f5f87a921cea019e3f29ce95fecdf6f86e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 10:26:00 +0200 Subject: [PATCH 01/10] don't jump to the product card when there's only one research result --- htdocs/product/stock/replenish.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 6b442f763f7..fb24b525cdb 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -199,11 +199,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'; From b58297a791f900043b750fc08c610a9fed81ea79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 10:55:10 +0200 Subject: [PATCH 02/10] fixed warning showing up when searching --- htdocs/product/stock/replenish.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index fb24b525cdb..7eed3f2b13b 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -66,9 +66,15 @@ $offset = $limit * $page ; * Actions */ +if (isset($_POST['button_removefilter'])) { + $sref = ''; + $snom = ''; + $sal = ''; +} + //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']); @@ -358,6 +364,8 @@ if ($resql) { '', '', + '', '', ''; @@ -482,7 +490,7 @@ if ($resql) { '', '', '
', - '', + '', '
', ''; From bbae47c48f8647d542dfed205a1ff3d1465acc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 11:06:33 +0200 Subject: [PATCH 03/10] natural search --- htdocs/product/stock/replenish.php | 12 ++++++++++-- htdocs/product/stock/replenishorders.php | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 7eed3f2b13b..5e4835ec4ff 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -181,10 +181,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'; 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) . '%"'; From 6015a36183536c449766979e6401610b603a4338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 11:43:47 +0200 Subject: [PATCH 04/10] filter on stock alert --- htdocs/langs/en_US/stocks.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 1 + htdocs/product/stock/replenish.php | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) 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/replenish.php b/htdocs/product/stock/replenish.php index 5e4835ec4ff..fa7663e1932 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'); +$salerte = GETPOST('salerte', 'alpha'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); @@ -66,10 +67,11 @@ $offset = $limit * $page ; * Actions */ -if (isset($_POST['button_removefilter'])) { +if (isset($_POST['button_removefilter']) || isset($_POST['valid'])) { $sref = ''; $snom = ''; $sal = ''; + $salerte = ''; } //orders creation @@ -206,6 +208,9 @@ $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 .= ' AND p.desiredstock > 0'; +if ($salerte == 'on') { + $sql .= ' AND SUM(s.reel) < p.seuil_stock_alerte AND p.seuil_stock_alerte is not NULL'; +} $sql .= $db->order($sortfield,$sortorder); $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); @@ -365,7 +370,7 @@ if ($resql) { ''; } echo ' ', - ' ', + '' . $langs->trans('AlertOnly') . ' ', ' ', ' ', ' ', From 41ad9bdb7f96353b99bbd69619542831f4f10448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 12:13:31 +0200 Subject: [PATCH 05/10] frenglish is bad --- htdocs/product/stock/replenish.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index fa7663e1932..d615a7ddc07 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -47,7 +47,7 @@ $snom = GETPOST('snom', 'alpha'); $sall = GETPOST('sall', 'alpha'); $type = GETPOST('type','int'); $tobuy = GETPOST('tobuy', 'int'); -$salerte = GETPOST('salerte', 'alpha'); +$salert = GETPOST('salert', 'alpha'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); @@ -71,7 +71,7 @@ if (isset($_POST['button_removefilter']) || isset($_POST['valid'])) { $sref = ''; $snom = ''; $sal = ''; - $salerte = ''; + $salert = ''; } //orders creation @@ -208,7 +208,7 @@ $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 .= ' AND p.desiredstock > 0'; -if ($salerte == 'on') { +if ($salert == 'on') { $sql .= ' AND SUM(s.reel) < p.seuil_stock_alerte AND p.seuil_stock_alerte is not NULL'; } $sql .= $db->order($sortfield,$sortorder); @@ -370,7 +370,7 @@ if ($resql) { ''; } echo ' ', - '' . $langs->trans('AlertOnly') . ' ', + '' . $langs->trans('AlertOnly') . ' ', ' ', ' ', ' ', From 0a6079934b880cf9a6b256a63e4fce5de81426b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 14:26:31 +0200 Subject: [PATCH 06/10] alertonly checkbox stays checked --- htdocs/product/stock/replenish.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index d615a7ddc07..f2d4f04a79b 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -210,6 +210,7 @@ $sql .= ' HAVING (p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL)'; $sql .= ' AND p.desiredstock > 0'; if ($salert == 'on') { $sql .= ' AND SUM(s.reel) < 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); @@ -370,7 +371,7 @@ if ($resql) { ''; } echo ' ', - '' . $langs->trans('AlertOnly') . ' ', + '' . $langs->trans('AlertOnly') . ' ', ' ', ' ', ' ', From a9ca9c04efd6897e3314856df97f178a30b05cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 15:12:04 +0200 Subject: [PATCH 07/10] Fixed request returning nothing when there's no records in llx_product_stock --- htdocs/product/stock/replenish.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index f2d4f04a79b..29823d81ca7 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -160,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'; @@ -206,10 +206,10 @@ $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(s.reel) < p.seuil_stock_alerte AND p.seuil_stock_alerte is not NULL'; + $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); @@ -413,9 +413,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); From d8e5fbc662b3f4359823bfd7332926b75cd4a3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 4 Sep 2013 15:50:36 +0200 Subject: [PATCH 08/10] keep the alert filter when changing page --- htdocs/product/stock/replenish.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 29823d81ca7..7f93c77878f 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -233,7 +233,7 @@ if ($resql) { dol_fiche_head($head, 'replenish', $langs->trans('Replenishment'), 0, 'stock'); if ($sref || $snom || $sall || GETPOST('search', 'alpha')) { $filters = '&sref=' . $sref . '&snom=' . $snom; - $filters .= '&sall=' . $sall; + $filters .= '&sall=' . $sall . '&salert=' . $salert; print_barre_liste($texte, $page, 'replenish.php', @@ -244,7 +244,7 @@ if ($resql) { $num ); } else { - $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters = '&sref=' . $sref . '&snom=' . $snom . '&salert=' . $salert; $filters .= '&fourn_id=' . $fourn_id; $filters .= (isset($type)?'&type=' . $type:''); print_barre_liste($texte, @@ -268,7 +268,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 From 1db9cdac287860818c2a1f4c2207e886df8e7296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 4 Sep 2013 16:26:00 +0200 Subject: [PATCH 09/10] Fixed pagination --- htdocs/product/stock/replenish.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 7f93c77878f..27e5e104160 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -231,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 . '&salert=' . $salert; + $filters .= '&sall=' . $sall; + $filters .= '&salert=' . $salert; print_barre_liste($texte, $page, 'replenish.php', @@ -244,9 +245,10 @@ if ($resql) { $num ); } else { - $filters = '&sref=' . $sref . '&snom=' . $snom . '&salert=' . $salert; + $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', @@ -506,9 +508,10 @@ 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', @@ -523,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', From 413d76ce513c42f5dde23b291b223ef31c03f704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 6 Sep 2013 09:39:48 +0200 Subject: [PATCH 10/10] fixed error level --- htdocs/product/stock/lib/replenishment.lib.php | 2 +- htdocs/product/stock/replenish.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 27e5e104160..fbb6edf3bae 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -113,7 +113,7 @@ if ($action == 'order' && isset($_POST['valid'])) { } 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]);