dolibarr  13.0.2
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 <https://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 
30 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
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->socid > 0)
39 {
40  $action = '';
41  $socid = $user->socid;
42 }
43 
44 $nowyear = strftime("%Y", dol_now());
45 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
46 //$startyear=$year-2;
47 $startyear = $year - 1;
48 $endyear = $year;
49 
50 $object_status = GETPOST('object_status', 'intcomma');
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, '', 'intervention');
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->sanitize($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->socid)
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 } else {
85  $filenamenb = $dir.'/interventionsnbinyear-'.$year.'.png';
86  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$year.'.png';
87 }
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->SetMinValue(min(0, $px1->GetFloorMinValue()));
103  $px1->SetWidth($WIDTH);
104  $px1->SetHeight($HEIGHT);
105  $px1->SetYLabel($langs->trans("NbOfIntervention"));
106  $px1->SetShading(3);
107  $px1->SetHorizTickIncrement(1);
108  $px1->mode = 'depth';
109  $px1->SetTitle($langs->trans("NumberOfInterventionsByMonth"));
110 
111  $px1->draw($filenamenb, $fileurlnb);
112 }
113 
114 // Build graphic amount of object
115 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
116 // $data = array(array('Lib',val1,val2,val3),...)
117 
118 if (!$user->rights->societe->client->voir || $user->socid)
119 {
120  $filenameamount = $dir.'/interventionsamountinyear-'.$user->id.'-'.$year.'.png';
121  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
122 } else {
123  $filenameamount = $dir.'/interventionsamountinyear-'.$year.'.png';
124  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.'.png';
125 }
126 
127 $px2 = new DolGraph();
128 $mesg = $px2->isGraphKo();
129 if (!$mesg)
130 {
131  $px2->SetData($data);
132  $i = $startyear; $legend = array();
133  while ($i <= $endyear)
134  {
135  $legend[] = $i;
136  $i++;
137  }
138  $px2->SetLegend($legend);
139  $px2->SetMaxValue($px2->GetCeilMaxValue());
140  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
141  $px2->SetWidth($WIDTH);
142  $px2->SetHeight($HEIGHT);
143  $px2->SetYLabel($langs->trans("AmountOfinterventions"));
144  $px2->SetShading(3);
145  $px2->SetHorizTickIncrement(1);
146  $px2->mode = 'depth';
147  $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
148 
149  $px2->draw($filenameamount, $fileurlamount);
150 }
151 
152 
153 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
154 
155 if (!$user->rights->societe->client->voir || $user->socid)
156 {
157  $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
158  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
159 } else {
160  $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
161  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
162 }
163 
164 $px3 = new DolGraph();
165 $mesg = $px3->isGraphKo();
166 if (!$mesg)
167 {
168  $px3->SetData($data);
169  $i = $startyear; $legend = array();
170  while ($i <= $endyear)
171  {
172  $legend[] = $i;
173  $i++;
174  }
175  $px3->SetLegend($legend);
176  $px3->SetYLabel($langs->trans("AmountAverage"));
177  $px3->SetMaxValue($px3->GetCeilMaxValue());
178  $px3->SetMinValue($px3->GetFloorMinValue());
179  $px3->SetWidth($WIDTH);
180  $px3->SetHeight($HEIGHT);
181  $px3->SetShading(3);
182  $px3->SetHorizTickIncrement(1);
183  $px3->mode = 'depth';
184  $px3->SetTitle($langs->trans("AmountAverage"));
185 
186  $px3->draw($filename_avg, $fileurl_avg);
187 }
188 
189 
190 
191 // Show array
192 $data = $stats->getAllByYear();
193 $arrayyears = array();
194 foreach ($data as $val) {
195  if (!empty($val['year'])) {
196  $arrayyears[$val['year']] = $val['year'];
197  }
198 }
199 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
200 
201 $h = 0;
202 $head = array();
203 $head[$h][0] = DOL_URL_ROOT.'/fichinter/stats/index.php';
204 $head[$h][1] = $langs->trans("ByMonthYear");
205 $head[$h][2] = 'byyear';
206 $h++;
207 
208 $type = 'fichinter_stats';
209 
210 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
211 
212 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
213 
214 
215 print '<div class="fichecenter"><div class="fichethirdleft">';
216 
217 
218 //if (empty($socid))
219 //{
220  // Show filter box
221  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
222  print '<input type="hidden" name="token" value="'.newToken().'">';
223  print '<input type="hidden" name="mode" value="'.$mode.'">';
224 
225  print '<table class="noborder centpercent">';
226  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
227  // Company
228  print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
229  $filter = 's.client IN (1,2,3)';
230  print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, '', 'style="width: 95%"');
231  print '</td></tr>';
232  // User
233  print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
234  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
235  // Status
236  print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
237  $tmp = $objectstatic->LibStatut(0); // To load $this->statuts_short
238  $liststatus = $objectstatic->statuts_short;
239  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
240  print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
241  print '</td></tr>';
242  // Year
243  print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
244  if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
245  if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
246  arsort($arrayyears);
247  print $form->selectarray('year', $arrayyears, $year, 0);
248  print '</td></tr>';
249  print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
250  print '</table>';
251  print '</form>';
252  print '<br><br>';
253 //}
254 
255 print '<div class="div-table-responsive-no-min">';
256 print '<table class="noborder centpercent">';
257 print '<tr class="liste_titre" height="24">';
258 print '<td class="center">'.$langs->trans("Year").'</td>';
259 print '<td class="right">'.$langs->trans("NbOfinterventions").'</td>';
260 print '<td class="right">%</td>';
261 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
262 print '<td class="right">%</td>';
263 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
264 print '<td class="right">%</td>';
265 print '</tr>';
266 
267 $oldyear = 0;
268 foreach ($data as $val)
269 {
270  $year = $val['year'];
271  while (!empty($year) && $oldyear > $year + 1)
272  {
273  // If we have empty year
274  $oldyear--;
275 
276  print '<tr class="oddeven" height="24">';
277  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
278 
279  print '<td class="right">0</td>';
280  print '<td class="right"></td>';
281  print '<td class="right">0</td>';
282  print '<td class="right"></td>';
283  print '<td class="right">0</td>';
284  print '<td class="right"></td>';
285  print '</tr>';
286  }
287 
288 
289  print '<tr class="oddeven" height="24">';
290  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
291  print '<td class="right">'.$val['nb'].'</td>';
292  print '<td class="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['nb_diff']).'</td>';
293  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
294  print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['total_diff']).'</td>';
295  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
296  print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['avg_diff']).'</td>';
297  print '</tr>';
298  $oldyear = $year;
299 }
300 
301 print '</table>';
302 print '</div>';
303 
304 
305 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
306 
307 
308 // Show graphs
309 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
310 if ($mesg) { print $mesg; } else {
311  print $px1->show();
312  /*print "<br>\n";
313  print $px2->show();
314  print "<br>\n";
315  print $px3->show();*/
316 }
317 print '</td></tr></table>';
318 
319 
320 print '</div></div></div>';
321 print '<div style="clear:both"></div>';
322 
323 print dol_get_fiche_end();
324 
325 
326 llxFooter();
327 
328 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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;...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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
Class to manage intervention statistics.
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)