dolibarr 23.0.3
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-2025 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->socid > 0) {
61 $action = '';
62 $socid = $user->socid;
63}
64if ($user->socid) {
65 $socid = $user->socid;
66}
67$result = restrictedArea($user, 'expensereport', $id, '');
68
69$parameters = array();
70$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
71if ($reshook < 0) {
72 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
73}
74
75$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
76$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
77$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
78$endyear = $year;
79
80
81
82/*
83 * View
84 */
85
86$form = new Form($db);
87$tmpexpensereport = new ExpenseReport($db);
88
89$title = $langs->trans("TripsAndExpensesStatistics");
90$dir = $conf->expensereport->dir_temp;
91
92llxHeader('', $title);
93
94print load_fiche_titre($title, '', 'trip');
95
96dol_mkdir($dir);
97
98$stats = new ExpenseReportStats($db, $socid, $userid);
99if ($object_status != '' && $object_status >= -1) {
100 $stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
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
170$fileurl_avg = null;
171if (!$user->hasRight('societe', 'client', 'voir')) {
172 $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
173 if ($mode == 'customer') {
174 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
175 }
176 if ($mode == 'supplier') {
177 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
178 }
179} else {
180 $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
181 if ($mode == 'customer') {
182 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
183 }
184 if ($mode == 'supplier') {
185 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
186 }
187}
188
189$px3 = new DolGraph();
190$mesg = $px3->isGraphKo();
191if (!$mesg && $fileurl_avg !== null) {
192 $px3->SetData($data);
193 $i = $startyear;
194 $legend = array();
195 while ($i <= $endyear) {
196 $legend[] = $i;
197 $i++;
198 }
199 $px3->SetLegend($legend);
200 $px3->SetYLabel($langs->trans("AmountAverage"));
201 $px3->SetMaxValue($px3->GetCeilMaxValue());
202 $px3->SetMinValue((int) $px3->GetFloorMinValue());
203 $px3->SetWidth($WIDTH);
204 $px3->SetHeight($HEIGHT);
205 $px3->SetShading(3);
206 $px3->SetHorizTickIncrement(1);
207 $px3->mode = 'depth';
208 $px3->SetTitle($langs->trans("AmountAverage"));
209
210 $px3->draw($filename_avg, $fileurl_avg);
211}
212
213
214// Show array
215$data = $stats->getAllByYear();
216$arrayyears = array();
217foreach ($data as $val) {
218 $arrayyears[$val['year']] = $val['year'];
219}
220if (!count($arrayyears)) {
221 $arrayyears[$nowyear] = $nowyear;
222}
223
224
225$h = 0;
226$head = array();
227$head[$h][0] = DOL_URL_ROOT.'/expensereport/stats/index.php';
228$head[$h][1] = $langs->trans("ByMonthYear");
229$head[$h][2] = 'byyear';
230$h++;
231
232complete_head_from_modules($conf, $langs, null, $head, $h, 'trip_stats');
233
234print dol_get_fiche_head($head, 'byyear', '', -1);
235
236
237print '<div class="fichecenter"><div class="fichethirdleft">';
238
239
240// Show filter box
241print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
242print '<input type="hidden" name="token" value="'.newToken().'">';
243print '<input type="hidden" name="mode" value="'.$mode.'">';
244
245print '<table class="noborder centpercent">';
246print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
247// Company
248/*
249print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
250print $form->select_company($socid,'socid','',1,1,0,array(),0,'widthcentpercentminusx maxwidth300','');
251print '</td></tr>';
252*/
253// User
254print '<tr><td>'.$langs->trans("User").'</td><td>';
255$include = '';
256if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')) {
257 $include = 'hierarchy';
258}
259print img_picto('', 'user', 'class="pictofixedwidth"');
260print $form->select_dolusers($userid, 'userid', 1, null, 0, $include, '', '', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
261print '</td></tr>';
262// Status
263print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
264$liststatus = $tmpexpensereport->labelStatus;
265print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
266print '</td></tr>';
267// Year
268print '<tr><td>';
269print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation"));
270print '</td><td>';
271if (!in_array($year, $arrayyears)) {
272 $arrayyears[$year] = $year;
273}
274arsort($arrayyears);
275print img_picto('', 'calendar', 'class="pictofixedwidth"');
276print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
277print '</td></tr>';
278print '<tr><td class="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="noborder centpercent">';
285print '<tr class="liste_titre" height="24">';
286print '<td class="center">'.$langs->trans("Year").'</td>';
287print '<td class="right">'.$langs->trans("Number").'</td>';
288print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
289print '<td class="right">'.$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
298 print '<tr class="oddeven" height="24">';
299 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
300 print '<td class="right">0</td>';
301 print '<td class="right amount nowraponall">0</td>';
302 print '<td class="right amount nowraponall">0</td>';
303 print '</tr>';
304 }
305
306
307 print '<tr class="oddeven" height="24">';
308 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
309 print '<td class="right">'.$val['nb'].'</td>';
310 print '<td class="right amount nowraponall">'.price(price2num($val['total'], 'MT'), 1).'</td>';
311 print '<td class="right amount nowraponall">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
312 print '</tr>';
313 $oldyear = $year;
314}
315
316print '</table>';
317print '</div>';
318
319print '</div><div class="fichetwothirdright">';
320
321
322// Show graphs
323print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
324if ($mesg) {
325 print $mesg;
326} else {
327 print $px1->show();
328 print "<br>\n";
329 print $px2->show();
330 print "<br>\n";
331 print $px3->show();
332}
333print '</td></tr></table>';
334
335
336print '</div></div>';
337print '<div class="clearboth"></div>';
338
339
340print dol_get_fiche_end();
341
342// End of page
343llxFooter();
344$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.
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.