dolibarr 24.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
38require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
41
44
45$userid = GETPOSTINT('userid');
46if ($userid < 0) {
47 $userid = 0;
48}
49$socid = GETPOSTINT('socid');
50if ($socid < 0) {
51 $socid = 0;
52}
53
54// Security check
55if ($user->socid > 0) {
56 $action = '';
57 $socid = $user->socid;
58}
59restrictedArea($user, 'adherent', '', '', 'cotisation');
60
61$year = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
62$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
63$endyear = $year;
64if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) {
65 $endyear = dol_print_date(dol_time_plus_duree(dol_now('gmt'), (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)), "%Y", 'gmt');
66}
67
68// Load translation files required by the page
69$langs->loadLangs(array("companies", "members"));
70
71
72/*
73 * View
74 */
75
76$memberstatic = new Adherent($db);
77$membershipstatic = new Subscription($db);
78$form = new Form($db);
79
80$title = $langs->trans("Subscriptions");
81$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
82
83llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-stats');
84
85$param = '';
86
87$newcardbutton = '';
88$queryforbutton = array();
89$queryforbutton['mode'] = 'common';
90$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', dolBuildUrl(DOL_URL_ROOT.'/adherents/subscription/list.php', $queryforbutton), '', 1, array('morecss' => 'reposition'));
91$queryforbutton['mode'] = 'kanban';
92$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', dolBuildUrl(DOL_URL_ROOT.'/adherents/subscription/list.php', $queryforbutton), '', 1, array('morecss' => 'reposition'));
93$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'));
94$newcardbutton .= dolGetButtonTitleSeparator();
95$newcardbutton .= dolGetButtonTitle($langs->trans('NewSubscription'), '', 'fa fa-plus-circle', dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', ['statut' => '-1,1']), '', $user->hasRight('adherent', 'creer'));
96
97print_barre_liste($title, 0, $_SERVER["PHP_SELF"], $param, '', '', '', 0, $langs->trans("Statistics"), $membershipstatic->picto, 0, $newcardbutton, '', 0, 0, 0, 1);
98
99$dir = $conf->member->dir_temp;
100
101dol_mkdir($dir);
102
103$stats = new AdherentStats($db, $socid, $userid);
104
105// Build graphic number of object
106$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
107//var_dump($data);
108// $data = array(array('Lib',val1,val2,val3),...)
109
110
111$filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
112$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
113
114
115$px1 = new DolGraph();
116$mesg = $px1->isGraphKo();
117if (!$mesg) {
118 $px1->SetData($data);
119 $i = $startyear;
120 $legend = array();
121 while ($i <= $endyear) {
122 $legend[] = $i;
123 $i++;
124 }
125 $px1->SetLegend($legend);
126 $px1->SetMaxValue($px1->GetCeilMaxValue());
127 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
128 $px1->SetWidth($WIDTH);
129 $px1->SetHeight($HEIGHT);
130 $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
131 $px1->SetShading(3);
132 $px1->SetHorizTickIncrement(1);
133 $px1->mode = 'depth';
134 $px1->SetTitle($langs->trans("NbOfSubscriptions"));
135
136 $px1->draw($filenamenb, $fileurlnb);
137}
138
139// Build graphic amount of object
140$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
141//var_dump($data);
142// $data = array(array('Lib',val1,val2,val3),...)
143
144$filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
145$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
146
147$px2 = new DolGraph();
148$mesg = $px2->isGraphKo();
149if (!$mesg) {
150 $px2->SetData($data);
151 $i = $startyear;
152 $legend = array();
153 while ($i <= $endyear) {
154 $legend[] = $i;
155 $i++;
156 }
157 $px2->SetLegend($legend);
158 $px2->SetMaxValue($px2->GetCeilMaxValue());
159 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
160 $px2->SetWidth($WIDTH);
161 $px2->SetHeight($HEIGHT);
162 $px2->SetYLabel($langs->trans("AmountOfSubscriptions"));
163 $px2->SetShading(3);
164 $px2->SetHorizTickIncrement(1);
165 $px2->mode = 'depth';
166 $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
167
168 $px2->draw($filenameamount, $fileurlamount);
169}
170
171
172$head = membership_stats_prepare_head($memberstatic);
173
174print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
175
176
177print '<div class="fichecenter"><div class="fichethirdleft">';
178
179// Show filter box
180/*print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
181print '<input type="hidden" name="token" value="'.newToken().'">';
182
183print '<table class="border centpercent">';
184print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
185print '<tr><td>'.$langs->trans("Member").'</td><td>';
186print img_picto('', 'company', 'class="pictofixedwidth"');
187print $form->select_company($id,'memberid','',1);
188print '</td></tr>';
189print '<tr><td>'.$langs->trans("User").'</td><td>';
190print img_picto('', 'user', 'class="pictofixedwidth"');
191print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
192print '</td></tr>';
193print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
194print '</table>';
195print '</form>';
196print '<br><br>';
197*/
198
199// Show array
200$data = $stats->getAllByYear();
201
202
203print '<div class="div-table-responsive-no-min">';
204print '<table class="noborder">';
205print '<tr class="liste_titre" height="24">';
206print '<td class="center">'.$langs->trans("Year").'</td>';
207print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
208print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
209print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
210print '</tr>';
211
212$MAXLINES = 5;
213$nbline = 0;
214$oldyear = 0;
215$cssline = '';
216foreach ($data as $val) {
217 $year = (int) $val['year'];
218 while ($oldyear > $year + 1) { // If we have empty year
219 $oldyear--;
220 $nbline++;
221 if ($nbline > $MAXLINES) {
222 $cssline = ' hidden';
223 }
224 print '<tr class="oddeven'.$cssline.'" height="24">';
225 print '<td class="center">';
226 //print '<a href="month.php?year='.$oldyear.'&mode='.$mode.'">';
227 print $oldyear;
228 //print '</a>';
229 print '</td>';
230 print '<td class="right">0</td>';
231 print '<td class="right amount nowraponall">0</td>';
232 print '<td class="right amount nowraponall">0</td>';
233 print '</tr>';
234 }
235 print '<tr class="oddeven'.$cssline.'" height="24">';
236 print '<td class="center">';
237 print '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
238 print '</td>';
239 print '<td class="right">'.$val['nb'].'</td>';
240 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
241 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
242 print '</tr>';
243 $oldyear = $year;
244 $nbline++;
245 if ($nbline > $MAXLINES) {
246 $cssline = ' hidden';
247 }
248}
249
250if ($nbline > $MAXLINES) {
251 print '<tr class="liste_total"><td colspan="4" class="center">';
252 print '<a href="#" class="showmoreoptions" onclick="javascript:$(\'.hidden\').toggle();$(this).toggle();">'.img_picto('', 'chevron-down', 'class="paddingright"').$langs->trans("More").'...</a>';
253 print '</td></tr>';
254}
255
256print '</table>';
257print '</div>';
258
259
260print '</div><div class="fichetwothirdright">';
261
262
263// Show graphs
264print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
265if ($mesg) {
266 print $mesg;
267} else {
268 print $px1->show();
269 print "<br>\n";
270 print $px2->show();
271}
272print '</td></tr></table>';
273
274
275print '</div></div>';
276print '<div class="clearboth"></div>';
277
278
279print dol_get_fiche_end();
280
281// End of page
282llxFooter();
283$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.
Class to manage statistics of members.
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
Class to manage subscriptions of foundation members.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
membership_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.