dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterstats.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28 
31 
32 $mode='customer';
33 if ($mode == 'customer' && ! $user->rights->ficheinter->lire) accessforbidden();
34 
35 $userid=GETPOST('userid','int');
36 $socid=GETPOST('socid','int');
37 // Security check
38 if ($user->societe_id > 0)
39 {
40  $action = '';
41  $socid = $user->societe_id;
42 }
43 
44 $nowyear=strftime("%Y", dol_now());
45 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
46 //$startyear=$year-2;
47 $startyear=$year-1;
48 $endyear=$year;
49 
50 $object_status=GETPOST('object_status');
51 
52 $langs->load('interventions');
53 $langs->load('companies');
54 $langs->load('other');
55 $langs->load('suppliers');
56 
57 
58 /*
59  * View
60  */
61 
62 $form=new Form($db);
63 $objectstatic=new FichInter($db);
64 
65 if ($mode == 'customer')
66 {
67  $title=$langs->trans("InterventionStatistics");
68  $dir=$conf->ficheinter->dir_temp;
69 }
70 
71 llxHeader('', $title);
72 
73 print load_fiche_titre($title,'','title_commercial.png');
74 
75 dol_mkdir($dir);
76 
77 $stats = new FichinterStats($db, $socid, $mode, ($userid>0?$userid:0));
78 if ($object_status != '' && $object_status > -1) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')';
79 
80 // Build graphic number of object
81 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
82 //var_dump($data);
83 // $data = array(array('Lib',val1,val2,val3),...)
84 
85 
86 if (!$user->rights->societe->client->voir || $user->societe_id)
87 {
88  $filenamenb = $dir.'/interventionsnbinyear-'.$user->id.'-'.$year.'.png';
89  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$user->id.'-'.$year.'.png';
90 }
91 else
92 {
93  $filenamenb = $dir.'/interventionsnbinyear-'.$year.'.png';
94  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$year.'.png';
95 }
96 
97 $px1 = new DolGraph();
98 $mesg = $px1->isGraphKo();
99 if (! $mesg)
100 {
101  $px1->SetData($data);
102  $px1->SetPrecisionY(0);
103  $i=$startyear;$legend=array();
104  while ($i <= $endyear)
105  {
106  $legend[]=$i;
107  $i++;
108  }
109  $px1->SetLegend($legend);
110  $px1->SetMaxValue($px1->GetCeilMaxValue());
111  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
112  $px1->SetWidth($WIDTH);
113  $px1->SetHeight($HEIGHT);
114  $px1->SetYLabel($langs->trans("NbOfIntervention"));
115  $px1->SetShading(3);
116  $px1->SetHorizTickIncrement(1);
117  $px1->SetPrecisionY(0);
118  $px1->mode='depth';
119  $px1->SetTitle($langs->trans("NumberOfInterventionsByMonth"));
120 
121  $px1->draw($filenamenb,$fileurlnb);
122 }
123 
124 // Build graphic amount of object
125 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
126 //var_dump($data);
127 // $data = array(array('Lib',val1,val2,val3),...)
128 
129 if (!$user->rights->societe->client->voir || $user->societe_id)
130 {
131  $filenameamount = $dir.'/interventionsamountinyear-'.$user->id.'-'.$year.'.png';
132  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
133  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstatssupplier&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
134 }
135 else
136 {
137  $filenameamount = $dir.'/interventionsamountinyear-'.$year.'.png';
138  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.'.png';
139  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstatssupplier&file=interventionsamountinyear-'.$year.'.png';
140 }
141 
142 $px2 = new DolGraph();
143 $mesg = $px2->isGraphKo();
144 if (! $mesg)
145 {
146  $px2->SetData($data);
147  $i=$startyear;$legend=array();
148  while ($i <= $endyear)
149  {
150  $legend[]=$i;
151  $i++;
152  }
153  $px2->SetLegend($legend);
154  $px2->SetMaxValue($px2->GetCeilMaxValue());
155  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
156  $px2->SetWidth($WIDTH);
157  $px2->SetHeight($HEIGHT);
158  $px2->SetYLabel($langs->trans("AmountOfinterventions"));
159  $px2->SetShading(3);
160  $px2->SetHorizTickIncrement(1);
161  $px2->SetPrecisionY(0);
162  $px2->mode='depth';
163  $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
164 
165  $px2->draw($filenameamount,$fileurlamount);
166 }
167 
168 
169 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
170 
171 if (!$user->rights->societe->client->voir || $user->societe_id)
172 {
173  $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
174  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
175  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstatssupplier&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
176 }
177 else
178 {
179  $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
180  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
181  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstatssupplier&file=interventionsaverage-'.$year.'.png';
182 }
183 
184 $px3 = new DolGraph();
185 $mesg = $px3->isGraphKo();
186 if (! $mesg)
187 {
188  $px3->SetData($data);
189  $i=$startyear;$legend=array();
190  while ($i <= $endyear)
191  {
192  $legend[]=$i;
193  $i++;
194  }
195  $px3->SetLegend($legend);
196  $px3->SetYLabel($langs->trans("AmountAverage"));
197  $px3->SetMaxValue($px3->GetCeilMaxValue());
198  $px3->SetMinValue($px3->GetFloorMinValue());
199  $px3->SetWidth($WIDTH);
200  $px3->SetHeight($HEIGHT);
201  $px3->SetShading(3);
202  $px3->SetHorizTickIncrement(1);
203  $px3->SetPrecisionY(0);
204  $px3->mode='depth';
205  $px3->SetTitle($langs->trans("AmountAverage"));
206 
207  $px3->draw($filename_avg,$fileurl_avg);
208 }
209 
210 
211 
212 // Show array
213 $data = $stats->getAllByYear();
214 $arrayyears=array();
215 foreach($data as $val) {
216  if (! empty($val['year'])) {
217  $arrayyears[$val['year']]=$val['year'];
218  }
219 }
220 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
221 
222 $h=0;
223 $head = array();
224 $head[$h][0] = DOL_URL_ROOT . '/commande/stats/index.php?mode='.$mode;
225 $head[$h][1] = $langs->trans("ByMonthYear");
226 $head[$h][2] = 'byyear';
227 $h++;
228 
229 if ($mode == 'customer') $type='order_stats';
230 if ($mode == 'supplier') $type='supplier_order_stats';
231 
232 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
233 
234 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
235 
236 
237 print '<div class="fichecenter"><div class="fichethirdleft">';
238 
239 
240 //if (empty($socid))
241 //{
242  // Show filter box
243  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
244  print '<input type="hidden" name="mode" value="'.$mode.'">';
245  print '<table class="noborder" width="100%">';
246  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
247  // Company
248  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
249  if ($mode == 'customer') $filter='s.client in (1,2,3)';
250  if ($mode == 'supplier') $filter='s.fournisseur = 1';
251  print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
252  print '</td></tr>';
253  // User
254  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
255  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
256  // Status
257  print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
258  $liststatus=$objectstatic->statuts_short;
259  if (empty($conf->global->FICHINTER_CLASSIFY_BILLED)) unset($liststatus[2]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
260  print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
261  print '</td></tr>';
262  // Year
263  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
264  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
265  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
266  arsort($arrayyears);
267  print $form->selectarray('year',$arrayyears,$year,0);
268  print '</td></tr>';
269  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
270  print '</table>';
271  print '</form>';
272  print '<br><br>';
273 //}
274 
275 print '<table class="noborder" width="100%">';
276 print '<tr class="liste_titre" height="24">';
277 print '<td align="center">'.$langs->trans("Year").'</td>';
278 print '<td align="right">'.$langs->trans("NbOfinterventions").'</td>';
279 print '<td align="right">%</td>';
280 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
281 print '<td align="right">%</td>';
282 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
283 print '<td align="right">%</td>';
284 print '</tr>';
285 
286 $oldyear=0;
287 $var=true;
288 foreach ($data as $val)
289 {
290  $year = $val['year'];
291  while (! empty($year) && $oldyear > $year+1)
292  { // If we have empty year
293  $oldyear--;
294 
295  print '<tr '.$bc[$var].' height="24">';
296  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$oldyear.'</a></td>';
297 
298  print '<td align="right">0</td>';
299  print '<td align="right"></td>';
300  print '<td align="right">0</td>';
301  print '<td align="right"></td>';
302  print '<td align="right">0</td>';
303  print '<td align="right"></td>';
304  print '</tr>';
305  }
306 
307 
308  print '<tr '.$bc[$var].' height="24">';
309  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$year.'</a></td>';
310  print '<td align="right">'.$val['nb'].'</td>';
311  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
312  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
313  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
314  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
315  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
316  print '</tr>';
317  $oldyear=$year;
318 }
319 
320 print '</table>';
321 
322 
323 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
324 
325 
326 // Show graphs
327 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
328 if ($mesg) { print $mesg; }
329 else {
330  print $px1->show();
331  /*print "<br>\n";
332  print $px2->show();
333  print "<br>\n";
334  print $px3->show();*/
335 }
336 print '</td></tr></table>';
337 
338 
339 print '</div></div></div>';
340 print '<div style="clear:both"></div>';
341 
342 dol_fiche_end();
343 
344 
345 llxFooter();
346 
347 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:37
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_now($mode='gmt')
Return date for now.
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to manage intervention statistics.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...