28include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
29include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
30include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
31include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
50 public $table_element;
80 public function __construct(
DoliDB $db, $socid, $mode, $userid = 0, $typentid = 0, $categid = 0)
83 $this->socid = ($socid > 0 ? $socid : 0);
84 $this->userid = $userid;
85 $this->cachefilesuffix = $mode;
88 if ($mode ==
'customer') {
90 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
91 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
92 $this->field =
'total_ht';
93 $this->field_line =
'total_ht';
95 if ($mode ==
'supplier') {
97 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
98 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
99 $this->field =
'total_ht';
100 $this->field_line =
'total_ht';
103 $this->where .= ($this->where ?
' AND ' :
'').
" f.fk_statut >= 0";
104 $this->where .=
" AND f.entity IN (".getEntity(
'invoice').
")";
106 if ($mode ==
'customer') {
107 $this->where .=
" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')";
110 $this->where .=
" AND f.fk_soc = ".((int) $this->socid);
112 if ($this->userid > 0) {
113 $this->where .=
' AND f.fk_user_author = '.((int) $this->userid);
115 if ($mode ==
'customer') {
117 $this->where .=
" AND f.type IN (0,1,2,5)";
119 $this->where .=
" AND f.type IN (0,1,2,3,5)";
122 if ($mode ==
'supplier') {
124 $this->where .=
" AND f.type IN (0,1,2,5)";
126 $this->where .=
" AND f.type IN (0,1,2,3,5)";
131 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = f.fk_soc';
132 $this->where .=
' AND s.fk_typent = '.((int) $typentid);
136 $this->where .=
' AND EXISTS (SELECT cats.fk_categorie FROM '.MAIN_DB_PREFIX.
'categorie_societe as cats WHERE cats.fk_soc = f.fk_soc AND cats.fk_categorie = '.((int) $categid).
')';
152 $sql =
"SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
153 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
155 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
156 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
160 $sql .=
" AND ".$this->where;
161 $sql .=
" GROUP BY dm";
162 $sql .= $this->db->order(
'dm',
'DESC');
179 $sql =
"SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->db->sanitize($this->field).
")";
180 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
181 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
182 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
185 $sql .=
" WHERE ".$this->where;
186 $sql .=
" GROUP BY dm";
187 $sql .= $this->db->order(
'dm',
'DESC');
204 $sql =
"SELECT date_format(datef,'%m') as dm, SUM(f.".$this->db->sanitize($this->field).
")";
205 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
206 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
207 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
211 $sql .=
" AND ".$this->where;
212 $sql .=
" GROUP BY dm";
213 $sql .= $this->db->order(
'dm',
'DESC');
230 $sql =
"SELECT date_format(datef,'%m') as dm, AVG(f.".$this->db->sanitize($this->field).
")";
231 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
232 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
233 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
237 $sql .=
" AND ".$this->where;
238 $sql .=
" GROUP BY dm";
239 $sql .= $this->db->order(
'dm',
'DESC');
253 $sql =
"SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->db->sanitize($this->field).
") as total, AVG(f.".$this->db->sanitize($this->field).
") as avg";
254 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
255 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
256 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
259 $sql .=
" WHERE ".$this->where;
260 $sql .=
" GROUP BY year";
261 $sql .= $this->db->order(
'year',
'DESC');
277 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->db->sanitize($this->field_line).
") as total, AVG(tl.".$this->db->sanitize($this->field_line).
") as avg";
278 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
279 $sql .=
" INNER JOIN ".$this->db->sanitize($this->from_line, 0, 1, 1).
" ON f.rowid = tl.fk_facture";
280 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"product as product ON tl.fk_product = product.rowid";
281 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
282 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
285 $sql .=
" WHERE ".$this->where;
287 $sql .=
" GROUP BY product.ref";
288 $sql .= $this->db->order(
'nb',
'DESC');
304 $endYear = (int)
date(
'Y');
305 $startYear = $endYear - $numberYears;
306 $sql =
"SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->db->sanitize($this->field).
")";
307 $sql .=
" FROM ".$this->db->sanitize($this->from, 0, 1, 1);
308 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
309 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
313 $sql .=
" AND ".$this->where;
314 $sql .=
" GROUP BY dm";
315 $sql .= $this->db->order(
'dm',
'ASC');
if(! $sortfield) if(! $sortorder) $object
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage stats for invoices (customer and supplier)
getAverageByMonth($year)
Return average amount.
getNbByMonth($year, $format=0)
Return orders number by month for a year.
getAmountByMonth($year, $format=0)
Return the invoices amount by month for a year.
__construct(DoliDB $db, $socid, $mode, $userid=0, $typentid=0, $categid=0)
Constructor.
getAllByProduct($year, $limit=10)
Return nb, amount of predefined product for year.
getNbByYear()
Return invoices number per year.
getAmountByYear($numberYears, $format=0)
Return the invoices amount by year for a number of past years.
getAllByYear()
Return nb, total and average.
Parent class of statistics class.
_getAmountByYear($sql)
Returns the summed amounts per year for a given number of past years ending now.
_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)
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date