dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2019 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.'/ticket/class/actions_ticket.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29 
31 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
32 
33 if (!$user->rights->ticket->read) {
35 }
36 
37 $object_status = GETPOST('object_status', 'intcomma');
38 
39 $userid = GETPOST('userid', 'int');
40 $socid = GETPOST('socid', 'int');
41 // Security check
42 if ($user->socid > 0) {
43  $action = '';
44  $socid = $user->socid;
45 }
46 
47 $nowyear = strftime("%Y", dol_now());
48 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
49 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
50 $endyear = $year;
51 
52 // Load translation files required by the page
53 $langs->loadLangs(array('orders', 'companies', 'other', 'tickets'));
54 
55 
56 /*
57  * View
58  */
59 
60 $form = new Form($db);
61 $object = new Ticket($db);
62 
63 $title = $langs->trans("Statistics");
64 $dir = $conf->ticket->dir_temp;
65 
66 llxHeader('', $title);
67 
68 print load_fiche_titre($title, '', 'ticket');
69 
70 dol_mkdir($dir);
71 
72 $stats = new TicketStats($db, $socid, ($userid > 0 ? $userid : 0));
73 if ($object_status != '' && $object_status >= -1) {
74  $stats->where .= ' AND fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
75 }
76 
77 
78 // Build graphic number of object
79 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
80 
81 //var_dump($data);
82 // $data = array(array('Lib',val1,val2,val3),...)
83 
84 
85 if (empty($user->rights->societe->client->voir) || $user->socid) {
86  $filenamenb = $dir.'/ticketsnbinyear-'.$user->id.'-'.$year.'.png';
87  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$user->id.'-'.$year.'.png';
88 } else {
89  $filenamenb = $dir.'/ticketsnbinyear-'.$year.'.png';
90  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$year.'.png';
91 }
92 
93 $px1 = new DolGraph();
94 $mesg = $px1->isGraphKo();
95 if (!$mesg) {
96  $px1->SetData($data);
97  $i = $startyear; $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("NbOfTicket"));
108  $px1->SetShading(3);
109  $px1->SetHorizTickIncrement(1);
110  $px1->mode = 'depth';
111  $px1->SetTitle($langs->trans("NumberOfTicketsByMonth"));
112 
113  $px1->draw($filenamenb, $fileurlnb);
114 }
115 
116 // Build graphic amount of object
117 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
118 //var_dump($data);
119 // $data = array(array('Lib',val1,val2,val3),...)
120 
121 /*if (empty($user->rights->societe->client->voir) || $user->socid) {
122  $filenameamount = $dir.'/ticketsamountinyear-'.$user->id.'-'.$year.'.png';
123  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsamountinyear-'.$user->id.'-'.$year.'.png';
124 } else {
125  $filenameamount = $dir.'/ticketsamountinyear-'.$year.'.png';
126  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsamountinyear-'.$year.'.png';
127 }
128 
129 $px2 = new DolGraph();
130 $mesg = $px2->isGraphKo();
131 if (!$mesg) {
132  $px2->SetData($data);
133  $i = $startyear; $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("AmountOfTickets"));
144  $px2->SetShading(3);
145  $px2->SetHorizTickIncrement(1);
146  $px2->mode = 'depth';
147  $px2->SetTitle($langs->trans("AmountOfTicketsByMonthHT"));
148 
149  $px2->draw($filenameamount, $fileurlamount);
150 }
151 
152 
153 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
154 
155 if (empty($user->rights->societe->client->voir) || $user->socid) {
156  $filename_avg = $dir.'/ticketsaverage-'.$user->id.'-'.$year.'.png';
157  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsaverage-'.$user->id.'-'.$year.'.png';
158 } else {
159  $filename_avg = $dir.'/ticketsaverage-'.$year.'.png';
160  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsaverage-'.$year.'.png';
161 }
162 
163 $px3 = new DolGraph();
164 $mesg = $px3->isGraphKo();
165 if (!$mesg) {
166  $px3->SetData($data);
167  $i = $startyear; $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();
191 foreach ($data as $val) {
192  if (!empty($val['year'])) {
193  $arrayyears[$val['year']] = $val['year'];
194  }
195 }
196 if (!count($arrayyears)) {
197  $arrayyears[$nowyear] = $nowyear;
198 }
199 
200 $h = 0;
201 $head = array();
202 $head[$h][0] = DOL_URL_ROOT.'/ticket/stats/index.php';
203 $head[$h][1] = $langs->trans("ByMonthYear");
204 $head[$h][2] = 'byyear';
205 $h++;
206 
207 $type = 'ticket_stats';
208 
209 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
210 
211 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
212 
213 
214 print '<div class="fichecenter"><div class="fichethirdleft">';
215 
216 
217 // Show filter box
218 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
219 print '<input type="hidden" name="token" value="'.newToken().'">';
220 
221 print '<table class="noborder centpercent">';
222 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
223 // Company
224 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
225 print img_picto('', 'company', 'class="pictofixedwidth"');
226 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
227 print '</td></tr>';
228 // User
229 print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
230 print img_picto('', 'user', 'class="pictofixedwidth"');
231 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
232 // Status
233 print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
234 $liststatus = $object->fields['fk_statut']['arrayofkeyval'];
235 print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
236 print '</td></tr>';
237 // Year
238 print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
239 if (!in_array($year, $arrayyears)) {
240  $arrayyears[$year] = $year;
241 }
242 if (!in_array($nowyear, $arrayyears)) {
243  $arrayyears[$nowyear] = $nowyear;
244 }
245 arsort($arrayyears);
246 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
247 print '</td></tr>';
248 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
249 print '</table>';
250 print '</form>';
251 print '<br><br>';
252 
253 
254 print '<div class="div-table-responsive-no-min">';
255 print '<table class="noborder centpercent">';
256 print '<tr class="liste_titre" height="24">';
257 print '<td class="center">'.$langs->trans("Year").'</td>';
258 print '<td class="right">'.$langs->trans("NbOfTickets").'</td>';
259 print '<td class="right">%</td>';
260 //print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
261 //print '<td class="right">%</td>';
262 //print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
263 //print '<td class="right">%</td>';
264 print '</tr>';
265 
266 $oldyear = 0;
267 foreach ($data as $val) {
268  $year = $val['year'];
269  while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
270  $oldyear--;
271 
272  print '<tr class="oddeven" height="24">';
273  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
274  print '<td class="right">0</td>';
275  print '<td class="right"></td>';
276  //print '<td class="right">0</td>';
277  //print '<td class="right"></td>';
278  //print '<td class="right">0</td>';
279  //print '<td class="right"></td>';
280  print '</tr>';
281  }
282 
283 
284  print '<tr class="oddeven" height="24">';
285  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
286  print '<td class="right">'.$val['nb'].'</td>';
287  print '<td class="right" style="'.((isset($val['nb_diff']) && $val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round(isset($val['nb_diff']) ? $val['nb_diff'] : 0).'</td>';
288  //print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
289  //print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
290  //print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
291  //print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
292  print '</tr>';
293  $oldyear = $year;
294 }
295 
296 print '</table>';
297 print '</div>';
298 
299 
300 print '</div><div class="fichetwothirdright">';
301 
302 
303 // Show graphs
304 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
305 if ($mesg) {
306  print $mesg;
307 } else {
308  print $px1->show();
309  print "<br>\n";
310  //print $px2->show();
311  //print "<br>\n";
312  //print $px3->show();
313 }
314 print '</td></tr></table>';
315 
316 
317 print '</div></div>';
318 print '<div style="clear:both"></div>';
319 
320 print dol_get_fiche_end();
321 
322 // End of page
323 llxFooter();
324 $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
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
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
Ticket
Class to generate the form for creating a new ticket.
Definition: html.formticket.class.php:31
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
TicketStats
Classe permettant la gestion des stats des deplacements et notes de frais.
Definition: ticketstats.class.php:30