dolibarr 21.0.0-alpha
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2019 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.'/ticket/class/actions_ticket.class.php';
28require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
29require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31
34
35$hookmanager->initHooks(array('ticketstats', 'globalcard'));
36
37if (!$user->hasRight('ticket', 'read')) {
39}
40
41$object_status = GETPOST('object_status', 'intcomma');
42
43$userid = GETPOSTINT('userid');
44$socid = GETPOSTINT('socid');
45// Security check
46if ($user->socid > 0) {
47 $action = '';
48 $socid = $user->socid;
49}
50
51$parameters = array();
52$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
53if ($reshook < 0) {
54 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
55}
56
57$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
58$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
59$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
60$endyear = $year;
61
62// Load translation files required by the page
63$langs->loadLangs(array('orders', 'companies', 'other', 'tickets'));
64
65
66/*
67 * View
68 */
69
70$form = new Form($db);
71$object = new Ticket($db);
72
73$title = $langs->trans("Statistics");
74$dir = $conf->ticket->dir_temp;
75$help_url = '';
76llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-ticket page-stats');
77
78print load_fiche_titre($title, '', 'ticket');
79
80dol_mkdir($dir);
81
82$stats = new TicketStats($db, $socid, ($userid > 0 ? $userid : 0));
83if ($object_status != '' && $object_status >= -1) {
84 $stats->where .= ' AND fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
85}
86
87
88// Build graphic number of object
89$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
90
91//var_dump($data);
92// $data = array(array('Lib',val1,val2,val3),...)
93
94
95if (!$user->hasRight('societe', 'client', 'voir')) {
96 $filenamenb = $dir.'/ticketsnbinyear-'.$user->id.'-'.$year.'.png';
97 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$user->id.'-'.$year.'.png';
98} else {
99 $filenamenb = $dir.'/ticketsnbinyear-'.$year.'.png';
100 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$year.'.png';
101}
102
103$px1 = new DolGraph();
104$mesg = $px1->isGraphKo();
105if (!$mesg) {
106 $px1->SetData($data);
107 $i = $startyear;
108 $legend = array();
109 while ($i <= $endyear) {
110 $legend[] = $i;
111 $i++;
112 }
113 $px1->SetLegend($legend);
114 $px1->SetMaxValue($px1->GetCeilMaxValue());
115 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
116 $px1->SetWidth($WIDTH);
117 $px1->SetHeight($HEIGHT);
118 $px1->SetYLabel($langs->trans("NbOfTicket"));
119 $px1->SetShading(3);
120 $px1->SetHorizTickIncrement(1);
121 $px1->mode = 'depth';
122 $px1->SetTitle($langs->trans("NumberOfTicketsByMonth"));
123
124 $px1->draw($filenamenb, $fileurlnb);
125}
126
127// Build graphic amount of object
128$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
129//var_dump($data);
130// $data = array(array('Lib',val1,val2,val3),...)
131
132
133// Show array
134$data = $stats->getAllByYear();
135$arrayyears = array();
136foreach ($data as $val) {
137 if (!empty($val['year'])) {
138 $arrayyears[$val['year']] = $val['year'];
139 }
140}
141if (!count($arrayyears)) {
142 $arrayyears[$nowyear] = $nowyear;
143}
144
145$h = 0;
146$head = array();
147$head[$h][0] = DOL_URL_ROOT.'/ticket/stats/index.php';
148$head[$h][1] = $langs->trans("ByMonthYear");
149$head[$h][2] = 'byyear';
150$h++;
151
152$type = 'ticket_stats';
153
154complete_head_from_modules($conf, $langs, null, $head, $h, $type);
155
156print dol_get_fiche_head($head, 'byyear', '', -1);
157
158
159print '<div class="fichecenter"><div class="fichethirdleft">';
160
161
162// Show filter box
163print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
164print '<input type="hidden" name="token" value="'.newToken().'">';
165
166print '<table class="noborder centpercent">';
167print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
168// Company
169print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
170print img_picto('', 'company', 'class="pictofixedwidth"');
171print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
172print '</td></tr>';
173// User
174print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
175print img_picto('', 'user', 'class="pictofixedwidth"');
176print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
177// Status
178print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
179$liststatus = $object->fields['fk_statut']['arrayofkeyval'];
180print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
181print '</td></tr>';
182// Year
183print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
184if (!in_array($year, $arrayyears)) {
185 $arrayyears[$year] = $year;
186}
187if (!in_array($nowyear, $arrayyears)) {
188 $arrayyears[$nowyear] = $nowyear;
189}
190arsort($arrayyears);
191print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
192print '</td></tr>';
193print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
194print '</table>';
195print '</form>';
196print '<br><br>';
197
198
199print '<div class="div-table-responsive-no-min">';
200print '<table class="noborder centpercent">';
201print '<tr class="liste_titre" height="24">';
202print '<td class="center">'.$langs->trans("Year").'</td>';
203print '<td class="right">'.$langs->trans("NbOfTickets").'</td>';
204print '<td class="right">%</td>';
205//print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
206//print '<td class="right">%</td>';
207//print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
208//print '<td class="right">%</td>';
209print '</tr>';
210
211$oldyear = 0;
212foreach ($data as $val) {
213 $year = $val['year'];
214 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
215 $oldyear--;
216
217 print '<tr class="oddeven" height="24">';
218 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
219 print '<td class="right">0</td>';
220 print '<td class="right"></td>';
221 //print '<td class="right">0</td>';
222 //print '<td class="right"></td>';
223 //print '<td class="right">0</td>';
224 //print '<td class="right"></td>';
225 print '</tr>';
226 }
227
228
229 print '<tr class="oddeven" height="24">';
230 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
231 print '<td class="right">'.$val['nb'].'</td>';
232 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>';
233 //print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
234 //print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
235 //print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
236 //print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
237 print '</tr>';
238 $oldyear = $year;
239}
240
241print '</table>';
242print '</div>';
243
244
245print '</div><div class="fichetwothirdright">';
246
247
248// Show graphs
249print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
250if ($mesg) {
251 print $mesg;
252} else {
253 print $px1->show();
254 print "<br>\n";
255 //print $px2->show();
256 //print "<br>\n";
257 //print $px3->show();
258}
259print '</td></tr></table>';
260
261
262print '</div></div>';
263print '<div class="clearboth"></div>';
264
265print dol_get_fiche_end();
266
267// End of page
268llxFooter();
269$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($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 generation of HTML components Only common components must be here.
Class to manage the ticket stats.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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 a 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.