29include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
30include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
41 public $table_element;
62 $this->socid = $socid;
63 $this->userid = $userid;
67 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as p";
68 $this->from .=
", ".MAIN_DB_PREFIX.
"adherent as m";
70 $this->field =
'subscription';
72 $this->where .=
" m.statut != -1";
73 $this->where .=
" AND p.fk_adherent = m.rowid AND m.entity IN (".getEntity(
'adherent').
")";
74 if ($this->memberid) {
75 $this->where .=
" AND m.rowid = ".((int) $this->memberid);
90 $sql =
"SELECT date_format(p.dateadh,'%m') as dm, count(*)";
91 $sql .=
" FROM ".$this->from;
92 $sql .=
" WHERE ".dolSqlDateFilter(
'p.dateadh', 0, 0, (
int) $year, 1);
93 $sql .=
" AND ".$this->where;
94 $sql .=
" GROUP BY dm";
95 $sql .= $this->db->order(
'dm',
'DESC');
107 $sql =
"SELECT date_format(p.dateadh,'%Y') as dm, count(*)";
108 $sql .=
" FROM ".$this->from;
109 $sql .=
" WHERE ".$this->where;
110 $sql .=
" GROUP BY dm";
111 $sql .= $this->db->order(
'dm',
'DESC');
125 $sql =
"SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.
")";
126 $sql .=
" FROM ".$this->from;
127 $sql .=
" WHERE ".dolSqlDateFilter(
'p.dateadh', 0, 0, (
int) $year, 1);
128 $sql .=
" AND ".$this->where;
129 $sql .=
" GROUP BY dm";
130 $sql .= $this->db->order(
'dm',
'DESC');
143 $sql =
"SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.
")";
144 $sql .=
" FROM ".$this->from;
145 $sql .=
" WHERE ".dolSqlDateFilter(
'p.dateadh', 0, 0, (
int) $year, 1);
146 $sql .=
" AND ".$this->where;
147 $sql .=
" GROUP BY dm";
148 $sql .= $this->db->order(
'dm',
'DESC');
161 $sql =
"SELECT date_format(p.dateadh,'%Y') as year, count(*) as nb, sum(".$this->field.
") as total, avg(".$this->field.
") as avg";
162 $sql .=
" FROM ".$this->from;
163 $sql .=
" WHERE ".$this->where;
164 $sql .=
" GROUP BY year";
165 $sql .= $this->db->order(
'year',
'DESC');
181 $endYear = (int) date(
'Y');
182 $startYear = $endYear - $numberYears;
184 $sql =
"SELECT t.rowid as fk_adherent_type, t.libelle as label";
185 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_DRAFT,
"'members_draft'",
'NULL').
") as members_draft";
186 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_VALIDATED.
" AND (d.datefin IS NULL AND t.subscription = '1')",
"'members_pending'",
'NULL').
") as members_pending";
187 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_VALIDATED.
" AND (d.datefin >= '".$this->db->idate($now).
"' OR t.subscription = 0)",
"'members_uptodate'",
'NULL').
") as members_uptodate";
188 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_VALIDATED.
" AND (d.datefin < '".$this->db->idate($now).
"' AND t.subscription = 1)",
"'members_expired'",
'NULL').
") as members_expired";
189 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_EXCLUDED,
"'members_excluded'",
'NULL').
") as members_excluded";
190 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_RESILIATED,
"'members_resiliated'",
'NULL').
") as members_resiliated";
191 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as t";
192 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" .
getEntity(
'adherent') .
")";
194 $sql .=
" AND d.datefin > '".$this->db->idate(
dol_get_first_day($startYear)).
"'";
196 $sql .=
" WHERE t.entity IN (".getEntity(
'member_type').
")";
197 $sql .=
" AND t.statut = 1";
198 $sql .=
" GROUP BY t.rowid, t.libelle";
200 dol_syslog(
"box_members_by_type::select nb of members per type", LOG_DEBUG);
201 $result = $this->db->query($sql);
203 $MembersCountArray = array();
206 $num = $this->db->num_rows($result);
208 $totalstatus = array(
209 'members_draft' => 0,
210 'members_pending' => 0,
211 'members_uptodate' => 0,
212 'members_expired' => 0,
213 'members_excluded' => 0,
214 'members_resiliated' => 0
217 $objp = $this->db->fetch_object($result);
218 $MembersCountArray[$objp->fk_adherent_type] = array(
219 'label' => $objp->label,
220 'members_draft' => (
int) $objp->members_draft,
221 'members_pending' => (
int) $objp->members_pending,
222 'members_uptodate' => (
int) $objp->members_uptodate,
223 'members_expired' => (
int) $objp->members_expired,
224 'members_excluded' => (
int) $objp->members_excluded,
225 'members_resiliated' => (
int) $objp->members_resiliated
228 foreach ($MembersCountArray[$objp->fk_adherent_type] as $key => $nb) {
229 if ($key !=
'label') {
231 $totalstatus[$key] += $nb;
234 $MembersCountArray[$objp->fk_adherent_type][
'total_adhtype'] = $totalrow;
237 $this->db->free($result);
238 $MembersCountArray[
'total'] = $totalstatus;
239 $MembersCountArray[
'total'][
'all'] = array_sum($totalstatus);
242 return $MembersCountArray;
256 $endYear = (int) date(
'Y');
257 $startYear = $endYear - $numberYears;
258 $MembersCountArray = [];
260 $sql =
"SELECT c.rowid as fk_categorie, c.label as label";
261 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_DRAFT,
"'members_draft'",
'NULL').
") as members_draft";
262 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_VALIDATED.
" AND (d.datefin IS NULL AND t.subscription = '1')",
"'members_pending'",
'NULL').
") as members_pending";
263 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_VALIDATED.
" AND (d.datefin >= '".$this->db->idate($now).
"' OR t.subscription = 0)",
"'members_uptodate'",
'NULL').
") as members_uptodate";
264 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_VALIDATED.
" AND (d.datefin < '".$this->db->idate($now).
"' AND t.subscription = 1)",
"'members_expired'",
'NULL').
") as members_expired";
265 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_EXCLUDED,
"'members_excluded'",
'NULL').
") as members_excluded";
266 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_RESILIATED,
"'members_resiliated'",
'NULL').
") as members_resiliated";
267 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
268 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_member as ct ON c.rowid = ct.fk_categorie";
269 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as d ON d.rowid = ct.fk_member";
270 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent_type as t ON t.rowid = d.fk_adherent_type";
271 $sql .=
" WHERE c.entity IN (".getEntity(
'member_type').
")";
272 $sql .=
" AND d.entity IN (" .
getEntity(
'adherent') .
")";
273 $sql .=
" AND t.entity IN (" .
getEntity(
'adherent') .
")";
275 $sql .=
" AND d.datefin > '".$this->db->idate(
dol_get_first_day($startYear)).
"'";
277 $sql .=
" AND c.fk_parent = 0";
278 $sql .=
" GROUP BY c.rowid, c.label";
279 $sql .=
" ORDER BY label ASC";
281 dol_syslog(
"box_members_by_tag::select nb of members per tag", LOG_DEBUG);
282 $result = $this->db->query($sql);
285 $num = $this->db->num_rows($result);
287 $totalstatus = array(
288 'members_draft' => 0,
289 'members_pending' => 0,
290 'members_uptodate' => 0,
291 'members_expired' => 0,
292 'members_excluded' => 0,
293 'members_resiliated' => 0
296 $objp = $this->db->fetch_object($result);
297 $MembersCountArray[$objp->fk_categorie] = array(
298 'label' => $objp->label,
299 'members_draft' => (
int) $objp->members_draft,
300 'members_pending' => (
int) $objp->members_pending,
301 'members_uptodate' => (
int) $objp->members_uptodate,
302 'members_expired' => (
int) $objp->members_expired,
303 'members_excluded' => (
int) $objp->members_excluded,
304 'members_resiliated' => (
int) $objp->members_resiliated
307 foreach ($MembersCountArray[$objp->fk_categorie] as $key => $nb) {
308 if ($key !=
'label') {
310 $totalstatus[$key] += $nb;
313 $MembersCountArray[$objp->fk_categorie][
'total_adhtag'] = $totalrow;
316 $this->db->free($result);
317 $MembersCountArray[
'total'] = $totalstatus;
318 $MembersCountArray[
'total'][
'all'] = array_sum($totalstatus);
321 return $MembersCountArray;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
const STATUS_EXCLUDED
Excluded.
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated.
const STATUS_VALIDATED
Validated status.
Class to manage statistics of members.
getNbByMonth($year, $format=0)
Return the number of proposition by month for a given year.
getAllByYear()
Return nb, total and average.
__construct($db, $socid=0, $userid=0)
Constructor.
getNbByYear()
Return the number of subscriptions by year.
getAverageByMonth($year)
Return average amount each month.
countMembersByTypeAndStatus($numberYears=0)
Return count of member by status group by adh type, total and average.
getAmountByMonth($year, $format=0)
Return the number of subscriptions by month for a given year.
countMembersByTagAndStatus($numberYears=0)
Return count of member by status group by adh type, total and average.
Parent class of statistics class.
_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.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
Class to manage subscriptions of foundation members.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.