dolibarr 23.0.3
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-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 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$hookmanager->initHooks(array('expeditionstats', 'globalcard'));
46
47$userid = GETPOSTINT('userid');
48$socid = GETPOSTINT('socid');
49// Security check
50if ($user->socid > 0) {
51 $action = '';
52 $socid = $user->socid;
53}
54
55$parameters = array();
56$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
57if ($reshook < 0) {
58 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
59}
60
61$nowyear = (int) dol_print_date(dol_now(), "%Y");
62$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
63$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
64$endyear = $year;
65
66// Load translation files required by the page
67$langs->loadLangs(array('sendings', 'other', 'companies'));
68
69// Security check
70if ($user->socid) {
71 $socid = $user->socid;
72}
73restrictedArea($user, 'expedition');
74
75
76/*
77 * View
78 */
79
80$form = new Form($db);
81
82llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-expedition page-stats_index');
83
84print load_fiche_titre($langs->trans("StatisticsOfSendings"), '', 'dolly');
85
86$dir = (!empty($conf->expedition->multidir_temp[$conf->entity]) ? $conf->expedition->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
87dol_mkdir($dir);
88
89$stats = new ExpeditionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
90
91// Build graphic number of object
92$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
93//var_dump($data);exit;
94// $data = array(array('Lib',val1,val2,val3),...)
95
96
97if (!$user->hasRight('societe', 'client', 'voir')) {
98 $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
99} else {
100 $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
101}
102
103$px1 = new DolGraph();
104$mesg = $px1->isGraphKo();
105$fileurlnb = '';
106if (!$mesg) {
107 $px1->SetData($data);
108 $i = $startyear;
109 $legend = array();
110 while ($i <= $endyear) {
111 $legend[] = $i;
112 $i++;
113 }
114 $px1->SetLegend($legend);
115 $px1->SetMaxValue($px1->GetCeilMaxValue());
116 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
117 $px1->SetWidth($WIDTH);
118 $px1->SetHeight($HEIGHT);
119 $px1->SetYLabel($langs->trans("NbOfSendings"));
120 $px1->SetShading(3);
121 $px1->SetHorizTickIncrement(1);
122 $px1->mode = 'depth';
123 $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
124
125 $px1->draw($filenamenb, $fileurlnb);
126}
127
128// Build graphic amount of object
129/*
130$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
131//var_dump($data);
132// $data = array(array('Lib',val1,val2,val3),...)
133
134if (empty($user->rights->societe->client->voir) || $user->socid)
135{
136 $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
137}
138else
139{
140 $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
141}
142
143$px2 = new DolGraph();
144$mesg = $px2->isGraphKo();
145if (! $mesg)
146{
147 $px2->SetData($data);
148 $i=$startyear;$legend=array();
149 while ($i <= $endyear)
150 {
151 $legend[]=$i;
152 $i++;
153 }
154 $px2->SetLegend($legend);
155 $px2->SetMaxValue($px2->GetCeilMaxValue());
156 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
157 $px2->SetWidth($WIDTH);
158 $px2->SetHeight($HEIGHT);
159 $px2->SetYLabel($langs->trans("AmountOfShipments"));
160 $px2->SetShading(3);
161 $px2->SetHorizTickIncrement(1);
162 $px2->mode='depth';
163 $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
164
165 $px2->draw($filenameamount,$fileurlamount);
166}
167*/
168
169/*
170$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
171
172if (empty($user->rights->societe->client->voir) || $user->socid)
173{
174 $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
175}
176else
177{
178 $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
179}
180
181$px3 = new DolGraph();
182$mesg = $px3->isGraphKo();
183if (! $mesg)
184{
185 $px3->SetData($data);
186 $i=$startyear;$legend=array();
187 while ($i <= $endyear)
188 {
189 $legend[]=$i;
190 $i++;
191 }
192 $px3->SetLegend($legend);
193 $px3->SetYLabel($langs->trans("AmountAverage"));
194 $px3->SetMaxValue($px3->GetCeilMaxValue());
195 $px3->SetMinValue($px3->GetFloorMinValue());
196 $px3->SetWidth($WIDTH);
197 $px3->SetHeight($HEIGHT);
198 $px3->SetShading(3);
199 $px3->SetHorizTickIncrement(1);
200 $px3->mode='depth';
201 $px3->SetTitle($langs->trans("AmountAverage"));
202
203 $px3->draw($filename_avg,$fileurl_avg);
204}
205*/
206
207
208// Show array
209$data = $stats->getAllByYear();
210$arrayyears = array();
211foreach ($data as $val) {
212 if (!empty($val['year'])) {
213 $arrayyears[$val['year']] = $val['year'];
214 }
215}
216if (!count($arrayyears)) {
217 $arrayyears[$nowyear] = $nowyear;
218}
219
220$h = 0;
221$head = array();
222$head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php';
223$head[$h][1] = $langs->trans("ByMonthYear");
224$head[$h][2] = 'byyear';
225$h++;
226
227$type = 'shipment_stats';
228
229complete_head_from_modules($conf, $langs, null, $head, $h, $type);
230
231print dol_get_fiche_head($head, 'byyear', '', -1);
232
233
234print '<div class="fichecenter"><div class="fichethirdleft">';
235
236
237// Show filter box
238print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
239print '<input type="hidden" name="token" value="'.newToken().'">';
240
241print '<table class="noborder centpercent">';
242print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
243// Company
244print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
245print img_picto('', 'company', 'class="pictofixedwidth"');
246print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
247print '</td></tr>';
248// User
249print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
250print img_picto('', 'user', 'class="pictofixedwidth"');
251print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
252print '</td></tr>';
253// Year
254print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
255if (!in_array($year, $arrayyears)) {
256 $arrayyears[$year] = $year;
257}
258if (!in_array($nowyear, $arrayyears)) {
259 $arrayyears[$nowyear] = $nowyear;
260}
261arsort($arrayyears);
262print img_picto('', 'calendar', 'class="pictofixedwidth"');
263print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
264print '</td></tr>';
265print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
266print '</table>';
267print '</form>';
268print '<br><br>';
269
270
271print '<div class="div-table-responsive-no-min">';
272print '<table class="noborder centpercent">';
273print '<tr class="liste_titre" height="24">';
274print '<td class="center">'.$langs->trans("Year").'</td>';
275print '<td class="right">'.$langs->trans("NbOfSendings").'</td>';
276/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
277print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
278print '</tr>';
279
280$oldyear = 0;
281foreach ($data as $val) {
282 $year = $val['year'];
283 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
284 $oldyear--;
285
286
287 print '<tr class="oddeven" height="24">';
288 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
289
290 print '<td class="right">0</td>';
291 /*print '<td class="right">0</td>';
292 print '<td class="right">0</td>';*/
293 print '</tr>';
294 }
295
296 print '<tr class="oddeven" height="24">';
297 print '<td class="center">';
298 if ($year) {
299 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
300 } else {
301 // Technical error that should not happen
302 print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed';
303 }
304 print '</td>';
305 print '<td class="right">'.$val['nb'].'</td>';
306 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
307 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
308 print '</tr>';
309 $oldyear = $year;
310}
311
312print '</table>';
313print '</div>';
314
315
316print '</div><div class="fichetwothirdright">';
317
318
319// Show graphs
320print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
321if ($mesg) {
322 print $mesg;
323} else {
324 print $px1->show();
325 print "<br>\n";
326 /*print $px2->show();
327 print "<br>\n";
328 print $px3->show();*/
329}
330print '</td></tr></table>';
331
332
333print '</div></div>';
334print '<div class="clearboth"></div>';
335
336print dol_get_fiche_end();
337
338
339
340// TODO USe code similar to commande/stats/index.php instead of this one.
341/*
342print '<table class="border centpercent">';
343print '<tr><td class="center">'.$langs->trans("Year").'</td>';
344print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
345
346$sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
347$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
348$sql.= " WHERE fk_statut > 0";
349$sql.= " AND entity = ".$conf->entity;
350$sql.= " GROUP BY dm DESC";
351
352$resql=$db->query($sql);
353if ($resql)
354{
355 $num = $db->num_rows($resql);
356 $i = 0;
357 while ($i < $num)
358 {
359 $row = $db->fetch_row($resql);
360 $nbproduct = $row[0];
361 $year = $row[1];
362 print "<tr>";
363 print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
364 $i++;
365 }
366}
367$db->free($resql);
368
369print '</table>';
370*/
371
372print '<br>';
373print '<i class="opacitymedium">'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
374
375// End of page
376llxFooter();
377$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.