25 include_once DOL_DOCUMENT_ROOT .
'/core/class/stats.class.php';
26 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
27 include_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
28 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
41 public $table_element;
61 $this->socid = ($socid > 0 ? $socid : 0);
62 $this->userid = $userid;
63 $this->cachefilesuffix = $mode;
65 if ($mode ==
'customer')
68 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
69 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
71 $this->field_line=
'total_ht';
73 if ($mode ==
'supplier')
76 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
77 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
78 $this->field=
'total_ht';
79 $this->field_line=
'total_ht';
82 $this->where =
" f.fk_statut > 0";
83 $this->where.=
" AND f.entity = ".$conf->entity;
84 if (!$user->rights->societe->client->voir && !$this->socid) $this->where .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
85 if ($mode ==
'customer') $this->where.=
" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')";
88 $this->where.=
" AND f.fk_soc = ".$this->socid;
90 if ($this->userid > 0) $this->where.=
' AND f.fk_user_author = '.$this->userid;
91 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $this->where.=
" AND f.type IN (0,1,2,5)";
92 else $this->where.=
" AND f.type IN (0,1,2,3,5)";
107 $sql =
"SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
108 $sql.=
" FROM ".$this->from;
109 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
111 $sql.=
" AND ".$this->where;
112 $sql.=
" GROUP BY dm";
113 $sql.= $this->db->order(
'dm',
'DESC');
130 $sql =
"SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.
")";
131 $sql.=
" FROM ".$this->from;
132 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
133 $sql.=
" WHERE ".$this->where;
134 $sql.=
" GROUP BY dm";
135 $sql.= $this->db->order(
'dm',
'DESC');
152 $sql =
"SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.
")";
153 $sql.=
" FROM ".$this->from;
154 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
156 $sql.=
" AND ".$this->where;
157 $sql.=
" GROUP BY dm";
158 $sql.= $this->db->order(
'dm',
'DESC');
175 $sql =
"SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.
")";
176 $sql.=
" FROM ".$this->from;
177 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
179 $sql.=
" AND ".$this->where;
180 $sql.=
" GROUP BY dm";
181 $sql.= $this->db->order(
'dm',
'DESC');
195 $sql =
"SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.
") as total, AVG(f.".$this->field.
") as avg";
196 $sql.=
" FROM ".$this->from;
197 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
198 $sql.=
" WHERE ".$this->where;
199 $sql.=
" GROUP BY year";
200 $sql.= $this->db->order(
'year',
'DESC');
215 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
216 $sql.=
" FROM ".$this->from.
", ".$this->from_line.
", ".MAIN_DB_PREFIX.
"product as product";
217 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
218 $sql.=
" WHERE ".$this->where;
219 $sql.=
" AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid";
221 $sql.=
" GROUP BY product.ref";
222 $sql.= $this->db->order(
'nb',
'DESC');
Parent class of statistics class.
getNbByMonth($year, $format=0)
Return orders number by month for a year.
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 proposition par mois pour une annee donnee.
getAllByProduct($year)
Return nb, amount of predefined product for year.
__construct($db, $socid, $mode, $userid=0)
Constructor.
_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)
Renvoie le nombre d'element par mois pour une annee donnee.
_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.
Class to manage stats for invoices (customer and supplier)