dolibarr  7.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  *
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 <http://www.gnu.org/licenses/>.
16  */
17 
23 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
24 
25 
30 {
31  var $boxcode="orderssupplierpermonth";
32  var $boximg="object_order";
33  var $boxlabel="BoxSuppliersOrdersPerMonth";
34  var $depends = array("fournisseur");
35 
36  var $db;
37 
38  var $info_box_head = array();
39  var $info_box_contents = array();
40 
41 
48  function __construct($db,$param)
49  {
50  global $user;
51 
52  $this->db=$db;
53 
54  $this->hidden = ! ($user->rights->fournisseur->commande->lire);
55  }
56 
63  function loadBox($max=5)
64  {
65  global $conf, $user, $langs, $db;
66 
67  $this->max=$max;
68 
69  $refreshaction='refresh_'.$this->boxcode;
70 
71  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
72 
73  $text = $langs->trans("BoxSuppliersOrdersPerMonth",$max);
74  $this->info_box_head = array(
75  'text' => $text,
76  'limit'=> dol_strlen($text),
77  'graph'=> 1,
78  'sublink'=>'',
79  'subtext'=>$langs->trans("Filter"),
80  'subpicto'=>'filter.png',
81  'subclass'=>'linkobject boxfilter',
82  'target'=>'none' // Set '' to get target="_blank"
83  );
84 
85  $dir=''; // We don't need a path because image file will not be saved into disk
86  $prefix='';
87  $socid=0;
88  if ($user->societe_id) $socid=$user->societe_id;
89  if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
90 
91  if ($user->rights->fournisseur->commande->lire)
92  {
93  $langs->load("orders");
94 
95  $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
96  $param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
97  $param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
98 
99  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
100  include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
101  $autosetarray=preg_split("/[,;:]+/",GETPOST('DOL_AUTOSET_COOKIE'));
102  if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode,$autosetarray))
103  {
104  $endyear=GETPOST($param_year,'int');
105  $shownb=GETPOST($param_shownb,'alpha');
106  $showtot=GETPOST($param_showtot,'alpha');
107  }
108  else
109  {
110  $tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
111  $endyear=$tmparray['year'];
112  $shownb=$tmparray['shownb'];
113  $showtot=$tmparray['showtot'];
114  }
115  if (empty($shownb) && empty($showtot)) { $shownb=1; $showtot=1; }
116  $nowarray=dol_getdate(dol_now(),true);
117  if (empty($endyear)) $endyear=$nowarray['year'];
118  $startyear=$endyear-1;
119  $mode='supplier';
120  $WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
121  $HEIGHT='192';
122 
123  $stats = new CommandeStats($this->db, $socid, $mode, 0);
124 
125  // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
126  if ($shownb)
127  {
128  $data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)), ($WIDTH<300?2:0));
129 
130  $filenamenb = $dir."/".$prefix."orderssuppliernbinyear-".$endyear.".png";
131  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
132  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssuppliernbinyear-'.$endyear.'.png';
133 
134  $px1 = new DolGraph();
135  $mesg = $px1->isGraphKo();
136  if (! $mesg)
137  {
138  $px1->SetData($data1);
139  unset($data1);
140  $px1->SetPrecisionY(0);
141  $i=$startyear;$legend=array();
142  while ($i <= $endyear)
143  {
144  $legend[]=$i;
145  $i++;
146  }
147  $px1->SetLegend($legend);
148  $px1->SetMaxValue($px1->GetCeilMaxValue());
149  $px1->SetWidth($WIDTH);
150  $px1->SetHeight($HEIGHT);
151  $px1->SetYLabel($langs->trans("NumberOfOrders"));
152  $px1->SetShading(3);
153  $px1->SetHorizTickIncrement(1);
154  $px1->SetPrecisionY(0);
155  $px1->SetCssPrefix("cssboxes");
156  $px1->mode='depth';
157  $px1->SetTitle($langs->trans("NumberOfOrdersByMonth"));
158 
159  $px1->draw($filenamenb,$fileurlnb);
160  }
161  }
162 
163  // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
164  if ($showtot)
165  {
166  $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)), ($WIDTH<300?2:0));
167 
168  $filenamenb = $dir."/".$prefix."orderssupplieramountinyear-".$endyear.".png";
169  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
170  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssupplieramountinyear-'.$endyear.'.png';
171 
172  $px2 = new DolGraph();
173  $mesg = $px2->isGraphKo();
174  if (! $mesg)
175  {
176  $px2->SetData($data2);
177  unset($data2);
178  $px2->SetPrecisionY(0);
179  $i=$startyear;$legend=array();
180  while ($i <= $endyear)
181  {
182  $legend[]=$i;
183  $i++;
184  }
185  $px2->SetLegend($legend);
186  $px2->SetMaxValue($px2->GetCeilMaxValue());
187  $px2->SetWidth($WIDTH);
188  $px2->SetHeight($HEIGHT);
189  $px2->SetYLabel($langs->trans("AmountOfOrdersHT"));
190  $px2->SetShading(3);
191  $px2->SetHorizTickIncrement(1);
192  $px2->SetPrecisionY(0);
193  $px2->SetCssPrefix("cssboxes");
194  $px2->mode='depth';
195  $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
196 
197  $px2->draw($filenamenb,$fileurlnb);
198  }
199  }
200 
201  if (empty($conf->use_javascript_ajax))
202  {
203  $langs->load("errors");
204  $mesg=$langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
205  }
206 
207  if (! $mesg)
208  {
209  $stringtoshow='';
210  $stringtoshow.='<script type="text/javascript" language="javascript">
211  jQuery(document).ready(function() {
212  jQuery("#idsubimg'.$this->boxcode.'").click(function() {
213  jQuery("#idfilter'.$this->boxcode.'").toggle();
214  });
215  });
216  </script>';
217  $stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
218  $stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
219  $stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
220  $stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
221  $stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked':'').'> '.$langs->trans("NumberOfOrdersByMonth");
222  $stringtoshow.=' &nbsp; ';
223  $stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked':'').'> '.$langs->trans("AmountOfOrdersByMonthHT");
224  $stringtoshow.='<br>';
225  $stringtoshow.=$langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
226  $stringtoshow.='<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"),'refresh.png','','',1).'">';
227  $stringtoshow.='</form>';
228  $stringtoshow.='</div>';
229  if ($shownb && $showtot)
230  {
231  $stringtoshow.='<div class="fichecenter">';
232  $stringtoshow.='<div class="fichehalfleft">';
233  }
234  if ($shownb) $stringtoshow.=$px1->show();
235  if ($shownb && $showtot)
236  {
237  $stringtoshow.='</div>';
238  $stringtoshow.='<div class="fichehalfright">';
239  }
240  if ($showtot) $stringtoshow.=$px2->show();
241  if ($shownb && $showtot)
242  {
243  $stringtoshow.='</div>';
244  $stringtoshow.='</div>';
245  }
246  $this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
247  }
248  else
249  {
250  $this->info_box_contents[0][0] = array( 'td' => 'align="left" class="nohover"',
251  'maxlength'=>500,
252  'text' => $mesg);
253  }
254 
255  }
256  else {
257  $this->info_box_contents[0][0] = array(
258  'td' => 'align="left" class="nohover opacitymedium"',
259  'text' => $langs->trans("ReadPermissionNotAllowed")
260  );
261  }
262  }
263 
272  function showBox($head = null, $contents = null, $nooutput=0)
273  {
274  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
275  }
276 
277 }
278 
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
loadBox($max=5)
Load data into info_box_contents array to show array later.
Class ModeleBoxes.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode='gmt')
Return date for now.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage order statistics (customer and supplier)
Class to manage the box to show last orders.
Class to build graphs.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.