dolibarr  13.0.2
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 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
30 
32 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
33 
34 $userid = GETPOST('userid', 'int'); if ($userid < 0) $userid = 0;
35 $socid = GETPOST('socid', 'int'); if ($socid < 0) $socid = 0;
36 
37 // Security check
38 if ($user->socid > 0) {
39  $action = '';
40  $socid = $user->socid;
41 }
42 $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
43 
44 $year = strftime("%Y", time());
45 $startyear = $year - 2;
46 $endyear = $year;
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array("companies", "members"));
50 
51 
52 /*
53  * View
54  */
55 
56 $form = new Form($db);
57 
58 $title = $langs->trans("SubscriptionsStatistics");
59 llxHeader('', $title);
60 
61 print load_fiche_titre($title, '', 'members');
62 
63 $dir = $conf->adherent->dir_temp;
64 
65 dol_mkdir($dir);
66 
67 $stats = new AdherentStats($db, $socid, $userid);
68 
69 // Build graphic number of object
70 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
71 //var_dump($data);
72 // $data = array(array('Lib',val1,val2,val3),...)
73 
74 
75 $filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
76 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
77 
78 
79 $px1 = new DolGraph();
80 $mesg = $px1->isGraphKo();
81 if (!$mesg) {
82  $px1->SetData($data);
83  $i = $startyear;
84  while ($i <= $endyear) {
85  $legend[] = $i;
86  $i++;
87  }
88  $px1->SetLegend($legend);
89  $px1->SetMaxValue($px1->GetCeilMaxValue());
90  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
91  $px1->SetWidth($WIDTH);
92  $px1->SetHeight($HEIGHT);
93  $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
94  $px1->SetShading(3);
95  $px1->SetHorizTickIncrement(1);
96  $px1->mode = 'depth';
97  $px1->SetTitle($langs->trans("NbOfSubscriptions"));
98 
99  $px1->draw($filenamenb, $fileurlnb);
100 }
101 
102 // Build graphic amount of object
103 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
104 //var_dump($data);
105 // $data = array(array('Lib',val1,val2,val3),...)
106 
107 $filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
108 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
109 
110 $px2 = new DolGraph();
111 $mesg = $px2->isGraphKo();
112 if (!$mesg) {
113  $px2->SetData($data);
114  $i = $startyear;
115  while ($i <= $endyear) {
116  $legend[] = $i;
117  $i++;
118  }
119  $px2->SetLegend($legend);
120  $px2->SetMaxValue($px2->GetCeilMaxValue());
121  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
122  $px2->SetWidth($WIDTH);
123  $px2->SetHeight($HEIGHT);
124  $px2->SetYLabel($langs->trans("AmountOfSubscriptions"));
125  $px2->SetShading(3);
126  $px2->SetHorizTickIncrement(1);
127  $px2->mode = 'depth';
128  $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
129 
130  $px2->draw($filenameamount, $fileurlamount);
131 }
132 
133 
134 $head = member_stats_prepare_head($adh);
135 
136 print dol_get_fiche_head($head, 'statssubscription', $langs->trans("Statistics"), -1, 'user');
137 
138 
139 print '<div class="fichecenter"><div class="fichethirdleft">';
140 
141 // Show filter box
142 /*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
143 print '<input type="hidden" name="token" value="'.newToken().'">';
144 
145 print '<table class="border centpercent">';
146 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
147 print '<tr><td>'.$langs->trans("Member").'</td><td>';
148 print $form->select_company($id,'memberid','',1);
149 print '</td></tr>';
150 print '<tr><td>'.$langs->trans("User").'</td><td>';
151 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
152 print '</td></tr>';
153 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
154 print '</table>';
155 print '</form>';
156 print '<br><br>';
157 */
158 
159 // Show array
160 $data = $stats->getAllByYear();
161 
162 
163 print '<div class="div-table-responsive-no-min">';
164 print '<table class="noborder">';
165 print '<tr class="liste_titre" height="24">';
166 print '<td class="center">'.$langs->trans("Year").'</td>';
167 print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
168 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
169 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
170 print '</tr>';
171 
172 $oldyear = 0;
173 foreach ($data as $val) {
174  $year = $val['year'];
175  while ($oldyear > $year + 1) { // If we have empty year
176  $oldyear--;
177  print '<tr class="oddeven" height="24">';
178  print '<td class="center">';
179  //print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
180  print $oldyear;
181  //print '</a>';
182  print '</td>';
183  print '<td class="right">0</td>';
184  print '<td class="right">0</td>';
185  print '<td class="right">0</td>';
186  print '</tr>';
187  }
188  print '<tr class="oddeven" height="24">';
189  print '<td class="center">';
190  //print '<a href="month.php?year='.$year.'">';
191  print $year;
192  //print '</a>';
193  print '</td>';
194  print '<td class="right">'.$val['nb'].'</td>';
195  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
196  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
197  print '</tr>';
198  $oldyear = $year;
199 }
200 
201 print '</table>';
202 print '</div>';
203 
204 
205 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
206 
207 
208 // Show graphs
209 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
210 if ($mesg) { print $mesg; } else {
211  print $px1->show();
212  print "<br>\n";
213  print $px2->show();
214 }
215 print '</td></tr></table>';
216 
217 
218 print '</div></div></div>';
219 print '<div style="clear:both"></div>';
220 
221 
222 print dol_get_fiche_end();
223 
224 // End of page
225 llxFooter();
226 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage statistics of members.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:217
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)