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