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