29include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
30include_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
31include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42 public $table_element;
89 $this->socid = ($socid > 0 ? $socid : 0);
90 $this->userid = $userid;
91 $this->cachefilesuffix = $mode;
94 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as c";
96 $this->field =
'weight';
97 $this->where .=
" c.fk_statut > 0";
100 $this->where .=
" AND c.entity = ".$conf->entity;
103 $this->where .=
" AND c.fk_soc = ".((int) $this->socid);
105 if ($this->userid > 0) {
106 $this->where .=
' AND c.fk_user_author = '.((int) $this->userid);
121 $sql =
"SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
122 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
123 if (!$user->hasRight(
'societe',
'client',
'voir')) {
124 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
127 $sql .=
" AND ".$this->where;
128 $sql .=
" GROUP BY dm";
129 $sql .= $this->db->order(
'dm',
'DESC');
144 $sql =
"SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).
")";
145 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
146 if (!$user->hasRight(
'societe',
'client',
'voir')) {
147 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
149 $sql .=
" WHERE ".$this->where;
150 $sql .=
" GROUP BY dm";
151 $sql .= $this->db->order(
'dm',
'DESC');
167 $sql =
"SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->db->sanitize($this->field).
")";
168 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
169 if (!$user->hasRight(
'societe',
'client',
'voir')) {
170 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
173 $sql .=
" WHERE ".$this->where;
174 $sql .=
" GROUP BY dm";
175 $sql .= $this->db->order(
'dm',
'DESC');
191 $sql =
"SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->db->sanitize($this->field).
")";
192 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
193 if (!$user->hasRight(
'societe',
'client',
'voir')) {
194 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
197 $sql .=
" WHERE ".$this->where;
198 $sql .=
" GROUP BY dm";
199 $sql .= $this->db->order(
'dm',
'DESC');
213 $sql =
"SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).
") as total, AVG(".$this->db->sanitize($this->field).
") as avg";
214 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
215 if (!$user->hasRight(
'societe',
'client',
'voir')) {
216 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
218 $sql .=
" WHERE ".$this->where;
219 $sql .=
" GROUP BY year";
220 $sql .= $this->db->order(
'year',
'DESC');
if(! $sortfield) if(! $sortorder) $object
Class to manage shipment statistics.
getNbByMonth($year, $format=0)
Return shipment number by month for a year.
__construct($db, $socid, $mode, $userid=0)
Constructor.
getAverageByMonth($year)
Return the orders amount average by month for a year.
getAmountByMonth($year, $format=0)
Return the orders amount by month for a year.
getNbByYear()
Return shipments number 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.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.