dolibarr 18.0.6
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 = GETPOST('userid', 'int');
36$socid = GETPOST('socid', 'int');
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 - (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
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 (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 = '';
88if (!$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
115if (empty($user->rights->societe->client->voir) || $user->socid)
116{
117 $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
118}
119else
120{
121 $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
122}
123
124$px2 = new DolGraph();
125$mesg = $px2->isGraphKo();
126if (! $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
153if (empty($user->rights->societe->client->voir) || $user->socid)
154{
155 $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
156}
157else
158{
159 $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
160}
161
162$px3 = new DolGraph();
163$mesg = $px3->isGraphKo();
164if (! $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();
192foreach ($data as $val) {
193 if (!empty($val['year'])) {
194 $arrayyears[$val['year']] = $val['year'];
195 }
196}
197if (!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
210complete_head_from_modules($conf, $langs, null, $head, $h, $type);
211
212print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
213
214
215print '<div class="fichecenter"><div class="fichethirdleft">';
216
217
218// Show filter box
219print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
220print '<input type="hidden" name="token" value="'.newToken().'">';
221
222print '<table class="noborder centpercent">';
223print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
224// Company
225print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
226print img_picto('', 'company', 'class="pictofixedwidth"');
227print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
228print '</td></tr>';
229// User
230print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
231print img_picto('', 'user', 'class="pictofixedwidth"');
232print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
233print '</td></tr>';
234// Year
235print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
236if (!in_array($year, $arrayyears)) {
237 $arrayyears[$year] = $year;
238}
239if (!in_array($nowyear, $arrayyears)) {
240 $arrayyears[$nowyear] = $nowyear;
241}
242arsort($arrayyears);
243print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
244print '</td></tr>';
245print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
246print '</table>';
247print '</form>';
248print '<br><br>';
249
250
251print '<div class="div-table-responsive-no-min">';
252print '<table class="noborder centpercent">';
253print '<tr class="liste_titre" height="24">';
254print '<td class="center">'.$langs->trans("Year").'</td>';
255print '<td class="right">'.$langs->trans("NbOfSendings").'</td>';
256/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
257print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
258print '</tr>';
259
260$oldyear = 0;
261foreach ($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
292print '</table>';
293print '</div>';
294
295
296print '</div><div class="fichetwothirdright">';
297
298
299// Show graphs
300print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
301if ($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}
310print '</td></tr></table>';
311
312
313print '</div></div>';
314print '<div class="clearboth"></div>';
315
316print dol_get_fiche_end();
317
318
319
320// TODO USe code similar to commande/stats/index.php instead of this one.
321/*
322print '<table class="border centpercent">';
323print '<tr><td class="center">'.$langs->trans("Year").'</td>';
324print '<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);
333if ($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
349print '</table>';
350*/
351
352print '<br>';
353print '<i class="opacitymedium">'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
354
355// End of page
356llxFooter();
357$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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($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)
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.