dolibarr  9.0.0
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 <http://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 
36 
37 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
38 $object_status=GETPOST('object_status');
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->societe_id > 0)
46 {
47  $action = '';
48  $socid = $user->societe_id;
49 }
50 if ($user->societe_id) $socid=$user->societe_id;
51 $result = restrictedArea($user, 'expensereport', $id,'');
52 
53 $nowyear=strftime("%Y", dol_now());
54 $year = GETPOST('year')>0?GETPOST('year'):$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, $mesg);
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->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  $px1->SetPrecisionY(0);
95  $i=$startyear;$legend=array();
96  while ($i <= $endyear)
97  {
98  $legend[]=$i;
99  $i++;
100  }
101  $px1->SetLegend($legend);
102  $px1->SetMaxValue($px1->GetCeilMaxValue());
103  $px1->SetWidth($WIDTH);
104  $px1->SetHeight($HEIGHT);
105  $px1->SetYLabel($langs->trans("Number"));
106  $px1->SetShading(3);
107  $px1->SetHorizTickIncrement(1);
108  $px1->SetPrecisionY(0);
109  $px1->mode='depth';
110  $px1->SetTitle($langs->trans("NumberByMonth"));
111 
112  $px1->draw($filenamenb,$fileurlnb);
113 }
114 
115 // Build graphic amount of object
116 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
117 //var_dump($data);
118 // $data = array(array('Lib',val1,val2,val3),...)
119 
120 $filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
121 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
122 
123 $px2 = new DolGraph();
124 $mesg = $px2->isGraphKo();
125 if (! $mesg)
126 {
127  $px2->SetData($data);
128  $i=$startyear;$legend=array();
129  while ($i <= $endyear)
130  {
131  $legend[]=$i;
132  $i++;
133  }
134  $px2->SetLegend($legend);
135  $px2->SetMaxValue($px2->GetCeilMaxValue());
136  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
137  $px2->SetWidth($WIDTH);
138  $px2->SetHeight($HEIGHT);
139  $px2->SetYLabel($langs->trans("Amount"));
140  $px2->SetShading(3);
141  $px2->SetHorizTickIncrement(1);
142  $px2->SetPrecisionY(0);
143  $px2->mode='depth';
144  $px2->SetTitle($langs->trans("AmountTotal"));
145 
146  $px2->draw($filenameamount,$fileurlamount);
147 }
148 
149 
150 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
151 
152 if (!$user->rights->societe->client->voir || $user->societe_id)
153 {
154  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
155  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
156  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
157 }
158 else
159 {
160  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
161  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
162  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
163 }
164 
165 $px3 = new DolGraph();
166 $mesg = $px3->isGraphKo();
167 if (! $mesg)
168 {
169  $px3->SetData($data);
170  $i = $startyear;$legend=array();
171  while ($i <= $endyear)
172  {
173  $legend[]=$i;
174  $i++;
175  }
176  $px3->SetLegend($legend);
177  $px3->SetYLabel($langs->trans("AmountAverage"));
178  $px3->SetMaxValue($px3->GetCeilMaxValue());
179  $px3->SetMinValue($px3->GetFloorMinValue());
180  $px3->SetWidth($WIDTH);
181  $px3->SetHeight($HEIGHT);
182  $px3->SetShading(3);
183  $px3->SetHorizTickIncrement(1);
184  $px3->SetPrecisionY(0);
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();
195 foreach($data as $val) {
196  $arrayyears[$val['year']]=$val['year'];
197 }
198 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
199 
200 
201 $h=0;
202 $head = array();
203 $head[$h][0] = DOL_URL_ROOT . '/expensereport/stats/index.php';
204 $head[$h][1] = $langs->trans("ByMonthYear");
205 $head[$h][2] = 'byyear';
206 $h++;
207 
208 complete_head_from_modules($conf,$langs,null,$head,$h,'trip_stats');
209 
210 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
211 
212 
213 print '<div class="fichecenter"><div class="fichethirdleft">';
214 
215 
216 // Show filter box
217 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
218 print '<input type="hidden" name="mode" value="'.$mode.'">';
219 print '<table class="noborder" width="100%">';
220 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
221 // Company
222 /*
223 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
224 $filter='';
225 print $form->select_company($socid,'socid',$filter,1,1,0,array(),0,'','style="width: 95%"');
226 print '</td></tr>';
227 */
228 // User
229 print '<tr><td>'.$langs->trans("User").'</td><td>';
230 $include='';
231 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include='hierarchy';
232 print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
233 print '</td></tr>';
234 // Status
235 print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
236 $liststatus=$tmpexpensereport->statuts;
237 print $form->selectarray('object_status', $liststatus, GETPOST('object_status'), -4, 0, 0, '', 1);
238 print '</td></tr>';
239 // Year
240 print '<tr><td>'.$langs->trans("Year").'</td><td>';
241 if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
242 arsort($arrayyears);
243 print $form->selectarray('year',$arrayyears,$year,0);
244 print '</td></tr>';
245 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
246 print '</table>';
247 print '</form>';
248 print '<br><br>';
249 
250 print '<div class="div-table-responsive-no-min">';
251 print '<table class="noborder" width="100%">';
252 print '<tr class="liste_titre" height="24">';
253 print '<td align="center">'.$langs->trans("Year").'</td>';
254 print '<td align="right">'.$langs->trans("Number").'</td>';
255 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
256 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
257 print '</tr>';
258 
259 $oldyear=0;
260 foreach ($data as $val)
261 {
262  $year = $val['year'];
263  while ($year && $oldyear > $year+1)
264  { // If we have empty year
265  $oldyear--;
266 
267  print '<tr class="oddeven" height="24">';
268  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
269  print '<td align="right">0</td>';
270  print '<td align="right">0</td>';
271  print '<td align="right">0</td>';
272  print '</tr>';
273  }
274 
275 
276  print '<tr class="oddeven" height="24">';
277  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
278  print '<td align="right">'.$val['nb'].'</td>';
279  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
280  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
281  print '</tr>';
282  $oldyear=$year;
283 }
284 
285 print '</table>';
286 print '</div>';
287 
288 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
289 
290 
291 // Show graphs
292 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
293 if ($mesg) { print $mesg; }
294 else {
295  print $px1->show();
296  print "<br>\n";
297  print $px2->show();
298  print "<br>\n";
299  print $px3->show();
300 }
301 print '</td></tr></table>';
302 
303 
304 print '</div></div></div>';
305 print '<div style="clear:both"></div>';
306 
307 
308 dol_fiche_end();
309 
310 // End of page
311 llxFooter();
312 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
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.
llxHeader()
Header empty.
Definition: index.php:36
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_now($mode='gmt')
Return date for now.
Class to manage Trips and Expenses.
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
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.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.