dolibarr  9.0.0
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 // Load translation files required by the page
61 $langs->loadLangs(array('bills', 'companies', 'other'));
62 
63 $form=new Form($db);
64 
65 llxHeader();
66 
67 if ($mode == 'customer')
68 {
69  $title=$langs->trans("BillsStatistics");
70  $dir=$conf->facture->dir_temp;
71 }
72 if ($mode == 'supplier')
73 {
74  $title=$langs->trans("BillsStatisticsSuppliers");
75  $dir=$conf->fournisseur->facture->dir_temp;
76 }
77 
78 print load_fiche_titre($title, $mesg, 'title_accountancy.png');
79 
80 dol_mkdir($dir);
81 
82 $stats = new FactureStats($db, $socid, $mode, ($userid>0?$userid:0));
83 if ($mode == 'customer')
84 {
85  if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->escape($object_status).')';
86 }
87 if ($mode == 'supplier')
88 {
89  if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->escape($object_status).')';
90 }
91 
92 // Build graphic number of object
93 // $data = array(array('Lib',val1,val2,val3),...)
94 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
95 //var_dump($data);
96 
97 $filenamenb = $dir."/invoicesnbinyear-".$year.".png";
98 if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
99 if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesnbinyear-'.$year.'.png';
100 
101 $px1 = new DolGraph();
102 $mesg = $px1->isGraphKo();
103 if (! $mesg)
104 {
105  $px1->SetData($data);
106  $px1->SetPrecisionY(0);
107  $i=$startyear;$legend=array();
108  while ($i <= $endyear)
109  {
110  $legend[]=$i;
111  $i++;
112  }
113  $px1->SetLegend($legend);
114  $px1->SetMaxValue($px1->GetCeilMaxValue());
115  $px1->SetWidth($WIDTH);
116  $px1->SetHeight($HEIGHT);
117  $px1->SetYLabel($langs->trans("NumberOfBills"));
118  $px1->SetShading(3);
119  $px1->SetHorizTickIncrement(1);
120  $px1->SetPrecisionY(0);
121  $px1->mode='depth';
122  $px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
123 
124  $px1->draw($filenamenb,$fileurlnb);
125 }
126 
127 // Build graphic amount of object
128 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
129 //var_dump($data);
130 // $data = array(array('Lib',val1,val2,val3),...)
131 
132 $filenameamount = $dir."/invoicesamountinyear-".$year.".png";
133 if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
134 if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesamountinyear-'.$year.'.png';
135 
136 $px2 = new DolGraph();
137 $mesg = $px2->isGraphKo();
138 if (! $mesg)
139 {
140  $px2->SetData($data);
141  $i=$startyear;$legend=array();
142  while ($i <= $endyear)
143  {
144  $legend[]=$i;
145  $i++;
146  }
147  $px2->SetLegend($legend);
148  $px2->SetMaxValue($px2->GetCeilMaxValue());
149  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
150  $px2->SetWidth($WIDTH);
151  $px2->SetHeight($HEIGHT);
152  $px2->SetYLabel($langs->trans("AmountOfBills"));
153  $px2->SetShading(3);
154  $px2->SetHorizTickIncrement(1);
155  $px2->SetPrecisionY(0);
156  $px2->mode='depth';
157  $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
158 
159  $px2->draw($filenameamount,$fileurlamount);
160 }
161 
162 
163 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
164 
165 if (!$user->rights->societe->client->voir || $user->societe_id)
166 {
167  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
168  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
169  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
170 }
171 else
172 {
173  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
174  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
175  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
176 }
177 
178 $px3 = new DolGraph();
179 $mesg = $px3->isGraphKo();
180 if (! $mesg)
181 {
182  $px3->SetData($data);
183  $i = $startyear;$legend=array();
184  while ($i <= $endyear)
185  {
186  $legend[]=$i;
187  $i++;
188  }
189  $px3->SetLegend($legend);
190  $px3->SetYLabel($langs->trans("AmountAverage"));
191  $px3->SetMaxValue($px3->GetCeilMaxValue());
192  $px3->SetMinValue($px3->GetFloorMinValue());
193  $px3->SetWidth($WIDTH);
194  $px3->SetHeight($HEIGHT);
195  $px3->SetShading(3);
196  $px3->SetHorizTickIncrement(1);
197  $px3->SetPrecisionY(0);
198  $px3->mode='depth';
199  $px3->SetTitle($langs->trans("AmountAverage"));
200 
201  $px3->draw($filename_avg,$fileurl_avg);
202 }
203 
204 
205 // Show array
206 $data = $stats->getAllByYear();
207 $arrayyears=array();
208 foreach($data as $val) {
209  $arrayyears[$val['year']]=$val['year'];
210 }
211 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
212 
213 
214 $h=0;
215 $head = array();
216 $head[$h][0] = DOL_URL_ROOT . '/compta/facture/stats/index.php?mode='.$mode;
217 $head[$h][1] = $langs->trans("ByMonthYear");
218 $head[$h][2] = 'byyear';
219 $h++;
220 
221 if ($mode == 'customer') $type='invoice_stats';
222 if ($mode == 'supplier') $type='supplier_invoice_stats';
223 
224 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
225 
226 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
227 
228 // We use select_thirdparty_list instead of select_company so we can use $filter and share same code for customer and supplier.
229 $tmp_companies = $form->select_thirdparty_list($socid, 'socid', $filter, 1, 0, 0, array(), '', 1);
230 //Array passed as an argument to Form::selectarray to build a proper select input
231 $companies = array();
232 
233 foreach ($tmp_companies as $value) {
234  $companies[$value['key']] = $value['label'];
235 }
236 
237 print '<div class="fichecenter"><div class="fichethirdleft">';
238 
239 
240 //if (empty($socid))
241 //{
242  // Show filter box
243  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
244  print '<input type="hidden" name="mode" value="'.$mode.'">';
245  print '<table class="noborder" width="100%">';
246  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
247  // Company
248  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
249  if ($mode == 'customer') $filter='s.client in (1,2,3)';
250  if ($mode == 'supplier') $filter='s.fournisseur = 1';
251  print $form->selectarray('socid', $companies, $socid, 1, 0, 0, 'style="width: 95%"', 0, 0, 0, '', '', 1);
252  print '</td></tr>';
253  // User
254  print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
255  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
256  print '</td></tr>';
257  // Status
258  print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
259  if ($mode == 'customer')
260  {
261  $liststatus=array('0'=>$langs->trans("BillStatusDraft"), '1'=>$langs->trans("BillStatusNotPaid"), '2'=>$langs->trans("BillStatusPaid"), '3'=>$langs->trans("BillStatusCanceled"));
262  print $form->selectarray('object_status', $liststatus, $object_status, 1);
263  }
264  if ($mode == 'supplier')
265  {
266  $liststatus=array('0'=>$langs->trans("BillStatusDraft"),'1'=>$langs->trans("BillStatusNotPaid"), '2'=>$langs->trans("BillStatusPaid"));
267  print $form->selectarray('object_status', $liststatus, $object_status, 1);
268  }
269  print '</td></tr>';
270  // Year
271  print '<tr><td>'.$langs->trans("Year").'</td><td>';
272  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
273  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
274  arsort($arrayyears);
275  print $form->selectarray('year',$arrayyears,$year,0);
276  print '</td></tr>';
277  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
278  print '</table>';
279  print '</form>';
280  print '<br><br>';
281 //}
282 
283 print '<div class="div-table-responsive-no-min">';
284 print '<table class="noborder" width="100%">';
285 print '<tr class="liste_titre" height="24">';
286 print '<td align="center">'.$langs->trans("Year").'</td>';
287 print '<td align="right">'.$langs->trans("NumberOfBills").'</td>';
288 print '<td align="right">%</td>';
289 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
290 print '<td align="right">%</td>';
291 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
292 print '<td align="right">%</td>';
293 print '</tr>';
294 
295 $oldyear=0;
296 foreach ($data as $val)
297 {
298  $year = $val['year'];
299  while ($year && $oldyear > $year+1)
300  { // If we have empty year
301  $oldyear--;
302 
303  print '<tr class="oddeven" height="24">';
304  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>';
305  print '<td align="right">0</td>';
306  print '<td align="right"></td>';
307  print '<td align="right">0</td>';
308  print '<td align="right"></td>';
309  print '<td align="right">0</td>';
310  print '<td align="right"></td>';
311  print '</tr>';
312  }
313 
314  print '<tr class="oddeven" height="24">';
315  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>';
316  print '<td align="right">'.$val['nb'].'</td>';
317  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
318  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
319  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
320  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
321  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
322  print '</tr>';
323  $oldyear=$year;
324 }
325 
326 print '</table>';
327 print '</div>';
328 
329 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
330 
331 
332 // Show graphs
333 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
334 if ($mesg) { print $mesg; }
335 else {
336  print $px1->show();
337  print "<br>\n";
338  print $px2->show();
339  print "<br>\n";
340  print $px3->show();
341 }
342 print '</td></tr></table>';
343 
344 
345 print '</div></div></div>';
346 print '<div style="clear:both"></div>';
347 
348 
349 dol_fiche_end();
350 
351 // End of page
352 llxFooter();
353 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
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:36
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_now($mode='gmt')
Return date for now.
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 &#39;...
Class to manage stats for invoices (customer and supplier)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.