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