dolibarr  9.0.0
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.'/compta/deplacement/class/deplacementstats.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array('trips', 'companies'));
32 
35 
36 $userid=GETPOST('userid','int'); if ($userid < 0) $userid=0;
37 $socid=GETPOST('socid','int'); if ($socid < 0) $socid=0;
38 $id = GETPOST('id','int');
39 
40 // Security check
41 if ($user->societe_id > 0)
42 {
43  $action = '';
44  $socid = $user->societe_id;
45 }
46 if ($user->societe_id) $socid=$user->societe_id;
47 $result = restrictedArea($user, 'deplacement', $id,'');
48 
49 // Other security check
50 $childids = $user->getAllChildIds();
51 $childids[]=$user->id;
52 if ($userid > 0)
53 {
54  if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous) && ! in_array($userid, $childids))
55  {
57  exit;
58  }
59 }
60 
61 $nowyear=strftime("%Y", dol_now());
62 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
63 //$startyear=$year-2;
64 $startyear=$year-1;
65 $endyear=$year;
66 
67 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
68 
69 
70 /*
71  * View
72  */
73 
74 $form=new Form($db);
75 
76 
77 llxHeader();
78 
79 $title=$langs->trans("TripsAndExpensesStatistics");
80 $dir=$conf->deplacement->dir_temp;
81 
82 print load_fiche_titre($title, $mesg);
83 
84 dol_mkdir($dir);
85 
86 $useridtofilter=$userid; // Filter from parameters
87 if (empty($useridtofilter))
88 {
89  $useridtofilter=$childids;
90  if (! empty($user->rights->deplacement->readall) || ! empty($user->rights->deplacement->lire_tous)) $useridtofilter=0;
91 }
92 
93 $stats = new DeplacementStats($db, $socid, $useridtofilter);
94 
95 
96 // Build graphic number of object
97 // $data = array(array('Lib',val1,val2,val3),...)
98 //print "$endyear, $startyear";
99 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
100 //var_dump($data);
101 
102 $filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
103 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
104 
105 $px1 = new DolGraph();
106 $mesg = $px1->isGraphKo();
107 if (! $mesg)
108 {
109  $px1->SetData($data);
110  $px1->SetPrecisionY(0);
111  $i=$startyear;$legend=array();
112  while ($i <= $endyear)
113  {
114  $legend[]=$i;
115  $i++;
116  }
117  $px1->SetLegend($legend);
118  $px1->SetMaxValue($px1->GetCeilMaxValue());
119  $px1->SetWidth($WIDTH);
120  $px1->SetHeight($HEIGHT);
121  $px1->SetYLabel($langs->trans("Number"));
122  $px1->SetShading(3);
123  $px1->SetHorizTickIncrement(1);
124  $px1->SetPrecisionY(0);
125  $px1->mode='depth';
126  $px1->SetTitle($langs->trans("NumberByMonth"));
127 
128  $px1->draw($filenamenb,$fileurlnb);
129 }
130 
131 // Build graphic amount of object
132 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
133 //var_dump($data);
134 // $data = array(array('Lib',val1,val2,val3),...)
135 
136 $filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
137 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
138 
139 $px2 = new DolGraph();
140 $mesg = $px2->isGraphKo();
141 if (! $mesg)
142 {
143  $px2->SetData($data);
144  $i=$startyear;$legend=array();
145  while ($i <= $endyear)
146  {
147  $legend[]=$i;
148  $i++;
149  }
150  $px2->SetLegend($legend);
151  $px2->SetMaxValue($px2->GetCeilMaxValue());
152  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
153  $px2->SetWidth($WIDTH);
154  $px2->SetHeight($HEIGHT);
155  $px2->SetYLabel($langs->trans("Amount"));
156  $px2->SetShading(3);
157  $px2->SetHorizTickIncrement(1);
158  $px2->SetPrecisionY(0);
159  $px2->mode='depth';
160  $px2->SetTitle($langs->trans("AmountTotal"));
161 
162  $px2->draw($filenameamount,$fileurlamount);
163 }
164 
165 
166 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
167 
168 if (!$user->rights->societe->client->voir || $user->societe_id)
169 {
170  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
171  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
172  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
173 }
174 else
175 {
176  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
177  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
178  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
179 }
180 
181 $px3 = new DolGraph();
182 $mesg = $px3->isGraphKo();
183 if (! $mesg)
184 {
185  $px3->SetData($data);
186  $i = $startyear;$legend=array();
187  while ($i <= $endyear)
188  {
189  $legend[]=$i;
190  $i++;
191  }
192  $px3->SetLegend($legend);
193  $px3->SetYLabel($langs->trans("AmountAverage"));
194  $px3->SetMaxValue($px3->GetCeilMaxValue());
195  $px3->SetMinValue($px3->GetFloorMinValue());
196  $px3->SetWidth($WIDTH);
197  $px3->SetHeight($HEIGHT);
198  $px3->SetShading(3);
199  $px3->SetHorizTickIncrement(1);
200  $px3->SetPrecisionY(0);
201  $px3->mode='depth';
202  $px3->SetTitle($langs->trans("AmountAverage"));
203 
204  $px3->draw($filename_avg,$fileurl_avg);
205 }
206 
207 
208 // Show array
209 $data = $stats->getAllByYear();
210 $arrayyears=array();
211 foreach($data as $val) {
212  $arrayyears[$val['year']]=$val['year'];
213 }
214 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
215 
216 
217 $h=0;
218 $head = array();
219 $head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/stats/index.php';
220 $head[$h][1] = $langs->trans("ByMonthYear");
221 $head[$h][2] = 'byyear';
222 $h++;
223 
224 complete_head_from_modules($conf,$langs,null,$head,$h,'trip_stats');
225 
226 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
227 
228 
229 print '<div class="fichecenter"><div class="fichethirdleft">';
230 
231 
232 // Show filter box
233 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
234 print '<input type="hidden" name="mode" value="'.$mode.'">';
235 print '<table class="border" width="100%">';
236 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
237 // Company
238 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
239 $filter='';
240 print $form->select_company($socid,'socid',$filter,1,1,0,array(),0,'','style="width: 95%"');
241 print '</td></tr>';
242 // User
243 print '<tr><td>'.$langs->trans("User").'</td><td>';
244 $include='';
245 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $include='hierarchy';
246 print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
247 print '</td></tr>';
248 // Year
249 print '<tr><td>'.$langs->trans("Year").'</td><td>';
250 if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
251 arsort($arrayyears);
252 print $form->selectarray('year',$arrayyears,$year,0);
253 print '</td></tr>';
254 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
255 print '</table>';
256 print '</form>';
257 print '<br><br>';
258 
259 print '<div class="div-table-responsive-no-min">';
260 print '<table class="border" width="100%">';
261 print '<tr height="24">';
262 print '<td align="center">'.$langs->trans("Year").'</td>';
263 print '<td align="center">'.$langs->trans("Number").'</td>';
264 print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
265 print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
266 print '</tr>';
267 
268 $oldyear=0;
269 foreach ($data as $val)
270 {
271  $year = $val['year'];
272  while ($year && $oldyear > $year+1)
273  { // If we have empty year
274  $oldyear--;
275  print '<tr height="24">';
276  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
277  print '<td align="right">0</td>';
278  print '<td align="right">0</td>';
279  print '<td align="right">0</td>';
280  print '</tr>';
281  }
282  print '<tr height="24">';
283  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
284  print '<td align="right">'.$val['nb'].'</td>';
285  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
286  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
287  print '</tr>';
288  $oldyear=$year;
289 }
290 
291 print '</table>';
292 print '</div>';
293 
294 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
295 
296 
297 // Show graphs
298 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
299 if ($mesg) { print $mesg; }
300 else {
301  print $px1->show();
302  print "<br>\n";
303  print $px2->show();
304  print "<br>\n";
305  print $px3->show();
306 }
307 print '</td></tr></table>';
308 
309 
310 print '</div></div></div>';
311 print '<div style="clear:both"></div>';
312 
313 
314 dol_fiche_end();
315 
316 // End of page
317 llxFooter();
318 $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
Classe permettant la gestion des stats des deplacements et notes de frais.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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.
dol_now($mode='gmt')
Return date for now.
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.