dolibarr 18.0.6
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// Load Dolibarr environment
25require '../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
27require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterstats.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29
32
33$mode = 'customer';
34if (!$user->rights->ficheinter->lire) {
36}
37
38$userid = GETPOST('userid', 'int');
39$socid = GETPOST('socid', 'int');
40// Security check
41if ($user->socid > 0) {
42 $action = '';
43 $socid = $user->socid;
44}
45
46$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
47$year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
48$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
49$endyear = $year;
50
51$object_status = GETPOST('object_status', 'intcomma');
52
53// Load translation files required by the page
54$langs->loadLangs(array('interventions', 'companies', 'other', 'suppliers'));
55
56
57/*
58 * View
59 */
60
61$form = new Form($db);
62$objectstatic = new Fichinter($db);
63
64$title = $langs->trans("InterventionStatistics");
65$dir = $conf->ficheinter->dir_temp;
66
67llxHeader('', $title);
68
69print load_fiche_titre($title, '', 'intervention');
70
71dol_mkdir($dir);
72
73$stats = new FichinterStats($db, $socid, $mode, ($userid > 0 ? $userid : 0));
74if ($object_status != '' && $object_status > -1) {
75 $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
76}
77
78// Build graphic number of object
79$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
80// $data = array(array('Lib',val1,val2,val3),...)
81
82
83if (empty($user->rights->societe->client->voir) || $user->socid) {
84 $filenamenb = $dir.'/interventionsnbinyear-'.$user->id.'-'.$year.'.png';
85 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$user->id.'-'.$year.'.png';
86} else {
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();
93if (!$mesg) {
94 $px1->SetData($data);
95 $i = $startyear; $legend = array();
96 while ($i <= $endyear) {
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
118if (empty($user->rights->societe->client->voir) || $user->socid) {
119 $filenameamount = $dir.'/interventionsamountinyear-'.$user->id.'-'.$year.'.png';
120 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
121} else {
122 $filenameamount = $dir.'/interventionsamountinyear-'.$year.'.png';
123 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.'.png';
124}
125
126$px2 = new DolGraph();
127$mesg = $px2->isGraphKo();
128if (!$mesg) {
129 $px2->SetData($data);
130 $i = $startyear; $legend = array();
131 while ($i <= $endyear) {
132 $legend[] = $i;
133 $i++;
134 }
135 $px2->SetLegend($legend);
136 $px2->SetMaxValue($px2->GetCeilMaxValue());
137 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
138 $px2->SetWidth($WIDTH);
139 $px2->SetHeight($HEIGHT);
140 $px2->SetYLabel($langs->trans("AmountOfinterventions"));
141 $px2->SetShading(3);
142 $px2->SetHorizTickIncrement(1);
143 $px2->mode = 'depth';
144 $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
145
146 $px2->draw($filenameamount, $fileurlamount);
147}
148
149
150$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
151
152if (empty($user->rights->societe->client->voir) || $user->socid) {
153 $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
154 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
155} else {
156 $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
157 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
158}
159
160$px3 = new DolGraph();
161$mesg = $px3->isGraphKo();
162if (!$mesg) {
163 $px3->SetData($data);
164 $i = $startyear; $legend = array();
165 while ($i <= $endyear) {
166 $legend[] = $i;
167 $i++;
168 }
169 $px3->SetLegend($legend);
170 $px3->SetYLabel($langs->trans("AmountAverage"));
171 $px3->SetMaxValue($px3->GetCeilMaxValue());
172 $px3->SetMinValue($px3->GetFloorMinValue());
173 $px3->SetWidth($WIDTH);
174 $px3->SetHeight($HEIGHT);
175 $px3->SetShading(3);
176 $px3->SetHorizTickIncrement(1);
177 $px3->mode = 'depth';
178 $px3->SetTitle($langs->trans("AmountAverage"));
179
180 $px3->draw($filename_avg, $fileurl_avg);
181}
182
183
184
185// Show array
186$data = $stats->getAllByYear();
187$arrayyears = array();
188foreach ($data as $val) {
189 if (!empty($val['year'])) {
190 $arrayyears[$val['year']] = $val['year'];
191 }
192}
193if (!count($arrayyears)) {
194 $arrayyears[$nowyear] = $nowyear;
195}
196
197$h = 0;
198$head = array();
199$head[$h][0] = DOL_URL_ROOT.'/fichinter/stats/index.php';
200$head[$h][1] = $langs->trans("ByMonthYear");
201$head[$h][2] = 'byyear';
202$h++;
203
204$type = 'fichinter_stats';
205
206complete_head_from_modules($conf, $langs, null, $head, $h, $type);
207
208print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
209
210
211print '<div class="fichecenter"><div class="fichethirdleft">';
212
213
214// Show filter box
215print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
216print '<input type="hidden" name="token" value="'.newToken().'">';
217print '<input type="hidden" name="mode" value="'.$mode.'">';
218
219print '<table class="noborder centpercent">';
220print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
221// Company
222print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
223$filter = '(s.client:IN:1,2,3)';
224print img_picto('', 'company', 'class="pictofixedwidth"');
225print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
226print '</td></tr>';
227// User
228print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
229print img_picto('', 'user', 'class="pictofixedwidth"');
230print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
231// Status
232print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
233$tmp = $objectstatic->LibStatut(0); // To force load of $this->labelStatus
234$liststatus = $objectstatic->labelStatus;
235if (empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
236 unset($liststatus[$objectstatic::STATUS_BILLED]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
237}
238print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
239print '</td></tr>';
240// Year
241print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
242if (!in_array($year, $arrayyears)) {
243 $arrayyears[$year] = $year;
244}
245if (!in_array($nowyear, $arrayyears)) {
246 $arrayyears[$nowyear] = $nowyear;
247}
248arsort($arrayyears);
249print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
250print '</td></tr>';
251print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
252print '</table>';
253print '</form>';
254print '<br><br>';
255
256print '<div class="div-table-responsive-no-min">';
257print '<table class="noborder centpercent">';
258print '<tr class="liste_titre" height="24">';
259print '<td class="center">'.$langs->trans("Year").'</td>';
260print '<td class="right">'.$langs->trans("NbOfinterventions").'</td>';
261print '<td class="right">%</td>';
262print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
263print '<td class="right">%</td>';
264print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
265print '<td class="right">%</td>';
266print '</tr>';
267
268$oldyear = 0;
269foreach ($data as $val) {
270 $year = $val['year'];
271 while (!empty($year) && $oldyear > $year + 1) {
272 // If we have empty year
273 $oldyear--;
274
275 print '<tr class="oddeven" height="24">';
276 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>';
277
278 print '<td class="right">0</td>';
279 print '<td class="right"></td>';
280 print '<td class="right">0</td>';
281 print '<td class="right"></td>';
282 print '<td class="right">0</td>';
283 print '<td class="right"></td>';
284 print '</tr>';
285 }
286
287
288 print '<tr class="oddeven" height="24">';
289 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>';
290 print '<td class="right">'.$val['nb'].'</td>';
291 print '<td class="right opacitylow" style="'.((!isset($val['nb_diff']) || $val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['nb_diff']) ? round($val['nb_diff']): "0").'%</td>';
292 print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
293 print '<td class="right opacitylow" style="'.((!isset($val['total_diff']) || $val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['total_diff']) ? round($val['total_diff']) : "0").'%</td>';
294 print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
295 print '<td class="right opacitylow" style="'.((!isset($val['avg_diff']) || $val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['avg_diff']) ? round($val['avg_diff']) : "0").'%</td>';
296 print '</tr>';
297 $oldyear = $year;
298}
299
300print '</table>';
301print '</div>';
302
303
304print '</div><div class="fichetwothirdright">';
305
306
307// Show graphs
308print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
309if ($mesg) {
310 print $mesg;
311} else {
312 print $px1->show();
313 /*print "<br>\n";
314 print $px2->show();
315 print "<br>\n";
316 print $px3->show();*/
317}
318print '</td></tr></table>';
319
320
321print '</div></div>';
322print '<div class="clearboth"></div>';
323
324print dol_get_fiche_end();
325
326
327llxFooter();
328
329$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage interventions.
Class to manage intervention statistics.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.