27 include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
28 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
29 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
30 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
41 public $table_element;
62 public function __construct($db, $socid, $mode, $userid = 0, $typentid = 0, $categid = 0)
68 $this->socid = ($socid > 0 ? $socid : 0);
69 $this->userid = $userid;
70 $this->cachefilesuffix = $mode;
73 if ($mode ==
'customer')
76 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as c";
77 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
78 $this->field =
'total_ht';
79 $this->field_line =
'total_ht';
81 } elseif ($mode ==
'supplier')
84 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as c";
85 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
86 $this->field =
'total_ht';
87 $this->field_line =
'total_ht';
91 $this->where .= ($this->where ?
' AND ' :
'').
'c.entity IN ('.
getEntity(
'commande').
')';
93 if (!$user->rights->societe->client->voir && !$this->socid) $this->where .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
96 $this->where .=
" AND c.fk_soc = ".$this->socid;
98 if ($this->userid > 0) $this->where .=
' AND c.fk_user_author = '.$this->userid;
102 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = c.fk_soc';
103 $this->where .=
' AND s.fk_typent = '.$typentid;
108 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cats ON cats.fk_soc = c.fk_soc';
109 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie as cat ON cat.rowid = cats.fk_categorie';
110 $this->where .=
' AND cat.rowid = '.$categid;
125 $sql =
"SELECT date_format(c.date_commande,'%m') as dm, COUNT(*) as nb";
126 $sql .=
" FROM ".$this->from;
127 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
130 $sql .=
" AND ".$this->where;
131 $sql .=
" GROUP BY dm";
132 $sql .= $this->
db->order(
'dm',
'DESC');
148 $sql =
"SELECT date_format(c.date_commande,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.
")";
149 $sql .=
" FROM ".$this->from;
150 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
152 $sql .=
" WHERE ".$this->where;
153 $sql .=
" GROUP BY dm";
154 $sql .= $this->
db->order(
'dm',
'DESC');
170 $sql =
"SELECT date_format(c.date_commande,'%m') as dm, SUM(c.".$this->field.
")";
171 $sql .=
" FROM ".$this->from;
172 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
175 $sql .=
" AND ".$this->where;
176 $sql .=
" GROUP BY dm";
177 $sql .= $this->
db->order(
'dm',
'DESC');
193 $sql =
"SELECT date_format(c.date_commande,'%m') as dm, AVG(c.".$this->field.
")";
194 $sql .=
" FROM ".$this->from;
195 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
198 $sql .=
" AND ".$this->where;
199 $sql .=
" GROUP BY dm";
200 $sql .= $this->
db->order(
'dm',
'DESC');
214 $sql =
"SELECT date_format(c.date_commande,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.
") as total, AVG(".$this->field.
") as avg";
215 $sql .=
" FROM ".$this->from;
216 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
218 $sql .=
" WHERE ".$this->where;
219 $sql .=
" GROUP BY year";
220 $sql .= $this->
db->order(
'year',
'DESC');
236 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
237 $sql .=
" FROM ".$this->from.
", ".$this->from_line.
", ".MAIN_DB_PREFIX.
"product as product";
238 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
240 $sql .=
" WHERE ".$this->where;
241 $sql .=
" AND c.rowid = tl.fk_commande AND tl.fk_product = product.rowid";
243 $sql .=
" GROUP BY product.ref";
244 $sql .= $this->
db->order(
'nb',
'DESC');
getAllByYear()
Return nb, total and average.
__construct($db, $socid, $mode, $userid=0, $typentid=0, $categid=0)
Constructor.
Parent class of statistics class.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
$conf db
API class for accounts.
_getAllByProduct($sql, $limit=10)
Return number or total of product refs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to manage customers orders.
getNbByYear()
Return orders number per year.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
Class to manage predefined suppliers products.
Class to manage order statistics (customer and supplier)
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
_getAmountByMonth($year, $sql, $format=0)
Return the amount per month for a given year.
_getNbByYear($sql)
Return nb of elements by year.
getAmountByMonth($year, $format=0)
Return the orders amount by month for a year.
getAverageByMonth($year)
Return the orders amount average by month for a year.
_getAverageByMonth($year, $sql, $format=0)
Renvoie le montant moyen par mois pour une annee donnee Return the amount average par month for a giv...
getAllByProduct($year, $limit=10)
Return nb, amount of predefined product for year.
getNbByMonth($year, $format=0)
Return orders number by month for a year.