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