dolibarr  7.0.0-beta
adherentstats.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (c) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
27 include_once DOL_DOCUMENT_ROOT . '/adherents/class/subscription.class.php';
28 
29 
33 class AdherentStats extends Stats
34 {
35  public $table_element;
36 
37  var $socid;
38  var $userid;
39 
40  var $from;
41  var $field;
42  var $where;
43 
44 
52  function __construct($db, $socid=0, $userid=0)
53  {
54  global $user, $conf;
55 
56  $this->db = $db;
57  $this->socid = $socid;
58  $this->userid = $userid;
59 
60  $object=new Subscription($this->db);
61 
62  $this->from = MAIN_DB_PREFIX.$object->table_element." as p";
63  $this->from.= ", ".MAIN_DB_PREFIX."adherent as m";
64 
65  $this->field='subscription';
66 
67  $this->where.= " m.statut != 0";
68  $this->where.= " AND p.fk_adherent = m.rowid AND m.entity IN (".getEntity('adherent').")";
69  //if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
70  if($this->memberid)
71  {
72  $this->where .= " AND m.rowid = ".$this->memberid;
73  }
74  //if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
75  }
76 
77 
85  function getNbByMonth($year, $format=0)
86  {
87  global $user;
88 
89  $sql = "SELECT date_format(p.dateadh,'%m') as dm, count(*)";
90  $sql.= " FROM ".$this->from;
91  //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
92  $sql.= " WHERE date_format(p.dateadh,'%Y') = '".$year."'";
93  $sql.= " AND ".$this->where;
94  $sql.= " GROUP BY dm";
95  $sql.= $this->db->order('dm','DESC');
96 
97  return $this->_getNbByMonth($year, $sql, $format);
98  }
99 
105  function getNbByYear()
106  {
107  global $user;
108 
109  $sql = "SELECT date_format(p.dateadh,'%Y') as dm, count(*)";
110  $sql.= " FROM ".$this->from;
111  //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
112  $sql.= " WHERE ".$this->where;
113  $sql.= " GROUP BY dm";
114  $sql.= $this->db->order('dm','DESC');
115 
116  return $this->_getNbByYear($sql);
117  }
118 
126  function getAmountByMonth($year, $format=0)
127  {
128  global $user;
129 
130  $sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.")";
131  $sql.= " FROM ".$this->from;
132  //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
133  $sql.= " WHERE date_format(p.dateadh,'%Y') = '".$year."'";
134  $sql.= " AND ".$this->where;
135  $sql.= " GROUP BY dm";
136  $sql.= $this->db->order('dm','DESC');
137 
138  return $this->_getAmountByMonth($year, $sql, $format);
139  }
140 
147  function getAverageByMonth($year)
148  {
149  global $user;
150 
151  $sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.")";
152  $sql.= " FROM ".$this->from;
153  //if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
154  $sql.= " WHERE date_format(p.dateadh,'%Y') = '".$year."'";
155  $sql.= " AND ".$this->where;
156  $sql.= " GROUP BY dm";
157  $sql.= $this->db->order('dm','DESC');
158 
159  return $this->_getAverageByMonth($year, $sql);
160  }
161 
162 
168  function getAllByYear()
169  {
170  global $user;
171 
172  $sql = "SELECT date_format(p.dateadh,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
173  $sql.= " FROM ".$this->from;
174  //if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
175  $sql.= " WHERE ".$this->where;
176  $sql.= " GROUP BY year";
177  $sql.= $this->db->order('year','DESC');
178 
179  return $this->_getAllByYear($sql);
180  }
181 
182 }
getAmountByMonth($year, $format=0)
Return the number of subscriptions by month for a given year.
__construct($db, $socid=0, $userid=0)
Constructor.
Parent class of statistics class.
Definition: stats.class.php:30
Class to manage statistics of members.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de proposition par mois pour une annee donnee.
getAllByYear()
Return nb, total and average.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
Class to manage subscriptions of foundation members.
getNbByYear()
Return the number of subscriptions by 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.
_getAverageByMonth($year, $sql, $format=0)
Renvoie le montant moyen par mois pour une annee donnee.
getAverageByMonth($year)
Return average amount each month.
getNbByMonth($year, $format=0)
Return the number of proposition by month for a given year.