New: Add number of product in stock before and after selected period

when a filter is done on a period + a specific product.
This commit is contained in:
Laurent Destailleur 2013-10-10 17:16:15 +02:00
parent 22fd5dfb8a
commit ae8f0c3efd
4 changed files with 109 additions and 18 deletions

View File

@ -102,4 +102,6 @@ WarehouseForStockIncrease=The warehouse <b>%s</b> will be used for stock increas
ForThisWarehouse=For this warehouse
ReplenishmentStatusDesc=This is list of all product with a physical stock lower than desired stock (or 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
Replenishments=Replenishments
Replenishments=Replenishments
NbOfProductBeforePeriod=Quantity of product %s in stock before selected period (< %s)
NbOfProductAfterPeriod=Quantity of product %s in stock after selected period (> %s)

View File

@ -103,3 +103,5 @@ ForThisWarehouse=Pour cet entrepôt
ReplenishmentStatusDesc=Cet écran permet de voir les produits avec un stock physique inférieure à la quantité minimale désirée (ou à la quantité du seuil d'alerte si la case "Alertes seulement" est cochée) et propose de créer des commandes fournisseurs pour compléter la différence
ReplenishmentOrdersDesc=Voici la liste des commandes fournisseurs en cours
Replenishments=Réapprovisionnement
NbOfProductBeforePeriod=Quantité du produit <b>%s</b> en stock avant la période sélectionnée (< <b>%s</b>)
NbOfProductAfterPeriod=Quantité du produit <b>%s</b> en stock après la période sélectionnée (> <b>%s</b>)

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -353,5 +353,35 @@ class MouvementStock
return $nbSP;
}
/**
* Count number of product in stock before a specific date
*
* @param int $productidselected Id of product to count
* @param timestamp $datebefore Date limit
* @return int Number
*/
function calculateBalanceForProductBefore($productidselected, $datebefore)
{
$nb=0;
$sql = 'SELECT SUM(value) as nb from '.MAIN_DB_PREFIX.'stock_mouvement';
$sql.= ' WHERE fk_product = '.$productidselected;
$sql.= " AND datem < '".$this->db->idate($datebefore)."'";
dol_syslog(get_class($this).__METHOD__.' sql='.$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$obj=$this->db->fetch_object($resql);
if ($obj) $nb = $obj->nb;
return (empty($nb)?0:$nb);
}
else
{
dol_print_error($this->db);
return -1;
}
}
}
?>

View File

@ -25,6 +25,7 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
@ -43,12 +44,13 @@ $product_id=GETPOST("product_id");
$action=GETPOST('action');
$cancel=GETPOST('cancel');
$idproduct = GETPOST('idproduct','int');
$year = isset($_GET["year"])?$_GET["year"]:$_POST["year"];
$month = isset($_GET["month"])?$_GET["month"]:$_POST["month"];
$search_movement = isset($_REQUEST["search_movement"])?$_REQUEST["search_movement"]:'';
$search_product = isset($_REQUEST["search_product"])?$_REQUEST["search_product"]:'';
$search_warehouse = isset($_REQUEST["search_warehouse"])?$_REQUEST["search_warehouse"]:'';
$search_user = isset($_REQUEST["search_user"])?$_REQUEST["search_user"]:'';
$year = GETPOST("year");
$month = GETPOST("month");
$search_movement = GETPOST("search_movement");
$search_product_ref = trim(GETPOST("search_product_ref"));
$search_product = trim(GETPOST("search_product"));
$search_warehouse = trim(GETPOST("search_warehouse"));
$search_user = trim(GETPOST("search_user"));
$page = GETPOST("page",'int');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
@ -63,6 +65,7 @@ if (GETPOST("button_removefilter"))
$year='';
$month='';
$search_movement="";
$search_product_ref="";
$search_product="";
$search_warehouse="";
$search_user="";
@ -109,12 +112,13 @@ if ($action == "correct_stock" && ! $_POST["cancel"])
$productstatic=new Product($db);
$warehousestatic=new Entrepot($db);
$movement=new MouvementStock($db);
$userstatic=new User($db);
$form=new Form($db);
$formother=new FormOther($db);
$formproduct=new FormProduct($db);
$sql = "SELECT p.rowid, p.label as produit, p.fk_product_type as type,";
$sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.fk_product_type as type,";
$sql.= " e.label as stock, e.rowid as entrepot_id,";
$sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label,";
$sql.= " u.login";
@ -145,6 +149,10 @@ if (! empty($search_movement))
{
$sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'";
}
if (! empty($search_product_ref))
{
$sql.= " AND p.ref LIKE '%".$db->escape($search_product_ref)."%'";
}
if (! empty($search_product))
{
$sql.= " AND p.label LIKE '%".$db->escape($search_product)."%'";
@ -157,7 +165,7 @@ if (! empty($search_user))
{
$sql.= " AND u.login LIKE '%".$db->escape($search_user)."%'";
}
if (! empty($_GET['idproduct']))
if ($idproduct > 0)
{
$sql.= " AND p.rowid = '".$idproduct."'";
}
@ -176,7 +184,7 @@ if ($resql)
$product->fetch($idproduct);
}
if ($_GET["id"])
if ($id > 0)
{
$entrepot = new Entrepot($db);
$result = $entrepot->fetch($id);
@ -392,6 +400,7 @@ if ($resql)
$param='';
if ($id) $param.='&id='.$id;
if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
if ($search_product_ref) $param.='&search_product_ref='.urlencode($search_product_ref);
if ($search_product) $param.='&search_product='.urlencode($search_product);
if ($search_warehouse) $param.='&search_warehouse='.urlencode($search_warehouse);
if ($sref) $param.='&sref='.urlencode($sref);
@ -406,7 +415,8 @@ if ($resql)
//print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"], "m.rowid","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"], "m.datem","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Product"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ProductRef"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ProductLabel"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); // We are on a specific warehouse card, no filter on other should be possible
print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Units"),$_SERVER["PHP_SELF"], "m.value","",$param,'align="right"',$sortfield,$sortorder);
@ -425,11 +435,15 @@ if ($resql)
print '</td>';
// Label of movement
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="12" name="search_movement" value="'.$search_movement.'">';
print '<input class="flat" type="text" size="10" name="search_movement" value="'.$search_movement.'">';
print '</td>';
// Product
// Product Ref
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="12" name="search_product" value="'.($idproduct?$product->libelle:$search_product).'">';
print '<input class="flat" type="text" size="6" name="search_product_ref" value="'.($idproduct?$product->ref:$search_product_ref).'">';
print '</td>';
// Product label
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="10" name="search_product" value="'.($idproduct?$product->libelle:$search_product).'">';
print '</td>';
print '<td class="liste_titre" align="left">';
if (empty($idproduct) || $idproduct < 0) print '<input class="flat" type="text" size="10" name="search_warehouse" value="'.($search_warehouse).'">'; // We are on a specific warehouse card, no filter on other should be possible
@ -445,10 +459,15 @@ if ($resql)
print "</tr>\n";
print '</form>';
$arrayofuniqueproduct=array();
$var=True;
while ($i < min($num,$conf->liste_limit))
{
$objp = $db->fetch_object($resql);
$arrayofuniqueproduct[$objp->rowid]=$objp->produit;
$var=!$var;
print "<tr ".$bc[$var].">";
// Id movement
@ -457,7 +476,14 @@ if ($resql)
print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>';
// Label of movement
print '<td>'.$objp->label.'</td>';
// Product
// Product ref
print '<td>';
$productstatic->id=$objp->rowid;
$productstatic->ref=$objp->product_ref;
$productstatic->type=$objp->type;
print $productstatic->getNomUrl(1,'',16);
print "</td>\n";
// Product label
print '<td>';
$productstatic->id=$objp->rowid;
$productstatic->ref=$objp->produit;
@ -485,7 +511,38 @@ if ($resql)
}
$db->free($resql);
print "</table>";
print "</table><br>";
// Add number of product when there is a filter on period
if (count($arrayofuniqueproduct) == 1)
{
$productidselected=0;
foreach ($arrayofuniqueproduct as $key => $val)
{
$productidselected=$key;
$productlabelselected=$val;
}
$datebefore=dol_get_first_day($year, $month?$month:1, true);
$dateafter=dol_get_last_day($year, $month?$month:12, true);
$balancebefore=$movement->calculateBalanceForProductBefore($productidselected, $datebefore);
$balanceafter=$movement->calculateBalanceForProductBefore($productidselected, $dateafter);
//print '<tr class="total"><td class="liste_total">';
print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore,'day','gmt'));
//print '</td>';
//print '<td class="liste_total" colspan="6" align="right">';
print ': '.$balancebefore;
print "<br>\n";
//print '</td></tr>';
//print '<tr class="total"><td class="liste_total">';
print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter,'day','gmt'));
//print '</td>';
//print '<td class="liste_total" colspan="6" align="right">';
print ': '.$balanceafter;
print "<br>\n";
//print '</td></tr>';
}
}
else