29include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
30include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
31include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
32include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43 public $table_element;
101 public function __construct($db, $socid, $mode, $userid = 0, $typentid = 0, $categid = 0)
106 $this->socid = ($socid > 0 ? $socid : 0);
107 $this->userid = $userid;
108 $this->cachefilesuffix = $mode;
112 if ($mode ==
'customer') {
114 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as c";
115 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
116 $this->field =
'total_ht';
117 $this->field_line =
'total_ht';
119 $this->categ_link = MAIN_DB_PREFIX.
'categorie_societe';
120 } elseif ($mode ==
'supplier') {
122 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as c";
123 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
124 $this->field =
'total_ht';
125 $this->field_line =
'total_ht';
127 $this->categ_link = MAIN_DB_PREFIX.
'categorie_fournisseur';
130 $this->where .= ($this->where ?
' AND ' :
'').
'c.entity IN ('.
getEntity(
'commande').
')';
133 $this->where .=
" AND c.fk_soc = ".((int) $this->socid);
135 if ($this->userid > 0) {
136 $this->where .=
' AND c.fk_user_author = '.((int) $this->userid);
140 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = c.fk_soc';
141 $this->where .=
' AND s.fk_typent = '.((int) $typentid);
145 $this->where .=
' AND EXISTS (SELECT rowid FROM '.$this->categ_link.
' as cats WHERE cats.fk_soc = c.fk_soc AND cats.fk_categorie = '.((int) $categid).
')';
148 $parameters = array(
'socid' => $socid);
149 $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
150 $this->where .= $hookmanager->resPrint;
164 $sql =
"SELECT date_format(c.date_commande,'%m') as dm, COUNT(*) as nb";
165 $sql .=
" FROM ".$this->from;
166 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
167 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
171 $sql .=
" AND ".$this->where;
172 $sql .=
" GROUP BY dm";
173 $sql .= $this->db->order(
'dm',
'DESC');
189 $sql =
"SELECT date_format(c.date_commande,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.
")";
190 $sql .=
" FROM ".$this->from;
191 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
192 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
195 $sql .=
" WHERE ".$this->where;
196 $sql .=
" GROUP BY dm";
197 $sql .= $this->db->order(
'dm',
'DESC');
213 $sql =
"SELECT date_format(c.date_commande,'%m') as dm, SUM(c.".$this->field.
")";
214 $sql .=
" FROM ".$this->from;
215 if (empty($user->socid) && !$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);
220 $sql .=
" AND ".$this->where;
221 $sql .=
" GROUP BY dm";
222 $sql .= $this->db->order(
'dm',
'DESC');
238 $sql =
"SELECT date_format(c.date_commande,'%m') as dm, AVG(c.".$this->field.
")";
239 $sql .=
" FROM ".$this->from;
240 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
241 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
245 $sql .=
" AND ".$this->where;
246 $sql .=
" GROUP BY dm";
247 $sql .= $this->db->order(
'dm',
'DESC');
261 $sql =
"SELECT date_format(c.date_commande,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.
") as total, AVG(".$this->field.
") as avg";
262 $sql .=
" FROM ".$this->from;
263 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
264 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
267 $sql .=
" WHERE ".$this->where;
268 $sql .=
" GROUP BY year";
269 $sql .= $this->db->order(
'year',
'DESC');
285 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
286 $sql .=
" FROM ".$this->from;
287 $sql .=
" INNER JOIN ".$this->from_line.
" ON c.rowid = tl.fk_commande";
288 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"product as product ON tl.fk_product = product.rowid";
289 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
290 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
293 $sql .=
" WHERE ".$this->where;
294 $sql .=
" AND c.date_commande BETWEEN '".$this->db->idate(
dol_get_first_day($year, 1,
false)).
"' AND '".$this->db->idate(
dol_get_last_day($year, 12,
false)).
"'";
295 $sql .=
" GROUP BY product.ref";
296 $sql .= $this->db->order(
'nb',
'DESC');
if(! $sortfield) if(! $sortorder) $object
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage order statistics (customer and supplier)
getAllByProduct($year, $limit=10)
Return nb, amount of predefined product for year.
getAmountByMonth($year, $format=0)
Return the orders amount by month for a year.
__construct($db, $socid, $mode, $userid=0, $typentid=0, $categid=0)
Constructor.
getNbByYear()
Return orders number per year.
getAllByYear()
Return nb, total and average.
getAverageByMonth($year)
Return the orders amount average by month for a year.
getNbByMonth($year, $format=0)
Return orders number by month for a year.
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.
_getAllByProduct($sql, $limit=10)
Return number or total of product refs.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.