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