dolibarr  9.0.0
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 (! $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 // Load translation files required by the page
53 $langs->loadLangs(array('interventions', 'companies', 'other', 'suppliers'));
54 
55 
56 /*
57  * View
58  */
59 
60 $form=new Form($db);
61 $objectstatic=new FichInter($db);
62 
63 $title=$langs->trans("InterventionStatistics");
64 $dir=$conf->ficheinter->dir_temp;
65 
66 llxHeader('', $title);
67 
68 print load_fiche_titre($title,'','title_commercial.png');
69 
70 dol_mkdir($dir);
71 
72 $stats = new FichinterStats($db, $socid, $mode, ($userid>0?$userid:0));
73 if ($object_status != '' && $object_status > -1) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')';
74 
75 // Build graphic number of object
76 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
77 // $data = array(array('Lib',val1,val2,val3),...)
78 
79 
80 if (!$user->rights->societe->client->voir || $user->societe_id)
81 {
82  $filenamenb = $dir.'/interventionsnbinyear-'.$user->id.'-'.$year.'.png';
83  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$user->id.'-'.$year.'.png';
84 }
85 else
86 {
87  $filenamenb = $dir.'/interventionsnbinyear-'.$year.'.png';
88  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$year.'.png';
89 }
90 
91 $px1 = new DolGraph();
92 $mesg = $px1->isGraphKo();
93 if (! $mesg)
94 {
95  $px1->SetData($data);
96  $px1->SetPrecisionY(0);
97  $i=$startyear;$legend=array();
98  while ($i <= $endyear)
99  {
100  $legend[]=$i;
101  $i++;
102  }
103  $px1->SetLegend($legend);
104  $px1->SetMaxValue($px1->GetCeilMaxValue());
105  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
106  $px1->SetWidth($WIDTH);
107  $px1->SetHeight($HEIGHT);
108  $px1->SetYLabel($langs->trans("NbOfIntervention"));
109  $px1->SetShading(3);
110  $px1->SetHorizTickIncrement(1);
111  $px1->SetPrecisionY(0);
112  $px1->mode='depth';
113  $px1->SetTitle($langs->trans("NumberOfInterventionsByMonth"));
114 
115  $px1->draw($filenamenb,$fileurlnb);
116 }
117 
118 // Build graphic amount of object
119 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
120 // $data = array(array('Lib',val1,val2,val3),...)
121 
122 if (!$user->rights->societe->client->voir || $user->societe_id)
123 {
124  $filenameamount = $dir.'/interventionsamountinyear-'.$user->id.'-'.$year.'.png';
125  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
126 }
127 else
128 {
129  $filenameamount = $dir.'/interventionsamountinyear-'.$year.'.png';
130  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.'.png';
131 }
132 
133 $px2 = new DolGraph();
134 $mesg = $px2->isGraphKo();
135 if (! $mesg)
136 {
137  $px2->SetData($data);
138  $i=$startyear;$legend=array();
139  while ($i <= $endyear)
140  {
141  $legend[]=$i;
142  $i++;
143  }
144  $px2->SetLegend($legend);
145  $px2->SetMaxValue($px2->GetCeilMaxValue());
146  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
147  $px2->SetWidth($WIDTH);
148  $px2->SetHeight($HEIGHT);
149  $px2->SetYLabel($langs->trans("AmountOfinterventions"));
150  $px2->SetShading(3);
151  $px2->SetHorizTickIncrement(1);
152  $px2->SetPrecisionY(0);
153  $px2->mode='depth';
154  $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
155 
156  $px2->draw($filenameamount,$fileurlamount);
157 }
158 
159 
160 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
161 
162 if (!$user->rights->societe->client->voir || $user->societe_id)
163 {
164  $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
165  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
166 }
167 else
168 {
169  $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
170  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
171 }
172 
173 $px3 = new DolGraph();
174 $mesg = $px3->isGraphKo();
175 if (! $mesg)
176 {
177  $px3->SetData($data);
178  $i=$startyear;$legend=array();
179  while ($i <= $endyear)
180  {
181  $legend[]=$i;
182  $i++;
183  }
184  $px3->SetLegend($legend);
185  $px3->SetYLabel($langs->trans("AmountAverage"));
186  $px3->SetMaxValue($px3->GetCeilMaxValue());
187  $px3->SetMinValue($px3->GetFloorMinValue());
188  $px3->SetWidth($WIDTH);
189  $px3->SetHeight($HEIGHT);
190  $px3->SetShading(3);
191  $px3->SetHorizTickIncrement(1);
192  $px3->SetPrecisionY(0);
193  $px3->mode='depth';
194  $px3->SetTitle($langs->trans("AmountAverage"));
195 
196  $px3->draw($filename_avg,$fileurl_avg);
197 }
198 
199 
200 
201 // Show array
202 $data = $stats->getAllByYear();
203 $arrayyears=array();
204 foreach($data as $val) {
205  if (! empty($val['year'])) {
206  $arrayyears[$val['year']]=$val['year'];
207  }
208 }
209 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
210 
211 $h=0;
212 $head = array();
213 $head[$h][0] = DOL_URL_ROOT . '/fichinter/stats/index.php';
214 $head[$h][1] = $langs->trans("ByMonthYear");
215 $head[$h][2] = 'byyear';
216 $h++;
217 
218 $type = 'fichinter_stats';
219 
220 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
221 
222 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
223 
224 
225 print '<div class="fichecenter"><div class="fichethirdleft">';
226 
227 
228 //if (empty($socid))
229 //{
230  // Show filter box
231  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
232  print '<input type="hidden" name="mode" value="'.$mode.'">';
233  print '<table class="noborder" width="100%">';
234  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
235  // Company
236  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
237  $filter = 's.client in (1,2,3)';
238  print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, '', 'style="width: 95%"');
239  print '</td></tr>';
240  // User
241  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
242  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
243  // Status
244  print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
245  $tmp = $objectstatic->LibStatut(0); // To load $this->statuts_short
246  $liststatus=$objectstatic->statuts_short;
247  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
248  print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
249  print '</td></tr>';
250  // Year
251  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
252  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
253  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
254  arsort($arrayyears);
255  print $form->selectarray('year',$arrayyears,$year,0);
256  print '</td></tr>';
257  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
258  print '</table>';
259  print '</form>';
260  print '<br><br>';
261 //}
262 
263 print '<div class="div-table-responsive-no-min">';
264 print '<table class="noborder" width="100%">';
265 print '<tr class="liste_titre" height="24">';
266 print '<td align="center">'.$langs->trans("Year").'</td>';
267 print '<td align="right">'.$langs->trans("NbOfinterventions").'</td>';
268 print '<td align="right">%</td>';
269 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
270 print '<td align="right">%</td>';
271 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
272 print '<td align="right">%</td>';
273 print '</tr>';
274 
275 $oldyear=0;
276 foreach ($data as $val)
277 {
278  $year = $val['year'];
279  while (! empty($year) && $oldyear > $year+1)
280  {
281  // If we have empty year
282  $oldyear--;
283 
284  print '<tr class="oddeven" height="24">';
285  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>';
286 
287  print '<td align="right">0</td>';
288  print '<td align="right"></td>';
289  print '<td align="right">0</td>';
290  print '<td align="right"></td>';
291  print '<td align="right">0</td>';
292  print '<td align="right"></td>';
293  print '</tr>';
294  }
295 
296 
297  print '<tr class="oddeven" height="24">';
298  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>';
299  print '<td align="right">'.$val['nb'].'</td>';
300  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
301  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
302  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
303  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
304  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
305  print '</tr>';
306  $oldyear=$year;
307 }
308 
309 print '</table>';
310 print '</div>';
311 
312 
313 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
314 
315 
316 // Show graphs
317 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
318 if ($mesg) { print $mesg; }
319 else {
320  print $px1->show();
321  /*print "<br>\n";
322  print $px2->show();
323  print "<br>\n";
324  print $px3->show();*/
325 }
326 print '</td></tr></table>';
327 
328 
329 print '</div></div></div>';
330 print '<div style="clear:both"></div>';
331 
332 dol_fiche_end();
333 
334 
335 llxFooter();
336 
337 $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).
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: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 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 &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.