28require_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
39 public $table_element;
69 private $datetouse =
'date_debut';
85 $this->socid = $socid;
86 $this->userid = $userid;
89 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as e";
90 $this->field =
'total_ht';
94 $this->where .=
' e.entity IN ('.getEntity(
'expensereport').
')';
98 $this->where .=
" AND e.fk_soc = ".((int) $this->socid);
102 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')) {
103 $childids = $user->getAllChildIds();
104 $childids[] = $user->id;
105 $this->where .=
" AND e.fk_user_author IN (".$this->db->sanitize(implode(
',', $childids)).
")";
108 if ($this->userid > 0) {
109 $this->where .=
' AND e.fk_user_author = '.((int) $this->userid);
121 $sql =
"SELECT YEAR(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
") as dm, count(*)";
122 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
123 $sql .=
" GROUP BY dm DESC";
124 $sql .=
" WHERE ".$this->where;
139 $sql =
"SELECT MONTH(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
") as dm, count(*)";
140 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
141 $sql .=
" WHERE YEAR(e.".$this->datetouse.
") = ".((int) $year);
142 $sql .=
" AND ".$this->where;
143 $sql .=
" GROUP BY dm";
144 $sql .= $this->db->order(
'dm',
'DESC');
161 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
",'%m') as dm, sum(".$this->db->sanitize($this->field).
")";
162 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
163 $sql .=
" WHERE date_format(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
",'%Y') = '".$this->db->escape((
string) $year).
"'";
164 $sql .=
" AND ".$this->where;
165 $sql .=
" GROUP BY dm";
166 $sql .= $this->db->order(
'dm',
'DESC');
181 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
",'%m') as dm, avg(".$this->db->sanitize($this->field).
")";
182 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
183 $sql .=
" WHERE date_format(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
",'%Y') = '".$this->db->escape((
string) $year).
"'";
184 $sql .=
" AND ".$this->where;
185 $sql .=
" GROUP BY dm";
186 $sql .= $this->db->order(
'dm',
'DESC');
198 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->db->sanitize($this->datetouse).
" IS NULL",
"e.date_create",
"e.".$this->db->sanitize($this->datetouse)).
",'%Y') as year, count(*) as nb, sum(".$this->db->sanitize($this->field).
") as total, avg(".$this->db->sanitize($this->field).
") as avg";
199 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
200 $sql .=
" WHERE ".$this->where;
201 $sql .=
" GROUP BY year";
202 $sql .= $this->db->order(
'year',
'DESC');
if(! $sortfield) if(! $sortorder) $object
Class to manage Trips and Expenses.
Class to manage the statistics of the expensereports and expense notes.
getNbByMonth($year, $format=0)
Return the quantity of invoices per month for a given year.
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)
Return the amount average par month for a given year.
_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)
Return number of documents per month for a given year.