diff --git a/htdocs/comm/propal/stats/month.php b/htdocs/comm/propal/stats/month.php index 2bad123327a..f1fcd615e19 100644 --- a/htdocs/comm/propal/stats/month.php +++ b/htdocs/comm/propal/stats/month.php @@ -54,8 +54,16 @@ $data = $stats->getNbByMonth($year); if (! is_dir($conf->propal->dir_images)) { mkdir($conf->propal->dir_images); } -$filename = $conf->propal->dir_images."/propale".$year.".png"; -$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale'.$year.'.png'; +if (!$user->rights->commercial->client->voir || $user->societe_id) +{ + $filename = $conf->propal->dir_images.'/propale-'.$user->id.'-'.$year.'.png'; + $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filename = $conf->propal->dir_images.'/propale'.$year.'.png'; + $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale'.$year.'.png'; +} $px = new BarGraph(); $mesg = $px->isGraphKo(); @@ -76,8 +84,16 @@ for ($i = 1 ; $i < 13 ; $i++) $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } -$filename_amount = $conf->propal->dir_images."/propaleamount".$year.".png"; -$fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount'.$year.'.png'; +if (!$user->rights->commercial->client->voir || $user->societe_id) +{ + $filename_amount = $conf->propal->dir_images.'/propaleamount-'.$user->id.'-'.$year.'.png'; + $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filename_amount = $conf->propal->dir_images.'/propaleamount'.$year.'.png'; + $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount'.$year.'.png'; +} $px = new BarGraph(); $mesg = $px->isGraphKo(); @@ -97,8 +113,17 @@ for ($i = 1 ; $i < 13 ; $i++) { $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } -$filename_avg = $conf->propal->dir_images."/propaleaverage".$year.".png"; -$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png'; + +if (!$user->rights->commercial->client->voir || $user->societe_id) +{ + $filename_avg = $conf->propal->dir_images.'/propaleaverage-'.$user->id.'-'.$year.'.png'; + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filename_avg = $conf->propal->dir_images.'/propaleaverage'.$year.'.png'; + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png'; +} $px = new BarGraph(); $mesg = $px->isGraphKo(); diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php index 0ca72731c2b..25d05be4a4c 100644 --- a/htdocs/comm/propal/stats/propalestats.class.php +++ b/htdocs/comm/propal/stats/propalestats.class.php @@ -58,7 +58,7 @@ class PropaleStats extends Stats 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"; + $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.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) { @@ -75,7 +75,17 @@ class PropaleStats extends Stats */ function getNbByYear() { - $sql = "SELECT date_format(datep,'%Y') as dm, count(*) FROM ".MAIN_DB_PREFIX."propal GROUP BY dm DESC WHERE fk_statut > 0"; + $sql = "SELECT date_format(p.datep,'%Y') 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 p.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->_getNbByYear($sql); } @@ -85,8 +95,16 @@ class PropaleStats extends Stats */ function getAmountByMonth($year) { - $sql = "SELECT date_format(datep,'%m') as dm, sum(price) FROM ".MAIN_DB_PREFIX."propal"; - $sql .= " WHERE date_format(datep,'%Y') = $year AND fk_statut > 0"; + $sql = "SELECT date_format(p.datep,'%m') 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 date_format(p.datep,'%Y') = $year AND p.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->_getAmountByMonth($year, $sql); @@ -97,8 +115,16 @@ class PropaleStats extends Stats */ function getAverageByMonth($year) { - $sql = "SELECT date_format(datep,'%m') as dm, avg(price) FROM ".MAIN_DB_PREFIX."propal"; - $sql .= " WHERE date_format(datep,'%Y') = $year AND fk_statut > 0"; + $sql = "SELECT date_format(p.datep,'%m') as dm, avg(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 date_format(p.datep,'%Y') = $year AND p.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->_getAverageByMonth($year, $sql);