dolibarr 21.0.0-beta
box_graph_new_vs_close_ticket.php
Go to the documentation of this file.
1<?php
2/* Module descriptor for ticket system
3 * Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
4 * 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2019-2021 Frédéric France <frederic.france@netlogic.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28
33{
34 public $boxcode = "box_nb_tickets_type";
35 public $boximg = "ticket";
39 public $boxlabel;
40 public $depends = array("ticket");
41
42 public $widgettype = 'graph';
43
49 public function __construct($db, $param = '')
50 {
51 global $langs;
52 $langs->load("boxes");
53 $this->db = $db;
54
55 $this->boxlabel = $langs->transnoentitiesnoconv("BoxNewTicketVSClose");
56 }
57
64 public function loadBox($max = 5)
65 {
66 global $conf, $user, $langs;
67
68 $badgeStatus0 = '#cbd3d3'; // draft
69 $badgeStatus1 = '#bc9526'; // validated
70 $badgeStatus1b = '#bc9526'; // validated
71 $badgeStatus2 = '#9c9c26'; // approved
72 $badgeStatus3 = '#bca52b';
73 $badgeStatus4 = '#25a580'; // Color ok
74 $badgeStatus4b = '#25a580'; // Color ok
75 $badgeStatus5 = '#cad2d2';
76 $badgeStatus6 = '#cad2d2';
77 $badgeStatus7 = '#baa32b';
78 $badgeStatus8 = '#993013';
79 $badgeStatus9 = '#e7f0f0';
80 $text = $langs->trans("BoxNewTicketVSClose");
81 $this->info_box_head = array(
82 'text' => $text,
83 'limit' => dol_strlen($text)
84 );
85
86 if ($user->hasRight('ticket', 'read')) {
87 $data = array();
88 $totalnb = 0;
89 $sql = "SELECT COUNT(t.datec) as nb";
90 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
91 $sql .= " WHERE CAST(t.datec AS DATE) = CURRENT_DATE";
92 $sql .= " AND t.fk_statut <> 8";
93 $sql .= " GROUP BY CAST(t.datec AS DATE)";
94 $resql = $this->db->query($sql);
95 if ($resql) {
96 $num = $this->db->num_rows($resql);
97 if ($num > 0) {
98 $objp = $this->db->fetch_object($resql);
99 $data[] = array($langs->transnoentitiesnoconv('TicketCreatedToday'), $objp->nb);
100 $totalnb += $objp->nb;
101 } else {
102 $data[] = array($langs->transnoentitiesnoconv('TicketCreatedToday'), 0);
103 }
104 } else {
105 dol_print_error($this->db);
106 }
107 $sql = "SELECT COUNT(t.date_close) as nb";
108 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
109 $sql .= " WHERE CAST(t.date_close AS DATE) = CURRENT_DATE";
110 $sql .= " AND t.fk_statut = 8";
111 $sql .= " GROUP BY CAST(t.date_close AS DATE)";
112 $resql = $this->db->query($sql);
113 if ($resql) {
114 $num = $this->db->num_rows($resql);
115 if ($num > 0) {
116 $objp = $this->db->fetch_object($resql);
117 $data[] = array($langs->transnoentitiesnoconv('TicketClosedToday'), $objp->nb);
118 $totalnb += $objp->nb;
119 } else {
120 $data[] = array($langs->transnoentitiesnoconv('TicketClosedToday'), 0);
121 }
122 } else {
123 dol_print_error($this->db);
124 }
125 $colorseries = array();
126 $colorseries[] = $badgeStatus8;
127 $colorseries[] = $badgeStatus2;
128 $stringtoprint = '';
129 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
130 if (!empty($data) && count($data) > 0) {
131 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
132 $px1 = new DolGraph();
133 $mesg = $px1->isGraphKo();
134 if (!$mesg) {
135 $px1->SetDataColor($colorseries);
136 $px1->SetData($data);
137 $px1->setShowLegend(2);
138 if (!empty($conf->dol_optimize_smallscreen)) {
139 $px1->SetWidth(320);
140 }
141 $px1->SetType(array('pie'));
142 $px1->SetMaxValue($px1->GetCeilMaxValue());
143 $px1->SetShading(3);
144 $px1->SetHorizTickIncrement(1);
145 $px1->SetCssPrefix("cssboxes");
146 $px1->mode = 'depth';
147
148 $px1->draw('idgraphticketnewvsclosetoday');
149 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
150 }
151 $stringtoprint .= '</div>';
152 $this->info_box_contents[][] = array(
153 'td' => 'class="center"',
154 'text' => $stringtoprint
155 );
156 } else {
157 $this->info_box_contents[0][0] = array(
158 'td' => 'class="center"',
159 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
160 );
161 }
162 } else {
163 $this->info_box_contents[0][0] = array(
164 'td' => 'class="left"',
165 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
166 );
167 }
168 }
169
170
171
180 public function showBox($head = null, $contents = null, $nooutput = 0)
181 {
182 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
183 }
184}
Class to build graphs.
Class ModeleBoxes.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79