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