dolibarr  13.0.2
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 <https://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 
34 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
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->socid > 0)
42 {
43  $action = '';
44  $socid = $user->socid;
45 }
46 if ($user->socid) $socid = $user->socid;
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  $i = $startyear; $legend = array();
111  while ($i <= $endyear)
112  {
113  $legend[] = $i;
114  $i++;
115  }
116  $px1->SetLegend($legend);
117  $px1->SetMaxValue($px1->GetCeilMaxValue());
118  $px1->SetWidth($WIDTH);
119  $px1->SetHeight($HEIGHT);
120  $px1->SetYLabel($langs->trans("Number"));
121  $px1->SetShading(3);
122  $px1->SetHorizTickIncrement(1);
123  $px1->mode = 'depth';
124  $px1->SetTitle($langs->trans("NumberByMonth"));
125 
126  $px1->draw($filenamenb, $fileurlnb);
127 }
128 
129 // Build graphic amount of object
130 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
131 //var_dump($data);
132 // $data = array(array('Lib',val1,val2,val3),...)
133 
134 $filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
135 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
136 
137 $px2 = new DolGraph();
138 $mesg = $px2->isGraphKo();
139 if (!$mesg)
140 {
141  $px2->SetData($data);
142  $i = $startyear; $legend = array();
143  while ($i <= $endyear)
144  {
145  $legend[] = $i;
146  $i++;
147  }
148  $px2->SetLegend($legend);
149  $px2->SetMaxValue($px2->GetCeilMaxValue());
150  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
151  $px2->SetWidth($WIDTH);
152  $px2->SetHeight($HEIGHT);
153  $px2->SetYLabel($langs->trans("Amount"));
154  $px2->SetShading(3);
155  $px2->SetHorizTickIncrement(1);
156  $px2->mode = 'depth';
157  $px2->SetTitle($langs->trans("AmountTotal"));
158 
159  $px2->draw($filenameamount, $fileurlamount);
160 }
161 
162 
163 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
164 
165 if (!$user->rights->societe->client->voir || $user->socid)
166 {
167  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
168  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
169  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
170 } else {
171  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
172  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
173  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
174 }
175 
176 $px3 = new DolGraph();
177 $mesg = $px3->isGraphKo();
178 if (!$mesg)
179 {
180  $px3->SetData($data);
181  $i = $startyear; $legend = array();
182  while ($i <= $endyear)
183  {
184  $legend[] = $i;
185  $i++;
186  }
187  $px3->SetLegend($legend);
188  $px3->SetYLabel($langs->trans("AmountAverage"));
189  $px3->SetMaxValue($px3->GetCeilMaxValue());
190  $px3->SetMinValue($px3->GetFloorMinValue());
191  $px3->SetWidth($WIDTH);
192  $px3->SetHeight($HEIGHT);
193  $px3->SetShading(3);
194  $px3->SetHorizTickIncrement(1);
195  $px3->mode = 'depth';
196  $px3->SetTitle($langs->trans("AmountAverage"));
197 
198  $px3->draw($filename_avg, $fileurl_avg);
199 }
200 
201 
202 // Show array
203 $data = $stats->getAllByYear();
204 $arrayyears = array();
205 foreach ($data as $val) {
206  $arrayyears[$val['year']] = $val['year'];
207 }
208 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
209 
210 
211 $h = 0;
212 $head = array();
213 $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/stats/index.php';
214 $head[$h][1] = $langs->trans("ByMonthYear");
215 $head[$h][2] = 'byyear';
216 $h++;
217 
218 complete_head_from_modules($conf, $langs, null, $head, $h, 'trip_stats');
219 
220 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
221 
222 
223 print '<div class="fichecenter"><div class="fichethirdleft">';
224 
225 
226 // Show filter box
227 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
228 print '<input type="hidden" name="token" value="'.newToken().'">';
229 print '<input type="hidden" name="mode" value="'.$mode.'">';
230 
231 print '<table class="border centpercent">';
232 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
233 // Company
234 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
235 $filter = '';
236 print $form->select_company($socid, 'socid', $filter, 1, 1, 0, array(), 0, '', 'style="width: 95%"');
237 print '</td></tr>';
238 // User
239 print '<tr><td>'.$langs->trans("User").'</td><td>';
240 $include = '';
241 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $include = 'hierarchy';
242 print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
243 print '</td></tr>';
244 // Year
245 print '<tr><td>'.$langs->trans("Year").'</td><td>';
246 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
247 arsort($arrayyears);
248 print $form->selectarray('year', $arrayyears, $year, 0);
249 print '</td></tr>';
250 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
251 print '</table>';
252 print '</form>';
253 print '<br><br>';
254 
255 print '<div class="div-table-responsive-no-min">';
256 print '<table class="border centpercent">';
257 print '<tr height="24">';
258 print '<td class="center">'.$langs->trans("Year").'</td>';
259 print '<td class="center">'.$langs->trans("Number").'</td>';
260 print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
261 print '<td class="center">'.$langs->trans("AmountAverage").'</td>';
262 print '</tr>';
263 
264 $oldyear = 0;
265 foreach ($data as $val)
266 {
267  $year = $val['year'];
268  while ($year && $oldyear > $year + 1)
269  { // If we have empty year
270  $oldyear--;
271  print '<tr height="24">';
272  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
273  print '<td class="right">0</td>';
274  print '<td class="right">0</td>';
275  print '<td class="right">0</td>';
276  print '</tr>';
277  }
278  print '<tr height="24">';
279  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
280  print '<td class="right">'.$val['nb'].'</td>';
281  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
282  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
283  print '</tr>';
284  $oldyear = $year;
285 }
286 
287 print '</table>';
288 print '</div>';
289 
290 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
291 
292 
293 // Show graphs
294 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
295 if ($mesg) { print $mesg; } else {
296  print $px1->show();
297  print "<br>\n";
298  print $px2->show();
299  print "<br>\n";
300  print $px3->show();
301 }
302 print '</td></tr></table>';
303 
304 
305 print '</div></div></div>';
306 print '<div style="clear:both"></div>';
307 
308 
309 print dol_get_fiche_end();
310 
311 // End of page
312 llxFooter();
313 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Classe permettant la gestion des stats des deplacements et notes de frais.
dol_now($mode= 'auto')
Return date for now.
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.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)