dolibarr 21.0.0-beta
box_graph_orders_supplier_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 = "orderssupplierpermonth";
34 public $boximg = "object_order";
35 public $boxlabel = "BoxSuppliersOrdersPerMonth";
36 public $depends = array("fournisseur");
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('fournisseur', '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.'/fourn/class/fournisseur.commande.class.php';
70
71 $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
72 if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) {
73 $startmonth = 1;
74 }
75
76 $text = $langs->trans("BoxSuppliersOrdersPerMonth", $max);
77 $this->info_box_head = array(
78 'text' => $text,
79 'limit' => dol_strlen($text),
80 'graph' => 1,
81 'sublink' => '',
82 'subtext' => $langs->trans("Filter"),
83 'subpicto' => 'filter.png',
84 'subclass' => 'linkobject boxfilter',
85 'target' => 'none' // Set '' to get target="_blank"
86 );
87
88 $dir = ''; // We don't need a path because image file will not be saved into disk
89 $prefix = '';
90 $mesg = '';
91 $px1 = null;
92 $px2 = null;
93 $socid = 0;
94 if ($user->socid) {
95 $socid = $user->socid;
96 }
97 if (!$user->hasRight('societe', 'client', 'voir')) {
98 $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
99 }
100
101 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
102 $langs->load("orders");
103
104 $param_year = 'DOLUSER_box_'.$this->boxcode.'_year';
105 $param_shownb = 'DOLUSER_box_'.$this->boxcode.'_shownb';
106 $param_showtot = 'DOLUSER_box_'.$this->boxcode.'_showtot';
107
108 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
109 include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
110 $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
111 if (in_array('DOLUSER_box_'.$this->boxcode, $autosetarray)) {
112 $endyear = GETPOSTINT($param_year);
113 $shownb = GETPOST($param_shownb, 'alpha');
114 $showtot = GETPOST($param_showtot, 'alpha');
115 } else {
116 $tmparray = (!empty($_COOKIE['DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE['DOLUSER_box_'.$this->boxcode], true) : array());
117 $endyear = (!empty($tmparray['year']) ? $tmparray['year'] : '');
118 $shownb = (!empty($tmparray['shownb']) ? $tmparray['shownb'] : '');
119 $showtot = (!empty($tmparray['showtot']) ? $tmparray['showtot'] : '');
120 }
121 if (empty($shownb) && empty($showtot)) {
122 $shownb = 1;
123 $showtot = 1;
124 }
125 $nowarray = dol_getdate(dol_now(), true);
126 if (empty($endyear)) {
127 $endyear = $nowarray['year'];
128 }
129 $startyear = $endyear - getDolGlobalInt('MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
130
131 $mode = 'supplier';
132 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
133 $HEIGHT = '192';
134
135 $stats = new CommandeStats($this->db, $socid, $mode, 0);
136
137 // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
138 if ($shownb) {
139 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
140
141 $filenamenb = $dir."/".$prefix."orderssuppliernbinyear-".$endyear.".png";
142 // default value for customer mode
143 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
144 if ($mode == 'supplier') {
145 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssuppliernbinyear-'.$endyear.'.png';
146 }
147
148 $px1 = new DolGraph();
149 $mesg = $px1->isGraphKo();
150 if (!$mesg) {
151 $px1->SetData($data1);
152 unset($data1);
153 $i = $startyear;
154 $legend = array();
155 while ($i <= $endyear) {
156 if ($startmonth != 1) {
157 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
158 } else {
159 $legend[] = $i;
160 }
161 $i++;
162 }
163 $px1->SetLegend($legend);
164 $px1->SetMaxValue($px1->GetCeilMaxValue());
165 $px1->SetWidth($WIDTH);
166 $px1->SetHeight($HEIGHT);
167 $px1->SetYLabel($langs->trans("NumberOfOrders"));
168 $px1->SetShading(3);
169 $px1->SetHorizTickIncrement(1);
170 $px1->SetCssPrefix("cssboxes");
171 $px1->mode = 'depth';
172 $px1->SetTitle($langs->trans("NumberOfOrdersByMonth"));
173
174 $px1->draw($filenamenb, $fileurlnb);
175 }
176 }
177
178 // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
179 if ($showtot) {
180 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
181
182 $filenamenb = $dir."/".$prefix."orderssupplieramountinyear-".$endyear.".png";
183 // default value for customer mode
184 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
185 if ($mode == 'supplier') {
186 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssupplieramountinyear-'.$endyear.'.png';
187 }
188
189 $px2 = new DolGraph();
190 $mesg = $px2->isGraphKo();
191 if (!$mesg) {
192 $px2->SetData($data2);
193 unset($data2);
194 $i = $startyear;
195 $legend = array();
196 while ($i <= $endyear) {
197 if ($startmonth != 1) {
198 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
199 } else {
200 $legend[] = $i;
201 }
202 $i++;
203 }
204 $px2->SetLegend($legend);
205 $px2->SetMaxValue($px2->GetCeilMaxValue());
206 $px2->SetWidth($WIDTH);
207 $px2->SetHeight($HEIGHT);
208 $px2->SetYLabel($langs->trans("AmountOfOrdersHT"));
209 $px2->SetShading(3);
210 $px2->SetHorizTickIncrement(1);
211 $px2->SetCssPrefix("cssboxes");
212 $px2->mode = 'depth';
213 $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
214
215 $px2->draw($filenamenb, $fileurlnb);
216 }
217 }
218
219 if (empty($conf->use_javascript_ajax)) {
220 $langs->load("errors");
221 $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
222 }
223
224 if (!$mesg) {
225 $stringtoshow = '';
226 $stringtoshow .= '<script nonce="'.getNonce().'" type="text/javascript">
227 jQuery(document).ready(function() {
228 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
229 jQuery("#idfilter'.$this->boxcode.'").toggle();
230 });
231 });
232 </script>';
233 $stringtoshow .= '<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
234 $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
235 $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
236 $stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
237 $stringtoshow .= '<input type="hidden" name="page_y" value="">';
238 $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.':year,shownb,showtot">';
239 $stringtoshow .= '<input type="checkbox" id="'.$param_shownb.'" name="'.$param_shownb.'"'.($shownb ? ' checked' : '').'><label for="'.$param_shownb.'"> '.$langs->trans("NumberOfOrdersByMonth").'</label>';
240 $stringtoshow .= ' &nbsp; ';
241 $stringtoshow .= '<input type="checkbox" id="'.$param_showtot.'" name="'.$param_showtot.'"'.($showtot ? ' checked' : '').'><label for="'.$param_showtot.'"> '.$langs->trans("AmountOfOrdersByMonthHT").'</label>';
242 $stringtoshow .= '<br>';
243 $stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
244 $stringtoshow .= '<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', 0, 1).'">';
245 $stringtoshow .= '</form>';
246 $stringtoshow .= '</div>';
247 if ($shownb && $showtot) {
248 $stringtoshow .= '<div class="fichecenter">';
249 $stringtoshow .= '<div class="fichehalfleft">';
250 }
251 if ($shownb && $px1 !== null) {
252 $stringtoshow .= $px1->show();
253 }
254 if ($shownb && $showtot) {
255 $stringtoshow .= '</div>';
256 $stringtoshow .= '<div class="fichehalfright">';
257 }
258 if ($showtot && $px2 !== null) {
259 $stringtoshow .= $px2->show();
260 }
261 if ($shownb && $showtot) {
262 $stringtoshow .= '</div>';
263 $stringtoshow .= '</div>';
264 }
265 $this->info_box_contents[0][0] = array(
266 'tr' => 'class="oddeven nohover"',
267 'td' => 'class="nohover center"',
268 'textnoformat' => $stringtoshow,
269 );
270 } else {
271 $this->info_box_contents[0][0] = array(
272 'tr' => 'class="oddeven nohover"',
273 'td' => 'class="nohover left"',
274 'maxlength' => 500,
275 'text' => $mesg,
276 );
277 }
278 } else {
279 $this->info_box_contents[0][0] = array(
280 'td' => 'class="nohover left"',
281 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
282 );
283 }
284 }
285
286
287
296 public function showBox($head = null, $contents = null, $nooutput = 0)
297 {
298 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
299 }
300}
Class to manage order statistics (customer and supplier)
Class to build graphs.
Class ModeleBoxes.
Class to manage the box to show last orders.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
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