dolibarr  19.0.0-dev
box_graph_nb_tickets_type.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 
26 require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27 
32 {
33 
34  public $boxcode = "box_graph_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("BoxTicketType");
58  }
59 
66  public function loadBox($max = 5)
67  {
68  global $conf, $user, $langs;
69  global $theme_datacolor, $badgeStatus8;
70 
71  require_once DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php";
72  require_once DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
73 
74 
75  $badgeStatus8 = '#993013';
76 
77  $text = $langs->trans("BoxTicketType");
78  $this->info_box_head = array(
79  'text' => $text,
80  'limit' => dol_strlen($text)
81  );
82 
83  $listofopplabel = array();
84  $listofoppcode = array();
85  $colorseriesstat = array();
86  if ($user->rights->ticket->read) {
87  $sql = "SELECT ctt.rowid, ctt.label, ctt.code";
88  $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_type as ctt";
89  $sql .= " WHERE ctt.active = 1";
90  $sql .= $this->db->order('ctt.rowid', 'ASC');
91  $resql = $this->db->query($sql);
92 
93  if ($resql) {
94  $num = $this->db->num_rows($resql);
95  $i = 0;
96  $newcolorkey = 0;
97  $colorused = array();
98  while ($i < $num) {
99  $objp = $this->db->fetch_object($resql);
100  $listofoppcode[$objp->rowid] = $objp->code;
101  $listofopplabel[$objp->rowid] = $objp->label;
102  if (empty($colorused[$objp->code])) {
103  if ($objp->code == 'ISSUE') {
104  $colorused[$objp->code] = $badgeStatus8;
105  } else {
106  $colorused[$objp->code] = colorArrayToHex($theme_datacolor[$newcolorkey]);
107  $newcolorkey++;
108  }
109  }
110  $colorseriesstat[$objp->rowid] = $colorused[$objp->code];
111 
112  $i++;
113  }
114  } else {
115  dol_print_error($this->db);
116  }
117  $dataseries = array();
118  $data = array();
119  $sql = "SELECT t.type_code, COUNT(t.type_code) as nb";
120  $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
121  $sql .= " WHERE t.fk_statut <> 8";
122  $sql .= " GROUP BY t.type_code";
123  $resql = $this->db->query($sql);
124  if ($resql) {
125  $num = $this->db->num_rows($resql);
126  $i = 0;
127  while ($i < $num) {
128  $objp = $this->db->fetch_object($resql);
129  $data[$objp->type_code] = $objp->nb;
130  $i++;
131  }
132  foreach ($listofoppcode as $rowid => $code) {
133  $dataseries[] = array(
134  'label' => $langs->getLabelFromKey($this->db, 'TicketTypeShort' . $code, 'c_ticket_type', 'code', 'label', $code),
135  'data' => (empty($data[$code]) ? 0 : $data[$code])
136  );
137  }
138  } else {
139  dol_print_error($this->db);
140  }
141  $stringtoprint = '';
142  $stringtoprint .= '<div class="div-table-responsive-no-min ">';
143  if (!empty($dataseries) && count($dataseries) > 0) {
144  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
145  $px1 = new DolGraph();
146 
147  $mesg = $px1->isGraphKo();
148  $totalnb = 0;
149  if (!$mesg) {
150  $px1->SetDataColor(array_values($colorseriesstat));
151  $data = array();
152  $legend = array();
153  foreach ($dataseries as $value) {
154  $data[] = array($value['label'], $value['data']);
155  $totalnb += $value['data'];
156  }
157  $px1->SetData($data);
158  $px1->setShowLegend(2);
159  if (!empty($conf->dol_optimize_smallscreen)) {
160  $px1->SetWidth(320);
161  }
162  $px1->SetType(array('pie'));
163  $px1->SetLegend($legend);
164  $px1->SetMaxValue($px1->GetCeilMaxValue());
165  $px1->SetShading(3);
166  $px1->SetHorizTickIncrement(1);
167  $px1->SetCssPrefix("cssboxes");
168  $px1->mode = 'depth';
169  $px1->draw('idgraphtickettype');
170  $stringtoprint .= $px1->show($totalnb ? 0 : 1);
171  }
172  $stringtoprint .= '</div>';
173  $this->info_box_contents[][]=array(
174  'td' => 'class="center"',
175  'text' => $stringtoprint
176  );
177  } else {
178  $this->info_box_contents[0][0] = array(
179  'td' => 'class="center opacitymedium"',
180  'text' => $langs->trans("BoxNoTicketSeverity"),
181  );
182  }
183  } else {
184  $this->info_box_contents[0][0] = array(
185  'td' => 'class="left"',
186  'text' => $langs->trans("ReadPermissionNotAllowed"),
187  );
188  }
189  }
190 
199  public function showBox($head = null, $contents = null, $nooutput = 0)
200  {
201  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
202  }
203 }
Class to build graphs.
Class ModeleBoxes.
Class to manage the box to show number of ticket types.
__construct($db, $param='')
Constructor.
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
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.