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)
85 $this->socid = ($socid > 0 ? $socid : 0);
86 $this->userid = $userid;
87 $this->cachefilesuffix = $mode;
90 if ($mode ==
'customer') {
92 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
93 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
94 $this->field =
'total_ht';
95 $this->field_line =
'total_ht';
97 if ($mode ==
'supplier') {
99 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as f";
100 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
101 $this->field =
'total_ht';
102 $this->field_line =
'total_ht';
105 $this->where .= ($this->where ?
' AND ' :
'').
" f.fk_statut >= 0";
106 $this->where .=
" AND f.entity IN (".getEntity(
'invoice').
")";
108 if ($mode ==
'customer') {
109 $this->where .=
" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')";
112 $this->where .=
" AND f.fk_soc = ".((int) $this->socid);
114 if ($this->userid > 0) {
115 $this->where .=
' AND f.fk_user_author = '.((int) $this->userid);
117 if ($mode ==
'customer') {
119 $this->where .=
" AND f.type IN (0,1,2,5)";
121 $this->where .=
" AND f.type IN (0,1,2,3,5)";
124 if ($mode ==
'supplier') {
126 $this->where .=
" AND f.type IN (0,1,2,5)";
128 $this->where .=
" AND f.type IN (0,1,2,3,5)";
133 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = f.fk_soc';
134 $this->where .=
' AND s.fk_typent = '.((int) $typentid);
138 $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).
')';
154 $sql =
"SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
155 $sql .=
" FROM ".$this->from;
156 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
157 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
161 $sql .=
" AND ".$this->where;
162 $sql .=
" GROUP BY dm";
163 $sql .= $this->db->order(
'dm',
'DESC');
180 $sql =
"SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.
")";
181 $sql .=
" FROM ".$this->from;
182 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
183 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
186 $sql .=
" WHERE ".$this->where;
187 $sql .=
" GROUP BY dm";
188 $sql .= $this->db->order(
'dm',
'DESC');
205 $sql =
"SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.
")";
206 $sql .=
" FROM ".$this->from;
207 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
208 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
212 $sql .=
" AND ".$this->where;
213 $sql .=
" GROUP BY dm";
214 $sql .= $this->db->order(
'dm',
'DESC');
231 $sql =
"SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.
")";
232 $sql .=
" FROM ".$this->from;
233 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
234 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
238 $sql .=
" AND ".$this->where;
239 $sql .=
" GROUP BY dm";
240 $sql .= $this->db->order(
'dm',
'DESC');
254 $sql =
"SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.
") as total, AVG(f.".$this->field.
") as avg";
255 $sql .=
" FROM ".$this->from;
256 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
257 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
260 $sql .=
" WHERE ".$this->where;
261 $sql .=
" GROUP BY year";
262 $sql .= $this->db->order(
'year',
'DESC');
278 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
279 $sql .=
" FROM ".$this->from;
280 $sql .=
" INNER JOIN ".$this->from_line.
" ON f.rowid = tl.fk_facture";
281 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"product as product ON tl.fk_product = product.rowid";
282 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
283 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
286 $sql .=
" WHERE ".$this->where;
288 $sql .=
" GROUP BY product.ref";
289 $sql .= $this->db->order(
'nb',
'DESC');
305 $endYear = (int)
date(
'Y');
306 $startYear = $endYear - $numberYears;
307 $sql =
"SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->field.
")";
308 $sql .=
" FROM ".$this->from;
309 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
310 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
314 $sql .=
" AND ".$this->where;
315 $sql .=
" GROUP BY dm";
316 $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)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date