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