Ajout de restriction pour les commerciaux et les accs socits

This commit is contained in:
Regis Houssin 2006-05-26 15:15:16 +00:00
parent c8882d7cf3
commit 956495499c
2 changed files with 63 additions and 12 deletions

View File

@ -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();

View File

@ -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);