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