FIX Some statistics not compatible with multicompany module.
This commit is contained in:
parent
b0ac0624db
commit
6e5a8b6787
@ -81,7 +81,8 @@ class CommandeStats extends Stats
|
||||
$this->where.= " c.fk_statut > 2"; // Only approved & ordered
|
||||
}
|
||||
//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
|
||||
$this->where.= " AND c.entity = ".$conf->entity;
|
||||
$this->where.= ' AND c.entity IN ('.getEntity('commande', 1).')';
|
||||
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($this->socid)
|
||||
{
|
||||
|
||||
@ -56,14 +56,17 @@ class ExpenseReportStats extends Stats
|
||||
$this->userid = $userid;
|
||||
|
||||
$object=new ExpenseReport($this->db);
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element;
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as e";
|
||||
$this->field='total_ht';
|
||||
|
||||
$this->where = " fk_statut > 0 and date_valid > '2000-01-01'";
|
||||
$this->where = " e.fk_statut > 0";
|
||||
//$this->where.= " AND e.date_valid > '2000-01-01'"; // To filter only approved
|
||||
$this->where.= ' AND e.entity IN ('.getEntity('expensereport', 1).')';
|
||||
|
||||
//$this->where.= " AND entity = ".$conf->entity;
|
||||
if ($this->socid)
|
||||
{
|
||||
$this->where.=" AND fk_soc = ".$this->socid;
|
||||
$this->where.=" AND e.fk_soc = ".$this->socid;
|
||||
}
|
||||
|
||||
// Only me and subordinates
|
||||
@ -71,10 +74,10 @@ class ExpenseReportStats extends Stats
|
||||
{
|
||||
$childids = $user->getAllChildIds();
|
||||
$childids[]=$user->id;
|
||||
$this->where.=" AND fk_user_author IN (".(join(',',$childids)).")";
|
||||
$this->where.=" AND e.fk_user_author IN (".(join(',',$childids)).")";
|
||||
}
|
||||
|
||||
if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
|
||||
if ($this->userid > 0) $this->where.=' AND e.fk_user_author = '.$this->userid;
|
||||
}
|
||||
|
||||
|
||||
@ -102,9 +105,9 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getNbByMonth($year)
|
||||
{
|
||||
$sql = "SELECT MONTH(date_valid) as dm, count(*)";
|
||||
$sql = "SELECT MONTH(e.date_valid) as dm, count(*)";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE YEAR(date_valid) = ".$year;
|
||||
$sql.= " WHERE YEAR(e.date_valid) = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
@ -123,9 +126,9 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getAmountByMonth($year)
|
||||
{
|
||||
$sql = "SELECT date_format(date_valid,'%m') as dm, sum(".$this->field.")";
|
||||
$sql = "SELECT date_format(e.date_valid,'%m') as dm, sum(".$this->field.")";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE date_format(date_valid,'%Y') = '".$year."'";
|
||||
$sql.= " WHERE date_format(e.date_valid,'%Y') = '".$year."'";
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
@ -143,9 +146,9 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getAverageByMonth($year)
|
||||
{
|
||||
$sql = "SELECT date_format(date_valid,'%m') as dm, avg(".$this->field.")";
|
||||
$sql = "SELECT date_format(e.date_valid,'%m') as dm, avg(".$this->field.")";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE date_format(date_valid,'%Y') = '".$year."'";
|
||||
$sql.= " WHERE date_format(e.date_valid,'%Y') = '".$year."'";
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
@ -160,7 +163,7 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getAllByYear()
|
||||
{
|
||||
$sql = "SELECT date_format(date_valid,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
|
||||
$sql = "SELECT date_format(e.date_valid,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY year";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user