dolibarr 21.0.0-alpha
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
30
31$graphwidth = 700;
32$mapratio = 0.5;
33$graphheight = round($graphwidth * $mapratio);
34
35$mode = GETPOST('mode') ? GETPOST('mode') : '';
36
37
38// Security check
39if ($user->socid > 0) {
40 $action = '';
41 $socid = $user->socid;
42}
43$result = restrictedArea($user, 'adherent', '', '', 'cotisation');
44
45$year = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
46$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
47$endyear = $year;
48
49// Load translation files required by the page
50$langs->loadLangs(array("companies", "members"));
51
52
53/*
54 * View
55 */
56
57$memberstatic = new Adherent($db);
58
59$title = $langs->trans("MembersStatisticsByProperties");
60$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
61
62llxHeader('', $title, $help_url, '', 0, 0, array('https://www.google.com/jsapi'), '', '', 'mod-member page-stats_byproperties');
63
64print load_fiche_titre($title, '', $memberstatic->picto);
65
66//dol_mkdir($dir);
67
68$data = array();
69
70$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
71$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
72$sql .= " d.morphy as code";
73$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
74$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
75$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
76$sql .= " AND d.statut <> ".Adherent::STATUS_DRAFT;
77$sql .= " GROUP BY d.morphy";
78$foundphy = $foundmor = 0;
79
80// Define $data array
81dol_syslog("Count member", LOG_DEBUG);
82$resql = $db->query($sql);
83if ($resql) {
84 $num = $db->num_rows($resql);
85 $i = 0;
86 while ($i < $num) {
87 $obj = $db->fetch_object($resql);
88
89 if ($obj->code == 'phy') {
90 $foundphy++;
91 }
92 if ($obj->code == 'mor') {
93 $foundmor++;
94 }
95
96 $data[$obj->code] = array('label' => $obj->code, 'nb' => $obj->nb, 'nbsubscriptions' => $obj->nbsubscriptions, 'lastdate' => $db->jdate($obj->lastdate), 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate));
97
98 $i++;
99 }
100 $db->free($resql);
101} else {
102 dol_print_error($db);
103}
104
105$sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
106$sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
107$sql .= " d.morphy as code";
108$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
109$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
110$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
111$sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
112$sql .= " GROUP BY d.morphy";
113$foundphy = $foundmor = 0;
114
115// Define $data array
116dol_syslog("Count member still active", LOG_DEBUG);
117$resql = $db->query($sql);
118if ($resql) {
119 $num = $db->num_rows($resql);
120 $i = 0;
121 while ($i < $num) {
122 $obj = $db->fetch_object($resql);
123
124 if ($obj->code == 'phy') {
125 $foundphy++;
126 }
127 if ($obj->code == 'mor') {
128 $foundmor++;
129 }
130
131 $data[$obj->code]['nbactive'] = $obj->nb;
132
133 $i++;
134 }
135 $db->free($resql);
136} else {
137 dol_print_error($db);
138}
139
140
141$head = member_stats_prepare_head($memberstatic);
142
143print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
144
145
146// Print title
147if (!count($data)) {
148 print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
149 print '<br>';
150} else {
151 print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
152 print '<br>';
153}
154
155// Print array
156print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
157
158print '<table class="liste centpercent noborder">';
159print '<tr class="liste_titre">';
160print '<th>'.$langs->trans("MemberNature").'</th>';
161print '<th class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></th>';
162print '<th class="right">'.$langs->trans("NbOfActiveMembers").'</th>';
163print '<th class="center">'.$langs->trans("LastMemberDate").'</th>';
164print '<th class="right">'.$langs->trans("NbOfSubscriptions").'</th>';
165print '<th class="center">'.$langs->trans("LatestSubscriptionDate").'</th>';
166print '</tr>';
167
168if (!$foundphy) {
169 $data[] = array('label' => 'phy', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
170}
171if (!$foundmor) {
172 $data[] = array('label' => 'mor', 'nb' => '0', 'nbactive' => '0', 'lastdate' => '', 'lastsubscriptiondate' => '');
173}
174
175foreach ($data as $val) {
176 $nb = $val['nb'];
177 $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
178 $nbactive = $val['nbactive'];
179
180 print '<tr class="oddeven">';
181 print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
182 print '<td class="right">'.$nb.'</td>';
183 print '<td class="right">'.$nbactive.'</td>';
184 print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
185 print '<td class="right">'.$nbsubscriptions.'</td>';
186 print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
187 print '</tr>';
188}
189
190print '</table>';
191print '</div>';
192
193print dol_get_fiche_end();
194
195// End of page
196llxFooter();
197$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:70
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.