dolibarr 21.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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacementstats.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array('trips', 'companies'));
43
46
47$userid = GETPOSTINT('userid');
48if ($userid < 0) {
49 $userid = 0;
50}
51$socid = GETPOSTINT('socid');
52if ($socid < 0) {
53 $socid = 0;
54}
55$id = GETPOSTINT('id');
56
57// Security check
58if ($user->socid > 0) {
59 $action = '';
60 $socid = $user->socid;
61}
62if ($user->socid) {
63 $socid = $user->socid;
64}
65$result = restrictedArea($user, 'deplacement', $id, '');
66
67// Other security check
68$childids = $user->getAllChildIds();
69$childids[] = $user->id;
70if ($userid > 0) {
71 if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous') && !in_array($userid, $childids)) {
73 }
74}
75
76$nowyear = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
77$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
78$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
79$endyear = $year;
80
81$mode = GETPOST("mode") ? GETPOST("mode") : 'customer';
82
83
84/*
85 * View
86 */
87
88$form = new Form($db);
89
90
91llxHeader();
92
93$title = $langs->trans("TripsAndExpensesStatistics");
94$dir = $conf->deplacement->dir_temp;
95
96print load_fiche_titre($title, $mesg);
97
98dol_mkdir($dir);
99
100$useridtofilter = $userid; // Filter from parameters
101if (empty($useridtofilter)) {
102 $useridtofilter = $childids;
103 if ($user->hasRight('deplacement', 'readall') || $user->hasRight('deplacement', 'lire_tous')) {
104 $useridtofilter = 0;
105 }
106}
107
108$stats = new DeplacementStats($db, $socid, $useridtofilter);
109
110
111// Build graphic number of object
112// $data = array(array('Lib',val1,val2,val3),...)
113//print "$endyear, $startyear";
114$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
115//var_dump($data);
116
117$filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
118$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
119
120$px1 = new DolGraph();
121$mesg = $px1->isGraphKo();
122if (!$mesg) {
123 $px1->SetData($data);
124 $i = $startyear;
125 $legend = array();
126 while ($i <= $endyear) {
127 $legend[] = $i;
128 $i++;
129 }
130 $px1->SetLegend($legend);
131 $px1->SetMaxValue($px1->GetCeilMaxValue());
132 $px1->SetWidth($WIDTH);
133 $px1->SetHeight($HEIGHT);
134 $px1->SetYLabel($langs->trans("Number"));
135 $px1->SetShading(3);
136 $px1->SetHorizTickIncrement(1);
137 $px1->mode = 'depth';
138 $px1->SetTitle($langs->trans("NumberByMonth"));
139
140 $px1->draw($filenamenb, $fileurlnb);
141}
142
143// Build graphic amount of object
144$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
145//var_dump($data);
146// $data = array(array('Lib',val1,val2,val3),...)
147
148$filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
149$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
150
151$px2 = new DolGraph();
152$mesg = $px2->isGraphKo();
153if (!$mesg) {
154 $px2->SetData($data);
155 $i = $startyear;
156 $legend = array();
157 while ($i <= $endyear) {
158 $legend[] = $i;
159 $i++;
160 }
161 $px2->SetLegend($legend);
162 $px2->SetMaxValue($px2->GetCeilMaxValue());
163 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
164 $px2->SetWidth($WIDTH);
165 $px2->SetHeight($HEIGHT);
166 $px2->SetYLabel($langs->trans("Amount"));
167 $px2->SetShading(3);
168 $px2->SetHorizTickIncrement(1);
169 $px2->mode = 'depth';
170 $px2->SetTitle($langs->trans("AmountTotal"));
171
172 $px2->draw($filenameamount, $fileurlamount);
173}
174
175
176$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
177
178$filename_avg = '';
179$fileurl_avg = '';
180if (!$user->hasRight('societe', 'client', 'voir')) {
181 $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
182 if ($mode == 'customer') {
183 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
184 }
185 if ($mode == 'supplier') {
186 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
187 }
188} else {
189 $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
190 if ($mode == 'customer') {
191 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
192 }
193 if ($mode == 'supplier') {
194 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
195 }
196}
197
198$px3 = new DolGraph();
199$mesg = $px3->isGraphKo();
200if (!$mesg) {
201 $px3->SetData($data);
202 $i = $startyear;
203 $legend = array();
204 while ($i <= $endyear) {
205 $legend[] = $i;
206 $i++;
207 }
208 $px3->SetLegend($legend);
209 $px3->SetYLabel($langs->trans("AmountAverage"));
210 $px3->SetMaxValue($px3->GetCeilMaxValue());
211 $px3->SetMinValue($px3->GetFloorMinValue());
212 $px3->SetWidth($WIDTH);
213 $px3->SetHeight($HEIGHT);
214 $px3->SetShading(3);
215 $px3->SetHorizTickIncrement(1);
216 $px3->mode = 'depth';
217 $px3->SetTitle($langs->trans("AmountAverage"));
218
219 $px3->draw($filename_avg, $fileurl_avg);
220}
221
222
223// Show array
224$data = $stats->getAllByYear();
225$arrayyears = array();
226foreach ($data as $val) {
227 $arrayyears[$val['year']] = $val['year'];
228}
229if (!count($arrayyears)) {
230 $arrayyears[$nowyear] = $nowyear;
231}
232
233
234$h = 0;
235$head = array();
236$head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/stats/index.php';
237$head[$h][1] = $langs->trans("ByMonthYear");
238$head[$h][2] = 'byyear';
239$h++;
240
241complete_head_from_modules($conf, $langs, null, $head, $h, 'trip_stats');
242
243print dol_get_fiche_head($head, 'byyear', '', -1);
244
245
246print '<div class="fichecenter"><div class="fichethirdleft">';
247
248
249// Show filter box
250print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
251print '<input type="hidden" name="token" value="'.newToken().'">';
252print '<input type="hidden" name="mode" value="'.$mode.'">';
253
254print '<table class="border centpercent">';
255print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
256// Company
257print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
258print img_picto('', 'company', 'class="pictofixedwidth"');
259print $form->select_company($socid, 'socid', '', 1, 1, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
260print '</td></tr>';
261// User
262print '<tr><td>'.$langs->trans("User").'</td><td>';
263$include = '';
264if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
265 $include = 'hierarchy';
266}
267print img_picto('', 'user', 'class="pictofixedwidth"');
268print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
269print '</td></tr>';
270// Year
271print '<tr><td>'.$langs->trans("Year").'</td><td>';
272if (!in_array($year, $arrayyears)) {
273 $arrayyears[$year] = $year;
274}
275arsort($arrayyears);
276print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
277print '</td></tr>';
278print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
279print '</table>';
280print '</form>';
281print '<br><br>';
282
283print '<div class="div-table-responsive-no-min">';
284print '<table class="border centpercent">';
285print '<tr>';
286print '<td class="center">'.$langs->trans("Year").'</td>';
287print '<td class="center">'.$langs->trans("Number").'</td>';
288print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
289print '<td class="center">'.$langs->trans("AmountAverage").'</td>';
290print '</tr>';
291
292$oldyear = 0;
293foreach ($data as $val) {
294 $year = $val['year'];
295 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
296 $oldyear--;
297 print '<tr>';
298 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
299 print '<td class="right">0</td>';
300 print '<td class="right">0</td>';
301 print '<td class="right">0</td>';
302 print '</tr>';
303 }
304
305 // Total
306 print '<tr>';
307 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
308 print '<td class="right">'.$val['nb'].'</td>';
309 print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
310 print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
311 print '</tr>';
312 $oldyear = $year;
313}
314
315print '</table>';
316print '</div>';
317
318print '</div><div class="fichetwothirdright">';
319
320
321// Show graphs
322print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
323if ($mesg) {
324 print $mesg;
325} else {
326 print $px1->show();
327 print "<br>\n";
328 print $px2->show();
329 print "<br>\n";
330 print $px3->show();
331}
332print '</td></tr></table>';
333
334
335print '</div></div>';
336print '<div class="clearboth"></div>';
337
338
339print dol_get_fiche_end();
340
341// End of page
342llxFooter();
343$db->close();
$id
Definition account.php:48
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage the statistics of travel and expense notes.
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.