dolibarr 20.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 <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->hasRight('ficheinter', 'lire')) {
36}
37
38$userid = GETPOSTINT('userid');
39$socid = GETPOSTINT('socid');
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 ? GETPOSTINT('year') : $nowyear;
48$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('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 (!$user->hasRight('societe', 'client', 'voir')) {
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;
96 $legend = array();
97 while ($i <= $endyear) {
98 $legend[] = $i;
99 $i++;
100 }
101 $px1->SetLegend($legend);
102 $px1->SetMaxValue($px1->GetCeilMaxValue());
103 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
104 $px1->SetWidth($WIDTH);
105 $px1->SetHeight($HEIGHT);
106 $px1->SetYLabel($langs->trans("NbOfIntervention"));
107 $px1->SetShading(3);
108 $px1->SetHorizTickIncrement(1);
109 $px1->mode = 'depth';
110 $px1->SetTitle($langs->trans("NumberOfInterventionsByMonth"));
111
112 $px1->draw($filenamenb, $fileurlnb);
113}
114
115// Build graphic amount of object
116$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
117// $data = array(array('Lib',val1,val2,val3),...)
118
119if (!$user->hasRight('societe', 'client', 'voir')) {
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();
129if (!$mesg) {
130 $px2->SetData($data);
131 $i = $startyear;
132 $legend = array();
133 while ($i <= $endyear) {
134 $legend[] = $i;
135 $i++;
136 }
137 $px2->SetLegend($legend);
138 $px2->SetMaxValue($px2->GetCeilMaxValue());
139 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
140 $px2->SetWidth($WIDTH);
141 $px2->SetHeight($HEIGHT);
142 $px2->SetYLabel($langs->trans("AmountOfinterventions"));
143 $px2->SetShading(3);
144 $px2->SetHorizTickIncrement(1);
145 $px2->mode = 'depth';
146 $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
147
148 $px2->draw($filenameamount, $fileurlamount);
149}
150
151
152$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
153
154if (!$user->hasRight('societe', 'client', 'voir')) {
155 $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
156 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
157} else {
158 $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
159 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
160}
161
162$px3 = new DolGraph();
163$mesg = $px3->isGraphKo();
164if (!$mesg) {
165 $px3->SetData($data);
166 $i = $startyear;
167 $legend = array();
168 while ($i <= $endyear) {
169 $legend[] = $i;
170 $i++;
171 }
172 $px3->SetLegend($legend);
173 $px3->SetYLabel($langs->trans("AmountAverage"));
174 $px3->SetMaxValue($px3->GetCeilMaxValue());
175 $px3->SetMinValue($px3->GetFloorMinValue());
176 $px3->SetWidth($WIDTH);
177 $px3->SetHeight($HEIGHT);
178 $px3->SetShading(3);
179 $px3->SetHorizTickIncrement(1);
180 $px3->mode = 'depth';
181 $px3->SetTitle($langs->trans("AmountAverage"));
182
183 $px3->draw($filename_avg, $fileurl_avg);
184}
185
186
187
188// Show array
189$data = $stats->getAllByYear();
190$arrayyears = array();
191foreach ($data as $val) {
192 if (!empty($val['year'])) {
193 $arrayyears[$val['year']] = $val['year'];
194 }
195}
196if (!count($arrayyears)) {
197 $arrayyears[$nowyear] = $nowyear;
198}
199
200$h = 0;
201$head = array();
202$head[$h][0] = DOL_URL_ROOT.'/fichinter/stats/index.php';
203$head[$h][1] = $langs->trans("ByMonthYear");
204$head[$h][2] = 'byyear';
205$h++;
206
207$type = 'fichinter_stats';
208
209complete_head_from_modules($conf, $langs, null, $head, $h, $type);
210
211print dol_get_fiche_head($head, 'byyear', '', -1);
212
213
214print '<div class="fichecenter"><div class="fichethirdleft">';
215
216
217// Show filter box
218print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
219print '<input type="hidden" name="token" value="'.newToken().'">';
220print '<input type="hidden" name="mode" value="'.$mode.'">';
221
222print '<table class="noborder centpercent">';
223print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
224// Company
225print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
226$filter = '(s.client:IN:1,2,3)';
227print img_picto('', 'company', 'class="pictofixedwidth"');
228print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
229print '</td></tr>';
230// User
231print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
232print img_picto('', 'user', 'class="pictofixedwidth"');
233print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
234// Status
235print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
236$tmp = $objectstatic->LibStatut(0); // To force load of $this->labelStatus
237$liststatus = $objectstatic->labelStatus;
238if (!getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
239 unset($liststatus[$objectstatic::STATUS_BILLED]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
240}
241print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
242print '</td></tr>';
243// Year
244print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
245if (!in_array($year, $arrayyears)) {
246 $arrayyears[$year] = $year;
247}
248if (!in_array($nowyear, $arrayyears)) {
249 $arrayyears[$nowyear] = $nowyear;
250}
251arsort($arrayyears);
252print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
253print '</td></tr>';
254print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
255print '</table>';
256print '</form>';
257print '<br><br>';
258
259print '<div class="div-table-responsive-no-min">';
260print '<table class="noborder centpercent">';
261print '<tr class="liste_titre" height="24">';
262print '<td class="center">'.$langs->trans("Year").'</td>';
263print '<td class="right">'.$langs->trans("NbOfinterventions").'</td>';
264print '<td class="right">%</td>';
265print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
266print '<td class="right">%</td>';
267print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
268print '<td class="right">%</td>';
269print '</tr>';
270
271$oldyear = 0;
272foreach ($data as $val) {
273 $year = $val['year'];
274 while (!empty($year) && $oldyear > $year + 1) {
275 // If we have empty year
276 $oldyear--;
277
278 print '<tr class="oddeven" height="24">';
279 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>';
280
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 '<td class="right">0</td>';
286 print '<td class="right"></td>';
287 print '</tr>';
288 }
289
290
291 print '<tr class="oddeven" height="24">';
292 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>';
293 print '<td class="right">'.$val['nb'].'</td>';
294 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>';
295 print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
296 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>';
297 print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
298 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>';
299 print '</tr>';
300 $oldyear = $year;
301}
302
303print '</table>';
304print '</div>';
305
306
307print '</div><div class="fichetwothirdright">';
308
309
310// Show graphs
311print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
312if ($mesg) {
313 print $mesg;
314} else {
315 print $px1->show();
316 /*print "<br>\n";
317 print $px2->show();
318 print "<br>\n";
319 print $px3->show();*/
320}
321print '</td></tr></table>';
322
323
324print '</div></div>';
325print '<div class="clearboth"></div>';
326
327print dol_get_fiche_end();
328
329
330llxFooter();
331
332$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.