dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
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.'/commande/class/commande.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
33 
36 
37 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
38 if ($mode == 'customer' && ! $user->rights->commande->lire) accessforbidden();
39 if ($mode == 'supplier' && ! $user->rights->fournisseur->commande->lire) accessforbidden();
40 
41 $object_status=GETPOST('object_status');
42 
43 $userid=GETPOST('userid','int');
44 $socid=GETPOST('socid','int');
45 // Security check
46 if ($user->societe_id > 0)
47 {
48  $action = '';
49  $socid = $user->societe_id;
50 }
51 
52 $nowyear=strftime("%Y", dol_now());
53 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
54 //$startyear=$year-2;
55 $startyear=$year-1;
56 $endyear=$year;
57 
58 $langs->load('orders');
59 $langs->load('companies');
60 $langs->load('other');
61 $langs->load('suppliers');
62 
63 
64 /*
65  * View
66  */
67 
68 $form=new Form($db);
69 $formorder=new FormOrder($db);
70 
71 if ($mode == 'customer')
72 {
73  $title=$langs->trans("OrdersStatistics");
74  $dir=$conf->commande->dir_temp;
75 }
76 if ($mode == 'supplier')
77 {
78  $title=$langs->trans("OrdersStatisticsSuppliers").' ('.$langs->trans("SentToSuppliers").")";
79  $dir=$conf->fournisseur->commande->dir_temp;
80 }
81 
82 llxHeader('', $title);
83 
84 print load_fiche_titre($title,'','title_commercial.png');
85 
86 dol_mkdir($dir);
87 
88 $stats = new CommandeStats($db, $socid, $mode, ($userid>0?$userid:0));
89 if ($mode == 'customer')
90 {
91  if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')';
92 }
93 if ($mode == 'supplier')
94 {
95  if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')';
96 }
97 
98 
99 // Build graphic number of object
100 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
101 
102 //var_dump($data);
103 // $data = array(array('Lib',val1,val2,val3),...)
104 
105 
106 if (!$user->rights->societe->client->voir || $user->societe_id)
107 {
108  $filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png';
109  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
110  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
111 }
112 else
113 {
114  $filenamenb = $dir.'/ordersnbinyear-'.$year.'.png';
115  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
116  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png';
117 }
118 
119 $px1 = new DolGraph();
120 $mesg = $px1->isGraphKo();
121 if (! $mesg)
122 {
123  $px1->SetData($data);
124  $px1->SetPrecisionY(0);
125  $i=$startyear;$legend=array();
126  while ($i <= $endyear)
127  {
128  $legend[]=$i;
129  $i++;
130  }
131  $px1->SetLegend($legend);
132  $px1->SetMaxValue($px1->GetCeilMaxValue());
133  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
134  $px1->SetWidth($WIDTH);
135  $px1->SetHeight($HEIGHT);
136  $px1->SetYLabel($langs->trans("NbOfOrder"));
137  $px1->SetShading(3);
138  $px1->SetHorizTickIncrement(1);
139  $px1->SetPrecisionY(0);
140  $px1->mode='depth';
141  $px1->SetTitle($langs->trans("NumberOfOrdersByMonth"));
142 
143  $px1->draw($filenamenb,$fileurlnb);
144 }
145 
146 // Build graphic amount of object
147 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
148 //var_dump($data);
149 // $data = array(array('Lib',val1,val2,val3),...)
150 
151 if (!$user->rights->societe->client->voir || $user->societe_id)
152 {
153  $filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png';
154  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
155  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
156 }
157 else
158 {
159  $filenameamount = $dir.'/ordersamountinyear-'.$year.'.png';
160  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png';
161  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png';
162 }
163 
164 $px2 = new DolGraph();
165 $mesg = $px2->isGraphKo();
166 if (! $mesg)
167 {
168  $px2->SetData($data);
169  $i=$startyear;$legend=array();
170  while ($i <= $endyear)
171  {
172  $legend[]=$i;
173  $i++;
174  }
175  $px2->SetLegend($legend);
176  $px2->SetMaxValue($px2->GetCeilMaxValue());
177  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
178  $px2->SetWidth($WIDTH);
179  $px2->SetHeight($HEIGHT);
180  $px2->SetYLabel($langs->trans("AmountOfOrders"));
181  $px2->SetShading(3);
182  $px2->SetHorizTickIncrement(1);
183  $px2->SetPrecisionY(0);
184  $px2->mode='depth';
185  $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
186 
187  $px2->draw($filenameamount,$fileurlamount);
188 }
189 
190 
191 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
192 
193 if (!$user->rights->societe->client->voir || $user->societe_id)
194 {
195  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
196  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
197  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
198 }
199 else
200 {
201  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
202  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
203  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
204 }
205 
206 $px3 = new DolGraph();
207 $mesg = $px3->isGraphKo();
208 if (! $mesg)
209 {
210  $px3->SetData($data);
211  $i=$startyear;$legend=array();
212  while ($i <= $endyear)
213  {
214  $legend[]=$i;
215  $i++;
216  }
217  $px3->SetLegend($legend);
218  $px3->SetYLabel($langs->trans("AmountAverage"));
219  $px3->SetMaxValue($px3->GetCeilMaxValue());
220  $px3->SetMinValue($px3->GetFloorMinValue());
221  $px3->SetWidth($WIDTH);
222  $px3->SetHeight($HEIGHT);
223  $px3->SetShading(3);
224  $px3->SetHorizTickIncrement(1);
225  $px3->SetPrecisionY(0);
226  $px3->mode='depth';
227  $px3->SetTitle($langs->trans("AmountAverage"));
228 
229  $px3->draw($filename_avg,$fileurl_avg);
230 }
231 
232 
233 
234 // Show array
235 $data = $stats->getAllByYear();
236 $arrayyears=array();
237 foreach($data as $val) {
238  if (! empty($val['year'])) {
239  $arrayyears[$val['year']]=$val['year'];
240  }
241 }
242 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
243 
244 $h=0;
245 $head = array();
246 $head[$h][0] = DOL_URL_ROOT . '/commande/stats/index.php?mode='.$mode;
247 $head[$h][1] = $langs->trans("ByMonthYear");
248 $head[$h][2] = 'byyear';
249 $h++;
250 
251 if ($mode == 'customer') $type='order_stats';
252 if ($mode == 'supplier') $type='supplier_order_stats';
253 
254 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
255 
256 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
257 
258 
259 print '<div class="fichecenter"><div class="fichethirdleft">';
260 
261 
262 // Show filter box
263 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
264 print '<input type="hidden" name="mode" value="'.$mode.'">';
265 print '<table class="noborder" width="100%">';
266 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
267 // Company
268 print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
269 if ($mode == 'customer') $filter='s.client in (1,2,3)';
270 if ($mode == 'supplier') $filter='s.fournisseur = 1';
271 print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
272 print '</td></tr>';
273 // User
274 print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
275 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
276 // Status
277 print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
278 if ($mode == 'customer')
279 {
280  $liststatus=array(
281  Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraft"),
282  Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
283  Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSent"),
284  Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
285  Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceled")
286  );
287  print $form->selectarray('object_status', $liststatus, GETPOST('object_status'), -4);
288 }
289 if ($mode == 'supplier')
290 {
291  $formorder->selectSupplierOrderStatus((strstr($object_status, ',')?-1:$object_status), 0, 'object_status');
292 }
293 print '</td></tr>';
294 // Year
295 print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
296 if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
297 if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
298 arsort($arrayyears);
299 print $form->selectarray('year',$arrayyears,$year,0);
300 print '</td></tr>';
301 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
302 print '</table>';
303 print '</form>';
304 print '<br><br>';
305 
306 
307 print '<table class="noborder" width="100%">';
308 print '<tr class="liste_titre" height="24">';
309 print '<td align="center">'.$langs->trans("Year").'</td>';
310 print '<td align="right">'.$langs->trans("NbOfOrders").'</td>';
311 print '<td align="right">%</td>';
312 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
313 print '<td align="right">%</td>';
314 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
315 print '<td align="right">%</td>';
316 print '</tr>';
317 
318 $oldyear=0;
319 foreach ($data as $val)
320 {
321  $year = $val['year'];
322  while (! empty($year) && $oldyear > $year+1)
323  { // If we have empty year
324  $oldyear--;
325 
326  print '<tr class="oddeven" height="24">';
327  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>';
328  print '<td align="right">0</td>';
329  print '<td align="right"></td>';
330  print '<td align="right">0</td>';
331  print '<td align="right"></td>';
332  print '<td align="right">0</td>';
333  print '<td align="right"></td>';
334  print '</tr>';
335  }
336 
337 
338  print '<tr class="oddeven" height="24">';
339  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>';
340  print '<td align="right">'.$val['nb'].'</td>';
341  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
342  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
343  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
344  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
345  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
346  print '</tr>';
347  $oldyear=$year;
348 }
349 
350 print '</table>';
351 
352 
353 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
354 
355 
356 // Show graphs
357 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
358 if ($mesg) { print $mesg; }
359 else {
360  print $px1->show();
361  print "<br>\n";
362  print $px2->show();
363  print "<br>\n";
364  print $px3->show();
365 }
366 print '</td></tr></table>';
367 
368 
369 print '</div></div></div>';
370 print '<div style="clear:both"></div>';
371 
372 dol_fiche_end();
373 
374 
375 llxFooter();
376 
377 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
const STATUS_CLOSED
Closed (Sent, billed or not)
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).
const STATUS_SHIPMENTONPROCESS
Shipment on process.
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
Class to manage HTML output components for orders Before adding component here, check they are not in...
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.
const STATUS_DRAFT
Draft status.
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.
const STATUS_VALIDATED
Validated status.
Class to manage order statistics (customer and supplier)
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 '...
const STATUS_CANCELED
Canceled status.