From 40ef5737fcb25bcfefb0c5f25ff348c88c7fb321 Mon Sep 17 00:00:00 2001
From: Francis Appels <francis.appels@yahoo.com>
Date: Tue, 19 May 2015 16:34:21 +0200
Subject: [PATCH] Fix: SQL error in facturestats on no view rights

table alias sc must be available when user has no rights to view
customers. see where defenition line 80
---
 htdocs/compta/facture/class/facturestats.class.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php
index 4028849b5fa..d1b39da15ce 100644
--- a/htdocs/compta/facture/class/facturestats.class.php
+++ b/htdocs/compta/facture/class/facturestats.class.php
@@ -206,7 +206,7 @@ class FactureStats extends Stats
 
 		$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
 		$sql.= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
-		//if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+		if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 		$sql.= " WHERE ".$this->where;
 		$sql.= " AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid";
     	$sql.= " AND f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year,1,false))."' AND '".$this->db->idate(dol_get_last_day($year,12,false))."'";
-- 
GitLab