dolibarr  7.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@capnetworks.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 $langs->load("members");
50 $langs->load("companies");
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 '<table class="noborder">';
171 print '<tr class="liste_titre" height="24">';
172 print '<td align="center">'.$langs->trans("Year").'</td>';
173 print '<td align="right">'.$langs->trans("NbOfSubscriptions").'</td>';
174 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
175 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
176 print '</tr>';
177 
178 $oldyear=0;
179 foreach ($data as $val)
180 {
181  $year = $val['year'];
182  while ($oldyear > $year+1)
183  { // If we have empty year
184  $oldyear--;
185  print '<tr class="oddeven" height="24">';
186  print '<td align="center">';
187  print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
188  print $oldyear;
189  print '</a>';
190  print '</td>';
191  print '<td align="right">0</td>';
192  print '<td align="right">0</td>';
193  print '<td align="right">0</td>';
194  print '</tr>';
195  }
196  print '<tr class="oddeven" height="24">';
197  print '<td align="center">';
198  //print '<a href="month.php?year='.$year.'">';
199  print $year;
200  //print '</a>';
201  print '</td>';
202  print '<td align="right">'.$val['nb'].'</td>';
203  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
204  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
205  print '</tr>';
206  $oldyear=$year;
207 }
208 
209 print '</table>';
210 
211 
212 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
213 
214 
215 // Show graphs
216 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
217 if ($mesg) { print $mesg; }
218 else {
219  print $px1->show();
220  print "<br>\n";
221  print $px2->show();
222 }
223 print '</td></tr></table>';
224 
225 
226 print '</div></div></div>';
227 print '<div style="clear:both"></div>';
228 
229 
230 dol_fiche_end();
231 
232 
233 llxFooter();
234 
235 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
Class to manage statistics of members.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:37
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:206
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.