dolibarr 24.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-2026 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';
37require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
38require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionstats.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
40
43
44$hookmanager->initHooks(array('expeditionstats', 'globalcard'));
45
46$action = '';
47
48$userid = GETPOSTINT('userid');
49$socid = GETPOSTINT('socid');
50// Security check
51if ($user->socid > 0) {
52 $socid = $user->socid;
53}
54
56
57$parameters = array();
58$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
59if ($reshook < 0) {
60 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
61}
62
63$nowyear = (int) dol_print_date(dol_now(), "%Y");
64$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
65$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
66$endyear = $year;
67
68// Load translation files required by the page
69$langs->loadLangs(array('sendings', 'other', 'companies'));
70
71// Security check
72if ($user->socid) {
73 $socid = $user->socid;
74}
75restrictedArea($user, 'expedition');
76
77
78/*
79 * View
80 */
81
82$form = new Form($db);
83
84$title = $langs->trans("Shipments");
85
86llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-expedition page-stats_index');
87
88$page = 0;
89$param = '';
90$sortfield = '';
91$sortorder = '';
92$massactionbutton = '';
93$num = 0;
94$nbtotalofrecords = $langs->trans("Statistics");
95$picto = $object->picto;
96$limit = 0;
97$mode = '';
98
99// Currently: a sending can't create from sending list
100// $url = DOL_URL_ROOT.'/expedition/card.php?action=create';
101// if (!empty($socid)) $url .= '&socid='.$socid;
102// $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);
103$newcardbutton = '';
104// @phpstan-ignore-next-line equals.alwaysFalse
105$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/expedition/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition'));
106// @phpstan-ignore-next-line equals.alwaysFalse
107$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/expedition/list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
108$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/expedition/stats/index.php?mode=statistics'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
109$newcardbutton .= dolGetButtonTitleSeparator();
110$newcardbutton .= dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expedition/card.php?action=create2', '', $user->hasRight('expedition', 'creer'));
111
112print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
113
114
115$dir = (!empty($conf->expedition->multidir_temp[$conf->entity]) ? $conf->expedition->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
116dol_mkdir($dir);
117
118$stats = new ExpeditionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
119
120// Build graphic number of object
121$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
122//var_dump($data);exit;
123// $data = array(array('Lib',val1,val2,val3),...)
124
125
126if (!$user->hasRight('societe', 'client', 'voir')) {
127 $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
128} else {
129 $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
130}
131
132$px1 = new DolGraph();
133$mesg = $px1->isGraphKo();
134$fileurlnb = '';
135if (!$mesg) {
136 $px1->SetData($data);
137 $i = $startyear;
138 $legend = array();
139 while ($i <= $endyear) {
140 $legend[] = $i;
141 $i++;
142 }
143 $px1->SetLegend($legend);
144 $px1->SetMaxValue($px1->GetCeilMaxValue());
145 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
146 $px1->SetWidth($WIDTH);
147 $px1->SetHeight($HEIGHT);
148 $px1->SetYLabel($langs->trans("NbOfSendings"));
149 $px1->SetShading(3);
150 $px1->SetHorizTickIncrement(1);
151 $px1->mode = 'depth';
152 $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
153
154 $px1->draw($filenamenb, $fileurlnb);
155}
156
157// Build graphic amount of object
158/*
159$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
160//var_dump($data);
161// $data = array(array('Lib',val1,val2,val3),...)
162
163if (empty($user->rights->societe->client->voir) || $user->socid)
164{
165 $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
166}
167else
168{
169 $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
170}
171
172$px2 = new DolGraph();
173$mesg = $px2->isGraphKo();
174if (! $mesg)
175{
176 $px2->SetData($data);
177 $i=$startyear;$legend=array();
178 while ($i <= $endyear)
179 {
180 $legend[]=$i;
181 $i++;
182 }
183 $px2->SetLegend($legend);
184 $px2->SetMaxValue($px2->GetCeilMaxValue());
185 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
186 $px2->SetWidth($WIDTH);
187 $px2->SetHeight($HEIGHT);
188 $px2->SetYLabel($langs->trans("AmountOfShipments"));
189 $px2->SetShading(3);
190 $px2->SetHorizTickIncrement(1);
191 $px2->mode='depth';
192 $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
193
194 $px2->draw($filenameamount,$fileurlamount);
195}
196*/
197
198/*
199$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
200
201if (empty($user->rights->societe->client->voir) || $user->socid)
202{
203 $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
204}
205else
206{
207 $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
208}
209
210$px3 = new DolGraph();
211$mesg = $px3->isGraphKo();
212if (! $mesg)
213{
214 $px3->SetData($data);
215 $i=$startyear;$legend=array();
216 while ($i <= $endyear)
217 {
218 $legend[]=$i;
219 $i++;
220 }
221 $px3->SetLegend($legend);
222 $px3->SetYLabel($langs->trans("AmountAverage"));
223 $px3->SetMaxValue($px3->GetCeilMaxValue());
224 $px3->SetMinValue($px3->GetFloorMinValue());
225 $px3->SetWidth($WIDTH);
226 $px3->SetHeight($HEIGHT);
227 $px3->SetShading(3);
228 $px3->SetHorizTickIncrement(1);
229 $px3->mode='depth';
230 $px3->SetTitle($langs->trans("AmountAverage"));
231
232 $px3->draw($filename_avg,$fileurl_avg);
233}
234*/
235
236
237// Show array
238$data = $stats->getAllByYear();
239$arrayyears = array();
240foreach ($data as $val) {
241 if (!empty($val['year'])) {
242 $arrayyears[$val['year']] = $val['year'];
243 }
244}
245if (!count($arrayyears)) {
246 $arrayyears[$nowyear] = $nowyear;
247}
248
249$h = 0;
250$head = array();
251$head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php';
252$head[$h][1] = $langs->trans("ByMonthYear");
253$head[$h][2] = 'byyear';
254$h++;
255
256$type = 'shipment_stats';
257
258complete_head_from_modules($conf, $langs, null, $head, $h, $type);
259
260print dol_get_fiche_head($head, 'byyear', '', -1);
261
262
263print '<div class="fichecenter"><div class="fichethirdleft">';
264
265
266// Show filter box
267print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
268print '<input type="hidden" name="token" value="'.newToken().'">';
269
270print '<table class="noborder centpercent">';
271print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
272// Company
273print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
274print img_picto('', 'company', 'class="pictofixedwidth"');
275print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
276print '</td></tr>';
277// User
278print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
279print img_picto('', 'user', 'class="pictofixedwidth"');
280print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
281print '</td></tr>';
282// Year
283print '<tr><td>'.$langs->trans("Year").'</td><td>';
284if (!in_array($year, $arrayyears)) {
285 $arrayyears[$year] = $year;
286}
287if (!in_array($nowyear, $arrayyears)) {
288 $arrayyears[$nowyear] = $nowyear;
289}
290arsort($arrayyears);
291print img_picto('', 'calendar', 'class="pictofixedwidth"');
292print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
293print '</td></tr>';
294print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
295print '</table>';
296print '</form>';
297print '<br><br>';
298
299
300print '<div class="div-table-responsive-no-min">';
301print '<table class="noborder centpercent">';
302print '<tr class="liste_titre" height="24">';
303print '<td class="center">'.$langs->trans("Year").'</td>';
304print '<td class="right">'.$langs->trans("NbOfSendings").'</td>';
305/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
306print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
307print '</tr>';
308
309$cssline = '';
310$MAXLINES = 5;
311$nbline = 0;
312$oldyear = 0;
313foreach ($data as $val) {
314 $year = $val['year'];
315 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
316 $oldyear--;
317 $nbline++;
318 if ($nbline > $MAXLINES) {
319 $cssline = ' hidden';
320 }
321
322 print '<tr class="oddeven'.$cssline.'" height="24">';
323 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
324
325 print '<td class="right">0</td>';
326 /*print '<td class="right">0</td>';
327 print '<td class="right">0</td>';*/
328 print '</tr>';
329 }
330
331 print '<tr class="oddeven'.$cssline.'" height="24">';
332 print '<td class="center">';
333 if ($year) {
334 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
335 } else {
336 // Technical error that should not happen
337 print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed';
338 }
339 print '</td>';
340 print '<td class="right">'.$val['nb'].'</td>';
341 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
342 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
343 print '</tr>';
344 $oldyear = $year;
345 $nbline++;
346 if ($nbline > $MAXLINES) {
347 $cssline = ' hidden';
348 }
349}
350
351if ($nbline > $MAXLINES) {
352 print '<tr class="liste_total"><td colspan="4" class="center">';
353 print '<a href="#" class="showmoreoptions" onclick="javascript:$(\'.hidden\').toggle();$(this).toggle();">'.img_picto('', 'chevron-down', 'class="paddingright"').$langs->trans("More").'...</a>';
354 print '</td></tr>';
355}
356
357print '</table>';
358print '</div>';
359
360
361print '</div><div class="fichetwothirdright">';
362
363
364// Show graphs
365print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
366if ($mesg) {
367 print $mesg;
368} else {
369 print $px1->show();
370 print "<br>\n";
371 /*print $px2->show();
372 print "<br>\n";
373 print $px3->show();*/
374}
375print '</td></tr></table>';
376
377
378print '</div></div>';
379print '<div class="clearboth"></div>';
380
381print dol_get_fiche_end();
382
383
384
385// TODO USe code similar to commande/stats/index.php instead of this one.
386/*
387print '<table class="border centpercent">';
388print '<tr><td class="center">'.$langs->trans("Year").'</td>';
389print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
390
391$sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
392$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
393$sql.= " WHERE fk_statut > 0";
394$sql.= " AND entity = ".$conf->entity;
395$sql.= " GROUP BY dm DESC";
396
397$resql=$db->query($sql);
398if ($resql)
399{
400 $num = $db->num_rows($resql);
401 $i = 0;
402 while ($i < $num)
403 {
404 $row = $db->fetch_row($resql);
405 $nbproduct = $row[0];
406 $year = $row[1];
407 print "<tr>";
408 print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
409 $i++;
410 }
411}
412$db->free($resql);
413
414print '</table>';
415*/
416
417print '<br>';
418print '<i class="opacitymedium">'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
419
420// End of page
421llxFooter();
422
423$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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).
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.