dolibarr  17.0.4
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 // Load Dolibarr environment
27 require '../../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacementstats.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('trips', 'companies'));
33 
35 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
36 
37 $userid = GETPOST('userid', 'int'); if ($userid < 0) {
38  $userid = 0;
39 }
40 $socid = GETPOST('socid', 'int'); if ($socid < 0) {
41  $socid = 0;
42 }
43 $id = GETPOST('id', 'int');
44 
45 // Security check
46 if ($user->socid > 0) {
47  $action = '';
48  $socid = $user->socid;
49 }
50 if ($user->socid) {
51  $socid = $user->socid;
52 }
53 $result = restrictedArea($user, 'deplacement', $id, '');
54 
55 // Other security check
56 $childids = $user->getAllChildIds();
57 $childids[] = $user->id;
58 if ($userid > 0) {
59  if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous) && !in_array($userid, $childids)) {
61  exit;
62  }
63 }
64 
65 $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
66 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
67 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
68 $endyear = $year;
69 
70 $mode = GETPOST("mode") ?GETPOST("mode") : 'customer';
71 
72 
73 /*
74  * View
75  */
76 
77 $form = new Form($db);
78 
79 
80 llxHeader();
81 
82 $title = $langs->trans("TripsAndExpensesStatistics");
83 $dir = $conf->deplacement->dir_temp;
84 
85 print load_fiche_titre($title, $mesg);
86 
87 dol_mkdir($dir);
88 
89 $useridtofilter = $userid; // Filter from parameters
90 if (empty($useridtofilter)) {
91  $useridtofilter = $childids;
92  if (!empty($user->rights->deplacement->readall) || !empty($user->rights->deplacement->lire_tous)) {
93  $useridtofilter = 0;
94  }
95 }
96 
97 $stats = new DeplacementStats($db, $socid, $useridtofilter);
98 
99 
100 // Build graphic number of object
101 // $data = array(array('Lib',val1,val2,val3),...)
102 //print "$endyear, $startyear";
103 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
104 //var_dump($data);
105 
106 $filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
107 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
108 
109 $px1 = new DolGraph();
110 $mesg = $px1->isGraphKo();
111 if (!$mesg) {
112  $px1->SetData($data);
113  $i = $startyear;
114  $legend = array();
115  while ($i <= $endyear) {
116  $legend[] = $i;
117  $i++;
118  }
119  $px1->SetLegend($legend);
120  $px1->SetMaxValue($px1->GetCeilMaxValue());
121  $px1->SetWidth($WIDTH);
122  $px1->SetHeight($HEIGHT);
123  $px1->SetYLabel($langs->trans("Number"));
124  $px1->SetShading(3);
125  $px1->SetHorizTickIncrement(1);
126  $px1->mode = 'depth';
127  $px1->SetTitle($langs->trans("NumberByMonth"));
128 
129  $px1->draw($filenamenb, $fileurlnb);
130 }
131 
132 // Build graphic amount of object
133 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
134 //var_dump($data);
135 // $data = array(array('Lib',val1,val2,val3),...)
136 
137 $filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
138 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
139 
140 $px2 = new DolGraph();
141 $mesg = $px2->isGraphKo();
142 if (!$mesg) {
143  $px2->SetData($data);
144  $i = $startyear;
145  $legend = array();
146  while ($i <= $endyear) {
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->mode = 'depth';
159  $px2->SetTitle($langs->trans("AmountTotal"));
160 
161  $px2->draw($filenameamount, $fileurlamount);
162 }
163 
164 
165 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
166 
167 if (empty($user->rights->societe->client->voir) || $user->socid) {
168  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
169  if ($mode == 'customer') {
170  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
171  }
172  if ($mode == 'supplier') {
173  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
174  }
175 } else {
176  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
177  if ($mode == 'customer') {
178  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
179  }
180  if ($mode == 'supplier') {
181  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
182  }
183 }
184 
185 $px3 = new DolGraph();
186 $mesg = $px3->isGraphKo();
187 if (!$mesg) {
188  $px3->SetData($data);
189  $i = $startyear;
190  $legend = array();
191  while ($i <= $endyear) {
192  $legend[] = $i;
193  $i++;
194  }
195  $px3->SetLegend($legend);
196  $px3->SetYLabel($langs->trans("AmountAverage"));
197  $px3->SetMaxValue($px3->GetCeilMaxValue());
198  $px3->SetMinValue($px3->GetFloorMinValue());
199  $px3->SetWidth($WIDTH);
200  $px3->SetHeight($HEIGHT);
201  $px3->SetShading(3);
202  $px3->SetHorizTickIncrement(1);
203  $px3->mode = 'depth';
204  $px3->SetTitle($langs->trans("AmountAverage"));
205 
206  $px3->draw($filename_avg, $fileurl_avg);
207 }
208 
209 
210 // Show array
211 $data = $stats->getAllByYear();
212 $arrayyears = array();
213 foreach ($data as $val) {
214  $arrayyears[$val['year']] = $val['year'];
215 }
216 if (!count($arrayyears)) {
217  $arrayyears[$nowyear] = $nowyear;
218 }
219 
220 
221 $h = 0;
222 $head = array();
223 $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/stats/index.php';
224 $head[$h][1] = $langs->trans("ByMonthYear");
225 $head[$h][2] = 'byyear';
226 $h++;
227 
228 complete_head_from_modules($conf, $langs, null, $head, $h, 'trip_stats');
229 
230 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
231 
232 
233 print '<div class="fichecenter"><div class="fichethirdleft">';
234 
235 
236 // Show filter box
237 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
238 print '<input type="hidden" name="token" value="'.newToken().'">';
239 print '<input type="hidden" name="mode" value="'.$mode.'">';
240 
241 print '<table class="border centpercent">';
242 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
243 // Company
244 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
245 $filter = '';
246 print img_picto('', 'company', 'class="pictofixedwidth"');
247 print $form->select_company($socid, 'socid', $filter, 1, 1, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
248 print '</td></tr>';
249 // User
250 print '<tr><td>'.$langs->trans("User").'</td><td>';
251 $include = '';
252 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
253  $include = 'hierarchy';
254 }
255 print img_picto('', 'user', 'class="pictofixedwidth"');
256 print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
257 print '</td></tr>';
258 // Year
259 print '<tr><td>'.$langs->trans("Year").'</td><td>';
260 if (!in_array($year, $arrayyears)) {
261  $arrayyears[$year] = $year;
262 }
263 arsort($arrayyears);
264 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
265 print '</td></tr>';
266 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
267 print '</table>';
268 print '</form>';
269 print '<br><br>';
270 
271 print '<div class="div-table-responsive-no-min">';
272 print '<table class="border centpercent">';
273 print '<tr>';
274 print '<td class="center">'.$langs->trans("Year").'</td>';
275 print '<td class="center">'.$langs->trans("Number").'</td>';
276 print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
277 print '<td class="center">'.$langs->trans("AmountAverage").'</td>';
278 print '</tr>';
279 
280 $oldyear = 0;
281 foreach ($data as $val) {
282  $year = $val['year'];
283  while ($year && $oldyear > $year + 1) { // If we have empty year
284  $oldyear--;
285  print '<tr>';
286  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
287  print '<td class="right">0</td>';
288  print '<td class="right">0</td>';
289  print '<td class="right">0</td>';
290  print '</tr>';
291  }
292 
293  // Total
294  print '<tr>';
295  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
296  print '<td class="right">'.$val['nb'].'</td>';
297  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
298  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
299  print '</tr>';
300  $oldyear = $year;
301 }
302 
303 print '</table>';
304 print '</div>';
305 
306 print '</div><div class="fichetwothirdright">';
307 
308 
309 // Show graphs
310 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
311 if ($mesg) {
312  print $mesg;
313 } else {
314  print $px1->show();
315  print "<br>\n";
316  print $px2->show();
317  print "<br>\n";
318  print $px3->show();
319 }
320 print '</td></tr></table>';
321 
322 
323 print '</div></div>';
324 print '<div style="clear:both"></div>';
325 
326 
327 print dol_get_fiche_end();
328 
329 // End of page
330 llxFooter();
331 $db->close();
Classe permettant la gestion des stats des deplacements et notes de frais.
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=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.