26 include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
27 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
28 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
29 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42 public $table_element;
60 public function __construct(
DoliDB $db, $socid, $mode, $userid = 0, $typentid = 0, $categid = 0)
65 $this->socid = ($socid > 0 ? $socid : 0);
66 $this->userid = $userid;
67 $this->cachefilesuffix = $mode;
70 if ($mode ==
'customer') {
72 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
73 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
74 $this->field =
'total_ht';
75 $this->field_line =
'total_ht';
77 if ($mode ==
'supplier') {
79 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
80 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
81 $this->field =
'total_ht';
82 $this->field_line =
'total_ht';
86 $this->where =
" f.fk_statut >= 0";
87 $this->where .=
" AND f.entity IN (".getEntity(
'invoice').
")";
88 if (empty($user->rights->societe->client->voir) && !$this->socid) {
89 $this->where .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
91 if ($mode ==
'customer') {
92 $this->where .=
" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')";
95 $this->where .=
" AND f.fk_soc = ".((int) $this->socid);
97 if ($this->userid > 0) {
98 $this->where .=
' AND f.fk_user_author = '.((int) $this->userid);
100 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
101 $this->where .=
" AND f.type IN (0,1,2,5)";
103 $this->where .=
" AND f.type IN (0,1,2,3,5)";
107 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = f.fk_soc';
108 $this->where .=
' AND s.fk_typent = '.((int) $typentid);
112 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cs ON cs.fk_soc = f.fk_soc';
113 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie as c ON c.rowid = cs.fk_categorie';
114 $this->where .=
' AND c.rowid = '.((int) $categid);
130 $sql =
"SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
131 $sql .=
" FROM ".$this->from;
132 if (empty($user->rights->societe->client->voir) && !$this->socid) {
133 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
137 $sql .=
" AND ".$this->where;
138 $sql .=
" GROUP BY dm";
139 $sql .= $this->
db->order(
'dm',
'DESC');
156 $sql =
"SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.
")";
157 $sql .=
" FROM ".$this->from;
158 if (empty($user->rights->societe->client->voir) && !$this->socid) {
159 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
162 $sql .=
" WHERE ".$this->where;
163 $sql .=
" GROUP BY dm";
164 $sql .= $this->
db->order(
'dm',
'DESC');
181 $sql =
"SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.
")";
182 $sql .=
" FROM ".$this->from;
183 if (empty($user->rights->societe->client->voir) && !$this->socid) {
184 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
188 $sql .=
" AND ".$this->where;
189 $sql .=
" GROUP BY dm";
190 $sql .= $this->
db->order(
'dm',
'DESC');
207 $sql =
"SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.
")";
208 $sql .=
" FROM ".$this->from;
209 if (empty($user->rights->societe->client->voir) && !$this->socid) {
210 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
214 $sql .=
" AND ".$this->where;
215 $sql .=
" GROUP BY dm";
216 $sql .= $this->
db->order(
'dm',
'DESC');
230 $sql =
"SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.
") as total, AVG(f.".$this->field.
") as avg";
231 $sql .=
" FROM ".$this->from;
232 if (empty($user->rights->societe->client->voir) && !$this->socid) {
233 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
236 $sql .=
" WHERE ".$this->where;
237 $sql .=
" GROUP BY year";
238 $sql .= $this->
db->order(
'year',
'DESC');
254 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
255 $sql .=
" FROM ".$this->from.
", ".$this->from_line.
", ".MAIN_DB_PREFIX.
"product as product";
256 if (empty($user->rights->societe->client->voir) && !$this->socid) {
257 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
260 $sql .=
" WHERE ".$this->where;
261 $sql .=
" AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid";
263 $sql .=
" GROUP BY product.ref";
264 $sql .= $this->
db->order(
'nb',
'DESC');
280 $endYear = date(
'Y');
281 $startYear = $endYear - $numberYears;
282 $sql =
"SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->field.
")";
283 $sql .=
" FROM ".$this->from;
284 if (empty($user->rights->societe->client->voir) && !$this->socid) {
285 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
289 $sql .=
" AND ".$this->where;
290 $sql .=
" GROUP BY dm";
291 $sql .= $this->
db->order(
'dm',
'ASC');
getAmountByYear($numberYears, $format=0)
Return the invoices amount by year for a number of past years.
__construct(DoliDB $db, $socid, $mode, $userid=0, $typentid=0, $categid=0)
Constructor.
Parent class of statistics class.
$conf db
API class for accounts.
getNbByMonth($year, $format=0)
Return orders number by month for a year.
getAllByProduct($year, $limit=10)
Return nb, amount of predefined product for year.
_getAmountByYear($sql)
Returns the summed amounts per year for a given number of past years ending now.
Class to manage Dolibarr database access.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
getAverageByMonth($year)
Return average amount.
Class to manage suppliers invoices.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
_getAllByProduct($sql, $limit=10)
Return number or total of product refs.
getNbByYear()
Return invoices number per year.
getAllByYear()
Return nb, total and average.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
getAmountByMonth($year, $format=0)
Return the invoices amount by month for a year.
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.
Class to manage invoices.
_getAverageByMonth($year, $sql, $format=0)
Renvoie le montant moyen par mois pour une annee donnee Return the amount average par month for a giv...
Class to manage stats for invoices (customer and supplier)