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