dolibarr 19.0.4
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 public $boxcode = "box_nb_tickets_type";
34 public $boximg = "ticket";
35 public $boxlabel;
36 public $depends = array("ticket");
37
38 public $param;
39 public $info_box_head = array();
40 public $info_box_contents = array();
41
42 public $widgettype = 'graph';
43
44
50 public function __construct($db, $param = '')
51 {
52 global $langs;
53 $langs->load("boxes");
54 $this->db = $db;
55
56 $this->boxlabel = $langs->transnoentitiesnoconv("BoxNewTicketVSClose");
57 }
58
65 public function loadBox($max = 5)
66 {
67 global $conf, $user, $langs;
68
69 $badgeStatus0 = '#cbd3d3'; // draft
70 $badgeStatus1 = '#bc9526'; // validated
71 $badgeStatus1b = '#bc9526'; // validated
72 $badgeStatus2 = '#9c9c26'; // approved
73 $badgeStatus3 = '#bca52b';
74 $badgeStatus4 = '#25a580'; // Color ok
75 $badgeStatus4b = '#25a580'; // Color ok
76 $badgeStatus5 = '#cad2d2';
77 $badgeStatus6 = '#cad2d2';
78 $badgeStatus7 = '#baa32b';
79 $badgeStatus8 = '#993013';
80 $badgeStatus9 = '#e7f0f0';
81 $text = $langs->trans("BoxNewTicketVSClose");
82 $this->info_box_head = array(
83 'text' => $text,
84 'limit' => dol_strlen($text)
85 );
86
87 if ($user->hasRight('ticket', 'read')) {
88 $data = array();
89 $totalnb = 0;
90 $sql = "SELECT COUNT(t.datec) as nb";
91 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
92 $sql .= " WHERE CAST(t.datec AS DATE) = CURRENT_DATE";
93 $sql .= " AND t.fk_statut <> 8";
94 $sql .= " GROUP BY CAST(t.datec AS DATE)";
95 $resql = $this->db->query($sql);
96 if ($resql) {
97 $num = $this->db->num_rows($resql);
98 if ($num > 0) {
99 $objp = $this->db->fetch_object($resql);
100 $data[] = array($langs->transnoentitiesnoconv('TicketCreatedToday'), $objp->nb);
101 $totalnb += $objp->nb;
102 } else {
103 $data[] = array($langs->transnoentitiesnoconv('TicketCreatedToday'), 0);
104 }
105 } else {
106 dol_print_error($this->db);
107 }
108 $sql = "SELECT COUNT(t.date_close) as nb";
109 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
110 $sql .= " WHERE CAST(t.date_close AS DATE) = CURRENT_DATE";
111 $sql .= " AND t.fk_statut = 8";
112 $sql .= " GROUP BY CAST(t.date_close AS DATE)";
113 $resql = $this->db->query($sql);
114 if ($resql) {
115 $num = $this->db->num_rows($resql);
116 if ($num > 0) {
117 $objp = $this->db->fetch_object($resql);
118 $data[] = array($langs->transnoentitiesnoconv('TicketClosedToday'), $objp->nb);
119 $totalnb += $objp->nb;
120 } else {
121 $data[] = array($langs->transnoentitiesnoconv('TicketClosedToday'), 0);
122 }
123 } else {
124 dol_print_error($this->db);
125 }
126 $colorseries = array();
127 $colorseries[] = $badgeStatus8;
128 $colorseries[] = $badgeStatus2;
129 $stringtoprint = '';
130 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
131 if (!empty($data) && count($data) > 0) {
132 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
133 $px1 = new DolGraph();
134 $mesg = $px1->isGraphKo();
135 if (!$mesg) {
136 $px1->SetDataColor(array_values($colorseries));
137 $px1->SetData($data);
138 $px1->setShowLegend(2);
139 if (!empty($conf->dol_optimize_smallscreen)) {
140 $px1->SetWidth(320);
141 }
142 $px1->SetType(array('pie'));
143 $px1->SetMaxValue($px1->GetCeilMaxValue());
144 $px1->SetShading(3);
145 $px1->SetHorizTickIncrement(1);
146 $px1->SetCssPrefix("cssboxes");
147 $px1->mode = 'depth';
148
149 $px1->draw('idgraphticketnewvsclosetoday');
150 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
151 }
152 $stringtoprint .= '</div>';
153 $this->info_box_contents[][] = array(
154 'td' => 'class="center"',
155 'text' => $stringtoprint
156 );
157 } else {
158 $this->info_box_contents[0][0] = array(
159 'td' => 'class="center"',
160 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
161 );
162 }
163 } else {
164 $this->info_box_contents[0][0] = array(
165 'td' => 'class="left"',
166 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
167 );
168 }
169 }
170
179 public function showBox($head = null, $contents = null, $nooutput = 0)
180 {
181 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
182 }
183}
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.