29include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
30include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
41 public $table_element;
80 $this->socid = $socid;
81 $this->userid = $userid;
85 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as p";
86 $this->from .=
", ".MAIN_DB_PREFIX.
"adherent as m";
88 $this->field =
'subscription';
90 $this->where .=
" m.statut != -1";
91 $this->where .=
" AND p.fk_adherent = m.rowid AND m.entity IN (".getEntity(
'adherent').
")";
92 if ($this->memberid) {
93 $this->where .=
" AND m.rowid = ".((int) $this->memberid);
108 $sql =
"SELECT date_format(p.dateadh,'%m') as dm, count(*)";
109 $sql .=
" FROM ".$this->from;
110 $sql .=
" WHERE ".dolSqlDateFilter(
'p.dateadh', 0, 0, (
int) $year, 1);
111 $sql .=
" AND ".$this->where;
112 $sql .=
" GROUP BY dm";
113 $sql .= $this->db->order(
'dm',
'DESC');
125 $sql =
"SELECT date_format(p.dateadh,'%Y') as dm, count(*)";
126 $sql .=
" FROM ".$this->from;
127 $sql .=
" WHERE ".$this->where;
128 $sql .=
" GROUP BY dm";
129 $sql .= $this->db->order(
'dm',
'DESC');
143 $sql =
"SELECT date_format(p.dateadh,'%m') as dm, sum(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,'%m') as dm, avg(p.".$this->field.
")";
162 $sql .=
" FROM ".$this->from;
163 $sql .=
" WHERE ".dolSqlDateFilter(
'p.dateadh', 0, 0, (
int) $year, 1);
164 $sql .=
" AND ".$this->where;
165 $sql .=
" GROUP BY dm";
166 $sql .= $this->db->order(
'dm',
'DESC');
179 $sql =
"SELECT date_format(p.dateadh,'%Y') as year, count(*) as nb, sum(".$this->field.
") as total, avg(".$this->field.
") as avg";
180 $sql .=
" FROM ".$this->from;
181 $sql .=
" WHERE ".$this->where;
182 $sql .=
" GROUP BY year";
183 $sql .= $this->db->order(
'year',
'DESC');
199 $endYear = (int) date(
'Y');
200 $startYear = $endYear - $numberYears;
202 $sql =
"SELECT t.rowid as fk_adherent_type, t.libelle as label";
203 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_DRAFT,
"'members_draft'",
'NULL').
") as members_draft";
204 $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";
205 $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";
206 $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";
207 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_EXCLUDED,
"'members_excluded'",
'NULL').
") as members_excluded";
208 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_RESILIATED,
"'members_resiliated'",
'NULL').
") as members_resiliated";
209 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as t";
210 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" .
getEntity(
'adherent') .
")";
212 $sql .=
" AND d.datefin > '".$this->db->idate(
dol_get_first_day($startYear)).
"'";
214 $sql .=
" WHERE t.entity IN (".getEntity(
'member_type').
")";
215 $sql .=
" AND t.statut = 1";
216 $sql .=
" GROUP BY t.rowid, t.libelle";
218 dol_syslog(
"box_members_by_type::select nb of members per type", LOG_DEBUG);
219 $result = $this->db->query($sql);
221 $MembersCountArray = array();
224 $num = $this->db->num_rows($result);
226 $totalstatus = array(
227 'members_draft' => 0,
228 'members_pending' => 0,
229 'members_uptodate' => 0,
230 'members_expired' => 0,
231 'members_excluded' => 0,
232 'members_resiliated' => 0
235 $objp = $this->db->fetch_object($result);
236 $MembersCountArray[$objp->fk_adherent_type] = array(
237 'label' => $objp->label,
238 'members_draft' => (
int) $objp->members_draft,
239 'members_pending' => (
int) $objp->members_pending,
240 'members_uptodate' => (
int) $objp->members_uptodate,
241 'members_expired' => (
int) $objp->members_expired,
242 'members_excluded' => (
int) $objp->members_excluded,
243 'members_resiliated' => (
int) $objp->members_resiliated
246 foreach ($MembersCountArray[$objp->fk_adherent_type] as $key => $nb) {
247 if ($key !=
'label') {
249 $totalstatus[$key] += $nb;
252 $MembersCountArray[$objp->fk_adherent_type][
'total_adhtype'] = $totalrow;
255 $this->db->free($result);
256 $MembersCountArray[
'total'] = $totalstatus;
257 $MembersCountArray[
'total'][
'all'] = array_sum($totalstatus);
260 return $MembersCountArray;
274 $endYear = (int) date(
'Y');
275 $startYear = $endYear - $numberYears;
276 $MembersCountArray = [];
278 $sql =
"SELECT c.rowid as fk_categorie, c.label as label";
279 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_DRAFT,
"'members_draft'",
'NULL').
") as members_draft";
280 $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";
281 $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";
282 $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";
283 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_EXCLUDED,
"'members_excluded'",
'NULL').
") as members_excluded";
284 $sql .=
", COUNT(".$this->db->ifsql(
"d.statut = ".
Adherent::STATUS_RESILIATED,
"'members_resiliated'",
'NULL').
") as members_resiliated";
285 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
286 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_member as ct ON c.rowid = ct.fk_categorie";
287 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as d ON d.rowid = ct.fk_member";
288 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent_type as t ON t.rowid = d.fk_adherent_type";
289 $sql .=
" WHERE c.entity IN (".getEntity(
'member_type').
")";
290 $sql .=
" AND d.entity IN (" .
getEntity(
'adherent') .
")";
291 $sql .=
" AND t.entity IN (" .
getEntity(
'adherent') .
")";
293 $sql .=
" AND d.datefin > '".$this->db->idate(
dol_get_first_day($startYear)).
"'";
295 $sql .=
" AND c.fk_parent = 0";
296 $sql .=
" GROUP BY c.rowid, c.label";
297 $sql .=
" ORDER BY label ASC";
299 dol_syslog(
"box_members_by_tag::select nb of members per tag", LOG_DEBUG);
300 $result = $this->db->query($sql);
303 $num = $this->db->num_rows($result);
305 $totalstatus = array(
306 'members_draft' => 0,
307 'members_pending' => 0,
308 'members_uptodate' => 0,
309 'members_expired' => 0,
310 'members_excluded' => 0,
311 'members_resiliated' => 0
314 $objp = $this->db->fetch_object($result);
315 $MembersCountArray[$objp->fk_categorie] = array(
316 'label' => $objp->label,
317 'members_draft' => (
int) $objp->members_draft,
318 'members_pending' => (
int) $objp->members_pending,
319 'members_uptodate' => (
int) $objp->members_uptodate,
320 'members_expired' => (
int) $objp->members_expired,
321 'members_excluded' => (
int) $objp->members_excluded,
322 'members_resiliated' => (
int) $objp->members_resiliated
325 foreach ($MembersCountArray[$objp->fk_categorie] as $key => $nb) {
326 if ($key !=
'label') {
328 $totalstatus[$key] += $nb;
331 $MembersCountArray[$objp->fk_categorie][
'total_adhtag'] = $totalrow;
334 $this->db->free($result);
335 $MembersCountArray[
'total'] = $totalstatus;
336 $MembersCountArray[
'total'][
'all'] = array_sum($totalstatus);
339 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.