dolibarr 21.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
29require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterstats.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31
42
43$mode = 'customer';
44if (!$user->hasRight('ficheinter', 'lire')) {
46}
47
48$userid = GETPOSTINT('userid');
49$socid = GETPOSTINT('socid');
50// Security check
51if ($user->socid > 0) {
52 $action = '';
53 $socid = $user->socid;
54}
55
56$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
57$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
58$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
59$endyear = $year;
60
61$object_status = GETPOST('object_status', 'intcomma');
62
63// Load translation files required by the page
64$langs->loadLangs(array('interventions', 'companies', 'other', 'suppliers'));
65
66
67/*
68 * View
69 */
70
71$form = new Form($db);
72$objectstatic = new Fichinter($db);
73
74$title = $langs->trans("InterventionStatistics");
75$dir = $conf->ficheinter->dir_temp;
76
77llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-fichinter page-stats_index');
78
79print load_fiche_titre($title, '', 'intervention');
80
81dol_mkdir($dir);
82
83$stats = new FichinterStats($db, $socid, $mode, ($userid > 0 ? $userid : 0));
84if ($object_status != '' && $object_status > -1) {
85 $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
86}
87
88// Build graphic number of object
89$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
90// $data = array(array('Lib',val1,val2,val3),...)
91
92
93if (!$user->hasRight('societe', 'client', 'voir')) {
94 $filenamenb = $dir.'/interventionsnbinyear-'.$user->id.'-'.$year.'.png';
95 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$user->id.'-'.$year.'.png';
96} else {
97 $filenamenb = $dir.'/interventionsnbinyear-'.$year.'.png';
98 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$year.'.png';
99}
100
101$px1 = new DolGraph();
102$mesg = $px1->isGraphKo();
103if (!$mesg) {
104 $px1->SetData($data);
105 $i = $startyear;
106 $legend = array();
107 while ($i <= $endyear) {
108 $legend[] = $i;
109 $i++;
110 }
111 $px1->SetLegend($legend);
112 $px1->SetMaxValue($px1->GetCeilMaxValue());
113 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
114 $px1->SetWidth($WIDTH);
115 $px1->SetHeight($HEIGHT);
116 $px1->SetYLabel($langs->trans("NbOfIntervention"));
117 $px1->SetShading(3);
118 $px1->SetHorizTickIncrement(1);
119 $px1->mode = 'depth';
120 $px1->SetTitle($langs->trans("NumberOfInterventionsByMonth"));
121
122 $px1->draw($filenamenb, $fileurlnb);
123}
124
125// Build graphic amount of object
126$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
127// $data = array(array('Lib',val1,val2,val3),...)
128
129if (!$user->hasRight('societe', 'client', 'voir')) {
130 $filenameamount = $dir.'/interventionsamountinyear-'.$user->id.'-'.$year.'.png';
131 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.'-'.$year.'.png';
132} else {
133 $filenameamount = $dir.'/interventionsamountinyear-'.$year.'.png';
134 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.'.png';
135}
136
137$px2 = new DolGraph();
138$mesg = $px2->isGraphKo();
139if (!$mesg) {
140 $px2->SetData($data);
141 $i = $startyear;
142 $legend = array();
143 while ($i <= $endyear) {
144 $legend[] = $i;
145 $i++;
146 }
147 $px2->SetLegend($legend);
148 $px2->SetMaxValue($px2->GetCeilMaxValue());
149 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
150 $px2->SetWidth($WIDTH);
151 $px2->SetHeight($HEIGHT);
152 $px2->SetYLabel($langs->trans("AmountOfinterventions"));
153 $px2->SetShading(3);
154 $px2->SetHorizTickIncrement(1);
155 $px2->mode = 'depth';
156 $px2->SetTitle($langs->trans("AmountOfinterventionsByMonthHT"));
157
158 $px2->draw($filenameamount, $fileurlamount);
159}
160
161
162$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
163
164if (!$user->hasRight('societe', 'client', 'voir')) {
165 $filename_avg = $dir.'/interventionsaverage-'.$user->id.'-'.$year.'.png';
166 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.'-'.$year.'.png';
167} else {
168 $filename_avg = $dir.'/interventionsaverage-'.$year.'.png';
169 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.'.png';
170}
171
172$px3 = new DolGraph();
173$mesg = $px3->isGraphKo();
174if (!$mesg) {
175 $px3->SetData($data);
176 $i = $startyear;
177 $legend = array();
178 while ($i <= $endyear) {
179 $legend[] = $i;
180 $i++;
181 }
182 $px3->SetLegend($legend);
183 $px3->SetYLabel($langs->trans("AmountAverage"));
184 $px3->SetMaxValue($px3->GetCeilMaxValue());
185 $px3->SetMinValue($px3->GetFloorMinValue());
186 $px3->SetWidth($WIDTH);
187 $px3->SetHeight($HEIGHT);
188 $px3->SetShading(3);
189 $px3->SetHorizTickIncrement(1);
190 $px3->mode = 'depth';
191 $px3->SetTitle($langs->trans("AmountAverage"));
192
193 $px3->draw($filename_avg, $fileurl_avg);
194}
195
196
197
198// Show array
199$data = $stats->getAllByYear();
200$arrayyears = array();
201foreach ($data as $val) {
202 if (!empty($val['year'])) {
203 $arrayyears[$val['year']] = $val['year'];
204 }
205}
206if (!count($arrayyears)) {
207 $arrayyears[$nowyear] = $nowyear;
208}
209
210$h = 0;
211$head = array();
212$head[$h][0] = DOL_URL_ROOT.'/fichinter/stats/index.php';
213$head[$h][1] = $langs->trans("ByMonthYear");
214$head[$h][2] = 'byyear';
215$h++;
216
217$type = 'fichinter_stats';
218
219complete_head_from_modules($conf, $langs, null, $head, $h, $type);
220
221print dol_get_fiche_head($head, 'byyear', '', -1);
222
223
224print '<div class="fichecenter"><div class="fichethirdleft">';
225
226
227// Show filter box
228print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
229print '<input type="hidden" name="token" value="'.newToken().'">';
230print '<input type="hidden" name="mode" value="'.$mode.'">';
231
232print '<table class="noborder centpercent">';
233print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
234// Company
235print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
236$filter = '(s.client:IN:1,2,3)';
237print img_picto('', 'company', 'class="pictofixedwidth"');
238print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
239print '</td></tr>';
240// User
241print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
242print img_picto('', 'user', 'class="pictofixedwidth"');
243print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
244// Status
245print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
246$tmp = $objectstatic->LibStatut(0); // To force load of $this->labelStatus
247$liststatus = $objectstatic->labelStatus;
248if (!getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
249 unset($liststatus[$objectstatic::STATUS_BILLED]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
250}
251print $form->selectarray('object_status', $liststatus, $object_status, 1, 0, 0, '', 1);
252print '</td></tr>';
253// Year
254print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
255if (!in_array($year, $arrayyears)) {
256 $arrayyears[$year] = $year;
257}
258if (!in_array($nowyear, $arrayyears)) {
259 $arrayyears[$nowyear] = $nowyear;
260}
261arsort($arrayyears);
262print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
263print '</td></tr>';
264print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
265print '</table>';
266print '</form>';
267print '<br><br>';
268
269print '<div class="div-table-responsive-no-min">';
270print '<table class="noborder centpercent">';
271print '<tr class="liste_titre" height="24">';
272print '<td class="center">'.$langs->trans("Year").'</td>';
273print '<td class="right">'.$langs->trans("NbOfinterventions").'</td>';
274print '<td class="right">%</td>';
275print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
276print '<td class="right">%</td>';
277print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
278print '<td class="right">%</td>';
279print '</tr>';
280
281$oldyear = 0;
282foreach ($data as $val) {
283 $year = $val['year'];
284 while (!empty($year) && $oldyear > (int) $year + 1) {
285 // If we have empty year
286 $oldyear--;
287
288 print '<tr class="oddeven" height="24">';
289 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>';
290
291 print '<td class="right">0</td>';
292 print '<td class="right"></td>';
293 print '<td class="right">0</td>';
294 print '<td class="right"></td>';
295 print '<td class="right">0</td>';
296 print '<td class="right"></td>';
297 print '</tr>';
298 }
299
300
301 print '<tr class="oddeven" height="24">';
302 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>';
303 print '<td class="right">'.$val['nb'].'</td>';
304 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>';
305 print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
306 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>';
307 print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
308 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>';
309 print '</tr>';
310 $oldyear = $year;
311}
312
313print '</table>';
314print '</div>';
315
316
317print '</div><div class="fichetwothirdright">';
318
319
320// Show graphs
321print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
322if ($mesg) {
323 print $mesg;
324} else {
325 print $px1->show();
326 /*print "<br>\n";
327 print $px2->show();
328 print "<br>\n";
329 print $px3->show();*/
330}
331print '</td></tr></table>';
332
333
334print '</div></div>';
335print '<div class="clearboth"></div>';
336
337print dol_get_fiche_end();
338
339
340llxFooter();
341
342$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage intervention statistics.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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 a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.