dolibarr 19.0.3
box_graph_orders_permonth.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
24
25
30{
31 public $boxcode = "orderspermonth";
32 public $boximg = "object_order";
33 public $boxlabel = "BoxCustomersOrdersPerMonth";
34 public $depends = array("commande");
35
39 public $db;
40
41 public $info_box_head = array();
42 public $info_box_contents = array();
43
44 public $widgettype = 'graph';
45
46
53 public function __construct($db, $param)
54 {
55 global $user;
56
57 $this->db = $db;
58
59 $this->hidden = empty($user->rights->commande->lire);
60 }
61
68 public function loadBox($max = 5)
69 {
70 global $conf, $user, $langs;
71
72 $this->max = $max;
73
74 $refreshaction = 'refresh_'.$this->boxcode;
75
76 //include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
77 //$commandestatic=new Commande($this->db);
78
79 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
80 if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) {
81 $startmonth = 1;
82 }
83
84 $text = $langs->trans("BoxCustomersOrdersPerMonth", $max);
85 $this->info_box_head = array(
86 'text' => $text,
87 'limit'=> dol_strlen($text),
88 'graph'=> 1,
89 'sublink'=>'',
90 'subtext'=>$langs->trans("Filter"),
91 'subpicto'=>'filter.png',
92 'subclass'=>'linkobject boxfilter',
93 'target'=>'none' // Set '' to get target="_blank"
94 );
95
96 $dir = ''; // We don't need a path because image file will not be saved into disk
97 $prefix = '';
98 $socid = 0;
99 if ($user->socid) {
100 $socid = $user->socid;
101 }
102 if (!$user->hasRight('societe', 'client', 'voir') || $socid) {
103 $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
104 }
105
106 if ($user->hasRight('commande', 'lire')) {
107 $langs->load("orders");
108
109 $param_year = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
110 $param_shownb = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
111 $param_showtot = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
112
113 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
114 include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
115 $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
116 if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
117 $endyear = GETPOST($param_year, 'int');
118 $shownb = GETPOST($param_shownb, 'alpha');
119 $showtot = GETPOST($param_showtot, 'alpha');
120 } else {
121 $tmparray = (!empty($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode], true) : array());
122 $endyear = (!empty($tmparray['year']) ? $tmparray['year'] : '');
123 $shownb = (!empty($tmparray['shownb']) ? $tmparray['shownb'] : '');
124 $showtot = (!empty($tmparray['showtot']) ? $tmparray['showtot'] : '');
125 }
126 if (empty($shownb) && empty($showtot)) {
127 $shownb = 1;
128 $showtot = 1;
129 }
130 $nowarray = dol_getdate(dol_now(), true);
131 if (empty($endyear)) {
132 $endyear = $nowarray['year'];
133 }
134 $startyear = $endyear - (!getDolGlobalString('MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH') ? 2 : ($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH - 1));
135
136 $mode = 'customer';
137 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
138 $HEIGHT = '192';
139
140 $stats = new CommandeStats($this->db, $socid, $mode, 0);
141
142 // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
143 if ($shownb) {
144 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
145
146 $filenamenb = $dir."/".$prefix."ordersnbinyear-".$endyear.".png";
147 // default value for customer mode
148 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
149 if ($mode == 'supplier') {
150 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersnbinyear-'.$endyear.'.png';
151 }
152
153 $px1 = new DolGraph();
154 $mesg = $px1->isGraphKo();
155 if (!$mesg) {
156 $px1->SetData($data1);
157 unset($data1);
158 $i = $startyear;
159 $legend = array();
160 while ($i <= $endyear) {
161 if ($startmonth != 1) {
162 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
163 } else {
164 $legend[] = $i;
165 }
166 $i++;
167 }
168 $px1->SetLegend($legend);
169 $px1->SetMaxValue($px1->GetCeilMaxValue());
170 $px1->SetWidth($WIDTH);
171 $px1->SetHeight($HEIGHT);
172 $px1->SetYLabel($langs->trans("NumberOfOrders"));
173 $px1->SetShading(3);
174 $px1->SetHorizTickIncrement(1);
175 $px1->SetCssPrefix("cssboxes");
176 $px1->mode = 'depth';
177 $px1->SetTitle($langs->trans("NumberOfOrdersByMonth"));
178
179 $px1->draw($filenamenb, $fileurlnb);
180 }
181 }
182
183 // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
184 if ($showtot) {
185 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
186
187 $filenamenb = $dir."/".$prefix."ordersamountinyear-".$endyear.".png";
188 // default value for customer mode
189 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
190 if ($mode == 'supplier') {
191 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersamountinyear-'.$endyear.'.png';
192 }
193
194 $px2 = new DolGraph();
195 $mesg = $px2->isGraphKo();
196 if (!$mesg) {
197 $px2->SetData($data2);
198 unset($data2);
199 $i = $startyear;
200 $legend = array();
201 while ($i <= $endyear) {
202 if ($startmonth != 1) {
203 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
204 } else {
205 $legend[] = $i;
206 }
207 $i++;
208 }
209 $px2->SetLegend($legend);
210 $px2->SetMaxValue($px2->GetCeilMaxValue());
211 $px2->SetWidth($WIDTH);
212 $px2->SetHeight($HEIGHT);
213 $px2->SetYLabel($langs->trans("AmountOfOrdersHT"));
214 $px2->SetShading(3);
215 $px2->SetHorizTickIncrement(1);
216 $px2->SetCssPrefix("cssboxes");
217 $px2->mode = 'depth';
218 $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
219
220 $px2->draw($filenamenb, $fileurlnb);
221 }
222 }
223
224 if (empty($conf->use_javascript_ajax)) {
225 $langs->load("errors");
226 $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
227 }
228
229 if (!$mesg) {
230 $stringtoshow = '';
231 $stringtoshow .= '<script nonce="'.getNonce().'" type="text/javascript">
232 jQuery(document).ready(function() {
233 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
234 jQuery("#idfilter'.$this->boxcode.'").toggle();
235 });
236 });
237 </script>';
238 $stringtoshow .= '<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
239 $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
240 $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
241 $stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
242 $stringtoshow .= '<input type="hidden" name="page_y" value="">';
243 $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
244 $stringtoshow .= '<input type="checkbox" name="'.$param_shownb.'"'.($shownb ? ' checked' : '').'> '.$langs->trans("NumberOfOrdersByMonth");
245 $stringtoshow .= ' &nbsp; ';
246 $stringtoshow .= '<input type="checkbox" name="'.$param_showtot.'"'.($showtot ? ' checked' : '').'> '.$langs->trans("AmountOfOrdersByMonthHT");
247 $stringtoshow .= '<br>';
248 $stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
249 $stringtoshow .= '<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
250 $stringtoshow .= '</form>';
251 $stringtoshow .= '</div>';
252 if ($shownb && $showtot) {
253 $stringtoshow .= '<div class="fichecenter">';
254 $stringtoshow .= '<div class="fichehalfleft">';
255 }
256 if ($shownb) {
257 $stringtoshow .= $px1->show();
258 }
259 if ($shownb && $showtot) {
260 $stringtoshow .= '</div>';
261 $stringtoshow .= '<div class="fichehalfright">';
262 }
263 if ($showtot) {
264 $stringtoshow .= $px2->show();
265 }
266 if ($shownb && $showtot) {
267 $stringtoshow .= '</div>';
268 $stringtoshow .= '</div>';
269 }
270 $this->info_box_contents[0][0] = array(
271 'tr'=>'class="oddeven nohover"',
272 'td' => 'class="nohover center"',
273 'textnoformat'=>$stringtoshow,
274 );
275 } else {
276 $this->info_box_contents[0][0] = array(
277 'tr'=>'class="oddeven nohover"',
278 'td' => 'class="nohover left"',
279 'maxlength'=>500,
280 'text' => $mesg,
281 );
282 }
283 } else {
284 $this->info_box_contents[0][0] = array(
285 'td' => 'class="nohover left"',
286 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
287 );
288 }
289 }
290
299 public function showBox($head = null, $contents = null, $nooutput = 0)
300 {
301 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
302 }
303}
Class to manage order statistics (customer and supplier)
Class to build graphs.
Class ModeleBoxes.
Class to manage the box to show orders per month graph.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.