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