dolibarr 20.0.0
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
25require '../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
27require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
28require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30
33
34if (!$user->hasRight('ticket', 'read')) {
36}
37
38$object_status = GETPOST('object_status', 'intcomma');
39
40$userid = GETPOSTINT('userid');
41$socid = GETPOSTINT('socid');
42// Security check
43if ($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 ? GETPOSTINT('year') : $nowyear;
50$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('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$help_url = '';
67llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-ticket page-stats');
68
69print load_fiche_titre($title, '', 'ticket');
70
71dol_mkdir($dir);
72
73$stats = new TicketStats($db, $socid, ($userid > 0 ? $userid : 0));
74if ($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
86if (!$user->hasRight('societe', 'client', 'voir')) {
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();
96if (!$mesg) {
97 $px1->SetData($data);
98 $i = $startyear;
99 $legend = array();
100 while ($i <= $endyear) {
101 $legend[] = $i;
102 $i++;
103 }
104 $px1->SetLegend($legend);
105 $px1->SetMaxValue($px1->GetCeilMaxValue());
106 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
107 $px1->SetWidth($WIDTH);
108 $px1->SetHeight($HEIGHT);
109 $px1->SetYLabel($langs->trans("NbOfTicket"));
110 $px1->SetShading(3);
111 $px1->SetHorizTickIncrement(1);
112 $px1->mode = 'depth';
113 $px1->SetTitle($langs->trans("NumberOfTicketsByMonth"));
114
115 $px1->draw($filenamenb, $fileurlnb);
116}
117
118// Build graphic amount of object
119$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
120//var_dump($data);
121// $data = array(array('Lib',val1,val2,val3),...)
122
123
124// Show array
125$data = $stats->getAllByYear();
126$arrayyears = array();
127foreach ($data as $val) {
128 if (!empty($val['year'])) {
129 $arrayyears[$val['year']] = $val['year'];
130 }
131}
132if (!count($arrayyears)) {
133 $arrayyears[$nowyear] = $nowyear;
134}
135
136$h = 0;
137$head = array();
138$head[$h][0] = DOL_URL_ROOT.'/ticket/stats/index.php';
139$head[$h][1] = $langs->trans("ByMonthYear");
140$head[$h][2] = 'byyear';
141$h++;
142
143$type = 'ticket_stats';
144
145complete_head_from_modules($conf, $langs, null, $head, $h, $type);
146
147print dol_get_fiche_head($head, 'byyear', '', -1);
148
149
150print '<div class="fichecenter"><div class="fichethirdleft">';
151
152
153// Show filter box
154print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
155print '<input type="hidden" name="token" value="'.newToken().'">';
156
157print '<table class="noborder centpercent">';
158print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
159// Company
160print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
161print img_picto('', 'company', 'class="pictofixedwidth"');
162print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
163print '</td></tr>';
164// User
165print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
166print img_picto('', 'user', 'class="pictofixedwidth"');
167print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
168// Status
169print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
170$liststatus = $object->fields['fk_statut']['arrayofkeyval'];
171print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
172print '</td></tr>';
173// Year
174print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
175if (!in_array($year, $arrayyears)) {
176 $arrayyears[$year] = $year;
177}
178if (!in_array($nowyear, $arrayyears)) {
179 $arrayyears[$nowyear] = $nowyear;
180}
181arsort($arrayyears);
182print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
183print '</td></tr>';
184print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
185print '</table>';
186print '</form>';
187print '<br><br>';
188
189
190print '<div class="div-table-responsive-no-min">';
191print '<table class="noborder centpercent">';
192print '<tr class="liste_titre" height="24">';
193print '<td class="center">'.$langs->trans("Year").'</td>';
194print '<td class="right">'.$langs->trans("NbOfTickets").'</td>';
195print '<td class="right">%</td>';
196//print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
197//print '<td class="right">%</td>';
198//print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
199//print '<td class="right">%</td>';
200print '</tr>';
201
202$oldyear = 0;
203foreach ($data as $val) {
204 $year = $val['year'];
205 while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
206 $oldyear--;
207
208 print '<tr class="oddeven" height="24">';
209 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
210 print '<td class="right">0</td>';
211 print '<td class="right"></td>';
212 //print '<td class="right">0</td>';
213 //print '<td class="right"></td>';
214 //print '<td class="right">0</td>';
215 //print '<td class="right"></td>';
216 print '</tr>';
217 }
218
219
220 print '<tr class="oddeven" height="24">';
221 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
222 print '<td class="right">'.$val['nb'].'</td>';
223 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>';
224 //print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
225 //print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
226 //print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
227 //print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
228 print '</tr>';
229 $oldyear = $year;
230}
231
232print '</table>';
233print '</div>';
234
235
236print '</div><div class="fichetwothirdright">';
237
238
239// Show graphs
240print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
241if ($mesg) {
242 print $mesg;
243} else {
244 print $px1->show();
245 print "<br>\n";
246 //print $px2->show();
247 //print "<br>\n";
248 //print $px3->show();
249}
250print '</td></tr></table>';
251
252
253print '</div></div>';
254print '<div class="clearboth"></div>';
255
256print dol_get_fiche_end();
257
258// End of page
259llxFooter();
260$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
Class to manage the ticket stats.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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 dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Class to generate the form for creating a new ticket.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.