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