dolibarr  16.0.5
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) {
35 }
36 
37 $userid = GETPOST('userid', 'int');
38 $socid = GETPOST('socid', 'int');
39 // Security check
40 if ($user->socid > 0) {
41  $action = '';
42  $socid = $user->socid;
43 }
44 
45 $nowyear = strftime("%Y", dol_now());
46 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
47 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
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) {
74  $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
75 }
76 
77 // Build graphic number of object
78 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
79 // $data = array(array('Lib',val1,val2,val3),...)
80 
81 
82 if (empty($user->rights->societe->client->voir) || $user->socid) {
83  $filenamenb = $dir.'/interventionsnbinyear-'.$user->id.'-'.$year.'.png';
84  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$user->id.'-'.$year.'.png';
85 } else {
86  $filenamenb = $dir.'/interventionsnbinyear-'.$year.'.png';
87  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$year.'.png';
88 }
89 
90 $px1 = new DolGraph();
91 $mesg = $px1->isGraphKo();
92 if (!$mesg) {
93  $px1->SetData($data);
94  $i = $startyear; $legend = array();
95  while ($i <= $endyear) {
96  $legend[] = $i;
97  $i++;
98  }
99  $px1->SetLegend($legend);
100  $px1->SetMaxValue($px1->GetCeilMaxValue());
101  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
102  $px1->SetWidth($WIDTH);
103  $px1->SetHeight($HEIGHT);
104  $px1->SetYLabel($langs->trans("NbOfIntervention"));
105  $px1->SetShading(3);
106  $px1->SetHorizTickIncrement(1);
107  $px1->mode = 'depth';
108  $px1->SetTitle($langs->trans("NumberOfInterventionsByMonth"));
109 
110  $px1->draw($filenamenb, $fileurlnb);
111 }
112 
113 // Build graphic amount of object
114 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
115 // $data = array(array('Lib',val1,val2,val3),...)
116 
117 if (empty($user->rights->societe->client->voir) || $user->socid) {
118  $filenameamount = $dir.'/interventionsamountinyear-'.$user->id.'-'.$year.'.png';
119  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
120 } else {
121  $filenameamount = $dir.'/interventionsamountinyear-'.$year.'.png';
122  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.'.png';
123 }
124 
125 $px2 = new DolGraph();
126 $mesg = $px2->isGraphKo();
127 if (!$mesg) {
128  $px2->SetData($data);
129  $i = $startyear; $legend = array();
130  while ($i <= $endyear) {
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("AmountOfinterventions"));
140  $px2->SetShading(3);
141  $px2->SetHorizTickIncrement(1);
142  $px2->mode = 'depth';
143  $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
144 
145  $px2->draw($filenameamount, $fileurlamount);
146 }
147 
148 
149 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
150 
151 if (empty($user->rights->societe->client->voir) || $user->socid) {
152  $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
153  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
154 } else {
155  $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
156  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
157 }
158 
159 $px3 = new DolGraph();
160 $mesg = $px3->isGraphKo();
161 if (!$mesg) {
162  $px3->SetData($data);
163  $i = $startyear; $legend = array();
164  while ($i <= $endyear) {
165  $legend[] = $i;
166  $i++;
167  }
168  $px3->SetLegend($legend);
169  $px3->SetYLabel($langs->trans("AmountAverage"));
170  $px3->SetMaxValue($px3->GetCeilMaxValue());
171  $px3->SetMinValue($px3->GetFloorMinValue());
172  $px3->SetWidth($WIDTH);
173  $px3->SetHeight($HEIGHT);
174  $px3->SetShading(3);
175  $px3->SetHorizTickIncrement(1);
176  $px3->mode = 'depth';
177  $px3->SetTitle($langs->trans("AmountAverage"));
178 
179  $px3->draw($filename_avg, $fileurl_avg);
180 }
181 
182 
183 
184 // Show array
185 $data = $stats->getAllByYear();
186 $arrayyears = array();
187 foreach ($data as $val) {
188  if (!empty($val['year'])) {
189  $arrayyears[$val['year']] = $val['year'];
190  }
191 }
192 if (!count($arrayyears)) {
193  $arrayyears[$nowyear] = $nowyear;
194 }
195 
196 $h = 0;
197 $head = array();
198 $head[$h][0] = DOL_URL_ROOT.'/fichinter/stats/index.php';
199 $head[$h][1] = $langs->trans("ByMonthYear");
200 $head[$h][2] = 'byyear';
201 $h++;
202 
203 $type = 'fichinter_stats';
204 
205 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
206 
207 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
208 
209 
210 print '<div class="fichecenter"><div class="fichethirdleft">';
211 
212 
213 // Show filter box
214 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
215 print '<input type="hidden" name="token" value="'.newToken().'">';
216 print '<input type="hidden" name="mode" value="'.$mode.'">';
217 
218 print '<table class="noborder centpercent">';
219 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
220 // Company
221 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
222 $filter = 's.client IN (1,2,3)';
223 print img_picto('', 'company', 'class="pictofixedwidth"');
224 print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
225 print '</td></tr>';
226 // User
227 print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
228 print img_picto('', 'user', 'class="pictofixedwidth"');
229 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
230 // Status
231 print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
232 $tmp = $objectstatic->LibStatut(0); // To force load of $this->statuts_short
233 $liststatus = $objectstatic->statuts_short;
234 if (empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
235  unset($liststatus[2]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
236 }
237 print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
238 print '</td></tr>';
239 // Year
240 print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
241 if (!in_array($year, $arrayyears)) {
242  $arrayyears[$year] = $year;
243 }
244 if (!in_array($nowyear, $arrayyears)) {
245  $arrayyears[$nowyear] = $nowyear;
246 }
247 arsort($arrayyears);
248 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
249 print '</td></tr>';
250 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
251 print '</table>';
252 print '</form>';
253 print '<br><br>';
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  $year = $val['year'];
270  while (!empty($year) && $oldyear > $year + 1) {
271  // If we have empty year
272  $oldyear--;
273 
274  print '<tr class="oddeven" height="24">';
275  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>';
276 
277  print '<td class="right">0</td>';
278  print '<td class="right"></td>';
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 '</tr>';
284  }
285 
286 
287  print '<tr class="oddeven" height="24">';
288  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>';
289  print '<td class="right">'.$val['nb'].'</td>';
290  print '<td class="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['nb_diff']).'</td>';
291  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
292  print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['total_diff']).'</td>';
293  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
294  print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['avg_diff']).'</td>';
295  print '</tr>';
296  $oldyear = $year;
297 }
298 
299 print '</table>';
300 print '</div>';
301 
302 
303 print '</div><div class="fichetwothirdright">';
304 
305 
306 // Show graphs
307 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
308 if ($mesg) {
309  print $mesg;
310 } 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>';
321 print '<div style="clear:both"></div>';
322 
323 print dol_get_fiche_end();
324 
325 
326 llxFooter();
327 
328 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1539
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
FichinterStats
Class to manage intervention statistics.
Definition: fichinterstats.class.php:34
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603