diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index 2c2115162ce..0ddb852ab9a 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -59,7 +59,17 @@ if (! $mesg) { $px->draw($filename); } -$sql = "SELECT count(*), date_format(datep,'%Y') as dm, sum(price) FROM ".MAIN_DB_PREFIX."propal WHERE fk_statut > 0 GROUP BY dm DESC "; +$sql = "SELECT count(*), date_format(p.datep,'%Y') as dm, sum(p.price)"; +if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; +$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; +if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +$sql.= " WHERE fk_statut > 0"; +if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; +if($user->societe_id) +{ + $sql .= " AND p.fk_soc = ".$user->societe_id; +} +$sql.= " GROUP BY dm DESC "; if ($db->query($sql)) { $num = $db->num_rows(); @@ -67,8 +77,16 @@ if ($db->query($sql)) print ''; print ''; print ''; $i = 0; while ($i < $num) @@ -77,7 +95,9 @@ if ($db->query($sql)) $nbproduct = $row[0]; $year = $row[1]; print ""; - print ''; + print ''; + print ''; + print ''; $i++; } diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php index c417fcaa58f..0ca72731c2b 100644 --- a/htdocs/comm/propal/stats/propalestats.class.php +++ b/htdocs/comm/propal/stats/propalestats.class.php @@ -52,8 +52,18 @@ class PropaleStats extends Stats */ function getNbByMonth($year) { - $sql = "SELECT date_format(datep,'%m') as dm, count(*) FROM ".MAIN_DB_PREFIX."propal"; + global $user; + + $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; + if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE date_format(datep,'%Y') = $year AND fk_statut > 0"; + if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) + { + $sql .= " AND p.fk_soc = ".$user->societe_id; + } $sql .= " GROUP BY dm DESC"; return $this->_getNbByMonth($year, $sql);
'.$langs->trans("Year").''.$langs->trans("NbOfProposals").''.$langs->trans("AmountTotal").''; - if ($mesg) { print "$mesg"; } - else { print 'Nombre de proposition par mois'; } + + if ($mesg) + { + print "$mesg"; + } + else + { + print 'Nombre de proposition par mois'; + } + print '
'.$year.''.$nbproduct.''.price($row[2]).'
'.$year.''.$nbproduct.''.price($row[2]).'