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($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')
73 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
74 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
75 $this->field =
'total';
76 $this->field_line =
'total_ht';
78 if ($mode ==
'supplier')
81 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
82 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
83 $this->field =
'total_ht';
84 $this->field_line =
'total_ht';
88 $this->where =
" f.fk_statut >= 0";
89 $this->where .=
" AND f.entity IN (".getEntity(
'invoice').
")";
90 if (!$user->rights->societe->client->voir && !$this->socid) $this->where .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
91 if ($mode ==
'customer') $this->where .=
" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')";
94 $this->where .=
" AND f.fk_soc = ".$this->socid;
96 if ($this->userid > 0) $this->where .=
' AND f.fk_user_author = '.$this->userid;
97 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $this->where .=
" AND f.type IN (0,1,2,5)";
98 else $this->where .=
" AND f.type IN (0,1,2,3,5)";
102 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = f.fk_soc';
103 $this->where .=
' AND s.fk_typent = '.$typentid;
108 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cs ON cs.fk_soc = f.fk_soc';
109 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie as c ON c.rowid = cs.fk_categorie';
110 $this->where .=
' AND c.rowid = '.$categid;
126 $sql =
"SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
127 $sql .=
" FROM ".$this->from;
128 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
131 $sql .=
" AND ".$this->where;
132 $sql .=
" GROUP BY dm";
133 $sql .= $this->
db->order(
'dm',
'DESC');
150 $sql =
"SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.
")";
151 $sql .=
" FROM ".$this->from;
152 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
154 $sql .=
" WHERE ".$this->where;
155 $sql .=
" GROUP BY dm";
156 $sql .= $this->
db->order(
'dm',
'DESC');
173 $sql =
"SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.
")";
174 $sql .=
" FROM ".$this->from;
175 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
178 $sql .=
" AND ".$this->where;
179 $sql .=
" GROUP BY dm";
180 $sql .= $this->
db->order(
'dm',
'DESC');
197 $sql =
"SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.
")";
198 $sql .=
" FROM ".$this->from;
199 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
202 $sql .=
" AND ".$this->where;
203 $sql .=
" GROUP BY dm";
204 $sql .= $this->
db->order(
'dm',
'DESC');
218 $sql =
"SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.
") as total, AVG(f.".$this->field.
") as avg";
219 $sql .=
" FROM ".$this->from;
220 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
222 $sql .=
" WHERE ".$this->where;
223 $sql .=
" GROUP BY year";
224 $sql .= $this->
db->order(
'year',
'DESC');
240 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
241 $sql .=
" FROM ".$this->from.
", ".$this->from_line.
", ".MAIN_DB_PREFIX.
"product as product";
242 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
244 $sql .=
" WHERE ".$this->where;
245 $sql .=
" AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid";
247 $sql .=
" GROUP BY product.ref";
248 $sql .= $this->
db->order(
'nb',
'DESC');
Parent class of statistics class.
getNbByMonth($year, $format=0)
Return orders number by month for a year.
getAllByProduct($year, $limit=10)
Return nb, amount of predefined product for 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 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.
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.
__construct($db, $socid, $mode, $userid=0, $typentid=0, $categid=0)
Constructor.
_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)