dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
31require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionstats.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
33
44
45$userid = GETPOSTINT('userid');
46$socid = GETPOSTINT('socid');
47// Security check
48if ($user->socid > 0) {
49 $action = '';
50 $socid = $user->socid;
51}
52
53$nowyear = (int) dol_print_date(dol_now(), "%Y");
54$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
55$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
56$endyear = $year;
57
58// Load translation files required by the page
59$langs->loadLangs(array('sendings', 'other', 'companies'));
60
61// Security check
62if ($user->socid) {
63 $socid = $user->socid;
64}
65restrictedArea($user, 'expedition');
66
67
68/*
69 * View
70 */
71
72$form = new Form($db);
73
74llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-expedition page-stats_index');
75
76print load_fiche_titre($langs->trans("StatisticsOfSendings"), '', 'dolly');
77
78$dir = (!empty($conf->expedition->multidir_temp[$conf->entity]) ? $conf->expedition->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
79dol_mkdir($dir);
80
81$stats = new ExpeditionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
82
83// Build graphic number of object
84$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
85//var_dump($data);exit;
86// $data = array(array('Lib',val1,val2,val3),...)
87
88
89if (!$user->hasRight('societe', 'client', 'voir')) {
90 $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
91} else {
92 $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
93}
94
95$px1 = new DolGraph();
96$mesg = $px1->isGraphKo();
97$fileurlnb = '';
98if (!$mesg) {
99 $px1->SetData($data);
100 $i = $startyear;
101 $legend = array();
102 while ($i <= $endyear) {
103 $legend[] = $i;
104 $i++;
105 }
106 $px1->SetLegend($legend);
107 $px1->SetMaxValue($px1->GetCeilMaxValue());
108 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
109 $px1->SetWidth($WIDTH);
110 $px1->SetHeight($HEIGHT);
111 $px1->SetYLabel($langs->trans("NbOfSendings"));
112 $px1->SetShading(3);
113 $px1->SetHorizTickIncrement(1);
114 $px1->mode = 'depth';
115 $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
116
117 $px1->draw($filenamenb, $fileurlnb);
118}
119
120// Build graphic amount of object
121/*
122$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
123//var_dump($data);
124// $data = array(array('Lib',val1,val2,val3),...)
125
126if (empty($user->rights->societe->client->voir) || $user->socid)
127{
128 $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
129}
130else
131{
132 $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
133}
134
135$px2 = new DolGraph();
136$mesg = $px2->isGraphKo();
137if (! $mesg)
138{
139 $px2->SetData($data);
140 $i=$startyear;$legend=array();
141 while ($i <= $endyear)
142 {
143 $legend[]=$i;
144 $i++;
145 }
146 $px2->SetLegend($legend);
147 $px2->SetMaxValue($px2->GetCeilMaxValue());
148 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
149 $px2->SetWidth($WIDTH);
150 $px2->SetHeight($HEIGHT);
151 $px2->SetYLabel($langs->trans("AmountOfShipments"));
152 $px2->SetShading(3);
153 $px2->SetHorizTickIncrement(1);
154 $px2->mode='depth';
155 $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
156
157 $px2->draw($filenameamount,$fileurlamount);
158}
159*/
160
161/*
162$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
163
164if (empty($user->rights->societe->client->voir) || $user->socid)
165{
166 $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
167}
168else
169{
170 $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
171}
172
173$px3 = new DolGraph();
174$mesg = $px3->isGraphKo();
175if (! $mesg)
176{
177 $px3->SetData($data);
178 $i=$startyear;$legend=array();
179 while ($i <= $endyear)
180 {
181 $legend[]=$i;
182 $i++;
183 }
184 $px3->SetLegend($legend);
185 $px3->SetYLabel($langs->trans("AmountAverage"));
186 $px3->SetMaxValue($px3->GetCeilMaxValue());
187 $px3->SetMinValue($px3->GetFloorMinValue());
188 $px3->SetWidth($WIDTH);
189 $px3->SetHeight($HEIGHT);
190 $px3->SetShading(3);
191 $px3->SetHorizTickIncrement(1);
192 $px3->mode='depth';
193 $px3->SetTitle($langs->trans("AmountAverage"));
194
195 $px3->draw($filename_avg,$fileurl_avg);
196}
197*/
198
199
200// Show array
201$data = $stats->getAllByYear();
202$arrayyears = array();
203foreach ($data as $val) {
204 if (!empty($val['year'])) {
205 $arrayyears[$val['year']] = $val['year'];
206 }
207}
208if (!count($arrayyears)) {
209 $arrayyears[$nowyear] = $nowyear;
210}
211
212$h = 0;
213$head = array();
214$head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php';
215$head[$h][1] = $langs->trans("ByMonthYear");
216$head[$h][2] = 'byyear';
217$h++;
218
219$type = 'shipment_stats';
220
221complete_head_from_modules($conf, $langs, null, $head, $h, $type);
222
223print dol_get_fiche_head($head, 'byyear', '', -1);
224
225
226print '<div class="fichecenter"><div class="fichethirdleft">';
227
228
229// Show filter box
230print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
231print '<input type="hidden" name="token" value="'.newToken().'">';
232
233print '<table class="noborder centpercent">';
234print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
235// Company
236print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
237print img_picto('', 'company', 'class="pictofixedwidth"');
238print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
239print '</td></tr>';
240// User
241print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
242print img_picto('', 'user', 'class="pictofixedwidth"');
243print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
244print '</td></tr>';
245// Year
246print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
247if (!in_array($year, $arrayyears)) {
248 $arrayyears[$year] = $year;
249}
250if (!in_array($nowyear, $arrayyears)) {
251 $arrayyears[$nowyear] = $nowyear;
252}
253arsort($arrayyears);
254print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
255print '</td></tr>';
256print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
257print '</table>';
258print '</form>';
259print '<br><br>';
260
261
262print '<div class="div-table-responsive-no-min">';
263print '<table class="noborder centpercent">';
264print '<tr class="liste_titre" height="24">';
265print '<td class="center">'.$langs->trans("Year").'</td>';
266print '<td class="right">'.$langs->trans("NbOfSendings").'</td>';
267/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
268print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
269print '</tr>';
270
271$oldyear = 0;
272foreach ($data as $val) {
273 $year = $val['year'];
274 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
275 $oldyear--;
276
277
278 print '<tr class="oddeven" height="24">';
279 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
280
281 print '<td class="right">0</td>';
282 /*print '<td class="right">0</td>';
283 print '<td class="right">0</td>';*/
284 print '</tr>';
285 }
286
287 print '<tr class="oddeven" height="24">';
288 print '<td class="center">';
289 if ($year) {
290 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
291 } else {
292 // Technical error that should not happen
293 print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed';
294 }
295 print '</td>';
296 print '<td class="right">'.$val['nb'].'</td>';
297 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
298 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
299 print '</tr>';
300 $oldyear = $year;
301}
302
303print '</table>';
304print '</div>';
305
306
307print '</div><div class="fichetwothirdright">';
308
309
310// Show graphs
311print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
312if ($mesg) {
313 print $mesg;
314} else {
315 print $px1->show();
316 print "<br>\n";
317 /*print $px2->show();
318 print "<br>\n";
319 print $px3->show();*/
320}
321print '</td></tr></table>';
322
323
324print '</div></div>';
325print '<div class="clearboth"></div>';
326
327print dol_get_fiche_end();
328
329
330
331// TODO USe code similar to commande/stats/index.php instead of this one.
332/*
333print '<table class="border centpercent">';
334print '<tr><td class="center">'.$langs->trans("Year").'</td>';
335print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
336
337$sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
338$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
339$sql.= " WHERE fk_statut > 0";
340$sql.= " AND entity = ".$conf->entity;
341$sql.= " GROUP BY dm DESC";
342
343$resql=$db->query($sql);
344if ($resql)
345{
346 $num = $db->num_rows($resql);
347 $i = 0;
348 while ($i < $num)
349 {
350 $row = $db->fetch_row($resql);
351 $nbproduct = $row[0];
352 $year = $row[1];
353 print "<tr>";
354 print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
355 $i++;
356 }
357}
358$db->free($resql);
359
360print '</table>';
361*/
362
363print '<br>';
364print '<i class="opacitymedium">'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
365
366// End of page
367llxFooter();
368$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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.
llxFooter()
Footer empty.
Definition document.php:107
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.