dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
29require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
30require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
42
43$hookmanager->initHooks(array('ticketstats', 'globalcard'));
44
45if (!$user->hasRight('ticket', 'read')) {
47}
48
49$object_status = GETPOST('object_status', 'intcomma');
50
51$userid = GETPOSTINT('userid');
52$socid = GETPOSTINT('socid');
53// Security check
54if ($user->socid > 0) {
55 $action = '';
56 $socid = $user->socid;
57}
58
59$parameters = array();
60$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
61if ($reshook < 0) {
62 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
63}
64
65$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
66$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
67$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
68$endyear = $year;
69
70// Load translation files required by the page
71$langs->loadLangs(array('orders', 'companies', 'other', 'tickets'));
72
73
74/*
75 * View
76 */
77
78$form = new Form($db);
79$object = new Ticket($db);
80
81$title = $langs->trans("Statistics");
82$dir = $conf->ticket->dir_temp;
83$help_url = '';
84llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-ticket page-stats');
85
86print load_fiche_titre($title, '', 'ticket');
87
88dol_mkdir($dir);
89
90$stats = new TicketStats($db, $socid, ($userid > 0 ? $userid : 0));
91if ($object_status != '' && $object_status >= -1) {
92 $stats->where .= ' AND fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
93}
94
95
96// Build graphic number of object
97$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
98
99//var_dump($data);
100// $data = array(array('Lib',val1,val2,val3),...)
101
102
103if (!$user->hasRight('societe', 'client', 'voir')) {
104 $filenamenb = $dir.'/ticketsnbinyear-'.$user->id.'-'.$year.'.png';
105 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$user->id.'-'.$year.'.png';
106} else {
107 $filenamenb = $dir.'/ticketsnbinyear-'.$year.'.png';
108 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$year.'.png';
109}
110
111$px1 = new DolGraph();
112$mesg = $px1->isGraphKo();
113if (!$mesg) {
114 $px1->SetData($data);
115 $i = $startyear;
116 $legend = array();
117 while ($i <= $endyear) {
118 $legend[] = $i;
119 $i++;
120 }
121 $px1->SetLegend($legend);
122 $px1->SetMaxValue($px1->GetCeilMaxValue());
123 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
124 $px1->SetWidth($WIDTH);
125 $px1->SetHeight($HEIGHT);
126 $px1->SetYLabel($langs->trans("NbOfTicket"));
127 $px1->SetShading(3);
128 $px1->SetHorizTickIncrement(1);
129 $px1->mode = 'depth';
130 $px1->SetTitle($langs->trans("NumberOfTicketsByMonth"));
131
132 $px1->draw($filenamenb, $fileurlnb);
133}
134
135// Build graphic amount of object
136$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
137//var_dump($data);
138// $data = array(array('Lib',val1,val2,val3),...)
139
140
141// Show array
142$data = $stats->getAllByYear();
143$arrayyears = array();
144foreach ($data as $val) {
145 if (!empty($val['year'])) {
146 $arrayyears[$val['year']] = $val['year'];
147 }
148}
149if (!count($arrayyears)) {
150 $arrayyears[$nowyear] = $nowyear;
151}
152
153$h = 0;
154$head = array();
155$head[$h][0] = DOL_URL_ROOT.'/ticket/stats/index.php';
156$head[$h][1] = $langs->trans("ByMonthYear");
157$head[$h][2] = 'byyear';
158$h++;
159
160$type = 'ticket_stats';
161
162complete_head_from_modules($conf, $langs, null, $head, $h, $type);
163
164print dol_get_fiche_head($head, 'byyear', '', -1);
165
166
167print '<div class="fichecenter"><div class="fichethirdleft">';
168
169
170// Show filter box
171print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
172print '<input type="hidden" name="token" value="'.newToken().'">';
173
174print '<table class="noborder centpercent">';
175print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
176// Company
177print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
178print img_picto('', 'company', 'class="pictofixedwidth"');
179print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
180print '</td></tr>';
181// User
182print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
183print img_picto('', 'user', 'class="pictofixedwidth"');
184print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
185// Status
186print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
187$liststatus = $object->fields['fk_statut']['arrayofkeyval'];
188print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4, 0, 0, '', 1);
189print '</td></tr>';
190// Year
191print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
192if (!in_array($year, $arrayyears)) {
193 $arrayyears[$year] = $year;
194}
195if (!in_array($nowyear, $arrayyears)) {
196 $arrayyears[$nowyear] = $nowyear;
197}
198arsort($arrayyears);
199print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
200print '</td></tr>';
201print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
202print '</table>';
203print '</form>';
204print '<br><br>';
205
206
207print '<div class="div-table-responsive-no-min">';
208print '<table class="noborder centpercent">';
209print '<tr class="liste_titre" height="24">';
210print '<td class="center">'.$langs->trans("Year").'</td>';
211print '<td class="right">'.$langs->trans("NbOfTickets").'</td>';
212print '<td class="right">%</td>';
213//print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
214//print '<td class="right">%</td>';
215//print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
216//print '<td class="right">%</td>';
217print '</tr>';
218
219$oldyear = 0;
220foreach ($data as $val) {
221 $year = $val['year'];
222 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
223 $oldyear--;
224
225 print '<tr class="oddeven" height="24">';
226 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
227 print '<td class="right">0</td>';
228 print '<td class="right"></td>';
229 //print '<td class="right">0</td>';
230 //print '<td class="right"></td>';
231 //print '<td class="right">0</td>';
232 //print '<td class="right"></td>';
233 print '</tr>';
234 }
235
236
237 print '<tr class="oddeven" height="24">';
238 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
239 print '<td class="right">'.$val['nb'].'</td>';
240 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>';
241 //print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
242 //print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
243 //print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
244 //print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
245 print '</tr>';
246 $oldyear = $year;
247}
248
249print '</table>';
250print '</div>';
251
252
253print '</div><div class="fichetwothirdright">';
254
255
256// Show graphs
257print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
258if ($mesg) {
259 print $mesg;
260} else {
261 print $px1->show();
262 print "<br>\n";
263 //print $px2->show();
264 //print "<br>\n";
265 //print $px3->show();
266}
267print '</td></tr></table>';
268
269
270print '</div></div>';
271print '<div class="clearboth"></div>';
272
273print dol_get_fiche_end();
274
275// End of page
276llxFooter();
277$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.