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@capnetworks.com>
5 * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
39require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionstats.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
41
44
45$hookmanager->initHooks(array('receptionstats', 'globalcard'));
46
47$action = '';
48
49$userid = GETPOSTINT('userid');
50$socid = GETPOSTINT('socid');
51
52$object = new Reception($db);
53
54$parameters = array();
55$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
56if ($reshook < 0) {
57 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
58}
59
60$nowyear = (int) dol_print_date(dol_now(), "%Y");
61;
62$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
63$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
64$endyear = $year;
65
66$langs->loadLangs(array("receptions", "other", "companies"));
67
68// Security check
69if ($user->socid) {
70 $socid = $user->socid;
71}
72$result = restrictedArea($user, 'reception', 0, '');
73
74
75/*
76 * View
77 */
78
79$form = new Form($db);
80
81$title = $langs->trans("Receptions");
82
83llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-reception page-stats_index');
84
85$page = 0;
86$param = '';
87$sortfield = '';
88$sortorder = '';
89$massactionbutton = '';
90$num = 0;
91$nbtotalofrecords = $langs->trans("Statistics");
92$picto = $object->picto;
93$limit = 0;
94$mode = '';
95
96$newcardbutton = '';
97$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/reception/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition')); // @phpstan-ignore-line booleanNot.alwaysFalse
98$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/reception/list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition')); // @phpstan-ignore-line booleanNot.alwaysFalse
99$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/reception/stats/index.php?mode=statistics'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
100$newcardbutton .= dolGetButtonTitleSeparator();
101$newcardbutton .= dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/reception/card.php?action=create', '', $user->hasRight('reception', 'creer'));
102
103print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
104
105$dir = (!empty($conf->reception->multidir_temp[$conf->entity]) ? $conf->reception->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
106dol_mkdir($dir);
107
108$stats = new ReceptionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
109
110// Build graphic number of object
111$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
112//var_dump($data);exit;
113// $data = array(array('Lib',val1,val2,val3),...)
114
115
116if (!$user->hasRight('societe', 'client', 'voir')) {
117 $filenamenb = $dir.'/receptionsnbinyear-'.$user->id.'-'.$year.'.png';
118} else {
119 $filenamenb = $dir.'/receptionsnbinyear-'.$year.'.png';
120}
121
122$px1 = new DolGraph();
123$mesg = $px1->isGraphKo();
124$fileurlnb = '';
125if (!$mesg) {
126 $px1->SetData($data);
127 $i = $startyear;
128 $legend = array();
129 while ($i <= $endyear) {
130 $legend[] = $i;
131 $i++;
132 }
133 $px1->SetLegend($legend);
134 $px1->SetMaxValue($px1->GetCeilMaxValue());
135 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
136 $px1->SetWidth($WIDTH);
137 $px1->SetHeight($HEIGHT);
138 $px1->SetYLabel($langs->trans("NbOfReceptions"));
139 $px1->SetShading(3);
140 $px1->SetHorizTickIncrement(1);
141 $px1->mode = 'depth';
142 $px1->SetTitle($langs->trans("NumberOfReceptionsByMonth"));
143
144 $px1->draw($filenamenb, $fileurlnb);
145}
146
147// Build graphic amount of object
148/*
149$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
150//var_dump($data);
151// $data = array(array('Lib',val1,val2,val3),...)
152
153if (empty($user->rights->societe->client->voir) || $user->socid)
154{
155 $filenameamount = $dir.'/receptionsamountinyear-'.$user->id.'-'.$year.'.png';
156}
157else
158{
159 $filenameamount = $dir.'/receptionsamountinyear-'.$year.'.png';
160}
161
162$px2 = new DolGraph();
163$mesg = $px2->isGraphKo();
164if (! $mesg)
165{
166 $px2->SetData($data);
167 $i=$startyear;$legend=array();
168 while ($i <= $endyear)
169 {
170 $legend[]=$i;
171 $i++;
172 }
173 $px2->SetLegend($legend);
174 $px2->SetMaxValue($px2->GetCeilMaxValue());
175 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
176 $px2->SetWidth($WIDTH);
177 $px2->SetHeight($HEIGHT);
178 $px2->SetYLabel($langs->trans("AmountOfReceptions"));
179 $px2->SetShading(3);
180 $px2->SetHorizTickIncrement(1);
181 $px2->mode='depth';
182 $px2->SetTitle($langs->trans("AmountOfReceptionsByMonthHT"));
183
184 $px2->draw($filenameamount,$fileurlamount);
185}
186*/
187
188/*
189$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
190
191if (empty($user->rights->societe->client->voir) || $user->socid)
192{
193 $filename_avg = $dir.'/receptionsaverage-'.$user->id.'-'.$year.'.png';
194}
195else
196{
197 $filename_avg = $dir.'/receptionsaverage-'.$year.'.png';
198}
199
200$px3 = new DolGraph();
201$mesg = $px3->isGraphKo();
202if (! $mesg)
203{
204 $px3->SetData($data);
205 $i=$startyear;$legend=array();
206 while ($i <= $endyear)
207 {
208 $legend[]=$i;
209 $i++;
210 }
211 $px3->SetLegend($legend);
212 $px3->SetYLabel($langs->trans("AmountAverage"));
213 $px3->SetMaxValue($px3->GetCeilMaxValue());
214 $px3->SetMinValue($px3->GetFloorMinValue());
215 $px3->SetWidth($WIDTH);
216 $px3->SetHeight($HEIGHT);
217 $px3->SetShading(3);
218 $px3->SetHorizTickIncrement(1);
219 $px3->mode='depth';
220 $px3->SetTitle($langs->trans("AmountAverage"));
221
222 $px3->draw($filename_avg,$fileurl_avg);
223}
224*/
225
226
227// Show array
228$data = $stats->getAllByYear();
229$arrayyears = array();
230foreach ($data as $val) {
231 if (!empty($val['year'])) {
232 $arrayyears[$val['year']] = $val['year'];
233 }
234}
235if (!count($arrayyears)) {
236 $arrayyears[$nowyear] = $nowyear;
237}
238
239$h = 0;
240$head = array();
241$head[$h][0] = DOL_URL_ROOT.'/reception/stats/index.php';
242$head[$h][1] = $langs->trans("ByMonthYear");
243$head[$h][2] = 'byyear';
244$h++;
245
246$type = 'reception_stats';
247
248complete_head_from_modules($conf, $langs, null, $head, $h, $type);
249
250print dol_get_fiche_head($head, 'byyear', '', -1);
251
252
253print '<div class="fichecenter"><div class="fichethirdleft">';
254
255
256// Show filter box
257print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
258print '<input type="hidden" name="token" value="'.newToken().'">';
259
260print '<table class="noborder centpercent">';
261print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
262// Company
263print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
264print img_picto('', 'company', 'class="pictofixedwidth"');
265print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
266print '</td></tr>';
267// User
268print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
269print img_picto('', 'user', 'class="pictofixedwidth"');
270print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
271print '</td></tr>';
272// Year
273print '<tr><td>'.$langs->trans("Year").'</td><td>';
274if (!in_array($year, $arrayyears)) {
275 $arrayyears[$year] = $year;
276}
277if (!in_array($nowyear, $arrayyears)) {
278 $arrayyears[$nowyear] = $nowyear;
279}
280arsort($arrayyears);
281print img_picto('', 'calendar', 'class="pictofixedwidth"');
282print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
283print '</td></tr>';
284print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
285print '</table>';
286print '</form>';
287print '<br><br>';
288
289print '<div class="div-table-responsive-no-min">';
290print '<table class="noborder centpercent">';
291print '<tr class="liste_titre" height="24">';
292print '<td class="center">'.$langs->trans("Year").'</td>';
293print '<td class="right">'.$langs->trans("NbOfReceptions").'</td>';
294/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
295print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
296print '</tr>';
297
298$cssline = '';
299$MAXLINES = 5;
300$nbline = 0;
301$oldyear = 0;
302foreach ($data as $val) {
303 $year = $val['year'];
304 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
305 $oldyear--;
306 $nbline++;
307 if ($nbline > $MAXLINES) {
308 $cssline = ' hidden';
309 }
310
311 print '<tr class="oddeven'.$cssline.'" height="24">';
312 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
313
314 print '<td class="right">0</td>';
315 /*print '<td class="right">0</td>';
316 print '<td class="right">0</td>';*/
317 print '</tr>';
318 }
319
320 print '<tr class="oddeven'.$cssline.'" height="24">';
321 print '<td class="center">';
322 if ($year) {
323 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
324 } else {
325 print $langs->trans("ValidationDateNotDefinedEvenIfReceptionValidated");
326 }
327 print '</td>';
328 print '<td class="right">'.$val['nb'].'</td>';
329 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
330 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
331 print '</tr>';
332 $oldyear = $year;
333 $nbline++;
334 if ($nbline > $MAXLINES) {
335 $cssline = ' hidden';
336 }
337}
338
339if ($nbline > $MAXLINES) {
340 print '<tr class="liste_total"><td colspan="4" class="center">';
341 print '<a href="#" class="showmoreoptions" onclick="javascript:$(\'.hidden\').toggle();$(this).toggle();">'.img_picto('', 'chevron-down', 'class="paddingright"').$langs->trans("More").'...</a>';
342 print '</td></tr>';
343}
344
345print '</table>';
346print '</div>';
347
348print '</div><div class="fichetwothirdright">';
349
350
351// Show graphs
352print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
353if ($mesg) {
354 print $mesg;
355} else {
356 print $px1->show();
357 print "<br>\n";
358 /*print $px2->show();
359 print "<br>\n";
360 print $px3->show();*/
361}
362print '</td></tr></table>';
363
364
365print '</div></div>';
366print '<div class="clearboth"></div>';
367
368print dol_get_fiche_end();
369
370
371
372// TODO USe code similar to commande/stats/index.php instead of this one.
373/*
374print '<table class="border centpercent">';
375print '<tr><td class="center">'.$langs->trans("Year").'</td>';
376print '<td width="40%" class="center">'.$langs->trans("NbOfReceptions").'</td></tr>';
377
378$sql = "SELECT count(*) as nb, date_format(date_reception,'%Y') as dm";
379$sql.= " FROM ".MAIN_DB_PREFIX."reception";
380$sql.= " WHERE fk_statut > 0";
381$sql.= " AND entity = ".$conf->entity;
382$sql.= " GROUP BY dm DESC";
383
384$resql=$db->query($sql);
385if ($resql)
386{
387 $num = $db->num_rows($resql);
388 $i = 0;
389 while ($i < $num)
390 {
391 $row = $db->fetch_row($resql);
392 $nbproduct = $row[0];
393 $year = $row[1];
394 print "<tr>";
395 print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
396 $i++;
397 }
398}
399$db->free($resql);
400
401print '</table>';
402*/
403
404print '<br>';
405print '<i class="opacitymedium">'.$langs->trans("StatsOnReceptionsOnlyValidated").'</i>';
406
407// End of page
408llxFooter();
409
410$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 generation of HTML components Only common components must be here.
Class to manage receptions.
Class to manage reception statistics.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.