Skip to content

Commit

Permalink
Fix stats opportunities
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 1, 2015
1 parent a846962 commit f57284f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions htdocs/core/class/stats.class.php
Expand Up @@ -383,11 +383,11 @@ function _getAllByYear($sql)
$row = $this->db->fetch_object($resql);
$result[$i]['year'] = $row->year;
$result[$i]['nb'] = $row->nb;
if($i>0) $result[$i-1]['nb_diff'] = ($result[$i-1]['nb'] - $row->nb) / $row->nb * 100;
if($i>0 && $row->nb) $result[$i-1]['nb_diff'] = ($result[$i-1]['nb'] - $row->nb) / $row->nb * 100;
$result[$i]['total'] = $row->total;
if($i>0) $result[$i-1]['total_diff'] = ($result[$i-1]['total'] - $row->total) / $row->total * 100;
if($i>0 && $row->total) $result[$i-1]['total_diff'] = ($result[$i-1]['total'] - $row->total) / $row->total * 100;
$result[$i]['avg'] = $row->avg;
if($i>0) $result[$i-1]['avg_diff'] = ($result[$i-1]['avg'] - $row->avg) / $row->avg * 100;
if($i>0 && $row->avg) $result[$i-1]['avg_diff'] = ($result[$i-1]['avg'] - $row->avg) / $row->avg * 100;
$i++;
}
$this->db->free($resql);
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/menus/standard/eldy.lib.php
Expand Up @@ -1190,12 +1190,12 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
// Project affected to user
$newmenu->add("/projet/index.php?leftmenu=projects&mode=mine", $langs->trans("MyProjects"), 0, $user->rights->projet->lire, '', $mainmenu, 'myprojects');
$newmenu->add("/projet/card.php?leftmenu=projects&action=create&mode=mine", $langs->trans("NewProject"), 1, $user->rights->projet->creer);
$newmenu->add("/projet/list.php?leftmenu=projects&mode=mine", $langs->trans("List"), 1, $user->rights->projet->lire);
$newmenu->add("/projet/list.php?leftmenu=projects&mode=mine&search_status=1", $langs->trans("List"), 1, $user->rights->projet->lire);

// All project i have permission on
$newmenu->add("/projet/index.php?leftmenu=projects", $langs->trans("Projects"), 0, $user->rights->projet->lire && $user->rights->projet->lire, '', $mainmenu, 'projects');
$newmenu->add("/projet/card.php?leftmenu=projects&action=create", $langs->trans("NewProject"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
$newmenu->add("/projet/list.php?leftmenu=projects", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
$newmenu->add("/projet/list.php?leftmenu=projects&search_status=1", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
$newmenu->add("/projet/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire && $user->rights->projet->lire);

if (empty($conf->global->PROJECT_HIDE_TASKS))
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/projects.lang
Expand Up @@ -27,7 +27,7 @@ OfficerProject=Officer project
LastProjects=Last %s projects
AllProjects=All projects
OpenedProjects=Opened projects
OpportunitiesStatusForOpenedProjects=Opportunities status for opened projects
OpportunitiesStatusForOpenedProjects=Opportunities amount of opened projects by status
ProjectsList=List of projects
ShowProject=Show project
SetProject=Set project
Expand Down
25 changes: 14 additions & 11 deletions htdocs/projet/class/projectstats.class.php
Expand Up @@ -44,8 +44,8 @@ function __construct($db)
/**
* Return all leads grouped by status
*
* @param int $limit Limit results
* @return array|int
* @param int $limit Limit results
* @return array|int Array with value or -1 if error
* @throws Exception
*/
function getAllProjectByStatus($limit = 5)
Expand All @@ -55,11 +55,11 @@ function getAllProjectByStatus($limit = 5)
$datay = array ();

$sql = "SELECT";
$sql .= " count(DISTINCT t.rowid), t.fk_opp_status";
$sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
$sql .= " SUM(t.opp_amount), t.fk_opp_status, cls.code, cls.label";
$sql .= " FROM " . MAIN_DB_PREFIX . "projet as t, ".MAIN_DB_PREFIX."c_lead_status as cls";
$sql .= $this->buildWhere();
$sql .= " AND t.fk_statut = 1";
$sql .= " GROUP BY t.fk_opp_status";
$sql .= " AND t.fk_opp_status = cls.rowid AND t.fk_statut = 1";
$sql .= " GROUP BY t.fk_opp_status, cls.code, cls.label";

$result = array ();
$res = array ();
Expand All @@ -73,13 +73,16 @@ function getAllProjectByStatus($limit = 5)
while ( $i < $num ) {
$row = $this->db->fetch_row($resql);
if ($i < $limit || $num == $limit)
$result[$i] = array (
$this->projet->status[$row[1]] . '(' . $row[0] . ')',
$row[0]
{
$label = (($langs->trans("OppStatus".$row[2]) != "OppStatus".$row[2]) ? $langs->trans("OppStatus".$row[2]) : $row[2]);
$result[$i] = array(
$label. ' (' . price(price2num($row[0], 'MT'), 1, $langs, 1, -1, -1, $conf->currency) . ')',
$row[0]
);
}
else
$other += $row[1];
$i ++;
$i++;
}
if ($num > $limit)
$result[$i] = array (
Expand All @@ -90,7 +93,7 @@ function getAllProjectByStatus($limit = 5)
} else {
$this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . '::' . __METHOD__ . ' ' . $this->error, LOG_ERR);
return - 1;
return -1;
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion htdocs/projet/stats/index.php
Expand Up @@ -122,7 +122,7 @@
$px->SetType(array (
'pie'
));
$px->SetTitle($langs->trans('ProjectOpenedProjectByOppStatus'));
$px->SetTitle($langs->trans('OpportunitiesStatusForOpenedProjects'));
$result=$px->draw($filenamenb, $fileurlnb);
if ($result<0) {
setEventMessages($px->error, null, 'errors');
Expand Down

0 comments on commit f57284f

Please sign in to comment.