dolibarr  19.0.0-dev
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 $dir = (!empty($conf->expedition->multidir_temp[$conf->entity]) ? $conf->expedition->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
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 $fileurlnb = '';
88 if (!$mesg) {
89  $px1->SetData($data);
90  $i = $startyear; $legend = array();
91  while ($i <= $endyear) {
92  $legend[] = $i;
93  $i++;
94  }
95  $px1->SetLegend($legend);
96  $px1->SetMaxValue($px1->GetCeilMaxValue());
97  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
98  $px1->SetWidth($WIDTH);
99  $px1->SetHeight($HEIGHT);
100  $px1->SetYLabel($langs->trans("NbOfSendings"));
101  $px1->SetShading(3);
102  $px1->SetHorizTickIncrement(1);
103  $px1->mode = 'depth';
104  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
105 
106  $px1->draw($filenamenb, $fileurlnb);
107 }
108 
109 // Build graphic amount of object
110 /*
111 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
112 //var_dump($data);
113 // $data = array(array('Lib',val1,val2,val3),...)
114 
115 if (empty($user->rights->societe->client->voir) || $user->socid)
116 {
117  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
118 }
119 else
120 {
121  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
122 }
123 
124 $px2 = new DolGraph();
125 $mesg = $px2->isGraphKo();
126 if (! $mesg)
127 {
128  $px2->SetData($data);
129  $i=$startyear;$legend=array();
130  while ($i <= $endyear)
131  {
132  $legend[]=$i;
133  $i++;
134  }
135  $px2->SetLegend($legend);
136  $px2->SetMaxValue($px2->GetCeilMaxValue());
137  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
138  $px2->SetWidth($WIDTH);
139  $px2->SetHeight($HEIGHT);
140  $px2->SetYLabel($langs->trans("AmountOfShipments"));
141  $px2->SetShading(3);
142  $px2->SetHorizTickIncrement(1);
143  $px2->mode='depth';
144  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
145 
146  $px2->draw($filenameamount,$fileurlamount);
147 }
148 */
149 
150 /*
151 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
152 
153 if (empty($user->rights->societe->client->voir) || $user->socid)
154 {
155  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
156 }
157 else
158 {
159  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
160 }
161 
162 $px3 = new DolGraph();
163 $mesg = $px3->isGraphKo();
164 if (! $mesg)
165 {
166  $px3->SetData($data);
167  $i=$startyear;$legend=array();
168  while ($i <= $endyear)
169  {
170  $legend[]=$i;
171  $i++;
172  }
173  $px3->SetLegend($legend);
174  $px3->SetYLabel($langs->trans("AmountAverage"));
175  $px3->SetMaxValue($px3->GetCeilMaxValue());
176  $px3->SetMinValue($px3->GetFloorMinValue());
177  $px3->SetWidth($WIDTH);
178  $px3->SetHeight($HEIGHT);
179  $px3->SetShading(3);
180  $px3->SetHorizTickIncrement(1);
181  $px3->mode='depth';
182  $px3->SetTitle($langs->trans("AmountAverage"));
183 
184  $px3->draw($filename_avg,$fileurl_avg);
185 }
186 */
187 
188 
189 // Show array
190 $data = $stats->getAllByYear();
191 $arrayyears = array();
192 foreach ($data as $val) {
193  if (!empty($val['year'])) {
194  $arrayyears[$val['year']] = $val['year'];
195  }
196 }
197 if (!count($arrayyears)) {
198  $arrayyears[$nowyear] = $nowyear;
199 }
200 
201 $h = 0;
202 $head = array();
203 $head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php';
204 $head[$h][1] = $langs->trans("ByMonthYear");
205 $head[$h][2] = 'byyear';
206 $h++;
207 
208 $type = 'shipment_stats';
209 
210 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
211 
212 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
213 
214 
215 print '<div class="fichecenter"><div class="fichethirdleft">';
216 
217 
218 // Show filter box
219 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
220 print '<input type="hidden" name="token" value="'.newToken().'">';
221 
222 print '<table class="noborder centpercent">';
223 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
224 // Company
225 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
226 print img_picto('', 'company', 'class="pictofixedwidth"');
227 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
228 print '</td></tr>';
229 // User
230 print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
231 print img_picto('', 'user', 'class="pictofixedwidth"');
232 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
233 print '</td></tr>';
234 // Year
235 print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
236 if (!in_array($year, $arrayyears)) {
237  $arrayyears[$year] = $year;
238 }
239 if (!in_array($nowyear, $arrayyears)) {
240  $arrayyears[$nowyear] = $nowyear;
241 }
242 arsort($arrayyears);
243 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
244 print '</td></tr>';
245 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
246 print '</table>';
247 print '</form>';
248 print '<br><br>';
249 
250 
251 print '<div class="div-table-responsive-no-min">';
252 print '<table class="noborder centpercent">';
253 print '<tr class="liste_titre" height="24">';
254 print '<td class="center">'.$langs->trans("Year").'</td>';
255 print '<td class="right">'.$langs->trans("NbOfSendings").'</td>';
256 /*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
257 print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
258 print '</tr>';
259 
260 $oldyear = 0;
261 foreach ($data as $val) {
262  $year = $val['year'];
263  while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
264  $oldyear--;
265 
266 
267  print '<tr class="oddeven" height="24">';
268  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
269 
270  print '<td class="right">0</td>';
271  /*print '<td class="right">0</td>';
272  print '<td class="right">0</td>';*/
273  print '</tr>';
274  }
275 
276  print '<tr class="oddeven" height="24">';
277  print '<td class="center">';
278  if ($year) {
279  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
280  } else {
281  // Technical error that should not happen
282  print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed';
283  }
284  print '</td>';
285  print '<td class="right">'.$val['nb'].'</td>';
286  /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
287  print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
288  print '</tr>';
289  $oldyear = $year;
290 }
291 
292 print '</table>';
293 print '</div>';
294 
295 
296 print '</div><div class="fichetwothirdright">';
297 
298 
299 // Show graphs
300 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
301 if ($mesg) {
302  print $mesg;
303 } else {
304  print $px1->show();
305  print "<br>\n";
306  /*print $px2->show();
307  print "<br>\n";
308  print $px3->show();*/
309 }
310 print '</td></tr></table>';
311 
312 
313 print '</div></div>';
314 print '<div class="clearboth"></div>';
315 
316 print dol_get_fiche_end();
317 
318 
319 
320 // TODO USe code similar to commande/stats/index.php instead of this one.
321 /*
322 print '<table class="border centpercent">';
323 print '<tr><td class="center">'.$langs->trans("Year").'</td>';
324 print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
325 
326 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
327 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
328 $sql.= " WHERE fk_statut > 0";
329 $sql.= " AND entity = ".$conf->entity;
330 $sql.= " GROUP BY dm DESC";
331 
332 $resql=$db->query($sql);
333 if ($resql)
334 {
335  $num = $db->num_rows($resql);
336  $i = 0;
337  while ($i < $num)
338  {
339  $row = $db->fetch_row($resql);
340  $nbproduct = $row[0];
341  $year = $row[1];
342  print "<tr>";
343  print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
344  $i++;
345  }
346 }
347 $db->free($resql);
348 
349 print '</table>';
350 */
351 
352 print '<br>';
353 print '<i class="opacitymedium">'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
354 
355 // End of page
356 llxFooter();
357 $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='', $dragdropfile=0)
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.