dolibarr  19.0.0-dev
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 // Load Dolibarr environment
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 
32 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
33 
34 if (!$user->rights->ticket->read) {
36 }
37 
38 $object_status = GETPOST('object_status', 'intcomma');
39 
40 $userid = GETPOST('userid', 'int');
41 $socid = GETPOST('socid', 'int');
42 // Security check
43 if ($user->socid > 0) {
44  $action = '';
45  $socid = $user->socid;
46 }
47 
48 $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
49 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
50 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
51 $endyear = $year;
52 
53 // Load translation files required by the page
54 $langs->loadLangs(array('orders', 'companies', 'other', 'tickets'));
55 
56 
57 /*
58  * View
59  */
60 
61 $form = new Form($db);
62 $object = new Ticket($db);
63 
64 $title = $langs->trans("Statistics");
65 $dir = $conf->ticket->dir_temp;
66 
67 llxHeader('', $title);
68 
69 print load_fiche_titre($title, '', 'ticket');
70 
71 dol_mkdir($dir);
72 
73 $stats = new TicketStats($db, $socid, ($userid > 0 ? $userid : 0));
74 if ($object_status != '' && $object_status >= -1) {
75  $stats->where .= ' AND fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
76 }
77 
78 
79 // Build graphic number of object
80 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
81 
82 //var_dump($data);
83 // $data = array(array('Lib',val1,val2,val3),...)
84 
85 
86 if (empty($user->rights->societe->client->voir) || $user->socid) {
87  $filenamenb = $dir.'/ticketsnbinyear-'.$user->id.'-'.$year.'.png';
88  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$user->id.'-'.$year.'.png';
89 } else {
90  $filenamenb = $dir.'/ticketsnbinyear-'.$year.'.png';
91  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$year.'.png';
92 }
93 
94 $px1 = new DolGraph();
95 $mesg = $px1->isGraphKo();
96 if (!$mesg) {
97  $px1->SetData($data);
98  $i = $startyear; $legend = array();
99  while ($i <= $endyear) {
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 
123 /*if (empty($user->rights->societe->client->voir) || $user->socid) {
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  $px2->SetData($data);
135  $i = $startyear; $legend = array();
136  while ($i <= $endyear) {
137  $legend[] = $i;
138  $i++;
139  }
140  $px2->SetLegend($legend);
141  $px2->SetMaxValue($px2->GetCeilMaxValue());
142  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
143  $px2->SetWidth($WIDTH);
144  $px2->SetHeight($HEIGHT);
145  $px2->SetYLabel($langs->trans("AmountOfTickets"));
146  $px2->SetShading(3);
147  $px2->SetHorizTickIncrement(1);
148  $px2->mode = 'depth';
149  $px2->SetTitle($langs->trans("AmountOfTicketsByMonthHT"));
150 
151  $px2->draw($filenameamount, $fileurlamount);
152 }
153 
154 
155 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
156 
157 if (empty($user->rights->societe->client->voir) || $user->socid) {
158  $filename_avg = $dir.'/ticketsaverage-'.$user->id.'-'.$year.'.png';
159  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsaverage-'.$user->id.'-'.$year.'.png';
160 } else {
161  $filename_avg = $dir.'/ticketsaverage-'.$year.'.png';
162  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsaverage-'.$year.'.png';
163 }
164 
165 $px3 = new DolGraph();
166 $mesg = $px3->isGraphKo();
167 if (!$mesg) {
168  $px3->SetData($data);
169  $i = $startyear; $legend = array();
170  while ($i <= $endyear) {
171  $legend[] = $i;
172  $i++;
173  }
174  $px3->SetLegend($legend);
175  $px3->SetYLabel($langs->trans("AmountAverage"));
176  $px3->SetMaxValue($px3->GetCeilMaxValue());
177  $px3->SetMinValue($px3->GetFloorMinValue());
178  $px3->SetWidth($WIDTH);
179  $px3->SetHeight($HEIGHT);
180  $px3->SetShading(3);
181  $px3->SetHorizTickIncrement(1);
182  $px3->mode = 'depth';
183  $px3->SetTitle($langs->trans("AmountAverage"));
184 
185  $px3->draw($filename_avg, $fileurl_avg);
186 }*/
187 
188 
189 
190 // Show array
191 $data = $stats->getAllByYear();
192 $arrayyears = array();
193 foreach ($data as $val) {
194  if (!empty($val['year'])) {
195  $arrayyears[$val['year']] = $val['year'];
196  }
197 }
198 if (!count($arrayyears)) {
199  $arrayyears[$nowyear] = $nowyear;
200 }
201 
202 $h = 0;
203 $head = array();
204 $head[$h][0] = DOL_URL_ROOT.'/ticket/stats/index.php';
205 $head[$h][1] = $langs->trans("ByMonthYear");
206 $head[$h][2] = 'byyear';
207 $h++;
208 
209 $type = 'ticket_stats';
210 
211 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
212 
213 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
214 
215 
216 print '<div class="fichecenter"><div class="fichethirdleft">';
217 
218 
219 // Show filter box
220 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
221 print '<input type="hidden" name="token" value="'.newToken().'">';
222 
223 print '<table class="noborder centpercent">';
224 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
225 // Company
226 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
227 print img_picto('', 'company', 'class="pictofixedwidth"');
228 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
229 print '</td></tr>';
230 // User
231 print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
232 print img_picto('', 'user', 'class="pictofixedwidth"');
233 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
234 // Status
235 print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
236 $liststatus = $object->fields['fk_statut']['arrayofkeyval'];
237 print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
238 print '</td></tr>';
239 // Year
240 print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
241 if (!in_array($year, $arrayyears)) {
242  $arrayyears[$year] = $year;
243 }
244 if (!in_array($nowyear, $arrayyears)) {
245  $arrayyears[$nowyear] = $nowyear;
246 }
247 arsort($arrayyears);
248 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
249 print '</td></tr>';
250 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
251 print '</table>';
252 print '</form>';
253 print '<br><br>';
254 
255 
256 print '<div class="div-table-responsive-no-min">';
257 print '<table class="noborder centpercent">';
258 print '<tr class="liste_titre" height="24">';
259 print '<td class="center">'.$langs->trans("Year").'</td>';
260 print '<td class="right">'.$langs->trans("NbOfTickets").'</td>';
261 print '<td class="right">%</td>';
262 //print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
263 //print '<td class="right">%</td>';
264 //print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
265 //print '<td class="right">%</td>';
266 print '</tr>';
267 
268 $oldyear = 0;
269 foreach ($data as $val) {
270  $year = $val['year'];
271  while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
272  $oldyear--;
273 
274  print '<tr class="oddeven" height="24">';
275  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></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 '<td class="right">0</td>';
281  //print '<td class="right"></td>';
282  print '</tr>';
283  }
284 
285 
286  print '<tr class="oddeven" height="24">';
287  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
288  print '<td class="right">'.$val['nb'].'</td>';
289  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>';
290  //print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
291  //print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
292  //print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
293  //print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
294  print '</tr>';
295  $oldyear = $year;
296 }
297 
298 print '</table>';
299 print '</div>';
300 
301 
302 print '</div><div class="fichetwothirdright">';
303 
304 
305 // Show graphs
306 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
307 if ($mesg) {
308  print $mesg;
309 } else {
310  print $px1->show();
311  print "<br>\n";
312  //print $px2->show();
313  //print "<br>\n";
314  //print $px3->show();
315 }
316 print '</td></tr></table>';
317 
318 
319 print '</div></div>';
320 print '<div class="clearboth"></div>';
321 
322 print dol_get_fiche_end();
323 
324 // End of page
325 llxFooter();
326 $db->close();
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
Classe permettant la gestion des stats des deplacements et notes de frais.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Class to generate the form for creating a new ticket.
llxFooter()
Footer empty.
Definition: index.php:71
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.