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