25require_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
26require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
36 public $table_element;
45 private $datetouse =
'date_valid';
61 $this->socid = $socid;
62 $this->userid = $userid;
65 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as e";
66 $this->field =
'total_ht';
70 $this->where .=
' e.entity IN ('.getEntity(
'expensereport').
')';
74 $this->where .=
" AND e.fk_soc = ".((int) $this->socid);
78 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')) {
79 $childids = $user->getAllChildIds();
80 $childids[] = $user->id;
81 $this->where .=
" AND e.fk_user_author IN (".$this->db->sanitize(join(
',', $childids)).
")";
84 if ($this->userid > 0) {
85 $this->where .=
' AND e.fk_user_author = '.((int) $this->userid);
97 $sql =
"SELECT YEAR(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
") as dm, count(*)";
98 $sql .=
" FROM ".$this->from;
99 $sql .=
" GROUP BY dm DESC";
100 $sql .=
" WHERE ".$this->where;
115 $sql =
"SELECT MONTH(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
") as dm, count(*)";
116 $sql .=
" FROM ".$this->from;
117 $sql .=
" WHERE YEAR(e.".$this->datetouse.
") = ".((int) $year);
118 $sql .=
" AND ".$this->where;
119 $sql .=
" GROUP BY dm";
120 $sql .= $this->db->order(
'dm',
'DESC');
137 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%m') as dm, sum(".$this->field.
")";
138 $sql .=
" FROM ".$this->from;
139 $sql .=
" WHERE date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%Y') = '".$this->db->escape($year).
"'";
140 $sql .=
" AND ".$this->where;
141 $sql .=
" GROUP BY dm";
142 $sql .= $this->db->order(
'dm',
'DESC');
157 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%m') as dm, avg(".$this->field.
")";
158 $sql .=
" FROM ".$this->from;
159 $sql .=
" WHERE date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%Y') = '".$this->db->escape($year).
"'";
160 $sql .=
" AND ".$this->where;
161 $sql .=
" GROUP BY dm";
162 $sql .= $this->db->order(
'dm',
'DESC');
174 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%Y') as year, count(*) as nb, sum(".$this->field.
") as total, avg(".$this->field.
") as avg";
175 $sql .=
" FROM ".$this->from;
176 $sql .=
" WHERE ".$this->where;
177 $sql .=
" GROUP BY year";
178 $sql .= $this->db->order(
'year',
'DESC');
Class to manage Trips and Expenses.
Classe permettant la gestion des stats des expensereports et notes de frais.
getNbByMonth($year, $format=0)
Renvoie le nombre de facture par mois pour une annee donnee.
getAverageByMonth($year)
Return average amount.
__construct($db, $socid=0, $userid=0)
Constructor.
getAmountByMonth($year, $format=0)
Renvoie le montant de facture par mois pour une annee donnee.
getNbByYear()
Return nb of expense report per year.
getAllByYear()
Return nb, total and average.
Parent class of statistics class.
_getAverageByMonth($year, $sql, $format=0)
Renvoie le montant moyen par mois pour une annee donnee Return the amount average par month for a giv...
_getAmountByMonth($year, $sql, $format=0)
Return the amount per month for a given year.
_getNbByYear($sql)
Return nb of elements by year.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...