dolibarr  13.0.2
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) accessforbidden();
34 
35 $object_status = GETPOST('object_status', 'intcomma');
36 
37 $userid = GETPOST('userid', 'int');
38 $socid = GETPOST('socid', 'int');
39 // Security check
40 if ($user->socid > 0)
41 {
42  $action = '';
43  $socid = $user->socid;
44 }
45 
46 $nowyear = strftime("%Y", dol_now());
47 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
48 //$startyear=$year-2;
49 $startyear = $year - 1;
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) $stats->where .= ' AND fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
74 
75 
76 // Build graphic number of object
77 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
78 
79 //var_dump($data);
80 // $data = array(array('Lib',val1,val2,val3),...)
81 
82 
83 if (!$user->rights->societe->client->voir || $user->socid)
84 {
85  $filenamenb = $dir.'/ticketsnbinyear-'.$user->id.'-'.$year.'.png';
86  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$user->id.'-'.$year.'.png';
87 } else {
88  $filenamenb = $dir.'/ticketsnbinyear-'.$year.'.png';
89  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$year.'.png';
90 }
91 
92 $px1 = new DolGraph();
93 $mesg = $px1->isGraphKo();
94 if (!$mesg)
95 {
96  $px1->SetData($data);
97  $i = $startyear; $legend = array();
98  while ($i <= $endyear)
99  {
100  $legend[] = $i;
101  $i++;
102  }
103  $px1->SetLegend($legend);
104  $px1->SetMaxValue($px1->GetCeilMaxValue());
105  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
106  $px1->SetWidth($WIDTH);
107  $px1->SetHeight($HEIGHT);
108  $px1->SetYLabel($langs->trans("NbOfTicket"));
109  $px1->SetShading(3);
110  $px1->SetHorizTickIncrement(1);
111  $px1->mode = 'depth';
112  $px1->SetTitle($langs->trans("NumberOfTicketsByMonth"));
113 
114  $px1->draw($filenamenb, $fileurlnb);
115 }
116 
117 // Build graphic amount of object
118 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
119 //var_dump($data);
120 // $data = array(array('Lib',val1,val2,val3),...)
121 
122 if (!$user->rights->societe->client->voir || $user->socid)
123 {
124  $filenameamount = $dir.'/ticketsamountinyear-'.$user->id.'-'.$year.'.png';
125  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsamountinyear-'.$user->id.'-'.$year.'.png';
126 } else {
127  $filenameamount = $dir.'/ticketsamountinyear-'.$year.'.png';
128  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsamountinyear-'.$year.'.png';
129 }
130 
131 $px2 = new DolGraph();
132 $mesg = $px2->isGraphKo();
133 if (!$mesg)
134 {
135  $px2->SetData($data);
136  $i = $startyear; $legend = array();
137  while ($i <= $endyear)
138  {
139  $legend[] = $i;
140  $i++;
141  }
142  $px2->SetLegend($legend);
143  $px2->SetMaxValue($px2->GetCeilMaxValue());
144  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
145  $px2->SetWidth($WIDTH);
146  $px2->SetHeight($HEIGHT);
147  $px2->SetYLabel($langs->trans("AmountOfTickets"));
148  $px2->SetShading(3);
149  $px2->SetHorizTickIncrement(1);
150  $px2->mode = 'depth';
151  $px2->SetTitle($langs->trans("AmountOfTicketsByMonthHT"));
152 
153  $px2->draw($filenameamount, $fileurlamount);
154 }
155 
156 
157 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
158 
159 if (!$user->rights->societe->client->voir || $user->socid)
160 {
161  $filename_avg = $dir.'/ticketsaverage-'.$user->id.'-'.$year.'.png';
162  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsaverage-'.$user->id.'-'.$year.'.png';
163 } else {
164  $filename_avg = $dir.'/ticketsaverage-'.$year.'.png';
165  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsaverage-'.$year.'.png';
166 }
167 
168 $px3 = new DolGraph();
169 $mesg = $px3->isGraphKo();
170 if (!$mesg)
171 {
172  $px3->SetData($data);
173  $i = $startyear; $legend = array();
174  while ($i <= $endyear)
175  {
176  $legend[] = $i;
177  $i++;
178  }
179  $px3->SetLegend($legend);
180  $px3->SetYLabel($langs->trans("AmountAverage"));
181  $px3->SetMaxValue($px3->GetCeilMaxValue());
182  $px3->SetMinValue($px3->GetFloorMinValue());
183  $px3->SetWidth($WIDTH);
184  $px3->SetHeight($HEIGHT);
185  $px3->SetShading(3);
186  $px3->SetHorizTickIncrement(1);
187  $px3->mode = 'depth';
188  $px3->SetTitle($langs->trans("AmountAverage"));
189 
190  $px3->draw($filename_avg, $fileurl_avg);
191 }
192 
193 
194 
195 // Show array
196 $data = $stats->getAllByYear();
197 $arrayyears = array();
198 foreach ($data as $val) {
199  if (!empty($val['year'])) {
200  $arrayyears[$val['year']] = $val['year'];
201  }
202 }
203 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
204 
205 $h = 0;
206 $head = array();
207 $head[$h][0] = DOL_URL_ROOT.'/ticket/stats/index.php';
208 $head[$h][1] = $langs->trans("ByMonthYear");
209 $head[$h][2] = 'byyear';
210 $h++;
211 
212 $type = 'ticket_stats';
213 
214 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
215 
216 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
217 
218 
219 print '<div class="fichecenter"><div class="fichethirdleft">';
220 
221 
222 // Show filter box
223 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
224 print '<input type="hidden" name="token" value="'.newToken().'">';
225 
226 print '<table class="noborder centpercent">';
227 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
228 // Company
229 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
230 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, '', 'style="width: 95%"');
231 print '</td></tr>';
232 // User
233 print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
234 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
235 // Status
236 print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
237 $liststatus = $object->fields['fk_statut']['arrayofkeyval'];
238 print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
239 print '</td></tr>';
240 // Year
241 print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
242 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
243 if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
244 arsort($arrayyears);
245 print $form->selectarray('year', $arrayyears, $year, 0);
246 print '</td></tr>';
247 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
248 print '</table>';
249 print '</form>';
250 print '<br><br>';
251 
252 
253 print '<div class="div-table-responsive-no-min">';
254 print '<table class="noborder centpercent">';
255 print '<tr class="liste_titre" height="24">';
256 print '<td class="center">'.$langs->trans("Year").'</td>';
257 print '<td class="right">'.$langs->trans("NbOfTickets").'</td>';
258 print '<td class="right">%</td>';
259 //print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
260 //print '<td class="right">%</td>';
261 //print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
262 //print '<td class="right">%</td>';
263 print '</tr>';
264 
265 $oldyear = 0;
266 foreach ($data as $val)
267 {
268  $year = $val['year'];
269  while (!empty($year) && $oldyear > $year + 1)
270  { // If we have empty year
271  $oldyear--;
272 
273  print '<tr class="oddeven" height="24">';
274  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
275  print '<td class="right">0</td>';
276  print '<td class="right"></td>';
277  //print '<td class="right">0</td>';
278  //print '<td class="right"></td>';
279  //print '<td class="right">0</td>';
280  //print '<td class="right"></td>';
281  print '</tr>';
282  }
283 
284 
285  print '<tr class="oddeven" height="24">';
286  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
287  print '<td class="right">'.$val['nb'].'</td>';
288  print '<td class="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['nb_diff']).'</td>';
289  //print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
290  //print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
291  //print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
292  //print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
293  print '</tr>';
294  $oldyear = $year;
295 }
296 
297 print '</table>';
298 print '</div>';
299 
300 
301 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
302 
303 
304 // Show graphs
305 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
306 if ($mesg) { print $mesg; } else {
307  print $px1->show();
308  print "<br>\n";
309  //print $px2->show();
310  //print "<br>\n";
311  //print $px3->show();
312 }
313 print '</td></tr></table>';
314 
315 
316 print '</div></div></div>';
317 print '<div style="clear:both"></div>';
318 
319 print dol_get_fiche_end();
320 
321 // End of page
322 llxFooter();
323 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Classe permettant la gestion des stats des deplacements et notes de frais.
dol_now($mode= 'auto')
Return date for now.
Class to manage ticket.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
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 ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)