diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index c2f4ace565d..78b4f9d916e 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -102,4 +102,6 @@ WarehouseForStockIncrease=The warehouse %s 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 \ No newline at end of file +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/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 61d4a4451b4..d9ffd5d5574 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -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 %s en stock avant la période sélectionnée (< %s) +NbOfProductAfterPeriod=Quantité du produit %s en stock après la période sélectionnée (> %s) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 3297b078fea..584f5773ede 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -1,7 +1,7 @@ - * Copyright (C) 2005-2009 Laurent Destailleur - * Copyright (C) 2011 Jean Heimburger + * Copyright (C) 2005-2013 Laurent Destailleur + * Copyright (C) 2011 Jean Heimburger * * 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; + } + } + } ?> diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 48d85b0a67b..02c7b617021 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -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 ''; // Label of movement print ''; - print ''; + print ''; print ''; - // Product + // Product Ref print ''; - print ''; + print ''; + print ''; + // Product label + print ''; + print ''; print ''; print ''; if (empty($idproduct) || $idproduct < 0) print ''; // We are on a specific warehouse card, no filter on other should be possible @@ -445,10 +459,15 @@ if ($resql) print "\n"; print ''; + $arrayofuniqueproduct=array(); + $var=True; while ($i < min($num,$conf->liste_limit)) { $objp = $db->fetch_object($resql); + + $arrayofuniqueproduct[$objp->rowid]=$objp->produit; + $var=!$var; print ""; // Id movement @@ -457,7 +476,14 @@ if ($resql) print ''.dol_print_date($db->jdate($objp->datem),'dayhour').''; // Label of movement print ''.$objp->label.''; - // Product + // Product ref + print ''; + $productstatic->id=$objp->rowid; + $productstatic->ref=$objp->product_ref; + $productstatic->type=$objp->type; + print $productstatic->getNomUrl(1,'',16); + print "\n"; + // Product label print ''; $productstatic->id=$objp->rowid; $productstatic->ref=$objp->produit; @@ -485,7 +511,38 @@ if ($resql) } $db->free($resql); - print ""; + print "
"; + + // 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 ''; + print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore,'day','gmt')); + //print ''; + //print ''; + print ': '.$balancebefore; + print "
\n"; + //print ''; + //print ''; + print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter,'day','gmt')); + //print ''; + //print ''; + print ': '.$balanceafter; + print "
\n"; + //print ''; + } + } else