dolibarr 19.0.3
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 *
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.'/adherents/class/adherent.class.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
32
35
36$userid = GETPOST('userid', 'int'); if ($userid < 0) {
37 $userid = 0;
38}
39$socid = GETPOST('socid', 'int'); if ($socid < 0) {
40 $socid = 0;
41}
42
43// Security check
44if ($user->socid > 0) {
45 $action = '';
46 $socid = $user->socid;
47}
48$result = restrictedArea($user, 'adherent', '', '', 'cotisation');
49
50$year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
51$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
52$endyear = $year;
53if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) {
54 $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');
55}
56
57// Load translation files required by the page
58$langs->loadLangs(array("companies", "members"));
59
60
61/*
62 * View
63 */
64
65$memberstatic = new Adherent($db);
66$form = new Form($db);
67
68$title = $langs->trans("SubscriptionsStatistics");
69llxHeader('', $title);
70
71print load_fiche_titre($title, '', $memberstatic->picto);
72
73$dir = $conf->adherent->dir_temp;
74
75dol_mkdir($dir);
76
77$stats = new AdherentStats($db, $socid, $userid);
78
79// Build graphic number of object
80$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
81//var_dump($data);
82// $data = array(array('Lib',val1,val2,val3),...)
83
84
85$filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
86$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
87
88
89$px1 = new DolGraph();
90$mesg = $px1->isGraphKo();
91if (!$mesg) {
92 $px1->SetData($data);
93 $i = $startyear;
94 while ($i <= $endyear) {
95 $legend[] = $i;
96 $i++;
97 }
98 $px1->SetLegend($legend);
99 $px1->SetMaxValue($px1->GetCeilMaxValue());
100 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
101 $px1->SetWidth($WIDTH);
102 $px1->SetHeight($HEIGHT);
103 $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
104 $px1->SetShading(3);
105 $px1->SetHorizTickIncrement(1);
106 $px1->mode = 'depth';
107 $px1->SetTitle($langs->trans("NbOfSubscriptions"));
108
109 $px1->draw($filenamenb, $fileurlnb);
110}
111
112// Build graphic amount of object
113$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
114//var_dump($data);
115// $data = array(array('Lib',val1,val2,val3),...)
116
117$filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
118$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
119
120$px2 = new DolGraph();
121$mesg = $px2->isGraphKo();
122if (!$mesg) {
123 $px2->SetData($data);
124 $i = $startyear;
125 while ($i <= $endyear) {
126 $legend[] = $i;
127 $i++;
128 }
129 $px2->SetLegend($legend);
130 $px2->SetMaxValue($px2->GetCeilMaxValue());
131 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
132 $px2->SetWidth($WIDTH);
133 $px2->SetHeight($HEIGHT);
134 $px2->SetYLabel($langs->trans("AmountOfSubscriptions"));
135 $px2->SetShading(3);
136 $px2->SetHorizTickIncrement(1);
137 $px2->mode = 'depth';
138 $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
139
140 $px2->draw($filenameamount, $fileurlamount);
141}
142
143
144$head = member_stats_prepare_head($memberstatic);
145
146print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
147
148
149print '<div class="fichecenter"><div class="fichethirdleft">';
150
151// Show filter box
152/*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
153print '<input type="hidden" name="token" value="'.newToken().'">';
154
155print '<table class="border centpercent">';
156print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
157print '<tr><td>'.$langs->trans("Member").'</td><td>';
158print img_picto('', 'company', 'class="pictofixedwidth"');
159print $form->select_company($id,'memberid','',1);
160print '</td></tr>';
161print '<tr><td>'.$langs->trans("User").'</td><td>';
162print img_picto('', 'user', 'class="pictofixedwidth"');
163print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
164print '</td></tr>';
165print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
166print '</table>';
167print '</form>';
168print '<br><br>';
169*/
170
171// Show array
172$data = $stats->getAllByYear();
173
174
175print '<div class="div-table-responsive-no-min">';
176print '<table class="noborder">';
177print '<tr class="liste_titre" height="24">';
178print '<td class="center">'.$langs->trans("Year").'</td>';
179print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
180print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
181print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
182print '</tr>';
183
184$oldyear = 0;
185foreach ($data as $val) {
186 $year = $val['year'];
187 while ($oldyear > $year + 1) { // If we have empty year
188 $oldyear--;
189 print '<tr class="oddeven" height="24">';
190 print '<td class="center">';
191 //print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
192 print $oldyear;
193 //print '</a>';
194 print '</td>';
195 print '<td class="right">0</td>';
196 print '<td class="right amount nowraponall">0</td>';
197 print '<td class="right amount nowraponall">0</td>';
198 print '</tr>';
199 }
200 print '<tr class="oddeven" height="24">';
201 print '<td class="center">';
202 print '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
203 print '</td>';
204 print '<td class="right">'.$val['nb'].'</td>';
205 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
206 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
207 print '</tr>';
208 $oldyear = $year;
209}
210
211print '</table>';
212print '</div>';
213
214
215print '</div><div class="fichetwothirdright">';
216
217
218// Show graphs
219print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
220if ($mesg) {
221 print $mesg;
222} else {
223 print $px1->show();
224 print "<br>\n";
225 print $px2->show();
226}
227print '</td></tr></table>';
228
229
230print '</div></div>';
231print '<div class="clearboth"></div>';
232
233
234print dol_get_fiche_end();
235
236// End of page
237llxFooter();
238$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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:124
load_fiche_titre($titre, $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.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return 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 informations.
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.