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-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.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 // Load translation files required by the page
50 $langs->loadLangs(array('sendings', 'other', 'companies'));
51 
52 
53 /*
54  * View
55  */
56 
57 $form=new Form($db);
58 
59 llxHeader();
60 
61 print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg);
62 
63 
64 dol_mkdir($dir);
65 
66 $stats = new ExpeditionStats($db, $socid, $mode, ($userid>0?$userid:0));
67 
68 // Build graphic number of object
69 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
70 //var_dump($data);exit;
71 // $data = array(array('Lib',val1,val2,val3),...)
72 
73 
74 if (!$user->rights->societe->client->voir || $user->societe_id)
75 {
76  $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
77  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
78  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
79 }
80 else
81 {
82  $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
83  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png';
84  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png';
85 }
86 
87 $px1 = new DolGraph();
88 $mesg = $px1->isGraphKo();
89 if (! $mesg)
90 {
91  $px1->SetData($data);
92  $px1->SetPrecisionY(0);
93  $i=$startyear;$legend=array();
94  while ($i <= $endyear)
95  {
96  $legend[]=$i;
97  $i++;
98  }
99  $px1->SetLegend($legend);
100  $px1->SetMaxValue($px1->GetCeilMaxValue());
101  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
102  $px1->SetWidth($WIDTH);
103  $px1->SetHeight($HEIGHT);
104  $px1->SetYLabel($langs->trans("NbOfSendings"));
105  $px1->SetShading(3);
106  $px1->SetHorizTickIncrement(1);
107  $px1->SetPrecisionY(0);
108  $px1->mode='depth';
109  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
110 
111  $px1->draw($filenamenb,$fileurlnb);
112 }
113 
114 // Build graphic amount of object
115 /*
116 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
117 //var_dump($data);
118 // $data = array(array('Lib',val1,val2,val3),...)
119 
120 if (!$user->rights->societe->client->voir || $user->societe_id)
121 {
122  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
123  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
124  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
125 }
126 else
127 {
128  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
129  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$year.'.png';
130  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$year.'.png';
131 }
132 
133 $px2 = new DolGraph();
134 $mesg = $px2->isGraphKo();
135 if (! $mesg)
136 {
137  $px2->SetData($data);
138  $i=$startyear;$legend=array();
139  while ($i <= $endyear)
140  {
141  $legend[]=$i;
142  $i++;
143  }
144  $px2->SetLegend($legend);
145  $px2->SetMaxValue($px2->GetCeilMaxValue());
146  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
147  $px2->SetWidth($WIDTH);
148  $px2->SetHeight($HEIGHT);
149  $px2->SetYLabel($langs->trans("AmountOfShipments"));
150  $px2->SetShading(3);
151  $px2->SetHorizTickIncrement(1);
152  $px2->SetPrecisionY(0);
153  $px2->mode='depth';
154  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
155 
156  $px2->draw($filenameamount,$fileurlamount);
157 }
158 */
159 
160 /*
161 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
162 
163 if (!$user->rights->societe->client->voir || $user->societe_id)
164 {
165  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
166  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$user->id.'-'.$year.'.png';
167  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$user->id.'-'.$year.'.png';
168 }
169 else
170 {
171  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
172  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$year.'.png';
173  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$year.'.png';
174 }
175 
176 $px3 = new DolGraph();
177 $mesg = $px3->isGraphKo();
178 if (! $mesg)
179 {
180  $px3->SetData($data);
181  $i=$startyear;$legend=array();
182  while ($i <= $endyear)
183  {
184  $legend[]=$i;
185  $i++;
186  }
187  $px3->SetLegend($legend);
188  $px3->SetYLabel($langs->trans("AmountAverage"));
189  $px3->SetMaxValue($px3->GetCeilMaxValue());
190  $px3->SetMinValue($px3->GetFloorMinValue());
191  $px3->SetWidth($WIDTH);
192  $px3->SetHeight($HEIGHT);
193  $px3->SetShading(3);
194  $px3->SetHorizTickIncrement(1);
195  $px3->SetPrecisionY(0);
196  $px3->mode='depth';
197  $px3->SetTitle($langs->trans("AmountAverage"));
198 
199  $px3->draw($filename_avg,$fileurl_avg);
200 }
201 */
202 
203 
204 // Show array
205 $data = $stats->getAllByYear();
206 $arrayyears=array();
207 foreach($data as $val) {
208  if (! empty($val['year'])) {
209  $arrayyears[$val['year']]=$val['year'];
210  }
211 }
212 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
213 
214 $h=0;
215 $head = array();
216 $head[$h][0] = DOL_URL_ROOT . '/expedition/stats/index.php?mode='.$mode;
217 $head[$h][1] = $langs->trans("ByMonthYear");
218 $head[$h][2] = 'byyear';
219 $h++;
220 
221 $type='shipment_stats';
222 
223 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
224 
225 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
226 
227 
228 print '<div class="fichecenter"><div class="fichethirdleft">';
229 
230 
231 //if (empty($socid))
232 //{
233  // Show filter box
234  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
235  print '<input type="hidden" name="mode" value="'.$mode.'">';
236 
237  print '<table class="noborder" width="100%">';
238  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239  // Company
240  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241  if ($mode == 'customer') $filter='s.client in (1,2,3)';
242  if ($mode == 'supplier') $filter='s.fournisseur = 1';
243  print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
244  print '</td></tr>';
245  // User
246  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
247  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
248  print '</td></tr>';
249  // Year
250  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
253  arsort($arrayyears);
254  print $form->selectarray('year',$arrayyears,$year,0);
255  print '</td></tr>';
256  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
257  print '</table>';
258  print '</form>';
259  print '<br><br>';
260 //}
261 
262 
263 print '<div class="div-table-responsive-no-min">';
264 print '<table class="noborder" width="100%">';
265 print '<tr class="liste_titre" height="24">';
266 print '<td align="center">'.$langs->trans("Year").'</td>';
267 print '<td align="right">'.$langs->trans("NbOfSendings").'</td>';
268 /*print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
269 print '<td align="center">'.$langs->trans("AmountAverage").'</td>';*/
270 print '</tr>';
271 
272 $oldyear=0;
273 foreach ($data as $val)
274 {
275  $year = $val['year'];
276  while (! empty($year) && $oldyear > $year+1)
277  { // If we have empty year
278  $oldyear--;
279 
280 
281  print '<tr class="oddeven" height="24">';
282  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
283 
284  print '<td align="right">0</td>';
285  /*print '<td align="right">0</td>';
286  print '<td align="right">0</td>';*/
287  print '</tr>';
288  }
289 
290  print '<tr class="oddeven" height="24">';
291  print '<td align="center">';
292  if ($year) print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a>';
293  else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated");
294  print '</td>';
295  print '<td align="right">'.$val['nb'].'</td>';
296  /*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
297  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
298  print '</tr>';
299  $oldyear=$year;
300 }
301 
302 print '</table>';
303 print '</div>';
304 
305 
306 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
307 
308 
309 // Show graphs
310 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
311 if ($mesg) { print $mesg; }
312 else {
313  print $px1->show();
314  print "<br>\n";
315  /*print $px2->show();
316  print "<br>\n";
317  print $px3->show();*/
318 }
319 print '</td></tr></table>';
320 
321 
322 print '</div></div></div>';
323 print '<div style="clear:both"></div>';
324 
325 dol_fiche_end();
326 
327 
328 
329 // TODO USe code similar to commande/stats/index.php instead of this one.
330 /*
331 print '<table class="border" width="100%">';
332 print '<tr><td align="center">'.$langs->trans("Year").'</td>';
333 print '<td width="40%" align="center">'.$langs->trans("NbOfSendings").'</td></tr>';
334 
335 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
336 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
337 $sql.= " WHERE fk_statut > 0";
338 $sql.= " AND entity = ".$conf->entity;
339 $sql.= " GROUP BY dm DESC";
340 
341 $resql=$db->query($sql);
342 if ($resql)
343 {
344  $num = $db->num_rows($resql);
345  $i = 0;
346  while ($i < $num)
347  {
348  $row = $db->fetch_row($resql);
349  $nbproduct = $row[0];
350  $year = $row[1];
351  print "<tr>";
352  print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td align="center">'.$nbproduct.'</td></tr>';
353  $i++;
354  }
355 }
356 $db->free($resql);
357 
358 print '</table>';
359 */
360 
361 print '<br>';
362 print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
363 
364 // End of page
365 llxFooter();
366 $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).
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)
Class to manage shipment statistics.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.