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