dolibarr 24.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) 2018-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
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.'/expensereport/class/expensereportstats.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array('trips', 'companies'));
43
46
47$hookmanager->initHooks(array('expensereportstats', 'globalcard'));
48
49$mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
50$object_status = GETPOST('object_status', 'intcomma');
51
52$userid = GETPOSTINT('userid');
53$socid = GETPOSTINT('socid');
54if ($socid < 0) {
55 $socid = 0;
56}
57$id = GETPOSTINT('id');
58
59// Security check
60if ($user->isExternalUser()) {
61 $action = '';
62 $socid = $user->isExternalUser();
63}
64
65$result = restrictedArea($user, 'expensereport', $id, '');
66
67$parameters = array();
68$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
69if ($reshook < 0) {
70 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
71}
72
73$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
74$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
75$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
76$endyear = $year;
77
78
79
80/*
81 * View
82 */
83
84$form = new Form($db);
85$tmpexpensereport = new ExpenseReport($db);
86
87$title = $langs->trans("TripsAndExpensesStatistics");
88$dir = $conf->expensereport->dir_temp;
89
90llxHeader('', $title);
91
92print load_fiche_titre($title, '', 'trip');
93
94dol_mkdir($dir);
95
96$stats = new ExpenseReportStats($db, $socid, $userid);
97if ($object_status != '' && $object_status >= -1) {
98 $stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
99}
100
101// Build graphic number of object
102// $data = array(array('Lib',val1,val2,val3),...)
103//print "$endyear, $startyear";
104$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
105//var_dump($data);
106
107$filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
108$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
109
110$px1 = new DolGraph();
111$mesg = $px1->isGraphKo();
112if (!$mesg) {
113 $px1->SetData($data);
114 $i = $startyear;
115 $legend = array();
116 while ($i <= $endyear) {
117 $legend[] = $i;
118 $i++;
119 }
120 $px1->SetLegend($legend);
121 $px1->SetMaxValue($px1->GetCeilMaxValue());
122 $px1->SetWidth($WIDTH);
123 $px1->SetHeight($HEIGHT);
124 $px1->SetYLabel($langs->trans("Number"));
125 $px1->SetShading(3);
126 $px1->SetHorizTickIncrement(1);
127 $px1->mode = 'depth';
128 $px1->SetTitle($langs->trans("NumberByMonth"));
129
130 $px1->draw($filenamenb, $fileurlnb);
131}
132
133// Build graphic amount of object
134$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
135//var_dump($data);
136// $data = array(array('Lib',val1,val2,val3),...)
137
138$filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
139$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
140
141$px2 = new DolGraph();
142$mesg = $px2->isGraphKo();
143if (!$mesg) {
144 $px2->SetData($data);
145 $i = $startyear;
146 $legend = array();
147 while ($i <= $endyear) {
148 $legend[] = $i;
149 $i++;
150 }
151 $px2->SetLegend($legend);
152 $px2->SetMaxValue($px2->GetCeilMaxValue());
153 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
154 $px2->SetWidth($WIDTH);
155 $px2->SetHeight($HEIGHT);
156 $px2->SetYLabel($langs->trans("Amount"));
157 $px2->SetShading(3);
158 $px2->SetHorizTickIncrement(1);
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$fileurl_avg = null;
169if (!$user->hasRight('societe', 'client', 'voir')) {
170 $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
171 if ($mode == 'customer') {
172 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
173 }
174 if ($mode == 'supplier') {
175 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
176 }
177} else {
178 $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
179 if ($mode == 'customer') {
180 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
181 }
182 if ($mode == 'supplier') {
183 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
184 }
185}
186
187$px3 = new DolGraph();
188$mesg = $px3->isGraphKo();
189if (!$mesg && $fileurl_avg !== null) {
190 $px3->SetData($data);
191 $i = $startyear;
192 $legend = array();
193 while ($i <= $endyear) {
194 $legend[] = $i;
195 $i++;
196 }
197 $px3->SetLegend($legend);
198 $px3->SetYLabel($langs->trans("AmountAverage"));
199 $px3->SetMaxValue($px3->GetCeilMaxValue());
200 $px3->SetMinValue((int) $px3->GetFloorMinValue());
201 $px3->SetWidth($WIDTH);
202 $px3->SetHeight($HEIGHT);
203 $px3->SetShading(3);
204 $px3->SetHorizTickIncrement(1);
205 $px3->mode = 'depth';
206 $px3->SetTitle($langs->trans("AmountAverage"));
207
208 $px3->draw($filename_avg, $fileurl_avg);
209}
210
211
212// Show array
213$data = $stats->getAllByYear();
214$arrayyears = array();
215foreach ($data as $val) {
216 $arrayyears[$val['year']] = $val['year'];
217}
218if (!count($arrayyears)) {
219 $arrayyears[$nowyear] = $nowyear;
220}
221
222
223$h = 0;
224$head = array();
225$head[$h][0] = DOL_URL_ROOT.'/expensereport/stats/index.php';
226$head[$h][1] = $langs->trans("ByMonthYear");
227$head[$h][2] = 'byyear';
228$h++;
229
230complete_head_from_modules($conf, $langs, null, $head, $h, 'trip_stats');
231
232print dol_get_fiche_head($head, 'byyear', '', -1);
233
234
235print '<div class="fichecenter"><div class="fichethirdleft">';
236
237
238// Show filter box
239print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
240print '<input type="hidden" name="token" value="'.newToken().'">';
241print '<input type="hidden" name="mode" value="'.$mode.'">';
242
243print '<table class="noborder centpercent">';
244print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
245// Company
246/*
247print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
248print $form->select_company($socid,'socid','',1,1,0,array(),0,'widthcentpercentminusx maxwidth300','');
249print '</td></tr>';
250*/
251// User
252print '<tr><td>'.$langs->trans("User").'</td><td>';
253$include = '';
254if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')) {
255 $include = 'hierarchy';
256}
257print img_picto('', 'user', 'class="pictofixedwidth"');
258print $form->select_dolusers($userid, 'userid', 1, null, 0, $include, '', '', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
259print '</td></tr>';
260// Status
261print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
262$liststatus = $tmpexpensereport->labelStatus;
263print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
264print '</td></tr>';
265// Year
266print '<tr><td>';
267print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation"));
268print '</td><td>';
269if (!in_array($year, $arrayyears)) {
270 $arrayyears[$year] = $year;
271}
272arsort($arrayyears);
273print img_picto('', 'calendar', 'class="pictofixedwidth"');
274print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
275print '</td></tr>';
276print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
277print '</table>';
278print '</form>';
279print '<br><br>';
280
281print '<div class="div-table-responsive-no-min">';
282print '<table class="noborder centpercent">';
283print '<tr class="liste_titre" height="24">';
284print '<td class="center">'.$langs->trans("Year").'</td>';
285print '<td class="right">'.$langs->trans("Number").'</td>';
286print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
287print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
288print '</tr>';
289
290$oldyear = 0;
291foreach ($data as $val) {
292 $year = $val['year'];
293 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
294 $oldyear--;
295
296 print '<tr class="oddeven" height="24">';
297 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
298 print '<td class="right">0</td>';
299 print '<td class="right amount nowraponall">0</td>';
300 print '<td class="right amount nowraponall">0</td>';
301 print '</tr>';
302 }
303
304
305 print '<tr class="oddeven" height="24">';
306 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
307 print '<td class="right">'.$val['nb'].'</td>';
308 print '<td class="right amount nowraponall">'.price(price2num($val['total'], 'MT'), 1).'</td>';
309 print '<td class="right amount nowraponall">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
310 print '</tr>';
311 $oldyear = $year;
312}
313
314print '</table>';
315print '</div>';
316
317print '</div><div class="fichetwothirdright">';
318
319
320// Show graphs
321print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
322if ($mesg) {
323 print $mesg;
324} else {
325 print $px1->show();
326 print "<br>\n";
327 print $px2->show();
328 print "<br>\n";
329 print $px3->show();
330}
331print '</td></tr></table>';
332
333
334print '</div></div>';
335print '<div class="clearboth"></div>';
336
337
338print dol_get_fiche_end();
339
340// End of page
341llxFooter();
342$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage Trips and Expenses.
Class to manage the statistics of the expensereports and expense notes.
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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, $morecssdiv='')
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.