27require_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
38 public $table_element;
68 private $datetouse =
'date_valid';
84 $this->socid = $socid;
85 $this->userid = $userid;
88 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as e";
89 $this->field =
'total_ht';
93 $this->where .=
' e.entity IN ('.getEntity(
'expensereport').
')';
97 $this->where .=
" AND e.fk_soc = ".((int) $this->socid);
101 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')) {
102 $childids = $user->getAllChildIds();
103 $childids[] = $user->id;
104 $this->where .=
" AND e.fk_user_author IN (".$this->db->sanitize(implode(
',', $childids)).
")";
107 if ($this->userid > 0) {
108 $this->where .=
' AND e.fk_user_author = '.((int) $this->userid);
120 $sql =
"SELECT YEAR(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
") as dm, count(*)";
121 $sql .=
" FROM ".$this->from;
122 $sql .=
" GROUP BY dm DESC";
123 $sql .=
" WHERE ".$this->where;
138 $sql =
"SELECT MONTH(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
") as dm, count(*)";
139 $sql .=
" FROM ".$this->from;
140 $sql .=
" WHERE YEAR(e.".$this->datetouse.
") = ".((int) $year);
141 $sql .=
" AND ".$this->where;
142 $sql .=
" GROUP BY dm";
143 $sql .= $this->db->order(
'dm',
'DESC');
160 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%m') as dm, sum(".$this->field.
")";
161 $sql .=
" FROM ".$this->from;
162 $sql .=
" WHERE date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%Y') = '".$this->db->escape($year).
"'";
163 $sql .=
" AND ".$this->where;
164 $sql .=
" GROUP BY dm";
165 $sql .= $this->db->order(
'dm',
'DESC');
180 $sql =
"SELECT date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%m') as dm, avg(".$this->field.
")";
181 $sql .=
" FROM ".$this->from;
182 $sql .=
" WHERE date_format(".$this->db->ifsql(
"e.".$this->datetouse.
" IS NULL",
"e.date_create",
"e.".$this->datetouse).
",'%Y') = '".$this->db->escape($year).
"'";
183 $sql .=
" AND ".$this->where;
184 $sql .=
" GROUP BY dm";
185 $sql .= $this->db->order(
'dm',
'DESC');
197 $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";
198 $sql .=
" FROM ".$this->from;
199 $sql .=
" WHERE ".$this->where;
200 $sql .=
" GROUP BY year";
201 $sql .= $this->db->order(
'year',
'DESC');
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...