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