dolibarr 22.0.5
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-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 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';
31require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
32require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionstats.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
34
45
46$hookmanager->initHooks(array('receptionstats', 'globalcard'));
47
48$userid = GETPOSTINT('userid');
49$socid = GETPOSTINT('socid');
50
51$parameters = array();
52$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
53if ($reshook < 0) {
54 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
55}
56
57$nowyear = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
58$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
59$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
60$endyear = $year;
61
62$langs->loadLangs(array("receptions", "other", "companies"));
63
64// Security check
65if ($user->socid) {
66 $socid = $user->socid;
67}
68$result = restrictedArea($user, 'reception', 0, '');
69
70
71/*
72 * View
73 */
74
75$form = new Form($db);
76
77llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-reception page-stats_index');
78
79print load_fiche_titre($langs->trans("StatisticsOfReceptions"), '', 'dollyrevert');
80
81$dir = (!empty($conf->reception->multidir_temp[$conf->entity]) ? $conf->reception->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
82dol_mkdir($dir);
83
84$stats = new ReceptionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
85
86// Build graphic number of object
87$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
88//var_dump($data);exit;
89// $data = array(array('Lib',val1,val2,val3),...)
90
91
92if (!$user->hasRight('societe', 'client', 'voir')) {
93 $filenamenb = $dir.'/receptionsnbinyear-'.$user->id.'-'.$year.'.png';
94} else {
95 $filenamenb = $dir.'/receptionsnbinyear-'.$year.'.png';
96}
97
98$px1 = new DolGraph();
99$mesg = $px1->isGraphKo();
100$fileurlnb = '';
101if (!$mesg) {
102 $px1->SetData($data);
103 $i = $startyear;
104 $legend = array();
105 while ($i <= $endyear) {
106 $legend[] = $i;
107 $i++;
108 }
109 $px1->SetLegend($legend);
110 $px1->SetMaxValue($px1->GetCeilMaxValue());
111 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
112 $px1->SetWidth($WIDTH);
113 $px1->SetHeight($HEIGHT);
114 $px1->SetYLabel($langs->trans("NbOfReceptions"));
115 $px1->SetShading(3);
116 $px1->SetHorizTickIncrement(1);
117 $px1->mode = 'depth';
118 $px1->SetTitle($langs->trans("NumberOfReceptionsByMonth"));
119
120 $px1->draw($filenamenb, $fileurlnb);
121}
122
123// Build graphic amount of object
124/*
125$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
126//var_dump($data);
127// $data = array(array('Lib',val1,val2,val3),...)
128
129if (empty($user->rights->societe->client->voir) || $user->socid)
130{
131 $filenameamount = $dir.'/receptionsamountinyear-'.$user->id.'-'.$year.'.png';
132}
133else
134{
135 $filenameamount = $dir.'/receptionsamountinyear-'.$year.'.png';
136}
137
138$px2 = new DolGraph();
139$mesg = $px2->isGraphKo();
140if (! $mesg)
141{
142 $px2->SetData($data);
143 $i=$startyear;$legend=array();
144 while ($i <= $endyear)
145 {
146 $legend[]=$i;
147 $i++;
148 }
149 $px2->SetLegend($legend);
150 $px2->SetMaxValue($px2->GetCeilMaxValue());
151 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
152 $px2->SetWidth($WIDTH);
153 $px2->SetHeight($HEIGHT);
154 $px2->SetYLabel($langs->trans("AmountOfReceptions"));
155 $px2->SetShading(3);
156 $px2->SetHorizTickIncrement(1);
157 $px2->mode='depth';
158 $px2->SetTitle($langs->trans("AmountOfReceptionsByMonthHT"));
159
160 $px2->draw($filenameamount,$fileurlamount);
161}
162*/
163
164/*
165$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
166
167if (empty($user->rights->societe->client->voir) || $user->socid)
168{
169 $filename_avg = $dir.'/receptionsaverage-'.$user->id.'-'.$year.'.png';
170}
171else
172{
173 $filename_avg = $dir.'/receptionsaverage-'.$year.'.png';
174}
175
176$px3 = new DolGraph();
177$mesg = $px3->isGraphKo();
178if (! $mesg)
179{
180 $px3->SetData($data);
181 $i=$startyear;$legend=array();
182 while ($i <= $endyear)
183 {
184 $legend[]=$i;
185 $i++;
186 }
187 $px3->SetLegend($legend);
188 $px3->SetYLabel($langs->trans("AmountAverage"));
189 $px3->SetMaxValue($px3->GetCeilMaxValue());
190 $px3->SetMinValue($px3->GetFloorMinValue());
191 $px3->SetWidth($WIDTH);
192 $px3->SetHeight($HEIGHT);
193 $px3->SetShading(3);
194 $px3->SetHorizTickIncrement(1);
195 $px3->mode='depth';
196 $px3->SetTitle($langs->trans("AmountAverage"));
197
198 $px3->draw($filename_avg,$fileurl_avg);
199}
200*/
201
202
203// Show array
204$data = $stats->getAllByYear();
205$arrayyears = array();
206foreach ($data as $val) {
207 if (!empty($val['year'])) {
208 $arrayyears[$val['year']] = $val['year'];
209 }
210}
211if (!count($arrayyears)) {
212 $arrayyears[$nowyear] = $nowyear;
213}
214
215$h = 0;
216$head = array();
217$head[$h][0] = DOL_URL_ROOT.'/reception/stats/index.php';
218$head[$h][1] = $langs->trans("ByMonthYear");
219$head[$h][2] = 'byyear';
220$h++;
221
222$type = 'reception_stats';
223
224complete_head_from_modules($conf, $langs, null, $head, $h, $type);
225
226print dol_get_fiche_head($head, 'byyear', '', -1);
227
228
229print '<div class="fichecenter"><div class="fichethirdleft">';
230
231
232// Show filter box
233print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
234print '<input type="hidden" name="token" value="'.newToken().'">';
235
236print '<table class="noborder centpercent">';
237print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
238// Company
239print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
240print img_picto('', 'company', 'class="pictofixedwidth"');
241print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
242print '</td></tr>';
243// User
244print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
245print img_picto('', 'user', 'class="pictofixedwidth"');
246print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
247print '</td></tr>';
248// Year
249print '<tr><td>'.$langs->trans("Year").'</td><td>';
250if (!in_array($year, $arrayyears)) {
251 $arrayyears[$year] = $year;
252}
253if (!in_array($nowyear, $arrayyears)) {
254 $arrayyears[$nowyear] = $nowyear;
255}
256arsort($arrayyears);
257print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
258print '</td></tr>';
259print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
260print '</table>';
261print '</form>';
262print '<br><br>';
263
264print '<div class="div-table-responsive-no-min">';
265print '<table class="noborder centpercent">';
266print '<tr class="liste_titre" height="24">';
267print '<td class="center">'.$langs->trans("Year").'</td>';
268print '<td class="right">'.$langs->trans("NbOfReceptions").'</td>';
269/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
270print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
271print '</tr>';
272
273$oldyear = 0;
274foreach ($data as $val) {
275 $year = $val['year'];
276 while (!empty($year) && $oldyear > (int) $year + 1) { // If we have empty year
277 $oldyear--;
278
279
280 print '<tr class="oddeven" height="24">';
281 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
282
283 print '<td class="right">0</td>';
284 /*print '<td class="right">0</td>';
285 print '<td class="right">0</td>';*/
286 print '</tr>';
287 }
288
289 print '<tr class="oddeven" height="24">';
290 print '<td class="center">';
291 if ($year) {
292 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
293 } else {
294 print $langs->trans("ValidationDateNotDefinedEvenIfReceptionValidated");
295 }
296 print '</td>';
297 print '<td class="right">'.$val['nb'].'</td>';
298 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
299 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
300 print '</tr>';
301 $oldyear = $year;
302}
303
304print '</table>';
305
306
307print '</div></div><div class="fichetwothirdright">';
308
309
310// Show graphs
311print '<table class="border centpercent"><tr valign="top"><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("NbOfReceptions").'</td></tr>';
336
337$sql = "SELECT count(*) as nb, date_format(date_reception,'%Y') as dm";
338$sql.= " FROM ".MAIN_DB_PREFIX."reception";
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("StatsOnReceptionsOnlyValidated").'</i>';
365
366llxFooter();
367
368$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 generation of HTML components Only common components must be here.
Class to manage reception statistics.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_now($mode='auto')
Return date for now.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.