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