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