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