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