24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/actions_ticket.class.php';
26 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticketstats.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticket.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
33 if (!$user->rights->ticket->read) {
37 $object_status =
GETPOST(
'object_status',
'intcomma');
39 $userid =
GETPOST(
'userid',
'int');
40 $socid =
GETPOST(
'socid',
'int');
42 if ($user->socid > 0) {
44 $socid = $user->socid;
47 $nowyear = strftime(
"%Y",
dol_now());
49 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
53 $langs->loadLangs(array(
'orders',
'companies',
'other',
'tickets'));
63 $title = $langs->trans(
"Statistics");
64 $dir = $conf->ticket->dir_temp;
72 $stats =
new TicketStats($db, $socid, ($userid > 0 ? $userid : 0));
73 if ($object_status !=
'' && $object_status >= -1) {
74 $stats->where .=
' AND fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
79 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
85 if (empty($user->rights->societe->client->voir) || $user->socid) {
86 $filenamenb = $dir.
'/ticketsnbinyear-'.$user->id.
'-'.$year.
'.png';
87 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$user->id.
'-'.$year.
'.png';
89 $filenamenb = $dir.
'/ticketsnbinyear-'.$year.
'.png';
90 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=ticketstats&file=ticketsnbinyear-'.$year.
'.png';
94 $mesg = $px1->isGraphKo();
97 $i = $startyear; $legend = array();
98 while ($i <= $endyear) {
102 $px1->SetLegend($legend);
103 $px1->SetMaxValue($px1->GetCeilMaxValue());
104 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
105 $px1->SetWidth($WIDTH);
106 $px1->SetHeight($HEIGHT);
107 $px1->SetYLabel($langs->trans(
"NbOfTicket"));
109 $px1->SetHorizTickIncrement(1);
110 $px1->mode =
'depth';
111 $px1->SetTitle($langs->trans(
"NumberOfTicketsByMonth"));
113 $px1->draw($filenamenb, $fileurlnb);
117 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
189 $data = $stats->getAllByYear();
190 $arrayyears = array();
191 foreach ($data as $val) {
192 if (!empty($val[
'year'])) {
193 $arrayyears[$val[
'year']] = $val[
'year'];
196 if (!count($arrayyears)) {
197 $arrayyears[$nowyear] = $nowyear;
202 $head[$h][0] = DOL_URL_ROOT.
'/ticket/stats/index.php';
203 $head[$h][1] = $langs->trans(
"ByMonthYear");
204 $head[$h][2] =
'byyear';
207 $type =
'ticket_stats';
214 print
'<div class="fichecenter"><div class="fichethirdleft">';
218 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
219 print
'<input type="hidden" name="token" value="'.newToken().
'">';
221 print
'<table class="noborder centpercent">';
222 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
224 print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
225 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
226 print
$form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300',
'');
229 print
'<tr><td class="left">'.$langs->trans(
"CreatedBy").
'</td><td class="left">';
230 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
231 print
$form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
233 print
'<tr><td class="left">'.$langs->trans(
"Status").
'</td><td class="left">';
234 $liststatus = $object->fields[
'fk_statut'][
'arrayofkeyval'];
235 print
$form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4, 0, 0,
'', 1);
238 print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
239 if (!in_array($year, $arrayyears)) {
240 $arrayyears[$year] = $year;
242 if (!in_array($nowyear, $arrayyears)) {
243 $arrayyears[$nowyear] = $nowyear;
246 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
248 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
254 print
'<div class="div-table-responsive-no-min">';
255 print
'<table class="noborder centpercent">';
256 print
'<tr class="liste_titre" height="24">';
257 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
258 print
'<td class="right">'.$langs->trans(
"NbOfTickets").
'</td>';
259 print
'<td class="right">%</td>';
267 foreach ($data as $val) {
268 $year = $val[
'year'];
269 while (!empty($year) && $oldyear > $year + 1) {
272 print
'<tr class="oddeven" height="24">';
273 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
274 print
'<td class="right">0</td>';
275 print
'<td class="right"></td>';
284 print
'<tr class="oddeven" height="24">';
285 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
286 print
'<td class="right">'.$val[
'nb'].
'</td>';
287 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>';
300 print
'</div><div class="fichetwothirdright">';
304 print
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
314 print
'</td></tr></table>';
317 print
'</div></div>';
318 print
'<div style="clear:both"></div>';