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