Merge pull request #1217 from csalvador/replenishment-fix

Replenishment fix
This commit is contained in:
Laurent Destailleur 2013-09-06 13:48:47 -07:00
commit 8a82b01b22
5 changed files with 53 additions and 26 deletions

View File

@ -95,3 +95,4 @@ ReplenishmentOrders=Replenishment orders
UseVirtualStock=Use virtual stock instead of physical stock UseVirtualStock=Use virtual stock instead of physical stock
RuleForStockReplenishment=Rule for stocks replenishment RuleForStockReplenishment=Rule for stocks replenishment
SelectProduct=Select at least one product SelectProduct=Select at least one product
AlertOnly= Alerts only

View File

@ -95,3 +95,4 @@ ReplenishmentOrders=Commandes de réapprovisionnement
UseVirtualStock=Utiliser le stock théorique à la place du stock physique UseVirtualStock=Utiliser le stock théorique à la place du stock physique
RuleForStockReplenishment=Règle de gestion du réapprovisionnement des stocks RuleForStockReplenishment=Règle de gestion du réapprovisionnement des stocks
SelectProduct=Sélectionnez au moins un produit SelectProduct=Sélectionnez au moins un produit
AlertOnly = Alertes seulement

View File

@ -117,7 +117,7 @@ function ordered($product_id)
} else { } else {
$error = $db->lasterror(); $error = $db->lasterror();
dol_print_error($db); dol_print_error($db);
dol_syslog('replenish.php: ' . $error, LOG_ERROR); dol_syslog('replenish.php: ' . $error, LOG_ERR);
return $langs->trans('error'); return $langs->trans('error');
} }

View File

@ -47,6 +47,7 @@ $snom = GETPOST('snom', 'alpha');
$sall = GETPOST('sall', 'alpha'); $sall = GETPOST('sall', 'alpha');
$type = GETPOST('type','int'); $type = GETPOST('type','int');
$tobuy = GETPOST('tobuy', 'int'); $tobuy = GETPOST('tobuy', 'int');
$salert = GETPOST('salert', 'alpha');
$sortfield = GETPOST('sortfield','alpha'); $sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha'); $sortorder = GETPOST('sortorder','alpha');
@ -66,9 +67,16 @@ $offset = $limit * $page ;
* Actions * Actions
*/ */
if (isset($_POST['button_removefilter']) || isset($_POST['valid'])) {
$sref = '';
$snom = '';
$sal = '';
$salert = '';
}
//orders creation //orders creation
//FIXME: could go in the lib //FIXME: could go in the lib
if ($action == 'order') { if ($action == 'order' && isset($_POST['valid'])) {
$linecount = GETPOST('linecount', 'int'); $linecount = GETPOST('linecount', 'int');
$box = 0; $box = 0;
unset($_POST['linecount']); unset($_POST['linecount']);
@ -105,7 +113,7 @@ if ($action == 'order') {
} else { } else {
$error=$db->lasterror(); $error=$db->lasterror();
dol_print_error($db); dol_print_error($db);
dol_syslog('replenish.php: '.$error, LOG_ERROR); dol_syslog('replenish.php: '.$error, LOG_ERR);
} }
$db->free($resql); $db->free($resql);
unset($_POST['fourn' . $i]); unset($_POST['fourn' . $i]);
@ -152,7 +160,7 @@ $title = $langs->trans('Status');
$sql = 'SELECT p.rowid, p.ref, p.label, p.price'; $sql = 'SELECT p.rowid, p.ref, p.label, p.price';
$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type'; $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 .= ', 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 .= ', p.desiredstock';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf';
@ -175,10 +183,18 @@ if (dol_strlen($type)) {
} }
} }
if ($sref) { 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) { 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'; $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.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$sql .= ', p.duration, p.tobuy, p.seuil_stock_alerte'; $sql .= ', p.duration, p.tobuy, p.seuil_stock_alerte';
$sql .= ', p.desiredstock'; $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'; $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->order($sortfield,$sortorder);
$sql .= $db->plimit($limit + 1, $offset); $sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql); $resql = $db->query($sql);
@ -199,11 +219,6 @@ $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $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 = 'EN:Module_Stocks_En|FR:Module_Stock|';
$helpurl .= 'ES:M&oacute;dulo_Stocks'; $helpurl .= 'ES:M&oacute;dulo_Stocks';
@ -216,9 +231,10 @@ if ($resql) {
$head[1][1] = $langs->trans("ReplenishmentOrders"); $head[1][1] = $langs->trans("ReplenishmentOrders");
$head[1][2] = 'replenishorders'; $head[1][2] = 'replenishorders';
dol_fiche_head($head, 'replenish', $langs->trans('Replenishment'), 0, 'stock'); 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 = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&amp;sall=' . $sall; $filters .= '&sall=' . $sall;
$filters .= '&salert=' . $salert;
print_barre_liste($texte, print_barre_liste($texte,
$page, $page,
'replenish.php', 'replenish.php',
@ -231,7 +247,8 @@ if ($resql) {
} else { } else {
$filters = '&sref=' . $sref . '&snom=' . $snom; $filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id; $filters .= '&fourn_id=' . $fourn_id;
$filters .= (isset($type)?'&amp;type=' . $type:''); $filters .= (isset($type)?'&type=' . $type:'');
$filters .= '&salert=' . $salert;
print_barre_liste($texte, print_barre_liste($texte,
$page, $page,
'replenish.php', 'replenish.php',
@ -253,7 +270,7 @@ if ($resql) {
'<table class="liste" width="100%">'; '<table class="liste" width="100%">';
$param = (isset($type)? '&type=' . $type : ''); $param = (isset($type)? '&type=' . $type : '');
$param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert;
$param .= '&sref=' . $sref; $param .= '&sref=' . $sref;
// Lignes des titres // Lignes des titres
@ -356,13 +373,15 @@ if ($resql) {
'</td>'; '</td>';
} }
echo '<td class="liste_titre">&nbsp;</td>', echo '<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre">&nbsp;</td>', '<td class="liste_titre" align="right">' . $langs->trans('AlertOnly') . '&nbsp;<input type="checkbox" name="salert" ' . $alertchecked . '></td>',
'<td class="liste_titre" align="right">&nbsp;</td>', '<td class="liste_titre" align="right">&nbsp;</td>',
'<td class="liste_titre">&nbsp;</td>', '<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre">&nbsp;</td>', '<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre" align="right">', '<td class="liste_titre" align="right">',
'<input type="image" class="liste_titre" name="button_search"', '<input type="image" class="liste_titre" name="button_search"',
'src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png" alt="' . $langs->trans("Search") . '">', 'src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png" alt="' . $langs->trans("Search") . '">',
'<input type="image" class="liste_titre" name="button_removefilter"
src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">',
'</td>', '</td>',
'</tr>'; '</tr>';
@ -396,9 +415,6 @@ if ($resql) {
$prod->type = $objp->fk_product_type; $prod->type = $objp->fk_product_type;
$ordered = ordered($prod->id); $ordered = ordered($prod->id);
if (!$objp->stock_physique) {
$objp->stock_physique = 0;
}
if ($conf->global->USE_VIRTUAL_STOCK) { if ($conf->global->USE_VIRTUAL_STOCK) {
//compute virtual stock //compute virtual stock
$prod->fetch($prod->id); $prod->fetch($prod->id);
@ -487,14 +503,15 @@ if ($resql) {
'</div>', '</div>',
'<table width="100%">', '<table width="100%">',
'<tr><td align="right">', '<tr><td align="right">',
'<input class="butAction" type="submit" value="' . $value . '">', '<input class="butAction" type="submit" name="valid" value="' . $value . '">',
'</td></tr></table>', '</td></tr></table>',
'</form>'; '</form>';
if ($num > $conf->liste_limit) { 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 = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&amp;sall=' . $sall; $filters .= '&sall=' . $sall;
$filters .= '&salert=' . $salert;
print_barre_liste('', print_barre_liste('',
$page, $page,
'replenish.php', 'replenish.php',
@ -509,7 +526,8 @@ if ($resql) {
} else { } else {
$filters = '&sref=' . $sref . '&snom=' . $snom; $filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id; $filters .= '&fourn_id=' . $fourn_id;
$filters .= (isset($type)? '&amp;type=' . $type : ''); $filters .= (isset($type)? '&type=' . $type : '');
$filters .= '&salert=' . $salert;
print_barre_liste('', print_barre_liste('',
$page, $page,
'replenish.php', 'replenish.php',

View File

@ -103,10 +103,17 @@ if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id; $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id;
} }
if ($sref) { 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) { 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) { if ($suser) {
$sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"';