dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (c) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.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.'/core/class/dolgraph.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereportstats.class.php';
29 
30 $langs->load("trips");
31 $langs->load("companies");
32 
35 
36 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
37 $object_status=GETPOST('object_status');
38 
39 $userid=GETPOST('userid','int');
40 $socid=GETPOST('socid','int'); if ($socid < 0) $socid=0;
41 $id = GETPOST('id','int');
42 
43 // Security check
44 if ($user->societe_id > 0)
45 {
46  $action = '';
47  $socid = $user->societe_id;
48 }
49 if ($user->societe_id) $socid=$user->societe_id;
50 $result = restrictedArea($user, 'expensereport', $id,'');
51 
52 $nowyear=strftime("%Y", dol_now());
53 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
54 //$startyear=$year-2;
55 $startyear=$year-1;
56 $endyear=$year;
57 
58 
59 
60 /*
61  * View
62  */
63 
64 $form=new Form($db);
65 $tmpexpensereport=new ExpenseReport($db);
66 
67 $title=$langs->trans("TripsAndExpensesStatistics");
68 $dir=$conf->expensereport->dir_temp;
69 
70 llxHeader('', $title);
71 
73 
74 dol_mkdir($dir);
75 
76 $stats = new ExpenseReportStats($db, $socid, $userid);
77 if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND e.fk_statut IN ('.$db->escape($object_status).')';
78 
79 // Build graphic number of object
80 // $data = array(array('Lib',val1,val2,val3),...)
81 //print "$endyear, $startyear";
82 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
83 //var_dump($data);
84 
85 $filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
86 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
87 
88 $px1 = new DolGraph();
89 $mesg = $px1->isGraphKo();
90 if (! $mesg)
91 {
92  $px1->SetData($data);
93  $px1->SetPrecisionY(0);
94  $i=$startyear;$legend=array();
95  while ($i <= $endyear)
96  {
97  $legend[]=$i;
98  $i++;
99  }
100  $px1->SetLegend($legend);
101  $px1->SetMaxValue($px1->GetCeilMaxValue());
102  $px1->SetWidth($WIDTH);
103  $px1->SetHeight($HEIGHT);
104  $px1->SetYLabel($langs->trans("Number"));
105  $px1->SetShading(3);
106  $px1->SetHorizTickIncrement(1);
107  $px1->SetPrecisionY(0);
108  $px1->mode='depth';
109  $px1->SetTitle($langs->trans("NumberByMonth"));
110 
111  $px1->draw($filenamenb,$fileurlnb);
112 }
113 
114 // Build graphic amount of object
115 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
116 //var_dump($data);
117 // $data = array(array('Lib',val1,val2,val3),...)
118 
119 $filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
120 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
121 
122 $px2 = new DolGraph();
123 $mesg = $px2->isGraphKo();
124 if (! $mesg)
125 {
126  $px2->SetData($data);
127  $i=$startyear;$legend=array();
128  while ($i <= $endyear)
129  {
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("Amount"));
139  $px2->SetShading(3);
140  $px2->SetHorizTickIncrement(1);
141  $px2->SetPrecisionY(0);
142  $px2->mode='depth';
143  $px2->SetTitle($langs->trans("AmountTotal"));
144 
145  $px2->draw($filenameamount,$fileurlamount);
146 }
147 
148 
149 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
150 
151 if (!$user->rights->societe->client->voir || $user->societe_id)
152 {
153  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
154  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
155  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
156 }
157 else
158 {
159  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
160  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
161  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
162 }
163 
164 $px3 = new DolGraph();
165 $mesg = $px3->isGraphKo();
166 if (! $mesg)
167 {
168  $px3->SetData($data);
169  $i = $startyear;$legend=array();
170  while ($i <= $endyear)
171  {
172  $legend[]=$i;
173  $i++;
174  }
175  $px3->SetLegend($legend);
176  $px3->SetYLabel($langs->trans("AmountAverage"));
177  $px3->SetMaxValue($px3->GetCeilMaxValue());
178  $px3->SetMinValue($px3->GetFloorMinValue());
179  $px3->SetWidth($WIDTH);
180  $px3->SetHeight($HEIGHT);
181  $px3->SetShading(3);
182  $px3->SetHorizTickIncrement(1);
183  $px3->SetPrecisionY(0);
184  $px3->mode='depth';
185  $px3->SetTitle($langs->trans("AmountAverage"));
186 
187  $px3->draw($filename_avg,$fileurl_avg);
188 }
189 
190 
191 // Show array
192 $data = $stats->getAllByYear();
193 $arrayyears=array();
194 foreach($data as $val) {
195  $arrayyears[$val['year']]=$val['year'];
196 }
197 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
198 
199 
200 $h=0;
201 $head = array();
202 $head[$h][0] = DOL_URL_ROOT . '/expensereport/stats/index.php';
203 $head[$h][1] = $langs->trans("ByMonthYear");
204 $head[$h][2] = 'byyear';
205 $h++;
206 
207 complete_head_from_modules($conf,$langs,null,$head,$h,'trip_stats');
208 
209 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
210 
211 
212 print '<div class="fichecenter"><div class="fichethirdleft">';
213 
214 
215 // Show filter box
216 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
217 print '<input type="hidden" name="mode" value="'.$mode.'">';
218 print '<table class="noborder" width="100%">';
219 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
220 // Company
221 /*
222 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
223 $filter='';
224 print $form->select_company($socid,'socid',$filter,1,1,0,array(),0,'','style="width: 95%"');
225 print '</td></tr>';
226 */
227 // User
228 print '<tr><td>'.$langs->trans("User").'</td><td>';
229 $include='';
230 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include='hierarchy';
231 print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
232 print '</td></tr>';
233 // Status
234 print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
235 $liststatus=$tmpexpensereport->statuts;
236 print $form->selectarray('object_status', $liststatus, GETPOST('object_status'), -4, 0, 0, '', 1);
237 print '</td></tr>';
238 // Year
239 print '<tr><td>'.$langs->trans("Year").'</td><td>';
240 if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
241 arsort($arrayyears);
242 print $form->selectarray('year',$arrayyears,$year,0);
243 print '</td></tr>';
244 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
245 print '</table>';
246 print '</form>';
247 print '<br><br>';
248 
249 print '<table class="noborder" width="100%">';
250 print '<tr class="liste_titre" height="24">';
251 print '<td align="center">'.$langs->trans("Year").'</td>';
252 print '<td align="right">'.$langs->trans("Number").'</td>';
253 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
254 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
255 print '</tr>';
256 
257 $oldyear=0;
258 $var=true;
259 foreach ($data as $val)
260 {
261  $year = $val['year'];
262  while ($year && $oldyear > $year+1)
263  { // If we have empty year
264  $oldyear--;
265 
266  print '<tr '.$bc[$var].' height="24">';
267  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
268  print '<td align="right">0</td>';
269  print '<td align="right">0</td>';
270  print '<td align="right">0</td>';
271  print '</tr>';
272  }
273 
274 
275  print '<tr '.$bc[$var].' height="24">';
276  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
277  print '<td align="right">'.$val['nb'].'</td>';
278  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
279  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
280  print '</tr>';
281  $oldyear=$year;
282 }
283 
284 print '</table>';
285 
286 
287 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
288 
289 
290 // Show graphs
291 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
292 if ($mesg) { print $mesg; }
293 else {
294  print $px1->show();
295  print "<br>\n";
296  print $px2->show();
297  print "<br>\n";
298  print $px3->show();
299 }
300 print '</td></tr></table>';
301 
302 
303 print '</div></div></div>';
304 print '<div style="clear:both"></div>';
305 
306 
307 dol_fiche_end();
308 
309 
310 llxFooter();
311 
312 $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.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Classe permettant la gestion des stats des expensereports et notes de frais.
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
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
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.
dol_now($mode='gmt')
Return date for now.
Class to manage Trips and Expenses.
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.