dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (c) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
5  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
31 
34 
35 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
36 if ($mode == 'customer' && ! $user->rights->facture->lire) accessforbidden();
37 if ($mode == 'supplier' && ! $user->rights->fournisseur->facture->lire) accessforbidden();
38 
39 $object_status=GETPOST('object_status');
40 
41 $userid=GETPOST('userid','int');
42 $socid=GETPOST('socid','int');
43 // Security check
44 if ($user->societe_id > 0)
45 {
46  $action = '';
47  $socid = $user->societe_id;
48 }
49 
50 $nowyear=strftime("%Y", dol_now());
51 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
52 //$startyear=$year-2;
53 $startyear=$year-1;
54 $endyear=$year;
55 
56 
57 /*
58  * View
59  */
60 
61 $langs->load('bills');
62 $langs->load('companies');
63 $langs->load('other');
64 
65 $form=new Form($db);
66 
67 llxHeader();
68 
69 if ($mode == 'customer')
70 {
71  $title=$langs->trans("BillsStatistics");
72  $dir=$conf->facture->dir_temp;
73 }
74 if ($mode == 'supplier')
75 {
76  $title=$langs->trans("BillsStatisticsSuppliers");
77  $dir=$conf->fournisseur->facture->dir_temp;
78 }
79 
80 print load_fiche_titre($title, $mesg, 'title_accountancy.png');
81 
82 dol_mkdir($dir);
83 
84 $stats = new FactureStats($db, $socid, $mode, ($userid>0?$userid:0));
85 if ($mode == 'customer')
86 {
87  if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->escape($object_status).')';
88 }
89 if ($mode == 'supplier')
90 {
91  if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->escape($object_status).')';
92 }
93 
94 // Build graphic number of object
95 // $data = array(array('Lib',val1,val2,val3),...)
96 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
97 //var_dump($data);
98 
99 $filenamenb = $dir."/invoicesnbinyear-".$year.".png";
100 if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
101 if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesnbinyear-'.$year.'.png';
102 
103 $px1 = new DolGraph();
104 $mesg = $px1->isGraphKo();
105 if (! $mesg)
106 {
107  $px1->SetData($data);
108  $px1->SetPrecisionY(0);
109  $i=$startyear;$legend=array();
110  while ($i <= $endyear)
111  {
112  $legend[]=$i;
113  $i++;
114  }
115  $px1->SetLegend($legend);
116  $px1->SetMaxValue($px1->GetCeilMaxValue());
117  $px1->SetWidth($WIDTH);
118  $px1->SetHeight($HEIGHT);
119  $px1->SetYLabel($langs->trans("NumberOfBills"));
120  $px1->SetShading(3);
121  $px1->SetHorizTickIncrement(1);
122  $px1->SetPrecisionY(0);
123  $px1->mode='depth';
124  $px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
125 
126  $px1->draw($filenamenb,$fileurlnb);
127 }
128 
129 // Build graphic amount of object
130 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
131 //var_dump($data);
132 // $data = array(array('Lib',val1,val2,val3),...)
133 
134 $filenameamount = $dir."/invoicesamountinyear-".$year.".png";
135 if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
136 if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesamountinyear-'.$year.'.png';
137 
138 $px2 = new DolGraph();
139 $mesg = $px2->isGraphKo();
140 if (! $mesg)
141 {
142  $px2->SetData($data);
143  $i=$startyear;$legend=array();
144  while ($i <= $endyear)
145  {
146  $legend[]=$i;
147  $i++;
148  }
149  $px2->SetLegend($legend);
150  $px2->SetMaxValue($px2->GetCeilMaxValue());
151  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
152  $px2->SetWidth($WIDTH);
153  $px2->SetHeight($HEIGHT);
154  $px2->SetYLabel($langs->trans("AmountOfBills"));
155  $px2->SetShading(3);
156  $px2->SetHorizTickIncrement(1);
157  $px2->SetPrecisionY(0);
158  $px2->mode='depth';
159  $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
160 
161  $px2->draw($filenameamount,$fileurlamount);
162 }
163 
164 
165 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
166 
167 if (!$user->rights->societe->client->voir || $user->societe_id)
168 {
169  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
170  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
171  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
172 }
173 else
174 {
175  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
176  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
177  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
178 }
179 
180 $px3 = new DolGraph();
181 $mesg = $px3->isGraphKo();
182 if (! $mesg)
183 {
184  $px3->SetData($data);
185  $i = $startyear;$legend=array();
186  while ($i <= $endyear)
187  {
188  $legend[]=$i;
189  $i++;
190  }
191  $px3->SetLegend($legend);
192  $px3->SetYLabel($langs->trans("AmountAverage"));
193  $px3->SetMaxValue($px3->GetCeilMaxValue());
194  $px3->SetMinValue($px3->GetFloorMinValue());
195  $px3->SetWidth($WIDTH);
196  $px3->SetHeight($HEIGHT);
197  $px3->SetShading(3);
198  $px3->SetHorizTickIncrement(1);
199  $px3->SetPrecisionY(0);
200  $px3->mode='depth';
201  $px3->SetTitle($langs->trans("AmountAverage"));
202 
203  $px3->draw($filename_avg,$fileurl_avg);
204 }
205 
206 
207 // Show array
208 $data = $stats->getAllByYear();
209 $arrayyears=array();
210 foreach($data as $val) {
211  $arrayyears[$val['year']]=$val['year'];
212 }
213 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
214 
215 
216 $h=0;
217 $head = array();
218 $head[$h][0] = DOL_URL_ROOT . '/compta/facture/stats/index.php?mode='.$mode;
219 $head[$h][1] = $langs->trans("ByMonthYear");
220 $head[$h][2] = 'byyear';
221 $h++;
222 
223 if ($mode == 'customer') $type='invoice_stats';
224 if ($mode == 'supplier') $type='supplier_invoice_stats';
225 
226 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
227 
228 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
229 
230 // We use select_thirdparty_list instead of select_company so we can use $filter and share same code for customer and supplier.
231 $tmp_companies = $form->select_thirdparty_list($socid, 'socid', $filter, 1, 0, 0, array(), '', 1);
232 //Array passed as an argument to Form::selectarray to build a proper select input
233 $companies = array();
234 
235 foreach ($tmp_companies as $value) {
236  $companies[$value['key']] = $value['label'];
237 }
238 
239 print '<div class="fichecenter"><div class="fichethirdleft">';
240 
241 
242 //if (empty($socid))
243 //{
244  // Show filter box
245  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
246  print '<input type="hidden" name="mode" value="'.$mode.'">';
247  print '<table class="noborder" width="100%">';
248  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
249  // Company
250  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
251  if ($mode == 'customer') $filter='s.client in (1,2,3)';
252  if ($mode == 'supplier') $filter='s.fournisseur = 1';
253  print $form->selectarray('socid', $companies, $socid, 1, 0, 0, 'style="width: 95%"', 0, 0, 0, '', '', 1);
254  print '</td></tr>';
255  // User
256  print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
257  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
258  print '</td></tr>';
259  // Status
260  print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
261  if ($mode == 'customer')
262  {
263  $liststatus=array('0'=>$langs->trans("BillStatusDraft"), '1'=>$langs->trans("BillStatusNotPaid"), '2'=>$langs->trans("BillStatusPaid"), '3'=>$langs->trans("BillStatusCanceled"));
264  print $form->selectarray('object_status', $liststatus, $object_status, 1);
265  }
266  if ($mode == 'supplier')
267  {
268  $liststatus=array('0'=>$langs->trans("BillStatusDraft"),'1'=>$langs->trans("BillStatusNotPaid"), '2'=>$langs->trans("BillStatusPaid"));
269  print $form->selectarray('object_status', $liststatus, $object_status, 1);
270  }
271  print '</td></tr>';
272  // Year
273  print '<tr><td>'.$langs->trans("Year").'</td><td>';
274  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
275  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
276  arsort($arrayyears);
277  print $form->selectarray('year',$arrayyears,$year,0);
278  print '</td></tr>';
279  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
280  print '</table>';
281  print '</form>';
282  print '<br><br>';
283 //}
284 
285 print '<table class="noborder" width="100%">';
286 print '<tr class="liste_titre" height="24">';
287 print '<td align="center">'.$langs->trans("Year").'</td>';
288 print '<td align="right">'.$langs->trans("NumberOfBills").'</td>';
289 print '<td align="right">%</td>';
290 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
291 print '<td align="right">%</td>';
292 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
293 print '<td align="right">%</td>';
294 print '</tr>';
295 
296 $oldyear=0;
297 foreach ($data as $val)
298 {
299  $year = $val['year'];
300  while ($year && $oldyear > $year+1)
301  { // If we have empty year
302  $oldyear--;
303 
304  print '<tr class="oddeven" height="24">';
305  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$oldyear.'</a></td>';
306  print '<td align="right">0</td>';
307  print '<td align="right"></td>';
308  print '<td align="right">0</td>';
309  print '<td align="right"></td>';
310  print '<td align="right">0</td>';
311  print '<td align="right"></td>';
312  print '</tr>';
313  }
314 
315  print '<tr class="oddeven" height="24">';
316  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$year.'</a></td>';
317  print '<td align="right">'.$val['nb'].'</td>';
318  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
319  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
320  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
321  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
322  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
323  print '</tr>';
324  $oldyear=$year;
325 }
326 
327 print '</table>';
328 
329 
330 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
331 
332 
333 // Show graphs
334 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
335 if ($mesg) { print $mesg; }
336 else {
337  print $px1->show();
338  print "<br>\n";
339  print $px2->show();
340  print "<br>\n";
341  print $px3->show();
342 }
343 print '</td></tr></table>';
344 
345 
346 print '</div></div></div>';
347 print '<div style="clear:both"></div>';
348 
349 
350 dol_fiche_end();
351 
352 
353 llxFooter();
354 
355 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:37
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_now($mode='gmt')
Return date for now.
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage stats for invoices (customer and supplier)