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