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