dolibarr  13.0.2
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 <https://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 
32 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
33 
34 $userid = GETPOST('userid', 'int');
35 $socid = GETPOST('socid', 'int');
36 // Security check
37 if ($user->socid > 0)
38 {
39  $action = '';
40  $socid = $user->socid;
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"), '', 'dolly');
62 
63 
64 dol_mkdir($dir);
65 
66 $stats = new ExpeditionStats($db, $socid, '', ($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->socid)
75 {
76  $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
77 } else {
78  $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
79 }
80 
81 $px1 = new DolGraph();
82 $mesg = $px1->isGraphKo();
83 if (!$mesg)
84 {
85  $px1->SetData($data);
86  $i = $startyear; $legend = array();
87  while ($i <= $endyear)
88  {
89  $legend[] = $i;
90  $i++;
91  }
92  $px1->SetLegend($legend);
93  $px1->SetMaxValue($px1->GetCeilMaxValue());
94  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
95  $px1->SetWidth($WIDTH);
96  $px1->SetHeight($HEIGHT);
97  $px1->SetYLabel($langs->trans("NbOfSendings"));
98  $px1->SetShading(3);
99  $px1->SetHorizTickIncrement(1);
100  $px1->mode = 'depth';
101  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
102 
103  $px1->draw($filenamenb, $fileurlnb);
104 }
105 
106 // Build graphic amount of object
107 /*
108 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
109 //var_dump($data);
110 // $data = array(array('Lib',val1,val2,val3),...)
111 
112 if (!$user->rights->societe->client->voir || $user->socid)
113 {
114  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
115 }
116 else
117 {
118  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
119 }
120 
121 $px2 = new DolGraph();
122 $mesg = $px2->isGraphKo();
123 if (! $mesg)
124 {
125  $px2->SetData($data);
126  $i=$startyear;$legend=array();
127  while ($i <= $endyear)
128  {
129  $legend[]=$i;
130  $i++;
131  }
132  $px2->SetLegend($legend);
133  $px2->SetMaxValue($px2->GetCeilMaxValue());
134  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
135  $px2->SetWidth($WIDTH);
136  $px2->SetHeight($HEIGHT);
137  $px2->SetYLabel($langs->trans("AmountOfShipments"));
138  $px2->SetShading(3);
139  $px2->SetHorizTickIncrement(1);
140  $px2->mode='depth';
141  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
142 
143  $px2->draw($filenameamount,$fileurlamount);
144 }
145 */
146 
147 /*
148 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
149 
150 if (!$user->rights->societe->client->voir || $user->socid)
151 {
152  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
153 }
154 else
155 {
156  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
157 }
158 
159 $px3 = new DolGraph();
160 $mesg = $px3->isGraphKo();
161 if (! $mesg)
162 {
163  $px3->SetData($data);
164  $i=$startyear;$legend=array();
165  while ($i <= $endyear)
166  {
167  $legend[]=$i;
168  $i++;
169  }
170  $px3->SetLegend($legend);
171  $px3->SetYLabel($langs->trans("AmountAverage"));
172  $px3->SetMaxValue($px3->GetCeilMaxValue());
173  $px3->SetMinValue($px3->GetFloorMinValue());
174  $px3->SetWidth($WIDTH);
175  $px3->SetHeight($HEIGHT);
176  $px3->SetShading(3);
177  $px3->SetHorizTickIncrement(1);
178  $px3->mode='depth';
179  $px3->SetTitle($langs->trans("AmountAverage"));
180 
181  $px3->draw($filename_avg,$fileurl_avg);
182 }
183 */
184 
185 
186 // Show array
187 $data = $stats->getAllByYear();
188 $arrayyears = array();
189 foreach ($data as $val) {
190  if (!empty($val['year'])) {
191  $arrayyears[$val['year']] = $val['year'];
192  }
193 }
194 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
195 
196 $h = 0;
197 $head = array();
198 $head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php';
199 $head[$h][1] = $langs->trans("ByMonthYear");
200 $head[$h][2] = 'byyear';
201 $h++;
202 
203 $type = 'shipment_stats';
204 
205 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
206 
207 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
208 
209 
210 print '<div class="fichecenter"><div class="fichethirdleft">';
211 
212 
213 //if (empty($socid))
214 //{
215  // Show filter box
216  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
217  print '<input type="hidden" name="token" value="'.newToken().'">';
218 
219  print '<table class="noborder centpercent">';
220  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
221  // Company
222  print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
223  print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, '', 'style="width: 95%"');
224  print '</td></tr>';
225  // User
226  print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
227  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
228  print '</td></tr>';
229  // Year
230  print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
231  if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
232  if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
233  arsort($arrayyears);
234  print $form->selectarray('year', $arrayyears, $year, 0);
235  print '</td></tr>';
236  print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
237  print '</table>';
238  print '</form>';
239  print '<br><br>';
240 //}
241 
242 
243 print '<div class="div-table-responsive-no-min">';
244 print '<table class="noborder centpercent">';
245 print '<tr class="liste_titre" height="24">';
246 print '<td class="center">'.$langs->trans("Year").'</td>';
247 print '<td class="right">'.$langs->trans("NbOfSendings").'</td>';
248 /*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
249 print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
250 print '</tr>';
251 
252 $oldyear = 0;
253 foreach ($data as $val)
254 {
255  $year = $val['year'];
256  while (!empty($year) && $oldyear > $year + 1)
257  { // If we have empty year
258  $oldyear--;
259 
260 
261  print '<tr class="oddeven" height="24">';
262  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
263 
264  print '<td class="right">0</td>';
265  /*print '<td class="right">0</td>';
266  print '<td class="right">0</td>';*/
267  print '</tr>';
268  }
269 
270  print '<tr class="oddeven" height="24">';
271  print '<td class="center">';
272  if ($year) {
273  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
274  } else {
275  // Technical error that should not happen
276  print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed';
277  }
278  print '</td>';
279  print '<td class="right">'.$val['nb'].'</td>';
280  /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
281  print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
282  print '</tr>';
283  $oldyear = $year;
284 }
285 
286 print '</table>';
287 print '</div>';
288 
289 
290 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
291 
292 
293 // Show graphs
294 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
295 if ($mesg) { print $mesg; } else {
296  print $px1->show();
297  print "<br>\n";
298  /*print $px2->show();
299  print "<br>\n";
300  print $px3->show();*/
301 }
302 print '</td></tr></table>';
303 
304 
305 print '</div></div></div>';
306 print '<div style="clear:both"></div>';
307 
308 print dol_get_fiche_end();
309 
310 
311 
312 // TODO USe code similar to commande/stats/index.php instead of this one.
313 /*
314 print '<table class="border centpercent">';
315 print '<tr><td class="center">'.$langs->trans("Year").'</td>';
316 print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
317 
318 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
319 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
320 $sql.= " WHERE fk_statut > 0";
321 $sql.= " AND entity = ".$conf->entity;
322 $sql.= " GROUP BY dm DESC";
323 
324 $resql=$db->query($sql);
325 if ($resql)
326 {
327  $num = $db->num_rows($resql);
328  $i = 0;
329  while ($i < $num)
330  {
331  $row = $db->fetch_row($resql);
332  $nbproduct = $row[0];
333  $year = $row[1];
334  print "<tr>";
335  print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
336  $i++;
337  }
338 }
339 $db->free($resql);
340 
341 print '</table>';
342 */
343 
344 print '<br>';
345 print '<i class="opacitymedium">'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
346 
347 // End of page
348 llxFooter();
349 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
Class to manage shipment statistics.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)