diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php
index 472b9ce4a4549bac4817402cb870cf55937d1a52..2ae1dcd1582799a4ba336222be9919cb6761acdb 100644
--- a/htdocs/product/stats/commande.php
+++ b/htdocs/product/stats/commande.php
@@ -2,6 +2,7 @@
 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
  *
  * 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
@@ -27,6 +28,7 @@ require '../../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
 
 $langs->load("orders");
 $langs->load("products");
@@ -38,7 +40,8 @@ $ref = GETPOST('ref', 'alpha');
 // Security check
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
-if ($user->societe_id) $socid=$user->societe_id;
+$socid='';
+if (! empty($user->societe_id)) $socid=$user->societe_id;
 $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
@@ -55,13 +58,23 @@ $pageprev = $page - 1;
 $pagenext = $page + 1;
 if (! $sortorder) $sortorder="DESC";
 if (! $sortfield) $sortfield="c.date_commande";
+$search_month = GETPOST('search_month', 'aplha');
+$search_year = GETPOST('search_year', 'int');
 
+if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) {
+	$search_month='';
+	$search_year='';
+}
 
 /*
  * View
  */
 
+$orderstatic=new Commande($db);
+$societestatic=new Societe($db);
+
 $form = new Form($db);
+$formother= new FormOther($db);
 
 if ($id > 0 || ! empty($ref))
 {
@@ -76,9 +89,6 @@ if ($id > 0 || ! empty($ref))
 
 	if ($result > 0)
 	{
-		/*
-		 *  En mode visu
-		 */
 		$head=product_prepare_head($product, $user);
 		$titre=$langs->trans("CardProduct".$product->type);
 		$picto=($product->type==1?'service':'product');
@@ -87,7 +97,6 @@ if ($id > 0 || ! empty($ref))
 		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action);    // Note that $action and $object may have been modified by hook
 		if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
-
 		print '<table class="border" width="100%">';
 
 		// Reference
@@ -117,83 +126,138 @@ if ($id > 0 || ! empty($ref))
 
 		print '</div>';
 
-
-		$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, c.rowid, c.total_ht as total_ht, c.ref,";
-		$sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.qty";
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
-		$sql.= ", ".MAIN_DB_PREFIX."commande as c";
-		$sql.= ", ".MAIN_DB_PREFIX."commandedet as d";
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-		$sql.= " WHERE c.fk_soc = s.rowid";
-		$sql.= " AND c.entity = ".$conf->entity;
-		$sql.= " AND d.fk_commande = c.rowid";
-		$sql.= " AND d.fk_product =".$product->id;
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
-		if ($socid) $sql.= " AND c.fk_soc = ".$socid;
-		$sql.= " ORDER BY $sortfield $sortorder ";
-		$sql.= $db->plimit($conf->liste_limit +1, $offset);
-
-		$result = $db->query($sql);
-		if ($result)
+		if ($user->rights->commande->lire) 
 		{
-			$num = $db->num_rows($result);
-
-			print_barre_liste($langs->trans("CustomersOrders"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
-
-			$i = 0;
-			print "<table class=\"noborder\" width=\"100%\">";
-
-			print '<tr class="liste_titre">';
-			print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-			print "</tr>\n";
-
-			$commandestatic=new Commande($db);
-
-			if ($num > 0)
+			$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, c.rowid, d.total_ht as total_ht, c.ref,";
+			$sql .= " c.ref_client,";
+			$sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.qty";
+			if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
+			$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
+			$sql.= ", ".MAIN_DB_PREFIX."commande as c";
+			$sql.= ", ".MAIN_DB_PREFIX."commandedet as d";
+			if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql.= " WHERE c.fk_soc = s.rowid";
+			$sql.= " AND c.entity = ".$conf->entity;
+			$sql.= " AND d.fk_commande = c.rowid";
+			$sql.= " AND d.fk_product =".$product->id;
+	            if (! empty($search_month))
+	            	$sql.= ' AND MONTH(f.datef) IN (' . $search_month . ')';
+	            if (! empty($search_year))
+	            	$sql.= ' AND YEAR(f.datef) IN (' . $search_year . ')';
+			if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+			if ($socid) $sql.= " AND c.fk_soc = ".$socid;
+			$sql.= " ORDER BY $sortfield $sortorder ";
+	            
+	        //Calcul total qty and amount for global if full scan list
+	        $total_ht=0;
+	        $total_qty=0;
+			$totalrecords=0;
+	        if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+	        	$result = $db->query($sql);
+	        	if ($result) {
+	        		$totalrecords = $db->num_rows($result);
+	        		while ($objp = $db->fetch_object($result)) {
+	        			$total_ht+=$objp->total_ht;
+	        			$total_qty+=$objp->qty;
+	        		}
+	        	}
+	        }
+	            
+			$sql.= $db->plimit($conf->liste_limit +1, $offset);
+	
+			$result = $db->query($sql);
+			if ($result)
 			{
-				$var=True;
-				while ($i < $num && $i < $conf->liste_limit)
+				$num = $db->num_rows($result);
+	 			
+				if (! empty($id))
+	            	$option .= '&amp;id='.$product->id;
+	            if (! empty($search_month))
+	            	$option .= '&amp;search_month='.$search_month;
+	            if (! empty($search_year))
+	            	$option .= '&amp;search_year='.$search_year;
+	            
+	            print '<form method="post" action="' . $_SERVER ['PHP_SELF'] . '?id='.$product->id.'" name="search_form">' . "\n";
+	            if (! empty($sortfield))
+	            	print '<input type="hidden" name="sortfield" value="' . $sortfield . '"/>';
+	            if (! empty($sortorder))
+	            	print '<input type="hidden" name="sortorder" value="' . $sortorder . '"/>';
+	            if (! empty($page)) {
+	            	print '<input type="hidden" name="page" value="' . $page . '"/>';
+	            	$option .= '&amp;page=' . $page;
+	            }
+	
+				print_barre_liste($langs->trans("CustomersOrders"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,$totalrecords,'');
+				print '<div class="liste_titre">';
+			    print $langs->trans('Period').'('.$langs->trans("DateInvoice") .') ';
+				print $langs->trans('Month') . ':<input class="flat" type="text" size="4" name="search_month" value="' . $search_month . '"> ';
+				print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
+				print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
+				print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
+			    print '</div>';
+	
+				$i = 0;
+	            print '<table class="noborder" width="100%">';
+				print '<tr class="liste_titre">';
+				print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","",$option,'',$sortfield,$sortorder);
+				print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$option,'',$sortfield,$sortorder);
+				print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","",$option,'',$sortfield,$sortorder);
+				print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","",$option,'align="center"',$sortfield,$sortorder);
+				print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","",$option,'align="center"',$sortfield,$sortorder);
+				print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","",$option,'align="right"',$sortfield,$sortorder);
+				print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","",$option,'align="right"',$sortfield,$sortorder);
+				print "</tr>\n";
+	
+				if ($num > 0)
 				{
-					$objp = $db->fetch_object($result);
-					$var=!$var;
-
-					print "<tr ".$bc[$var].">";
-					print '<td><a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$objp->commandeid.'">'.img_object($langs->trans("ShowOrder"),"order").' ';
-					print $objp->ref;
-					print "</a></td>\n";
-					print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
-					print "<td>".$objp->code_client."</td>\n";
-					print "<td align=\"center\">";
-					print dol_print_date($db->jdate($objp->date_commande))."</td>";
-					print "<td align=\"center\">".$objp->qty."</td>\n";
-					print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
-					print '<td align="right">'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'</td>';
-					print "</tr>\n";
-					$i++;
+					$var=True;
+					while ($i < $num && $i < $conf->liste_limit)
+					{
+						$objp = $db->fetch_object($result);
+						$var=!$var;
+	
+						print '<tr '.$bc[$var].'>';
+	 					print '<td>';
+	                    $orderstatic->id=$objp->commandeid;
+	                    $orderstatic->ref=$objp->ref;
+	                    $orderstatic->ref_client=$objp->ref_client;
+	                    print $orderstatic->getNomUrl(1);
+	                    print "</td>\n";
+						$societestatic->fetch($objp->socid);
+	                    print '<td>'.$societestatic->getNomUrl(1).'</td>';
+	                    print "<td>".$objp->code_client."</td>\n";
+						print '<td align="center">';
+						print dol_print_date($db->jdate($objp->date_commande))."</td>";
+						print  '<td align="center">'.$objp->qty."</td>\n";
+	                    print '<td align="right">'.price($objp->total_ht)."</td>\n";
+						print '<td align="right">'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'</td>';
+						print "</tr>\n";
+						$i++;
+	                        
+	                    if (!empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+	                        $total_ht+=$objp->total_ht;
+	                        $total_qty+=$objp->qty;
+						}
+					}
 				}
+                print '<tr class="liste_total">';
+                print '<td>' . $langs->trans('Total') . '</td>';
+                print '<td colspan="3"></td>';
+                print '<td align="center">'.$total_qty.'</td>';
+                print '<td align="right">'.price($total_ht).'</td>';
+                print '<td></td>';
+                print "</table>";
+                print '</form>';
+                print '<br>';
+            } else {
+				dol_print_error($db);
 			}
+			$db->free($result);
 		}
-		else
-		{
-			dol_print_error($db);
-		}
-		print "</table>";
-		print '<br>';
-		$db->free($result);
 	}
-}
-else
-{
+} else {
 	dol_print_error();
 }
 
-
 llxFooter();
 $db->close();
diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php
index 73de0374ebe61c353f954bedc51e1cf0dc4d378b..3141b3266e9ae90c20fc8075a23c46aa00b0622a 100644
--- a/htdocs/product/stats/commande_fournisseur.php
+++ b/htdocs/product/stats/commande_fournisseur.php
@@ -2,6 +2,7 @@
 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
  *
  * 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
@@ -18,15 +19,15 @@
  */
 
 /**
- *	\file       htdocs/product/stats/commande_fournisseur.php
- *	\ingroup    product service commande
- *	\brief      Page des stats des commandes fournisseurs pour un produit
+ * \file htdocs/product/stats/commande_fournisseur.php
+ * \ingroup product service commande
+ * \brief Page des stats des commandes fournisseurs pour un produit
  */
-
 require '../../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
 
 $langs->load("orders");
 $langs->load("products");
@@ -38,157 +39,233 @@ $ref = GETPOST('ref', 'alpha');
 // Security check
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
-if ($user->societe_id) $socid=$user->societe_id;
-$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
+$socid = '';
+if (! empty($user->societe_id))
+	$socid = $user->societe_id;
+$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
-$hookmanager->initHooks(array('productstatssupplyorder'));
+$hookmanager->initHooks(array (
+		'productstatssupplyorder' 
+));
 
 $mesg = '';
 
-$sortfield = GETPOST("sortfield",'alpha');
-$sortorder = GETPOST("sortorder",'alpha');
-$page = GETPOST("page",'int');
-if ($page == -1) { $page = 0; }
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOST("page", 'int');
+if ($page == - 1) {
+	$page = 0;
+}
 $offset = $conf->liste_limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
-if (! $sortorder) $sortorder="DESC";
-if (! $sortfield) $sortfield="c.date_commande";
-
+if (! $sortorder)
+	$sortorder = "DESC";
+if (! $sortfield)
+	$sortfield = "c.date_commande";
+$search_month = GETPOST('search_month', 'aplha');
+$search_year = GETPOST('search_year', 'int');
+
+if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) {
+	$search_month = '';
+	$search_year = '';
+}
 
 /*
  * View
  */
 
+$commandefournstatic = new CommandeFournisseur($db);
+$societestatic = new Societe($db);
+
 $form = new Form($db);
+$formother = new FormOther($db);
 
-if ($id > 0 || ! empty($ref))
-{
+if ($id > 0 || ! empty($ref)) {
 	$product = new Product($db);
 	$result = $product->fetch($id, $ref);
-
-	$parameters=array('id'=>$id);
-	$reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action);    // Note that $action and $object may have been modified by some hooks
-	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
-	llxHeader("","",$langs->trans("CardProduct".$product->type));
-
-	if ($result > 0)
-	{
-		$head=product_prepare_head($product, $user);
-		$titre=$langs->trans("CardProduct".$product->type);
-		$picto=($product->type==1?'service':'product');
+	
+	$parameters = array (
+			'id' => $id 
+	);
+	$reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
+	if ($reshook < 0)
+		setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+	
+	llxHeader("", "", $langs->trans("CardProduct" . $product->type));
+	
+	if ($result > 0) {
+		$head = product_prepare_head($product, $user);
+		$titre = $langs->trans("CardProduct" . $product->type);
+		$picto = ($product->type == 1 ? 'service' : 'product');
 		dol_fiche_head($head, 'referers', $titre, 0, $picto);
-
-		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action);    // Note that $action and $object may have been modified by hook
-		if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
+		
+		$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
+		if ($reshook < 0)
+			setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+		
 		print '<table class="border" width="100%">';
-
+		
 		// Reference
 		print '<tr>';
-		print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
-		print $form->showrefnav($product,'ref','',1,'ref');
-		print '</td></tr>';
-
+		print '<td width="30%">' . $langs->trans("Ref") . '</td><td colspan="3">';
+		print $form->showrefnav($product, 'ref', '', 1, 'ref');
+		print '</td>';
+		print '</tr>';
+		
 		// Libelle
-		print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td></tr>';
-
+		print '<tr><td>' . $langs->trans("Label") . '</td><td colspan="3">' . $product->libelle . '</td>';
+		print '</tr>';
+		
 		// Status (to sell)
-		print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
-		print $product->getLibStatut(2,0);
+		print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')</td><td colspan="3">';
+		print $product->getLibStatut(2, 0);
 		print '</td></tr>';
-
+		
 		// Status (to buy)
-		print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
-		print $product->getLibStatut(2,1);
+		print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Buy") . ')</td><td colspan="3">';
+		print $product->getLibStatut(2, 1);
 		print '</td></tr>';
-
-		show_stats_for_company($product,$socid);
-
+		
+		show_stats_for_company($product, $socid);
+		
 		print "</table>";
+		
 		print '</div>';
-
-		$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,";
-		$sql.= " c.rowid, c.total_ht as total_ht, c.ref,";
-		$sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.qty";
-		if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
-		$sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
-		$sql.= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as d";
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-		$sql.= " WHERE c.fk_soc = s.rowid";
-		$sql.= " AND c.entity = ".$conf->entity;
-		$sql.= " AND d.fk_commande = c.rowid";
-		$sql.= " AND d.fk_product =".$product->id;
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
-		if ($socid)	$sql.= " AND c.fk_soc = ".$socid;
-		$sql.= " ORDER BY $sortfield $sortorder ";
-		$sql.= $db->plimit($conf->liste_limit +1, $offset);
-
-		$result = $db->query($sql);
-		if ($result)
-		{
-			$num = $db->num_rows($result);
-
-			print_barre_liste($langs->trans("SuppliersOrders"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
-
-			$i = 0;
-			print "<table class=\"noborder\" width=\"100%\">";
-
-			print '<tr class="liste_titre">';
-			print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-			print "</tr>\n";
-
-			$commandestatic=new CommandeFournisseur($db);
-
-			if ($num > 0)
-			{
-				$var=True;
-				while ($i < $num && $i < $conf->liste_limit)
-				{
-					$objp = $db->fetch_object($result);
-					$var=!$var;
-
-					$commandestatic->id=$objp->commandeid;
-					$commandestatic->ref=$objp->ref;
-					$commandestatic->statut=$objp->statut;
-
-					print "<tr ".$bc[$var].">";
-					print '<td>'.$commandestatic->getNomUrl(1)."</td>\n";
-					print "</a></td>\n";
-					print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
-					print "<td>".$objp->code_client."</td>\n";
-					print '<td align="center">'.dol_print_date($db->jdate($objp->date_commande))."</td>";
-					print "<td align=\"center\">".$objp->qty."</td>\n";
-					print '<td align="right">'.price($objp->total_ht)."</td>\n";
-					print '<td align="right">'.$commandestatic->getLibStatut(4).'</td>';
-					print "</tr>\n";
-					$i++;
+		
+		if ($user->rights->fournisseur->commande->lire) {
+			$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,";
+			$sql .= " c.rowid, d.total_ht as total_ht, c.ref,";
+			$sql .= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.qty";
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= ", sc.fk_soc, sc.fk_user ";
+			$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
+			$sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c";
+			$sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseurdet as d";
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
+			$sql .= " WHERE c.fk_soc = s.rowid";
+			$sql .= " AND c.entity = " . $conf->entity;
+			$sql .= " AND d.fk_commande = c.rowid";
+			$sql .= " AND d.fk_product =" . $product->id;
+			if (! empty($search_month))
+				$sql .= ' AND MONTH(f.datef) IN (' . $search_month . ')';
+			if (! empty($search_year))
+				$sql .= ' AND YEAR(f.datef) IN (' . $search_year . ')';
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
+			if ($socid)
+				$sql .= " AND c.fk_soc = " . $socid;
+			$sql .= " ORDER BY $sortfield $sortorder ";
+			
+			// Calcul total qty and amount for global if full scan list
+			$total_ht = 0;
+			$total_qty = 0;
+			$totalrecords = 0;
+			if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+				$result = $db->query($sql);
+				if ($result) {
+					$totalrecords = $db->num_rows($result);
+					while ( $objp = $db->fetch_object($result) ) {
+						$total_ht += $objp->total_ht;
+						$total_qty += $objp->qty;
+					}
 				}
 			}
+			
+			$sql .= $db->plimit($conf->liste_limit + 1, $offset);
+			
+			$result = $db->query($sql);
+			if ($result) {
+				$num = $db->num_rows($result);
+				
+				if (! empty($id))
+					$option .= '&amp;id=' . $product->id;
+				if (! empty($search_month))
+					$option .= '&amp;search_month=' . $search_month;
+				if (! empty($search_year))
+					$option .= '&amp;search_year=' . $search_year;
+				
+				print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $product->id . '" name="search_form">' . "\n";
+				if (! empty($sortfield))
+					print '<input type="hidden" name="sortfield" value="' . $sortfield . '"/>';
+				if (! empty($sortorder))
+					print '<input type="hidden" name="sortorder" value="' . $sortorder . '"/>';
+				if (! empty($page)) {
+					print '<input type="hidden" name="page" value="' . $page . '"/>';
+					$option .= '&amp;page=' . $page;
+				}
+				
+				print_barre_liste($langs->trans("SuppliersOrders"), $page, $_SERVER["PHP_SELF"], "&amp;id=$product->id", $sortfield, $sortorder, '', $num, $totalrecords, '');
+				print '<div class="liste_titre">';
+				print $langs->trans('Period') . '(' . $langs->trans("DateInvoice") . ') ';
+				print $langs->trans('Month') . ':<input class="flat" type="text" size="4" name="search_month" value="' . $search_month . '"> ';
+				print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
+				print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
+				print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
+				print '</div>';
+				
+				$i = 0;
+				print '<table class="noborder" width="100%">';
+				print '<tr class="liste_titre">';
+				print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "c.rowid", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("SupplierCode"), $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("OrderDate"), $_SERVER["PHP_SELF"], "c.date_commande", "", $option, 'align="center"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "c.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "c.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
+				print "</tr>\n";
+				
+				if ($num > 0) {
+					$var = True;
+					while ( $i < $num && $i < $conf->liste_limit ) {
+						$objp = $db->fetch_object($result);
+						$var = ! $var;
+						
+						print '<tr ' . $bc[$var] . '>';
+						print '<td>';
+						$commandestatic->id = $objp->commandeid;
+						$commandestatic->ref = $objp->ref;
+						$commandestatic->statut = $objp->statut;
+						print $commandestatic->getNomUrl(1);
+						print "</td>\n";
+						$societestatic->fetch($objp->socid);
+						print '<td>' . $societestatic->getNomUrl(1) . '</td>';
+						print "<td>" . $objp->code_client . "</td>\n";
+						print '<td align="center">';
+						print dol_print_date($db->jdate($objp->date_commande)) . "</td>";
+						print '<td align="center">' . $objp->qty . "</td>\n";
+						print '<td align="right">' . price($objp->total_ht) . "</td>\n";
+						print '<td align="right">' . $commandestatic->getLibStatut(4) . '</td>';
+						print "</tr>\n";
+						$i ++;
+						
+						if (! empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+							$total_ht += $objp->total_ht;
+							$total_qty += $objp->qty;
+						}
+					}
+				}
+				print '<tr class="liste_total">';
+				print '<td>' . $langs->trans('Total') . '</td>';
+				print '<td colspan="3"></td>';
+				print '<td align="center">' . $total_qty . '</td>';
+				print '<td align="right">' . price($total_ht) . '</td>';
+				print '<td></td>';
+				print "</table>";
+				print '</form>';
+				print '<br>';
+			} else {
+				dol_print_error($db);
+			}
+			$db->free($result);
 		}
-		else
-		{
-			dol_print_error($db);
-		}
-		print "</table>";
-		print '<br>';
-		$db->free($result);
 	}
-}
-else
-{
+} else {
 	dol_print_error();
 }
 
-
 llxFooter();
 $db->close();
diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php
index 49e5651b0651d8670acc23863c863a6411fb66eb..b59bc008f17e21c3408b454bc121e981858d5511 100644
--- a/htdocs/product/stats/facture.php
+++ b/htdocs/product/stats/facture.php
@@ -3,6 +3,7 @@
  * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2014	   Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
  *
  * 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
@@ -28,6 +29,7 @@ require '../../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
 
 $langs->load("companies");
 $langs->load("bills");
@@ -36,12 +38,11 @@ $langs->load("products");
 $id = GETPOST('id', 'int');
 $ref = GETPOST('ref', 'alpha');
 
-$socid='';
-if (! empty($user->societe_id)) $socid=$user->societe_id;
-
 // Security check
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
+$socid='';
+if (! empty($user->societe_id)) $socid=$user->societe_id;
 $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
@@ -58,16 +59,23 @@ $pageprev = $page - 1;
 $pagenext = $page + 1;
 if (! $sortorder) $sortorder="DESC";
 if (! $sortfield) $sortfield="f.datef";
+$search_month = GETPOST('search_month', 'aplha');
+$search_year = GETPOST('search_year', 'int');
 
+if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) {
+	$search_month='';
+	$search_year='';
+}
 
 /*
  * View
  */
 
 $invoicestatic=new Facture($db);
+$societestatic=new Societe($db);
 
 $form = new Form($db);
-
+$formother= new FormOther($db);
 
 if ($id > 0 || ! empty($ref))
 {
@@ -80,9 +88,6 @@ if ($id > 0 || ! empty($ref))
 
 	llxHeader("","",$langs->trans("CardProduct".$product->type));
 
-	/*
-	 *  En mode visu
-	 */
 	if ($result > 0)
 	{
 		$head=product_prepare_head($product, $user);
@@ -125,7 +130,7 @@ if ($id > 0 || ! empty($ref))
 
         if ($user->rights->facture->lire) {
             $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,";
-            $sql.= " f.facnumber, f.total as total_ht,";
+            $sql.= " f.facnumber, d.total_ht as total_ht,";
             $sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
             if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
             $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -136,33 +141,79 @@ if ($id > 0 || ! empty($ref))
             $sql.= " AND f.entity = ".$conf->entity;
             $sql.= " AND d.fk_facture = f.rowid";
             $sql.= " AND d.fk_product =".$product->id;
+            if (! empty($search_month))
+            	$sql.= ' AND MONTH(f.datef) IN (' . $search_month . ')';
+            if (! empty($search_year))
+            	$sql.= ' AND YEAR(f.datef) IN (' . $search_year . ')';
             if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
-            if ($socid) $sql.= " AND f.fk_soc = $socid";
+            if ($socid) $sql.= " AND f.fk_soc = ".$socid;
             $sql.= " ORDER BY $sortfield $sortorder ";
+            
+            //Calcul total qty and amount for global if full scan list
+            $total_ht=0;
+            $total_qty=0;
+			$totalrecords=0;
+            if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+            	$result = $db->query($sql);
+            	if ($result) {
+            		$totalrecords = $db->num_rows($result);
+            		while ($objp = $db->fetch_object($result)) {
+            			$total_ht+=$objp->total_ht;
+            			$total_qty+=$objp->qty;
+            		}
+            	}
+            }
+            
             $sql.= $db->plimit($conf->liste_limit +1, $offset);
 
             $result = $db->query($sql);
-            if ($result) {
+            if ($result) 
+			{
                 $num = $db->num_rows($result);
-
-                print_barre_liste($langs->trans("CustomersInvoices"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
+                
+                if (! empty($id))
+                	$option .= '&amp;id='.$product->id;
+                if (! empty($search_month))
+                	$option .= '&amp;search_month='.$search_month;
+                if (! empty($search_year))
+                	$option .= '&amp;search_year='.$search_year;
+                
+                print '<form method="post" action="' . $_SERVER ['PHP_SELF'] . '?id='.$product->id.'" name="search_form">' . "\n";
+                if (! empty($sortfield))
+                	print '<input type="hidden" name="sortfield" value="' . $sortfield . '"/>';
+                if (! empty($sortorder))
+                	print '<input type="hidden" name="sortorder" value="' . $sortorder . '"/>';
+                if (! empty($page)) {
+                	print '<input type="hidden" name="page" value="' . $page . '"/>';
+                	$option .= '&amp;page=' . $page;
+                }
+                
+                print_barre_liste($langs->trans("CustomersInvoices"),$page,$_SERVER["PHP_SELF"],"&amp;id=".$product->id,$sortfield,$sortorder,'',$num,$totalrecords,'');
+                print '<div class="liste_titre">';
+                print $langs->trans('Period').'('.$langs->trans("DateInvoice") .') ';
+				print $langs->trans('Month') . ':<input class="flat" type="text" size="4" name="search_month" value="' . $search_month . '"> ';
+				print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
+				print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
+				print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
+                print '</div>';
 
                 $i = 0;
                 print '<table class="noborder" width="100%">';
-
                 print '<tr class="liste_titre">';
-                print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-                print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-                print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-                print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-                print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-                print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-                print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","",$option,'',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$option,'',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","",$option,'',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","",$option,'align="center"',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","",$option,'align="center"',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","",$option,'align="right"',$sortfield,$sortorder);
+                print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","",$option,'align="right"',$sortfield,$sortorder);
                 print "</tr>\n";
 
-                if ($num > 0) {
+                if ($num > 0)
+				{
                     $var=True;
-                    while ($i < $num && $i < $conf->liste_limit) {
+                    while ($i < $num && $i < $conf->liste_limit)
+					{
                         $objp = $db->fetch_object($result);
                         $var=!$var;
 
@@ -172,7 +223,8 @@ if ($id > 0 || ! empty($ref))
                         $invoicestatic->ref=$objp->facnumber;
                         print $invoicestatic->getNomUrl(1);
                         print "</td>\n";
-                        print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
+                        $societestatic->fetch($objp->socid);
+                        print '<td>'.$societestatic->getNomUrl(1).'</td>';
                         print "<td>".$objp->code_client."</td>\n";
                         print '<td align="center">';
                         print dol_print_date($db->jdate($objp->datef),'day')."</td>";
@@ -181,9 +233,21 @@ if ($id > 0 || ! empty($ref))
                         print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
                         print "</tr>\n";
                         $i++;
+                        
+                        if (!empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+                        	$total_ht+=$objp->total_ht;
+                        	$total_qty+=$objp->qty;
+                        }
                     }
                 }
+                print '<tr class="liste_total">';
+                print '<td>' . $langs->trans('Total') . '</td>';
+                print '<td colspan="3"></td>';
+                print '<td align="center">'.$total_qty.'</td>';
+                print '<td align="right">'.price($total_ht).'</td>';
+                print '<td></td>';
                 print "</table>";
+                print '</form>';
                 print '<br>';
             } else {
                 dol_print_error($db);
@@ -195,6 +259,5 @@ if ($id > 0 || ! empty($ref))
 	dol_print_error();
 }
 
-
 llxFooter();
 $db->close();
diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php
index d8e30bdae6ae34253bc76cfa060b2bb77a299eb4..0feb415cc434735856bcbef8a714320c1860d0fe 100644
--- a/htdocs/product/stats/facture_fournisseur.php
+++ b/htdocs/product/stats/facture_fournisseur.php
@@ -3,6 +3,7 @@
  * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2013	   Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
  *
  * 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
@@ -19,15 +20,16 @@
  */
 
 /**
- *       \file       htdocs/product/stats/facture_fournisseur.php
- *       \ingroup    product service facture
- *       \brief      Page des stats des factures fournisseurs pour un produit
+ * \file htdocs/product/stats/facture_fournisseur.php
+ * \ingroup product service facture
+ * \brief Page des stats des factures fournisseurs pour un produit
  */
 
 require '../../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
 
 $langs->load("companies");
 $langs->load("bills");
@@ -40,164 +42,223 @@ $ref = GETPOST('ref', 'alpha');
 // Security check
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
-if ($user->societe_id) $socid=$user->societe_id;
-$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
+$socid = '';
+if (! empty($user->societe_id)) $socid=$user->societe_id;
+$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('productstatssupplyinvoice'));
 
 $mesg = '';
 
-$sortfield = GETPOST("sortfield",'alpha');
-$sortorder = GETPOST("sortorder",'alpha');
-$page = GETPOST("page",'int');
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOST("page", 'int');
 if ($page == -1) { $page = 0; }
 $offset = $conf->liste_limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
-if (! $sortorder) $sortorder="DESC";
-if (! $sortfield) $sortfield="f.datef";
-
-
+if (! $sortorder) $sortorder = "DESC";
+if (! $sortfield) $sortfield = "f.datef";
+$search_month = GETPOST('search_month', 'aplha');
+$search_year = GETPOST('search_year', 'int');
+
+if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) {
+	$search_month = '';
+	$search_year = '';
+}
 
 /*
  * View
  */
 
-$supplierinvoicestatic=new FactureFournisseur($db);
+$supplierinvoicestatic = new FactureFournisseur($db);
+$societestatic = new Societe($db);
 
 $form = new Form($db);
+$formother = new FormOther($db);
 
 if ($id > 0 || ! empty($ref))
 {
 	$product = new Product($db);
 	$result = $product->fetch($id, $ref);
-
-	$parameters=array('id'=>$id);
-	$reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action);    // Note that $action and $object may have been modified by some hooks
+	
+	$parameters = array('id' => $id);
+	$reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
 	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
-    llxHeader("","",$langs->trans("CardProduct".$product->type));
-
-    if ($result > 0)
-    {
-        /*
-         *  En mode visu
-         */
-		$head=product_prepare_head($product, $user);
-		$titre=$langs->trans("CardProduct".$product->type);
-		$picto=($product->type==1?'service':'product');
+	
+	llxHeader("", "", $langs->trans("CardProduct" . $product->type));
+	
+	if ($result > 0)
+	{
+		$head = product_prepare_head($product, $user);
+		$titre = $langs->trans("CardProduct" . $product->type);
+		$picto = ($product->type == 1 ? 'service' : 'product');
 		dol_fiche_head($head, 'referers', $titre, 0, $picto);
-
-		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action);    // Note that $action and $object may have been modified by hook
+		
+		$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
 		if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
-        print '<table class="border" width="100%">';
-
-        // Reference
-        print '<tr>';
-        print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
-		print $form->showrefnav($product,'ref','',1,'ref');
-        print '</td>';
-        print '</tr>';
-
-        // Libelle
-        print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
-        print '</tr>';
-
+		
+		print '<table class="border" width="100%">';
+		
+		// Reference
+		print '<tr>';
+		print '<td width="30%">' . $langs->trans("Ref") . '</td><td colspan="3">';
+		print $form->showrefnav($product, 'ref', '', 1, 'ref');
+		print '</td>';
+		print '</tr>';
+		
+		// Libelle
+		print '<tr><td>' . $langs->trans("Label") . '</td><td colspan="3">' . $product->libelle . '</td>';
+		print '</tr>';
+		
 		// Status (to sell)
-		print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
-		print $product->getLibStatut(2,0);
+		print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')</td><td colspan="3">';
+		print $product->getLibStatut(2, 0);
 		print '</td></tr>';
-
+		
 		// Status (to buy)
-		print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
-		print $product->getLibStatut(2,1);
+		print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Buy") . ')</td><td colspan="3">';
+		print $product->getLibStatut(2, 1);
 		print '</td></tr>';
-
-		show_stats_for_company($product,$socid);
-
-        print "</table>";
-
-        print '</div>';
-
-
-        $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, f.ref, f.total_ht as total_ht,";
-        $sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
-        if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
-        $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
-        $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d";
-        if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-        $sql.= " WHERE f.fk_soc = s.rowid";
-        $sql.= " AND f.entity = ".$conf->entity;
-        $sql.= " AND d.fk_facture_fourn = f.rowid";
-        $sql.= " AND d.fk_product =".$product->id;
-        if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
-        if ($socid) $sql.= " AND f.fk_soc = ".$socid;
-        $sql.= " ORDER BY $sortfield $sortorder ";
-        $sql.= $db->plimit($conf->liste_limit +1, $offset);
-
-        $result = $db->query($sql);
-        if ($result)
-        {
-            $num = $db->num_rows($result);
-
-            print_barre_liste($langs->trans("SuppliersInvoices"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
-
-            $i = 0;
-            print "<table class=\"noborder\" width=\"100%\">";
-
-            print '<tr class="liste_titre">';
-            print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-            print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-            print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-            print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-            print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-            print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-            print "</tr>\n";
-
-            if ($num > 0)
-            {
-                $var=True;
-                while ($i < $num && $conf->liste_limit)
-                {
-                    $objp = $db->fetch_object($result);
-                    $var=!$var;
-
-                    print "<tr ".$bc[$var].">";
-                    print '<td>';
-                    $supplierinvoicestatic->id=$objp->facid;
-                    $supplierinvoicestatic->ref=$objp->facnumber;
-					print $supplierinvoicestatic->getNomUrl(1);
-                    print "</td>\n";
-                    print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
-                    print "<td>".$objp->code_client."</td>\n";
-                    print "<td align=\"center\">";
-                    print dol_print_date($db->jdate($objp->datef))."</td>";
-					print "<td align=\"center\">".$objp->qty."</td>\n";
-                    print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
-                    print '<td align="right">'.$supplierinvoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
-                    print "</tr>\n";
-                    $i++;
-                }
-            }
-        }
-        else
-        {
-            dol_print_error($db);
-        }
-        print "</table>";
-        print '<br>';
-        $db->free($result);
-    }
+		
+		show_stats_for_company($product, $socid);
+		
+		print "</table>";
+		
+		print '</div>';
+		
+		if ($user->rights->fournisseur->facture->lire)
+		{
+			$sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, f.ref, d.total_ht as total_ht,";
+			$sql .= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= ", sc.fk_soc, sc.fk_user ";
+			$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
+			$sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as f";
+			$sql .= ", " . MAIN_DB_PREFIX . "facture_fourn_det as d";
+			if (! $user->rights->societe->client->voir && ! $socid)	$sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
+			$sql .= " WHERE f.fk_soc = s.rowid";
+			$sql .= " AND f.entity = " . $conf->entity;
+			$sql .= " AND d.fk_facture_fourn = f.rowid";
+			$sql .= " AND d.fk_product =" . $product->id;
+			if (! empty($search_month))	
+				$sql .= ' AND MONTH(f.datef) IN (' . $search_month . ')';
+			if (! empty($search_year)) 
+				$sql .= ' AND YEAR(f.datef) IN (' . $search_year . ')';
+			if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
+			if ($socid) $sql .= " AND f.fk_soc = " . $socid;
+			$sql .= " ORDER BY $sortfield $sortorder ";
+			
+			// Calcul total qty and amount for global if full scan list
+			$total_ht = 0;
+			$total_qty = 0;
+			$totalrecords = 0;
+			if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+				$result = $db->query($sql);
+				if ($result) {
+					$totalrecords = $db->num_rows($result);
+					while ( $objp = $db->fetch_object($result) ) {
+						$total_ht += $objp->total_ht;
+						$total_qty += $objp->qty;
+					}
+				}
+			}
+			
+			$sql .= $db->plimit($conf->liste_limit + 1, $offset);
+			
+			$result = $db->query($sql);
+			if ($result)
+			{
+				$num = $db->num_rows($result);
+				
+				if (! empty($id))
+					$option .= '&amp;id=' . $product->id;
+				if (! empty($search_month))
+					$option .= '&amp;search_month=' . $search_month;
+				if (! empty($search_year))
+					$option .= '&amp;search_year=' . $search_year;
+				
+				print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $product->id . '" name="search_form">' . "\n";
+				if (! empty($sortfield))
+					print '<input type="hidden" name="sortfield" value="' . $sortfield . '"/>';
+				if (! empty($sortorder))
+					print '<input type="hidden" name="sortorder" value="' . $sortorder . '"/>';
+				if (! empty($page)) {
+					print '<input type="hidden" name="page" value="' . $page . '"/>';
+					$option .= '&amp;page=' . $page;
+				}
+
+				print_barre_liste($langs->trans("SuppliersInvoices"), $page, $_SERVER["PHP_SELF"], "&amp;id=$product->id", $sortfield, $sortorder, '', $num, $totalrecords, '');
+				print '<div class="liste_titre">';
+				print $langs->trans('Period') . '(' . $langs->trans("DateInvoice") . ') ';
+				print $langs->trans('Month') . ':<input class="flat" type="text" size="4" name="search_month" value="' . $search_month . '"> ';
+				print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
+				print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
+				print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
+				print '</div>';
+				
+				$i = 0;
+				print '<table class="noborder" width="100%">';
+				print '<tr class="liste_titre">';
+				print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("SupplierCode"), $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("DateInvoice"), $_SERVER["PHP_SELF"], "f.datef", "", $option, 'align="center"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "f.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
+				print "</tr>\n";
+				
+				if ($num > 0)
+				{
+					$var = True;
+					while ($i < $num && $i < $conf->liste_limit)
+					{
+						$objp = $db->fetch_object($result);
+						$var = ! $var;
+						
+						print '<tr ' . $bc[$var] . '>';
+						print '<td>';
+						$supplierinvoicestatic->id = $objp->facid;
+						$supplierinvoicestatic->ref = $objp->facnumber;
+						print $supplierinvoicestatic->getNomUrl(1);
+						print "</td>\n";
+						$societestatic->fetch($objp->socid);
+						print '<td>' . $societestatic->getNomUrl(1) . '</td>';
+						print "<td>" . $objp->code_client . "</td>\n";
+                   		print '<td align="center">';
+						print dol_print_date($db->jdate($objp->datef)) . "</td>";
+						print '<td align="center">' . $objp->qty . "</td>\n";
+						print '<td align="right">' . price($objp->total_ht) . "</td>\n";
+						print '<td align="right">' . $supplierinvoicestatic->LibStatut($objp->paye, $objp->statut, 5) . '</td>';
+						print "</tr>\n";
+						$i ++;
+						
+						if (! empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+							$total_ht += $objp->total_ht;
+							$total_qty += $objp->qty;
+						}
+					}
+				}
+				print '<tr class="liste_total">';
+				print '<td>' . $langs->trans('Total') . '</td>';
+				print '<td colspan="3"></td>';
+				print '<td align="center">' . $total_qty . '</td>';
+				print '<td align="right">' . price($total_ht) . '</td>';
+				print '<td></td>';
+				print "</table>";
+				print '</form>';
+				print '<br>';
+			} else {
+				dol_print_error($db);
+			}
+			$db->free($result);
+		}
+	}
+} else {
+	dol_print_error();
 }
-else
-{
-    dol_print_error();
-}
-
 
 llxFooter();
 $db->close();
diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php
index 566961d9c5f37b0329356833e6dda524542844c8..50d7c952b6d624463539fcf197a89cce1862d4e7 100644
--- a/htdocs/product/stats/propal.php
+++ b/htdocs/product/stats/propal.php
@@ -2,6 +2,7 @@
 /* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2014	   Florian Henry		<florian.henry@open-concept.pro>
  *
  * 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
@@ -18,16 +19,16 @@
  */
 
 /**
- *	    \file       htdocs/product/stats/propal.php
- *      \ingroup    product service propal
- *		\brief      Page des stats des propals pour un produit
+ * \file htdocs/product/stats/propal.php
+ * \ingroup product service propal
+ * \brief Page des stats des propals pour un produit
  */
 
-
 require '../../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
 
 $langs->load("products");
 $langs->load("companies");
@@ -38,154 +39,226 @@ $ref = GETPOST('ref', 'alpha');
 // Security check
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
-if ($user->societe_id) $socid=$user->societe_id;
-$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
+$socid='';
+if (! empty($user->societe_id)) $socid=$user->societe_id;
+$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
-$hookmanager->initHooks(array('productstatspropal'));
+$hookmanager->initHooks(array ('productstatspropal'));
 
 $mesg = '';
 
-$sortfield = GETPOST("sortfield",'alpha');
-$sortorder = GETPOST("sortorder",'alpha');
-$page = GETPOST("page",'int');
-if ($page == -1) { $page = 0; }
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOST("page", 'int');
+if ($page == - 1) {	$page = 0;}
 $offset = $conf->liste_limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
-if (! $sortorder) $sortorder="DESC";
-if (! $sortfield) $sortfield="p.datep";
+if (! $sortorder) $sortorder = "DESC";
+if (! $sortfield) $sortfield = "p.datep";
+
+$search_month = GETPOST('search_month', 'aplha');
+$search_year = GETPOST('search_year', 'int');
 
+if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) {
+	$search_month = '';
+	$search_year = '';
+}
 
 /*
  * View
  */
+
+$propalstatic = new Propal($db);
+$societestatic=new Societe($db);
+
 $form = new Form($db);
+$formother = new FormOther($db);
 
 if ($id > 0 || ! empty($ref))
 {
 	$product = new Product($db);
 	$result = $product->fetch($id, $ref);
-
-	$parameters=array('id'=>$id);
-	$reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action);    // Note that $action and $object may have been modified by some hooks
+	
+	$parameters = array ('id' => $id);
+	$reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
 	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
-	llxHeader("","",$langs->trans("CardProduct".$product->type));
-
+	
+	llxHeader("", "", $langs->trans("CardProduct" . $product->type));
+	
 	if ($result > 0)
 	{
-		$head=product_prepare_head($product, $user);
-		$titre=$langs->trans("CardProduct".$product->type);
-		$picto=($product->type==1?'service':'product');
-		dol_fiche_head($head, 'referers', $titre,0,$picto);
-
-		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action);    // Note that $action and $object may have been modified by hook
+		$head = product_prepare_head($product, $user);
+		$titre = $langs->trans("CardProduct" . $product->type);
+		$picto = ($product->type == 1 ? 'service' : 'product');
+		dol_fiche_head($head, 'referers', $titre, 0, $picto);
+		
+		$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
 		if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
+		
 		print '<table class="border" width="100%">';
-
+		
 		// Reference
 		print '<tr>';
-		print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
-		print $form->showrefnav($product,'ref','',1,'ref');
+		print '<td width="30%">' . $langs->trans("Ref") . '</td><td colspan="3">';
+		print $form->showrefnav($product, 'ref', '', 1, 'ref');
 		print '</td>';
 		print '</tr>';
-
+		
 		// Libelle
-		print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
+		print '<tr><td>' . $langs->trans("Label") . '</td><td colspan="3">' . $product->libelle . '</td>';
 		print '</tr>';
-
+		
 		// Status (to sell)
-		print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
-		print $product->getLibStatut(2,0);
+		print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')</td><td colspan="3">';
+		print $product->getLibStatut(2, 0);
 		print '</td></tr>';
-
+		
 		// Status (to buy)
-		print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
-		print $product->getLibStatut(2,1);
+		print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Buy") . ')</td><td colspan="3">';
+		print $product->getLibStatut(2, 1);
 		print '</td></tr>';
-
-		show_stats_for_company($product,$socid);
-
+		
+		show_stats_for_company($product, $socid);
+		
 		print "</table>";
-
+		
 		print '</div>';
-
-
-		$sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,";
-		$sql.= "p.datep, p.fk_statut as statut, d.qty";
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
-		$sql.= ",".MAIN_DB_PREFIX."propal as p";
-		$sql.= ", ".MAIN_DB_PREFIX."propaldet as d";
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-		$sql.= " WHERE p.fk_soc = s.rowid";
-		$sql.= " AND p.entity = ".$conf->entity;
-		$sql.= " AND d.fk_propal = p.rowid";
-		$sql.= " AND d.fk_product =".$product->id;
-		if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
-		if ($socid) $sql.= " AND p.fk_soc = ".$socid;
-		$sql.= " ORDER BY $sortfield $sortorder ";
-		$sql.= $db->plimit($conf->liste_limit +1, $offset);
-
-		$result = $db->query($sql);
-		if ($result)
-		{
-			$num = $db->num_rows($result);
-
-			print_barre_liste($langs->trans("Proposals"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
-
-			$i = 0;
-			print '<table class="noborder" width="100%">';
-			print '<tr class="liste_titre">';
-			print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("DatePropal"),$_SERVER["PHP_SELF"],"p.datep","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"p.total","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-			print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
-			print "</tr>\n";
-
-			$propalstatic=new Propal($db);
-
-			if ($num > 0)
-			{
-				$var=True;
-				while ($i < $num && $i < $conf->liste_limit)
-				{
-					$objp = $db->fetch_object($result);
-					$var=!$var;
-
-					print '<tr '.$bc[$var].'>';
-					print '<td><a href="'.DOL_URL_ROOT.'/comm/propal.php?id='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' ';
-					print $objp->ref;
-					print '</a></td>'."\n";
-					print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
-					print '<td align="center">';
-					print dol_print_date($db->jdate($objp->datep))."</td>";
-					print "<td align=\"center\">".$objp->qty."</td>\n";
-					print '<td align="right">'.price($objp->amount).'</td>'."\n";
-					print '<td align="right">'.$propalstatic->LibStatut($objp->statut,5).'</td>';
-					print '</tr>'."\n";
-					$i++;
+		
+		if ($user->rights->propale->lire) {
+			$sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, d.total_ht as amount,";
+			$sql .= " p.ref_client,";
+			$sql .= "p.datep, p.fk_statut as statut, d.qty";
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= ", sc.fk_soc, sc.fk_user ";
+			$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
+			$sql .= "," . MAIN_DB_PREFIX . "propal as p";
+			$sql .= ", " . MAIN_DB_PREFIX . "propaldet as d";
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
+			$sql .= " WHERE p.fk_soc = s.rowid";
+			$sql .= " AND p.entity = " . $conf->entity;
+			$sql .= " AND d.fk_propal = p.rowid";
+			$sql .= " AND d.fk_product =" . $product->id;
+			if (! empty($search_month))
+				$sql .= ' AND MONTH(p.datep) IN (' . $search_month . ')';
+			if (! empty($search_year))
+				$sql .= ' AND YEAR(p.datep) IN (' . $search_year . ')';
+			if (! $user->rights->societe->client->voir && ! $socid)
+				$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
+			if ($socid)
+				$sql .= " AND p.fk_soc = " . $socid;
+			$sql .= " ORDER BY $sortfield $sortorder ";
+			
+			// Calcul total qty and amount for global if full scan list
+			$total_ht = 0;
+			$total_qty = 0;
+			$totalrecords = 0;
+			if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+				$result = $db->query($sql);
+				if ($result) {
+					$totalrecords = $db->num_rows($result);
+					while ( $objp = $db->fetch_object($result) ) {
+						$total_ht += $objp->amount;
+						$total_qty += $objp->qty;
+					}
 				}
 			}
-		}
-		else
-		{
+			
+			$sql .= $db->plimit($conf->liste_limit + 1, $offset);
+			
+			$result = $db->query($sql);
+			if ($result)
+			{
+				$num = $db->num_rows($result);
+				
+				if (! empty($id))
+					$option .= '&amp;id=' . $product->id;
+				if (! empty($search_month))
+					$option .= '&amp;search_month=' . $search_month;
+				if (! empty($search_year))
+					$option .= '&amp;search_year=' . $search_year;
+				
+				print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $product->id . '" name="search_form">' . "\n";
+				if (! empty($sortfield))
+					print '<input type="hidden" name="sortfield" value="' . $sortfield . '"/>';
+				if (! empty($sortorder))
+					print '<input type="hidden" name="sortorder" value="' . $sortorder . '"/>';
+				if (! empty($page)) {
+					print '<input type="hidden" name="page" value="' . $page . '"/>';
+					$option .= '&amp;page=' . $page;
+				}
+				
+				print_barre_liste($langs->trans("Proposals"), $page, $_SERVER["PHP_SELF"], "&amp;id=$product->id", $sortfield, $sortorder, '', $num, $totalrecords, '');
+				print '<div class="liste_titre">';
+				print $langs->trans('Period') . '(' . $langs->trans("DateInvoice") . ') ';
+				print $langs->trans('Month') . ':<input class="flat" type="text" size="4" name="search_month" value="' . $search_month . '"> ';
+				print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
+				print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
+				print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
+				print '</div>';
+				
+				$i = 0;
+				print '<table class="noborder" width="100%">';
+				print '<tr class="liste_titre">';
+				print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.rowid", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("DatePropal"), $_SERVER["PHP_SELF"], "p.datep", "", $option, 'align="center"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "p.total", "", $option, 'align="right"', $sortfield, $sortorder);
+				print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "p.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
+				print "</tr>\n";
+				
+				if ($num > 0)
+				{
+					$var = True;
+					while ($i < $num && $i < $conf->liste_limit)
+					{
+						$objp = $db->fetch_object($result);
+						$var = ! $var;
+						
+						print '<tr ' . $bc[$var] . '>';
+						print '<td>';
+						$propalstatic->id=$objp->propalid;
+						$propalstatic->ref=$objp->ref;
+						$propalstatic->ref_client=$objp->ref_client;
+						print $propalstatic->getNomUrl(1);
+						 print "</td>\n";
+						$societestatic->fetch($objp->socid);
+                        print '<td>'.$societestatic->getNomUrl(1).'</td>';
+						print '<td align="center">';
+						print dol_print_date($db->jdate($objp->datep)) . "</td>";
+						print "<td align=\"center\">" . $objp->qty . "</td>\n";
+						print '<td align="right">' . price($objp->amount) . '</td>' . "\n";
+						print '<td align="right">' . $propalstatic->LibStatut($objp->statut, 5) . '</td>';
+						print "</tr>\n";
+						$i ++;
+						
+						if (! empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+							$total_ht += $objp->total_ht;
+							$total_qty += $objp->qty;
+						}
+					}
+				}		
+			print '<tr class="liste_total">';
+			print '<td>' . $langs->trans('Total') . '</td>';
+			print '<td colspan="2"></td>';
+			print '<td align="center">' . $total_qty . '</td>';
+			print '<td align="right">' . price($total_ht) . '</td>';
+			print '<td></td>';
+			print "</table>";
+			print '</form>';
+			print '<br>';		
+		} else {
 			dol_print_error($db);
 		}
-		print "</table>";
-		print '<br>';
 		$db->free($result);
+		}		
 	}
-}
-else
-{
+} else {
 	dol_print_error();
 }
 
-
 llxFooter();
 $db->close();