dolibarr 20.0.0
byproperties.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
29
30$graphwidth = 700;
31$mapratio = 0.5;
32$graphheight = round($graphwidth * $mapratio);
33
34$mode = GETPOST('mode') ? GETPOST('mode') : '';
35
36
37// Security check
38if ($user->socid > 0) {
39 $action = '';
40 $socid = $user->socid;
41}
42$result = restrictedArea($user, 'adherent', '', '', 'cotisation');
43
44$year = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
45$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
46$endyear = $year;
47
48// Load translation files required by the page
49$langs->loadLangs(array("companies", "members"));
50
51
52/*
53 * View
54 */
55
56$memberstatic = new Adherent($db);
57
58llxHeader('', $langs->trans("MembersStatisticsByProperties"), '', '', 0, 0, array('https://www.google.com/jsapi'));
59
60$title = $langs->trans("MembersStatisticsByProperties");
61
62print load_fiche_titre($title, '', $memberstatic->picto);
63
64//dol_mkdir($dir);
65
66$data = array();
67
68$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
69$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
70$sql .= " d.morphy as code";
71$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
72$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
73$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
74$sql .= " AND d.statut <> ".Adherent::STATUS_DRAFT;
75$sql .= " GROUP BY d.morphy";
76$foundphy = $foundmor = 0;
77
78// Define $data array
79dol_syslog("Count member", LOG_DEBUG);
80$resql = $db->query($sql);
81if ($resql) {
82 $num = $db->num_rows($resql);
83 $i = 0;
84 while ($i < $num) {
85 $obj = $db->fetch_object($resql);
86
87 if ($obj->code == 'phy') {
88 $foundphy++;
89 }
90 if ($obj->code == 'mor') {
91 $foundmor++;
92 }
93
94 $data[$obj->code] = array('label' => $obj->code, 'nb' => $obj->nb, 'nbsubscriptions' => $obj->nbsubscriptions, 'lastdate' => $db->jdate($obj->lastdate), 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate));
95
96 $i++;
97 }
98 $db->free($resql);
99} else {
100 dol_print_error($db);
101}
102
103$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
104$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
105$sql .= " d.morphy as code";
106$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
107$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
108$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
109$sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
110$sql .= " GROUP BY d.morphy";
111$foundphy = $foundmor = 0;
112
113// Define $data array
114dol_syslog("Count member still active", LOG_DEBUG);
115$resql = $db->query($sql);
116if ($resql) {
117 $num = $db->num_rows($resql);
118 $i = 0;
119 while ($i < $num) {
120 $obj = $db->fetch_object($resql);
121
122 if ($obj->code == 'phy') {
123 $foundphy++;
124 }
125 if ($obj->code == 'mor') {
126 $foundmor++;
127 }
128
129 $data[$obj->code]['nbactive'] = $obj->nb;
130
131 $i++;
132 }
133 $db->free($resql);
134} else {
135 dol_print_error($db);
136}
137
138
139$head = member_stats_prepare_head($memberstatic);
140
141print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
142
143
144// Print title
145if (!count($data)) {
146 print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
147 print '<br>';
148} else {
149 print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
150 print '<br>';
151}
152
153// Print array
154print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
155print '<table class="liste centpercent">';
156print '<tr class="liste_titre">';
157print '<td>'.$langs->trans("MemberNature").'</td>';
158print '<td class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></td>';
159print '<td class="right">'.$langs->trans("NbOfActiveMembers").'</td>';
160print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
161print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
162print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
163print '</tr>';
164
165if (!$foundphy) {
166 $data[] = array('label' => 'phy', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
167}
168if (!$foundmor) {
169 $data[] = array('label' => 'mor', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
170}
171
172foreach ($data as $val) {
173 $nb = $val['nb'];
174 $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
175 $nbactive = $val['nbactive'];
176
177 print '<tr class="oddeven">';
178 print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
179 print '<td class="right">'.$nb.'</td>';
180 print '<td class="right">'.$nbactive.'</td>';
181 print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
182 print '<td class="right">'.$nbsubscriptions.'</td>';
183 print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
184 print '</tr>';
185}
186
187print '</table>';
188print '</div>';
189
190print dol_get_fiche_end();
191
192// End of page
193llxFooter();
194$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage members of a foundation.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats information.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.