dolibarr 21.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';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
31
40$graphwidth = 700;
41$mapratio = 0.5;
42$graphheight = round($graphwidth * $mapratio);
43
44$mode = GETPOST('mode') ? GETPOST('mode') : '';
45
46
47// Security check
48if ($user->socid > 0) {
49 $action = '';
50 $socid = $user->socid;
51}
52$result = restrictedArea($user, 'adherent', '', '', 'cotisation');
53
54$year = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
55$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
56$endyear = $year;
57
58// Load translation files required by the page
59$langs->loadLangs(array("companies", "members"));
60
61
62/*
63 * View
64 */
65
66$memberstatic = new Adherent($db);
67
68$title = $langs->trans("MembersStatisticsByProperties");
69$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
70
71llxHeader('', $title, $help_url, '', 0, 0, array('https://www.google.com/jsapi'), '', '', 'mod-member page-stats_byproperties');
72
73print load_fiche_titre($title, '', $memberstatic->picto);
74
75//dol_mkdir($dir);
76
77$data = array();
78
79$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
80$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
81$sql .= " d.morphy as code";
82$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
83$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
84$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
85$sql .= " AND d.statut <> ".Adherent::STATUS_DRAFT;
86$sql .= " GROUP BY d.morphy";
87$foundphy = $foundmor = 0;
88
89// Define $data array
90dol_syslog("Count member", LOG_DEBUG);
91$resql = $db->query($sql);
92if ($resql) {
93 $num = $db->num_rows($resql);
94 $i = 0;
95 while ($i < $num) {
96 $obj = $db->fetch_object($resql);
97
98 if ($obj->code == 'phy') {
99 $foundphy++;
100 }
101 if ($obj->code == 'mor') {
102 $foundmor++;
103 }
104
105 $data[$obj->code] = array('label' => $obj->code, 'nb' => $obj->nb, 'nbsubscriptions' => $obj->nbsubscriptions, 'lastdate' => $db->jdate($obj->lastdate), 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate));
106
107 $i++;
108 }
109 $db->free($resql);
110} else {
111 dol_print_error($db);
112}
113
114$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
115$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
116$sql .= " d.morphy as code";
117$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
118$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
119$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
120$sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
121$sql .= " GROUP BY d.morphy";
122$foundphy = $foundmor = 0;
123
124// Define $data array
125dol_syslog("Count member still active", LOG_DEBUG);
126$resql = $db->query($sql);
127if ($resql) {
128 $num = $db->num_rows($resql);
129 $i = 0;
130 while ($i < $num) {
131 $obj = $db->fetch_object($resql);
132
133 if ($obj->code == 'phy') {
134 $foundphy++;
135 }
136 if ($obj->code == 'mor') {
137 $foundmor++;
138 }
139
140 $data[$obj->code]['nbactive'] = $obj->nb;
141
142 $i++;
143 }
144 $db->free($resql);
145} else {
146 dol_print_error($db);
147}
148
149
150$head = member_stats_prepare_head($memberstatic);
151
152print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
153
154
155// Print title
156if (!count($data)) {
157 print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
158 print '<br>';
159} else {
160 print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
161 print '<br>';
162}
163
164// Print array
165print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
166
167print '<table class="liste centpercent noborder">';
168print '<tr class="liste_titre">';
169print '<th>'.$langs->trans("MemberNature").'</th>';
170print '<th class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></th>';
171print '<th class="right">'.$langs->trans("NbOfActiveMembers").'</th>';
172print '<th class="center">'.$langs->trans("LastMemberDate").'</th>';
173print '<th class="right">'.$langs->trans("NbOfSubscriptions").'</th>';
174print '<th class="center">'.$langs->trans("LatestSubscriptionDate").'</th>';
175print '</tr>';
176
177if (!$foundphy) {
178 $data[] = array('label' => 'phy', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
179}
180if (!$foundmor) {
181 $data[] = array('label' => 'mor', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
182}
183
184foreach ($data as $val) {
185 $nb = $val['nb'];
186 $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
187 $nbactive = $val['nbactive'];
188
189 print '<tr class="oddeven">';
190 print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
191 print '<td class="right">'.$nb.'</td>';
192 print '<td class="right">'.$nbactive.'</td>';
193 print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
194 print '<td class="right">'.$nbsubscriptions.'</td>';
195 print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
196 print '</tr>';
197}
198
199print '</table>';
200print '</div>';
201
202print dol_get_fiche_end();
203
204// End of page
205llxFooter();
206$db->close();
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:71
Class to manage members of a foundation.
llxFooter()
Footer empty.
Definition document.php:107
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 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.