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