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