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