dolibarr  16.0.5
box_graph_nb_ticket_last_x_days.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_ticket_last_x_days";
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 
50  public function __construct($db, $param = '')
51  {
52  global $langs;
53  $langs->load("boxes");
54  $this->db = $db;
55 
56  $this->boxlabel = $langs->transnoentitiesnoconv("BoxNumberOfTicketByDay");
57  }
58 
65  public function loadBox($max = 5)
66  {
67  global $conf, $user, $langs;
68  $dataseries = array();
69  $graphtoshow = "";
70 
71  $badgeStatus0 = '#cbd3d3'; // draft
72  $badgeStatus1 = '#bc9526'; // validated
73  $badgeStatus1b = '#bc9526'; // validated
74  $badgeStatus2 = '#9c9c26'; // approved
75  $badgeStatus3 = '#bca52b';
76  $badgeStatus4 = '#25a580'; // Color ok
77  $badgeStatus4b = '#25a580'; // Color ok
78  $badgeStatus5 = '#cad2d2';
79  $badgeStatus6 = '#cad2d2';
80  $badgeStatus7 = '#baa32b';
81  $badgeStatus8 = '#993013';
82  $badgeStatus9 = '#e7f0f0';
83  if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php')) {
84  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
85  }
86  $this->max = $max;
87 
88 
89  $param_day = 'DOLUSERCOOKIE_ticket_last_days';
90  if (GETPOST($param_day)) {
91  if (GETPOST($param_day) >= 15) {
92  $days = 14;
93  } else {
94  $days = GETPOST($param_day);
95  }
96  } else {
97  $days = 7;
98  }
99  require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
100  $text = $langs->trans("BoxTicketLastXDays", $days).'&nbsp;'.img_picto('', 'filter.png', 'id="idsubimgDOLUSERCOOKIE_ticket_last_days" class="linkobject"');
101  $this->info_box_head = array(
102  'text' => $text,
103  'limit' => dol_strlen($text)
104  );
105  $today = dol_now();
106  $intervaltoadd = 1;
107  $minimumdatec = dol_time_plus_duree($today, -1 * ($days - 1), 'd');
108  $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
109 
110  if ($user->rights->ticket->read) {
111  $sql = "SELECT CAST(t.datec AS DATE) as datec, COUNT(t.datec) as nb";
112  $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
113  $sql .= " WHERE CAST(t.datec AS DATE) > '".$this->db->idate($minimumdatec)."'";
114  $sql .= " GROUP BY CAST(t.datec AS DATE)";
115 
116  $resql = $this->db->query($sql);
117  if ($resql) {
118  $num = $this->db->num_rows($resql);
119  $i = 0;
120  while ($i < $num) {
121  $objp = $this->db->fetch_object($resql);
122  while ($minimumdatecformated < $objp->datec) {
123  $dataseries[] = array('label' => dol_print_date($minimumdatecformated, 'day'), 'data' => 0);
124  $minimumdatec = dol_time_plus_duree($minimumdatec, $intervaltoadd, 'd');
125  $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
126  }
127  $dataseries[] = array('label' => dol_print_date($objp->datec, 'day'), 'data' => $objp->nb);
128  $minimumdatec = dol_time_plus_duree($minimumdatec, $intervaltoadd, 'd');
129  $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
130  $i++;
131  }
132  while (count($dataseries) < $days) {
133  $dataseries[] = array('label' => dol_print_date($minimumdatecformated, 'day'), 'data' => 0);
134  $minimumdatec = dol_time_plus_duree($minimumdatec, $intervaltoadd, 'd');
135  $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
136  $i++;
137  }
138  } else {
139  dol_print_error($this->db);
140  }
141  $stringtoshow = '<div class="div-table-responsive-no-min">';
142  $stringtoshow .= '<script type="text/javascript">
143  jQuery(document).ready(function() {
144  jQuery("#idsubimgDOLUSERCOOKIE_ticket_last_days").click(function() {
145  jQuery("#idfilterDOLUSERCOOKIE_ticket_last_days").toggle();
146  });
147  });
148  </script>';
149  $stringtoshow .= '<div class="center hideobject" id="idfilterDOLUSERCOOKIE_ticket_last_days">'; // hideobject is to start hidden
150  $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
151  $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
152  $stringtoshow .= '<input type="hidden" name="action" value="refresh">';
153  $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_ticket_last_days:days">';
154  $stringtoshow .= ' <input class="flat" size="4" type="text" name="'.$param_day.'" value="'.$days.'">'.$langs->trans("Days");
155  $stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
156  $stringtoshow .= '</form>';
157  $stringtoshow .= '</div>';
158 
159  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
160  $px1 = new DolGraph();
161 
162  $mesg = $px1->isGraphKo();
163  $totalnb = 0;
164  if (!$mesg) {
165  $data = array();
166  foreach ($dataseries as $value) {
167  $data[] = array($value['label'], $value['data']);
168  $totalnb += $value['data'];
169  }
170  $px1->SetData($data);
171  //$px1->setShowLegend(2);
172  $px1->setShowLegend(0);
173  $px1->SetType(array('bars'));
174  $px1->SetLegend(array($langs->trans('BoxNumberOfTicketByDay')));
175  $px1->SetMaxValue($px1->GetCeilMaxValue());
176  $px1->SetHeight(192);
177  $px1->SetShading(3);
178  $px1->SetHorizTickIncrement(1);
179  $px1->SetCssPrefix("cssboxes");
180  $px1->mode = 'depth';
181 
182  $px1->draw('idgraphticketlastxdays');
183  $graphtoshow = $px1->show($totalnb ? 0 : 1);
184  }
185  if ($totalnb) {
186  $stringtoshow .= $graphtoshow;
187  }
188  $stringtoshow .= '</div>';
189  if ($totalnb) {
190  $this->info_box_contents[][] = array(
191  'td' => 'center',
192  'text' => $stringtoshow
193  );
194  } else {
195  $this->info_box_contents[0][0] = array(
196  'td' => 'class="center opacitymedium"',
197  'text' => $stringtoshow.$langs->trans("BoxNoTicketLastXDays", $days)
198  );
199  }
200  } else {
201  $this->info_box_contents[0][0] = array(
202  'td' => 'class="left"',
203  'text' => $langs->trans("ReadPermissionNotAllowed"),
204  );
205  }
206  }
207 
216  public function showBox($head = null, $contents = null, $nooutput = 0)
217  {
218  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
219  }
220 }
db
$conf db
API class for accounts.
Definition: inc.php:41
box_graph_nb_ticket_last_x_days\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_graph_nb_ticket_last_x_days.php:216
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
box_graph_nb_ticket_last_x_days\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_graph_nb_ticket_last_x_days.php:65
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
box_graph_nb_ticket_last_x_days
Class to manage the box.
Definition: box_graph_nb_ticket_last_x_days.php:31
box_graph_nb_ticket_last_x_days\__construct
__construct($db, $param='')
Constructor.
Definition: box_graph_nb_ticket_last_x_days.php:50
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34