dolibarr 21.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 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';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
31require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
34
45
46$userid = GETPOSTINT('userid');
47if ($userid < 0) {
48 $userid = 0;
49}
50$socid = GETPOSTINT('socid');
51if ($socid < 0) {
52 $socid = 0;
53}
54
55// Security check
56if ($user->socid > 0) {
57 $action = '';
58 $socid = $user->socid;
59}
60$result = restrictedArea($user, 'adherent', '', '', 'cotisation');
61
62$year = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
63$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
64$endyear = $year;
65if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) {
66 $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');
67}
68
69// Load translation files required by the page
70$langs->loadLangs(array("companies", "members"));
71
72
73/*
74 * View
75 */
76
77$memberstatic = new Adherent($db);
78$form = new Form($db);
79
80$title = $langs->trans("SubscriptionsStatistics");
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
85print load_fiche_titre($title, '', $memberstatic->picto);
86
87$dir = $conf->adherent->dir_temp;
88
89dol_mkdir($dir);
90
91$stats = new AdherentStats($db, $socid, $userid);
92
93// Build graphic number of object
94$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
95//var_dump($data);
96// $data = array(array('Lib',val1,val2,val3),...)
97
98
99$filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
100$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
101
102
103$px1 = new DolGraph();
104$mesg = $px1->isGraphKo();
105if (!$mesg) {
106 $px1->SetData($data);
107 $i = $startyear;
108 $legend = array();
109 while ($i <= $endyear) {
110 $legend[] = $i;
111 $i++;
112 }
113 $px1->SetLegend($legend);
114 $px1->SetMaxValue($px1->GetCeilMaxValue());
115 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
116 $px1->SetWidth($WIDTH);
117 $px1->SetHeight($HEIGHT);
118 $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
119 $px1->SetShading(3);
120 $px1->SetHorizTickIncrement(1);
121 $px1->mode = 'depth';
122 $px1->SetTitle($langs->trans("NbOfSubscriptions"));
123
124 $px1->draw($filenamenb, $fileurlnb);
125}
126
127// Build graphic amount of object
128$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
129//var_dump($data);
130// $data = array(array('Lib',val1,val2,val3),...)
131
132$filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
133$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
134
135$px2 = new DolGraph();
136$mesg = $px2->isGraphKo();
137if (!$mesg) {
138 $px2->SetData($data);
139 $i = $startyear;
140 $legend = array();
141 while ($i <= $endyear) {
142 $legend[] = $i;
143 $i++;
144 }
145 $px2->SetLegend($legend);
146 $px2->SetMaxValue($px2->GetCeilMaxValue());
147 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
148 $px2->SetWidth($WIDTH);
149 $px2->SetHeight($HEIGHT);
150 $px2->SetYLabel($langs->trans("AmountOfSubscriptions"));
151 $px2->SetShading(3);
152 $px2->SetHorizTickIncrement(1);
153 $px2->mode = 'depth';
154 $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
155
156 $px2->draw($filenameamount, $fileurlamount);
157}
158
159
160$head = member_stats_prepare_head($memberstatic);
161
162print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
163
164
165print '<div class="fichecenter"><div class="fichethirdleft">';
166
167// Show filter box
168/*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
169print '<input type="hidden" name="token" value="'.newToken().'">';
170
171print '<table class="border centpercent">';
172print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
173print '<tr><td>'.$langs->trans("Member").'</td><td>';
174print img_picto('', 'company', 'class="pictofixedwidth"');
175print $form->select_company($id,'memberid','',1);
176print '</td></tr>';
177print '<tr><td>'.$langs->trans("User").'</td><td>';
178print img_picto('', 'user', 'class="pictofixedwidth"');
179print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
180print '</td></tr>';
181print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
182print '</table>';
183print '</form>';
184print '<br><br>';
185*/
186
187// Show array
188$data = $stats->getAllByYear();
189
190
191print '<div class="div-table-responsive-no-min">';
192print '<table class="noborder">';
193print '<tr class="liste_titre" height="24">';
194print '<td class="center">'.$langs->trans("Year").'</td>';
195print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
196print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
197print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
198print '</tr>';
199
200$oldyear = 0;
201foreach ($data as $val) {
202 $year = (int) $val['year'];
203 while ($oldyear > $year + 1) { // If we have empty year
204 $oldyear--;
205 print '<tr class="oddeven" height="24">';
206 print '<td class="center">';
207 //print '<a href="month.php?year='.$oldyear.'&mode='.$mode.'">';
208 print $oldyear;
209 //print '</a>';
210 print '</td>';
211 print '<td class="right">0</td>';
212 print '<td class="right amount nowraponall">0</td>';
213 print '<td class="right amount nowraponall">0</td>';
214 print '</tr>';
215 }
216 print '<tr class="oddeven" height="24">';
217 print '<td class="center">';
218 print '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
219 print '</td>';
220 print '<td class="right">'.$val['nb'].'</td>';
221 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
222 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
223 print '</tr>';
224 $oldyear = $year;
225}
226
227print '</table>';
228print '</div>';
229
230
231print '</div><div class="fichetwothirdright">';
232
233
234// Show graphs
235print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
236if ($mesg) {
237 print $mesg;
238} else {
239 print $px1->show();
240 print "<br>\n";
241 print $px2->show();
242}
243print '</td></tr></table>';
244
245
246print '</div></div>';
247print '<div class="clearboth"></div>';
248
249
250print dol_get_fiche_end();
251
252// End of page
253llxFooter();
254$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.
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats information.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.