dolibarr  9.0.0
box_graph_invoices_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="invoicespermonth";
32  var $boximg="object_bill";
33  var $boxlabel="BoxCustomersInvoicesPerMonth";
34  var $depends = array("facture");
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->facture->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.'/compta/facture/class/facture.class.php';
75  //$facturestatic=new Facture($db);
76 
77  $text = $langs->trans("BoxCustomersInvoicesPerMonth",$max);
78  $this->info_box_head = array(
79  'text' => $text,
80  'limit'=> dol_strlen($text),
81  'graph'=> 1,
82  'sublink'=>'',
83  'subtext'=>$langs->trans("Filter"),
84  'subpicto'=>'filter.png',
85  'subclass'=>'linkobject boxfilter',
86  'target'=>'none' // Set '' to get target="_blank"
87  );
88 
89  $dir=''; // We don't need a path because image file will not be saved into disk
90  $prefix='';
91  $socid=0;
92  if ($user->societe_id) $socid=$user->societe_id;
93  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
94 
95  if ($user->rights->facture->lire)
96  {
97  $mesg = '';
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.'/compta/facture/class/facturestats.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  $mode='customer';
124  $WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
125  $HEIGHT='192';
126 
127  $stats = new FactureStats($this->db, $socid, $mode, 0);
128 
129  // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
130  if ($shownb)
131  {
132  $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)), ($WIDTH<300?2:0));
133 
134  $filenamenb = $dir."/".$prefix."invoicesnbinyear-".$endyear.".png";
135  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$endyear.'.png';
136  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-'.$endyear.'.png';
137 
138  $px1 = new DolGraph();
139  $mesg = $px1->isGraphKo();
140  if (! $mesg)
141  {
142  $langs->load("bills");
143 
144  $px1->SetData($data1);
145  unset($data1);
146  $px1->SetPrecisionY(0);
147  $i=$startyear;$legend=array();
148  while ($i <= $endyear)
149  {
150  $legend[]=$i;
151  $i++;
152  }
153  $px1->SetLegend($legend);
154  $px1->SetMaxValue($px1->GetCeilMaxValue());
155  $px1->SetWidth($WIDTH);
156  $px1->SetHeight($HEIGHT);
157  $px1->SetYLabel($langs->trans("NumberOfBills"));
158  $px1->SetShading(3);
159  $px1->SetHorizTickIncrement(1);
160  $px1->SetPrecisionY(0);
161  $px1->SetCssPrefix("cssboxes");
162  $px1->mode='depth';
163  $px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
164 
165  $px1->draw($filenamenb,$fileurlnb);
166  }
167  }
168 
169  // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
170  if ($showtot)
171  {
172  $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)), ($WIDTH<300?2:0));
173 
174  $filenamenb = $dir."/".$prefix."invoicesamountinyear-".$endyear.".png";
175  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$endyear.'.png';
176  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-'.$endyear.'.png';
177 
178  $px2 = new DolGraph();
179  $mesg = $px2->isGraphKo();
180  if (! $mesg)
181  {
182  $langs->load("bills");
183 
184  $px2->SetData($data2);
185  unset($data2);
186  $px2->SetPrecisionY(0);
187  $i=$startyear;$legend=array();
188  while ($i <= $endyear)
189  {
190  $legend[]=$i;
191  $i++;
192  }
193  $px2->SetLegend($legend);
194  $px2->SetMaxValue($px2->GetCeilMaxValue());
195  $px2->SetWidth($WIDTH);
196  $px2->SetHeight($HEIGHT);
197  $px2->SetYLabel($langs->trans("AmountOfBillsHT"));
198  $px2->SetShading(3);
199  $px2->SetHorizTickIncrement(1);
200  $px2->SetPrecisionY(0);
201  $px2->SetCssPrefix("cssboxes");
202  $px2->mode='depth';
203  $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
204 
205  $px2->draw($filenamenb,$fileurlnb);
206  }
207  }
208 
209  if (empty($conf->use_javascript_ajax))
210  {
211  $langs->load("errors");
212  $mesg=$langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
213  }
214 
215  if (! $mesg)
216  {
217  $stringtoshow='';
218  $stringtoshow.='<script type="text/javascript" language="javascript">
219  jQuery(document).ready(function() {
220  jQuery("#idsubimg'.$this->boxcode.'").click(function() {
221  jQuery("#idfilter'.$this->boxcode.'").toggle();
222  });
223  });
224  </script>';
225  $stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
226  $stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
227  $stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
228  $stringtoshow.='<input type="hidden" name="page_y" value="">';
229  $stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
230  $stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked':'').'> '.$langs->trans("NumberOfBillsByMonth");
231  $stringtoshow.=' &nbsp; ';
232  $stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked':'').'> '.$langs->trans("AmountOfBillsByMonthHT");
233  $stringtoshow.='<br>';
234  $stringtoshow.=$langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
235  $stringtoshow.='<input class="reposition inline-block valigntextbottom" type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"),'refresh.png','','',1).'">';
236  $stringtoshow.='</form>';
237  $stringtoshow.='</div>';
238  if ($shownb && $showtot)
239  {
240  $stringtoshow.='<div class="fichecenter">';
241  $stringtoshow.='<div class="fichehalfleft">';
242  }
243  if ($shownb) $stringtoshow.=$px1->show();
244  if ($shownb && $showtot)
245  {
246  $stringtoshow.='</div>';
247  $stringtoshow.='<div class="fichehalfright">';
248  }
249  if ($showtot) $stringtoshow.=$px2->show();
250  if ($shownb && $showtot)
251  {
252  $stringtoshow.='</div>';
253  $stringtoshow.='</div>';
254  }
255  $this->info_box_contents[0][0] = array('tr'=>'class="oddeven nohover"', 'td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
256  }
257  else
258  {
259  $this->info_box_contents[0][0] = array('tr'=>'class="oddeven nohover"', 'td' => 'align="left" class="nohover"', 'maxlength'=>500, 'text' => $mesg);
260  }
261  }
262  else {
263  $this->info_box_contents[0][0] = array(
264  'td' => 'align="left" class="nohover opacitymedium"',
265  'text' => $langs->trans("ReadPermissionNotAllowed")
266  );
267  }
268  }
269 
278  function showBox($head = null, $contents = null, $nooutput=0)
279  {
280  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
281  }
282 }
283 
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
loadBox($max=5)
Load data into info_box_contents array to show array later.
Class to manage the box to show last invoices.
Class ModeleBoxes.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_now($mode='gmt')
Return date for now.
Class to build graphs.
__construct($db, $param)
Constructor.
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)
Class to manage stats for invoices (customer and supplier)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.