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) 2018-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 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$mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
48$object_status = GETPOST('object_status', 'intcomma');
49
50$userid = GETPOSTINT('userid');
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, 'expensereport', $id, '');
66
67$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
68$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
69$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
70$endyear = $year;
71
72
73
74/*
75 * View
76 */
77
78$form = new Form($db);
79$tmpexpensereport = new ExpenseReport($db);
80
81$title = $langs->trans("TripsAndExpensesStatistics");
82$dir = $conf->expensereport->dir_temp;
83
84llxHeader('', $title);
85
86print load_fiche_titre($title, '', 'trip');
87
88dol_mkdir($dir);
89
90$stats = new ExpenseReportStats($db, $socid, $userid);
91if ($object_status != '' && $object_status >= -1) {
92 $stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
93}
94
95// Build graphic number of object
96// $data = array(array('Lib',val1,val2,val3),...)
97//print "$endyear, $startyear";
98$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
99//var_dump($data);
100
101$filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
102$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
103
104$px1 = new DolGraph();
105$mesg = $px1->isGraphKo();
106if (!$mesg) {
107 $px1->SetData($data);
108 $i = $startyear;
109 $legend = array();
110 while ($i <= $endyear) {
111 $legend[] = $i;
112 $i++;
113 }
114 $px1->SetLegend($legend);
115 $px1->SetMaxValue($px1->GetCeilMaxValue());
116 $px1->SetWidth($WIDTH);
117 $px1->SetHeight($HEIGHT);
118 $px1->SetYLabel($langs->trans("Number"));
119 $px1->SetShading(3);
120 $px1->SetHorizTickIncrement(1);
121 $px1->mode = 'depth';
122 $px1->SetTitle($langs->trans("NumberByMonth"));
123
124 $px1->draw($filenamenb, $fileurlnb);
125}
126
127// Build graphic amount of object
128$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
129//var_dump($data);
130// $data = array(array('Lib',val1,val2,val3),...)
131
132$filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
133$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
134
135$px2 = new DolGraph();
136$mesg = $px2->isGraphKo();
137if (!$mesg) {
138 $px2->SetData($data);
139 $i = $startyear;
140 $legend = array();
141 while ($i <= $endyear) {
142 $legend[] = $i;
143 $i++;
144 }
145 $px2->SetLegend($legend);
146 $px2->SetMaxValue($px2->GetCeilMaxValue());
147 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
148 $px2->SetWidth($WIDTH);
149 $px2->SetHeight($HEIGHT);
150 $px2->SetYLabel($langs->trans("Amount"));
151 $px2->SetShading(3);
152 $px2->SetHorizTickIncrement(1);
153 $px2->mode = 'depth';
154 $px2->SetTitle($langs->trans("AmountTotal"));
155
156 $px2->draw($filenameamount, $fileurlamount);
157}
158
159
160$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
161
162if (!$user->hasRight('societe', 'client', 'voir')) {
163 $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
164 if ($mode == 'customer') {
165 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
166 }
167 if ($mode == 'supplier') {
168 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
169 }
170} else {
171 $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
172 if ($mode == 'customer') {
173 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
174 }
175 if ($mode == 'supplier') {
176 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
177 }
178}
179
180$px3 = new DolGraph();
181$mesg = $px3->isGraphKo();
182if (!$mesg) {
183 $px3->SetData($data);
184 $i = $startyear;
185 $legend = array();
186 while ($i <= $endyear) {
187 $legend[] = $i;
188 $i++;
189 }
190 $px3->SetLegend($legend);
191 $px3->SetYLabel($langs->trans("AmountAverage"));
192 $px3->SetMaxValue($px3->GetCeilMaxValue());
193 $px3->SetMinValue($px3->GetFloorMinValue());
194 $px3->SetWidth($WIDTH);
195 $px3->SetHeight($HEIGHT);
196 $px3->SetShading(3);
197 $px3->SetHorizTickIncrement(1);
198 $px3->mode = 'depth';
199 $px3->SetTitle($langs->trans("AmountAverage"));
200
201 $px3->draw($filename_avg, $fileurl_avg);
202}
203
204
205// Show array
206$data = $stats->getAllByYear();
207$arrayyears = array();
208foreach ($data as $val) {
209 $arrayyears[$val['year']] = $val['year'];
210}
211if (!count($arrayyears)) {
212 $arrayyears[$nowyear] = $nowyear;
213}
214
215
216$h = 0;
217$head = array();
218$head[$h][0] = DOL_URL_ROOT.'/expensereport/stats/index.php';
219$head[$h][1] = $langs->trans("ByMonthYear");
220$head[$h][2] = 'byyear';
221$h++;
222
223complete_head_from_modules($conf, $langs, null, $head, $h, 'trip_stats');
224
225print dol_get_fiche_head($head, 'byyear', '', -1);
226
227
228print '<div class="fichecenter"><div class="fichethirdleft">';
229
230
231// Show filter box
232print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
233print '<input type="hidden" name="token" value="'.newToken().'">';
234print '<input type="hidden" name="mode" value="'.$mode.'">';
235
236print '<table class="noborder centpercent">';
237print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
238// Company
239/*
240print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
241print $form->select_company($socid,'socid','',1,1,0,array(),0,'widthcentpercentminusx maxwidth300','');
242print '</td></tr>';
243*/
244// User
245print '<tr><td>'.$langs->trans("User").'</td><td>';
246$include = '';
247if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')) {
248 $include = 'hierarchy';
249}
250print img_picto('', 'user', 'class="pictofixedwidth"');
251print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
252print '</td></tr>';
253// Status
254print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
255$liststatus = $tmpexpensereport->labelStatus;
256print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
257print '</td></tr>';
258// Year
259print '<tr><td>';
260print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation"));
261print '</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 class="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="noborder centpercent">';
275print '<tr class="liste_titre" height="24">';
276print '<td class="center">'.$langs->trans("Year").'</td>';
277print '<td class="right">'.$langs->trans("Number").'</td>';
278print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
279print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
280print '</tr>';
281
282$oldyear = 0;
283foreach ($data as $val) {
284 $year = $val['year'];
285 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
286 $oldyear--;
287
288 print '<tr class="oddeven" height="24">';
289 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
290 print '<td class="right">0</td>';
291 print '<td class="right amount nowraponall">0</td>';
292 print '<td class="right amount nowraponall">0</td>';
293 print '</tr>';
294 }
295
296
297 print '<tr class="oddeven" height="24">';
298 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
299 print '<td class="right">'.$val['nb'].'</td>';
300 print '<td class="right amount nowraponall">'.price(price2num($val['total'], 'MT'), 1).'</td>';
301 print '<td class="right amount nowraponall">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
302 print '</tr>';
303 $oldyear = $year;
304}
305
306print '</table>';
307print '</div>';
308
309print '</div><div class="fichetwothirdright">';
310
311
312// Show graphs
313print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
314if ($mesg) {
315 print $mesg;
316} else {
317 print $px1->show();
318 print "<br>\n";
319 print $px2->show();
320 print "<br>\n";
321 print $px3->show();
322}
323print '</td></tr></table>';
324
325
326print '</div></div>';
327print '<div class="clearboth"></div>';
328
329
330print dol_get_fiche_end();
331
332// End of page
333llxFooter();
334$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 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.
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.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.