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-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionstats.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 
33 
34 $userid=GETPOST('userid','int');
35 $socid=GETPOST('socid','int');
36 // Security check
37 if ($user->societe_id > 0)
38 {
39  $action = '';
40  $socid = $user->societe_id;
41 }
42 
43 $nowyear=strftime("%Y", dol_now());
44 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
45 //$startyear=$year-2;
46 $startyear=$year-1;
47 $endyear=$year;
48 
49 $langs->load("sendings");
50 $langs->load("other");
51 $langs->load("companies");
52 
53 
54 /*
55  * View
56  */
57 
58 $form=new Form($db);
59 
60 llxHeader();
61 
62 print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg);
63 
64 
65 dol_mkdir($dir);
66 
67 $stats = new ExpeditionStats($db, $socid, $mode, ($userid>0?$userid:0));
68 
69 // Build graphic number of object
70 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
71 //var_dump($data);exit;
72 // $data = array(array('Lib',val1,val2,val3),...)
73 
74 
75 if (!$user->rights->societe->client->voir || $user->societe_id)
76 {
77  $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
78  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
79  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
80 }
81 else
82 {
83  $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
84  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png';
85  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png';
86 }
87 
88 $px1 = new DolGraph();
89 $mesg = $px1->isGraphKo();
90 if (! $mesg)
91 {
92  $px1->SetData($data);
93  $px1->SetPrecisionY(0);
94  $i=$startyear;$legend=array();
95  while ($i <= $endyear)
96  {
97  $legend[]=$i;
98  $i++;
99  }
100  $px1->SetLegend($legend);
101  $px1->SetMaxValue($px1->GetCeilMaxValue());
102  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
103  $px1->SetWidth($WIDTH);
104  $px1->SetHeight($HEIGHT);
105  $px1->SetYLabel($langs->trans("NbOfSendings"));
106  $px1->SetShading(3);
107  $px1->SetHorizTickIncrement(1);
108  $px1->SetPrecisionY(0);
109  $px1->mode='depth';
110  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
111 
112  $px1->draw($filenamenb,$fileurlnb);
113 }
114 
115 // Build graphic amount of object
116 /*
117 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
118 //var_dump($data);
119 // $data = array(array('Lib',val1,val2,val3),...)
120 
121 if (!$user->rights->societe->client->voir || $user->societe_id)
122 {
123  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
124  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
125  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
126 }
127 else
128 {
129  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
130  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$year.'.png';
131  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$year.'.png';
132 }
133 
134 $px2 = new DolGraph();
135 $mesg = $px2->isGraphKo();
136 if (! $mesg)
137 {
138  $px2->SetData($data);
139  $i=$startyear;$legend=array();
140  while ($i <= $endyear)
141  {
142  $legend[]=$i;
143  $i++;
144  }
145  $px2->SetLegend($legend);
146  $px2->SetMaxValue($px2->GetCeilMaxValue());
147  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
148  $px2->SetWidth($WIDTH);
149  $px2->SetHeight($HEIGHT);
150  $px2->SetYLabel($langs->trans("AmountOfShipments"));
151  $px2->SetShading(3);
152  $px2->SetHorizTickIncrement(1);
153  $px2->SetPrecisionY(0);
154  $px2->mode='depth';
155  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
156 
157  $px2->draw($filenameamount,$fileurlamount);
158 }
159 */
160 
161 /*
162 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
163 
164 if (!$user->rights->societe->client->voir || $user->societe_id)
165 {
166  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
167  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$user->id.'-'.$year.'.png';
168  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$user->id.'-'.$year.'.png';
169 }
170 else
171 {
172  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
173  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$year.'.png';
174  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$year.'.png';
175 }
176 
177 $px3 = new DolGraph();
178 $mesg = $px3->isGraphKo();
179 if (! $mesg)
180 {
181  $px3->SetData($data);
182  $i=$startyear;$legend=array();
183  while ($i <= $endyear)
184  {
185  $legend[]=$i;
186  $i++;
187  }
188  $px3->SetLegend($legend);
189  $px3->SetYLabel($langs->trans("AmountAverage"));
190  $px3->SetMaxValue($px3->GetCeilMaxValue());
191  $px3->SetMinValue($px3->GetFloorMinValue());
192  $px3->SetWidth($WIDTH);
193  $px3->SetHeight($HEIGHT);
194  $px3->SetShading(3);
195  $px3->SetHorizTickIncrement(1);
196  $px3->SetPrecisionY(0);
197  $px3->mode='depth';
198  $px3->SetTitle($langs->trans("AmountAverage"));
199 
200  $px3->draw($filename_avg,$fileurl_avg);
201 }
202 */
203 
204 
205 // Show array
206 $data = $stats->getAllByYear();
207 $arrayyears=array();
208 foreach($data as $val) {
209  if (! empty($val['year'])) {
210  $arrayyears[$val['year']]=$val['year'];
211  }
212 }
213 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
214 
215 $h=0;
216 $head = array();
217 $head[$h][0] = DOL_URL_ROOT . '/commande/stats/index.php?mode='.$mode;
218 $head[$h][1] = $langs->trans("ByMonthYear");
219 $head[$h][2] = 'byyear';
220 $h++;
221 
222 $type='shipment_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 
229 print '<div class="fichecenter"><div class="fichethirdleft">';
230 
231 
232 //if (empty($socid))
233 //{
234  // Show filter box
235  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
236  print '<input type="hidden" name="mode" value="'.$mode.'">';
237 
238  print '<table class="noborder" width="100%">';
239  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
240  // Company
241  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
242  if ($mode == 'customer') $filter='s.client in (1,2,3)';
243  if ($mode == 'supplier') $filter='s.fournisseur = 1';
244  print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
245  print '</td></tr>';
246  // User
247  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
248  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
249  print '</td></tr>';
250  // Year
251  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
252  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
253  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
254  arsort($arrayyears);
255  print $form->selectarray('year',$arrayyears,$year,0);
256  print '</td></tr>';
257  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
258  print '</table>';
259  print '</form>';
260  print '<br><br>';
261 //}
262 
263 print '<table class="noborder" width="100%">';
264 print '<tr class="liste_titre" height="24">';
265 print '<td align="center">'.$langs->trans("Year").'</td>';
266 print '<td align="right">'.$langs->trans("NbOfSendings").'</td>';
267 /*print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
268 print '<td align="center">'.$langs->trans("AmountAverage").'</td>';*/
269 print '</tr>';
270 
271 $oldyear=0;
272 foreach ($data as $val)
273 {
274  $year = $val['year'];
275  while (! empty($year) && $oldyear > $year+1)
276  { // If we have empty year
277  $oldyear--;
278 
279 
280  print '<tr class="oddeven" height="24">';
281  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
282 
283  print '<td align="right">0</td>';
284  /*print '<td align="right">0</td>';
285  print '<td align="right">0</td>';*/
286  print '</tr>';
287  }
288 
289  print '<tr class="oddeven" height="24">';
290  print '<td align="center">';
291  if ($year) print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a>';
292  else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated");
293  print '</td>';
294  print '<td align="right">'.$val['nb'].'</td>';
295  /*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
296  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
297  print '</tr>';
298  $oldyear=$year;
299 }
300 
301 print '</table>';
302 
303 
304 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
305 
306 
307 // Show graphs
308 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
309 if ($mesg) { print $mesg; }
310 else {
311  print $px1->show();
312  print "<br>\n";
313  /*print $px2->show();
314  print "<br>\n";
315  print $px3->show();*/
316 }
317 print '</td></tr></table>';
318 
319 
320 print '</div></div></div>';
321 print '<div style="clear:both"></div>';
322 
323 dol_fiche_end();
324 
325 
326 
327 // TODO USe code similar to commande/stats/index.php instead of this one.
328 /*
329 print '<table class="border" width="100%">';
330 print '<tr><td align="center">'.$langs->trans("Year").'</td>';
331 print '<td width="40%" align="center">'.$langs->trans("NbOfSendings").'</td></tr>';
332 
333 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
334 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
335 $sql.= " WHERE fk_statut > 0";
336 $sql.= " AND entity = ".$conf->entity;
337 $sql.= " GROUP BY dm DESC";
338 
339 $resql=$db->query($sql);
340 if ($resql)
341 {
342  $num = $db->num_rows($resql);
343  $i = 0;
344  while ($i < $num)
345  {
346  $row = $db->fetch_row($resql);
347  $nbproduct = $row[0];
348  $year = $row[1];
349  print "<tr>";
350  print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td align="center">'.$nbproduct.'</td></tr>';
351  $i++;
352  }
353 }
354 $db->free($resql);
355 
356 print '</table>';
357 */
358 
359 print '<br>';
360 print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
361 
362 llxFooter();
363 
364 $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.
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
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)
Class to manage shipment statistics.