dolibarr 24.0.0-beta
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 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
38
39$graphwidth = 700;
40$mapratio = 0.5;
41$graphheight = round($graphwidth * $mapratio);
42
43$mode = GETPOST('mode') ? GETPOST('mode') : '';
44
45
46// Security check
47restrictedArea($user, 'adherent', '', '', 'cotisation');
48
49$year = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
50$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
51$endyear = $year;
52
53// Load translation files required by the page
54$langs->loadLangs(array("companies", "members"));
55
56
57/*
58 * View
59 */
60
61$memberstatic = new Adherent($db);
62
63$title = $langs->trans("Members");
64$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
65
66llxHeader('', $title, $help_url, '', 0, 0, array('https://www.google.com/jsapi'), '', '', 'mod-member page-stats_byproperties');
67
68$param = '';
69
70$newcardbutton = '';
71$queryforbutton = array();
72$queryforbutton['mode'] = 'common';
73$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', $queryforbutton), '', 1, array('morecss' => 'reposition'));
74$queryforbutton['mode'] = 'kanban';
75$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', $queryforbutton), '', 1, array('morecss' => 'reposition'));
76$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', dol_buildpath('/adherents/stats/index.php', 1).'?objecttype=adherent@adherent'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
77$newcardbutton .= dolGetButtonTitleSeparator();
78$newcardbutton .= dolGetButtonTitle($langs->trans('NewMember'), '', 'fa fa-plus-circle', dolBuildUrl(DOL_URL_ROOT.'/adherents/card.php', ['action' => 'create']), '', $user->hasRight('adherent', 'creer'));
79
80print_barre_liste($title, 0, $_SERVER["PHP_SELF"], $param, '', '', '', 0, $langs->trans("Statistics"), $memberstatic->picto, 0, $newcardbutton, '', 0, 0, 0, 1);
81
82//dol_mkdir($dir);
83
84$data = array();
85
86$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
87$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
88$sql .= " d.morphy as code";
89$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
90$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
91$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
92$sql .= " AND d.statut <> ".Adherent::STATUS_DRAFT;
93$sql .= " GROUP BY d.morphy";
94
95$foundphy = $foundmor = 0;
96
97// Define $data array
98dol_syslog("Count member", LOG_DEBUG);
99$resql = $db->query($sql);
100if ($resql) {
101 $num = $db->num_rows($resql);
102 $i = 0;
103 while ($i < $num) {
104 $obj = $db->fetch_object($resql);
105
106 if ($obj->code == 'phy') {
107 $foundphy++;
108 }
109 if ($obj->code == 'mor') {
110 $foundmor++;
111 }
112
113 $data[$obj->code] = array('label' => $obj->code, 'nb' => $obj->nb, 'nbsubscriptions' => $obj->nbsubscriptions, 'lastdate' => $db->jdate($obj->lastdate), 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate));
114
115 $i++;
116 }
117 $db->free($resql);
118} else {
120}
121
122$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
123$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
124$sql .= " d.morphy as code";
125$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
126$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
127$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
128$sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
129$sql .= " GROUP BY d.morphy";
130$foundphy = $foundmor = 0;
131
132// Define $data array
133dol_syslog("Count member still active", LOG_DEBUG);
134$resql = $db->query($sql);
135if ($resql) {
136 $num = $db->num_rows($resql);
137 $i = 0;
138 while ($i < $num) {
139 $obj = $db->fetch_object($resql);
140
141 if ($obj->code == 'phy') {
142 $foundphy++;
143 }
144 if ($obj->code == 'mor') {
145 $foundmor++;
146 }
147
148 $data[$obj->code]['nbactive'] = $obj->nb;
149
150 $i++;
151 }
152 $db->free($resql);
153} else {
155}
156
157
158$head = member_stats_prepare_head($memberstatic);
159
160print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
161
162
163// Print title
164if (!count($data)) {
165 print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
166} else {
167 print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
168}
169print '<span class="opacitymedium">'.$langs->trans("DraftMembersAreExcluded").'</span><br>';
170print '<br>';
171
172// Print array
173print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
174
175print '<table class="liste centpercent noborder">';
176print '<tr class="liste_titre">';
177print '<th>'.$langs->trans("MemberNature").'</th>';
178print '<th class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></th>';
179print '<th class="right">'.$langs->trans("NbOfActiveMembers").'</th>';
180print '<th class="center">'.$langs->trans("LastMemberDate").'</th>';
181print '<th class="right">'.$langs->trans("NbOfSubscriptions").'</th>';
182print '<th class="center">'.$langs->trans("LatestSubscriptionDate").'</th>';
183print '</tr>';
184
185if (!$foundphy) {
186 $data[] = array('label' => 'phy', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
187}
188if (!$foundmor) {
189 $data[] = array('label' => 'mor', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
190}
191
192foreach ($data as $val) {
193 $nb = $val['nb'];
194 $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
195 $nbactive = $val['nbactive'];
196
197 print '<tr class="oddeven">';
198 print '<td>';
199
200 print $memberstatic->getmorphylib($val['label'], 1);
201 print '</td>';
202 print '<td class="right">'.$nb.'</td>';
203 print '<td class="right">'.$nbactive.'</td>';
204 print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour', 'auto', null, false, 1).'</td>';
205 print '<td class="right">'.$nbsubscriptions.'</td>';
206 print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour', 'auto', null, false, 1).'</td>';
207 print '</tr>';
208}
209
210print '</table>';
211print '</div>';
212
213print dol_get_fiche_end();
214
215// End of page
216llxFooter();
217$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage members of a foundation.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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 a 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.