Ajout de la permission "consulter tous les clients" dans le module commercial, afin

qu'un commercial puisse voir que les clients qui lui sont affectés.
This commit is contained in:
Regis Houssin 2006-03-13 15:16:08 +00:00
parent 1c1095fe35
commit c276e7996d

View File

@ -51,11 +51,17 @@ class CommandeStats extends Stats
*/ */
function getNbByMonth($year) function getNbByMonth($year)
{ {
$sql = "SELECT date_format(date_commande,'%m') as dm, count(*) nb FROM ".MAIN_DB_PREFIX."commande"; global $conf;
$sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($this->socidp) if ($this->socidp)
{ {
$sql .= " AND fk_soc = ".$this->socidp; $sql .= " AND c.fk_soc = ".$this->socidp;
} }
$sql .= " GROUP BY dm"; $sql .= " GROUP BY dm";
$sql .= " ORDER BY dm DESC"; $sql .= " ORDER BY dm DESC";
@ -69,10 +75,17 @@ class CommandeStats extends Stats
*/ */
function getNbByYear() function getNbByYear()
{ {
$sql = "SELECT date_format(date_commande,'%Y') as dm, count(*), sum(total_ht) FROM ".MAIN_DB_PREFIX."commande WHERE fk_statut > 0"; global $conf;
global $user;
$sql = "SELECT date_format(c.date_commande,'%Y') as dm, count(*), sum(c.total_ht)";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE c.fk_statut > 0";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($this->socidp) if ($this->socidp)
{ {
$sql .= " AND fk_soc = ".$this->socidp; $sql .= " AND c.fk_soc = ".$this->socidp;
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
@ -85,11 +98,17 @@ class CommandeStats extends Stats
*/ */
function getAmountByMonth($year) function getAmountByMonth($year)
{ {
$sql = "SELECT date_format(date_commande,'%m') as dm, sum(total_ht) FROM ".MAIN_DB_PREFIX."commande"; global $conf;
$sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.total_ht)";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($this->socidp) if ($this->socidp)
{ {
$sql .= " AND fk_soc = ".$this->socidp; $sql .= " AND c.fk_soc = ".$this->socidp;
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
@ -102,11 +121,17 @@ class CommandeStats extends Stats
*/ */
function getAverageByMonth($year) function getAverageByMonth($year)
{ {
$sql = "SELECT date_format(date_commande,'%m') as dm, avg(total_ht) FROM ".MAIN_DB_PREFIX."commande"; global $conf;
$sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.total_ht)";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0";
if (!$user->rights->commercial->client->voir && !$this->socidp) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($this->socidp) if ($this->socidp)
{ {
$sql .= " AND fk_soc = ".$this->socidp; $sql .= " AND c.fk_soc = ".$this->socidp;
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";