dolibarr 18.0.6
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 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27
32{
33
34 public $boxcode = "box_nb_tickets_type";
35 public $boximg = "ticket";
36 public $boxlabel;
37 public $depends = array("ticket");
38
39 public $param;
40 public $info_box_head = array();
41 public $info_box_contents = array();
42
43 public $widgettype = 'graph';
44
45
51 public function __construct($db, $param = '')
52 {
53 global $langs;
54 $langs->load("boxes");
55 $this->db = $db;
56
57 $this->boxlabel = $langs->transnoentitiesnoconv("BoxNewTicketVSClose");
58 }
59
66 public function loadBox($max = 5)
67 {
68 global $conf, $user, $langs;
69
70 $badgeStatus0 = '#cbd3d3'; // draft
71 $badgeStatus1 = '#bc9526'; // validated
72 $badgeStatus1b = '#bc9526'; // validated
73 $badgeStatus2 = '#9c9c26'; // approved
74 $badgeStatus3 = '#bca52b';
75 $badgeStatus4 = '#25a580'; // Color ok
76 $badgeStatus4b = '#25a580'; // Color ok
77 $badgeStatus5 = '#cad2d2';
78 $badgeStatus6 = '#cad2d2';
79 $badgeStatus7 = '#baa32b';
80 $badgeStatus8 = '#993013';
81 $badgeStatus9 = '#e7f0f0';
82 $text = $langs->trans("BoxNewTicketVSClose");
83 $this->info_box_head = array(
84 'text' => $text,
85 'limit' => dol_strlen($text)
86 );
87
88 if ($user->hasRight('ticket', 'read')) {
89 $data = array();
90 $totalnb = 0;
91 $sql = "SELECT COUNT(t.datec) as nb";
92 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
93 $sql .= " WHERE CAST(t.datec AS DATE) = CURRENT_DATE";
94 $sql .= " AND t.fk_statut <> 8";
95 $sql .= " GROUP BY CAST(t.datec AS DATE)";
96 $resql = $this->db->query($sql);
97 if ($resql) {
98 $num = $this->db->num_rows($resql);
99 if ($num > 0) {
100 $objp = $this->db->fetch_object($resql);
101 $data[] = array($langs->transnoentitiesnoconv('TicketCreatedToday'), $objp->nb);
102 $totalnb += $objp->nb;
103 } else {
104 $data[] = array($langs->transnoentitiesnoconv('TicketCreatedToday'), 0);
105 }
106 } else {
107 dol_print_error($this->db);
108 }
109 $sql = "SELECT COUNT(t.date_close) as nb";
110 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
111 $sql .= " WHERE CAST(t.date_close AS DATE) = CURRENT_DATE";
112 $sql .= " AND t.fk_statut = 8";
113 $sql .= " GROUP BY CAST(t.date_close AS DATE)";
114 $resql = $this->db->query($sql);
115 if ($resql) {
116 $num = $this->db->num_rows($resql);
117 if ($num > 0) {
118 $objp = $this->db->fetch_object($resql);
119 $data[] = array($langs->transnoentitiesnoconv('TicketClosedToday'), $objp->nb);
120 $totalnb += $objp->nb;
121 } else {
122 $data[] = array($langs->transnoentitiesnoconv('TicketClosedToday'), 0);
123 }
124 } else {
125 dol_print_error($this->db);
126 }
127 $colorseries = array();
128 $colorseries[] = $badgeStatus8;
129 $colorseries[] = $badgeStatus2;
130 $stringtoprint = '';
131 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
132 if (!empty($data) && count($data) > 0) {
133 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
134 $px1 = new DolGraph();
135 $mesg = $px1->isGraphKo();
136 if (!$mesg) {
137 $px1->SetDataColor(array_values($colorseries));
138 $px1->SetData($data);
139 $px1->setShowLegend(2);
140 if (!empty($conf->dol_optimize_smallscreen)) {
141 $px1->SetWidth(320);
142 }
143 $px1->SetType(array('pie'));
144 $px1->SetMaxValue($px1->GetCeilMaxValue());
145 $px1->SetShading(3);
146 $px1->SetHorizTickIncrement(1);
147 $px1->SetCssPrefix("cssboxes");
148 $px1->mode = 'depth';
149
150 $px1->draw('idgraphticketnewvsclosetoday');
151 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
152 }
153 $stringtoprint .= '</div>';
154 $this->info_box_contents[][] = array(
155 'td' => 'class="center"',
156 'text' => $stringtoprint
157 );
158 } else {
159 $this->info_box_contents[0][0] = array(
160 'td' => 'class="center opacitymedium"',
161 'text' => $langs->trans("BoxNoTicketSeverity"),
162 );
163 }
164 } else {
165 $this->info_box_contents[0][0] = array(
166 'td' => 'class="left"',
167 'text' => $langs->trans("ReadPermissionNotAllowed"),
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.