dolibarr 19.0.3
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
30require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionstats.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
32
35
36$userid = GETPOST('userid', 'int');
37$socid = GETPOST('socid', 'int');
38
39$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
40$year = GETPOST('year') > 0 ? GETPOST('year') : $nowyear;
41$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
42$endyear = $year;
43
44$langs->loadLangs(array("receptions", "other", "companies"));
45
46// Security check
47if ($user->socid) {
48 $socid = $user->socid;
49}
50$result = restrictedArea($user, 'reception', 0, '');
51
52
53/*
54 * View
55 */
56
57$form = new Form($db);
58
59llxHeader();
60
61print load_fiche_titre($langs->trans("StatisticsOfReceptions"), '', 'dollyrevert');
62
63$dir = (!empty($conf->reception->multidir_temp[$conf->entity]) ? $conf->reception->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
64dol_mkdir($dir);
65
66$stats = new ReceptionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
67
68// Build graphic number of object
69$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
70//var_dump($data);exit;
71// $data = array(array('Lib',val1,val2,val3),...)
72
73
74if (!$user->hasRight('societe', 'client', 'voir') || $user->socid) {
75 $filenamenb = $dir.'/receptionsnbinyear-'.$user->id.'-'.$year.'.png';
76} else {
77 $filenamenb = $dir.'/receptionsnbinyear-'.$year.'.png';
78}
79
80$px1 = new DolGraph();
81$mesg = $px1->isGraphKo();
82$fileurlnb = '';
83if (!$mesg) {
84 $px1->SetData($data);
85 $i = $startyear;
86 $legend = array();
87 while ($i <= $endyear) {
88 $legend[] = $i;
89 $i++;
90 }
91 $px1->SetLegend($legend);
92 $px1->SetMaxValue($px1->GetCeilMaxValue());
93 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
94 $px1->SetWidth($WIDTH);
95 $px1->SetHeight($HEIGHT);
96 $px1->SetYLabel($langs->trans("NbOfReceptions"));
97 $px1->SetShading(3);
98 $px1->SetHorizTickIncrement(1);
99 $px1->mode = 'depth';
100 $px1->SetTitle($langs->trans("NumberOfReceptionsByMonth"));
101
102 $px1->draw($filenamenb, $fileurlnb);
103}
104
105// Build graphic amount of object
106/*
107$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
108//var_dump($data);
109// $data = array(array('Lib',val1,val2,val3),...)
110
111if (empty($user->rights->societe->client->voir) || $user->socid)
112{
113 $filenameamount = $dir.'/receptionsamountinyear-'.$user->id.'-'.$year.'.png';
114}
115else
116{
117 $filenameamount = $dir.'/receptionsamountinyear-'.$year.'.png';
118}
119
120$px2 = new DolGraph();
121$mesg = $px2->isGraphKo();
122if (! $mesg)
123{
124 $px2->SetData($data);
125 $i=$startyear;$legend=array();
126 while ($i <= $endyear)
127 {
128 $legend[]=$i;
129 $i++;
130 }
131 $px2->SetLegend($legend);
132 $px2->SetMaxValue($px2->GetCeilMaxValue());
133 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
134 $px2->SetWidth($WIDTH);
135 $px2->SetHeight($HEIGHT);
136 $px2->SetYLabel($langs->trans("AmountOfReceptions"));
137 $px2->SetShading(3);
138 $px2->SetHorizTickIncrement(1);
139 $px2->mode='depth';
140 $px2->SetTitle($langs->trans("AmountOfReceptionsByMonthHT"));
141
142 $px2->draw($filenameamount,$fileurlamount);
143}
144*/
145
146/*
147$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
148
149if (empty($user->rights->societe->client->voir) || $user->socid)
150{
151 $filename_avg = $dir.'/receptionsaverage-'.$user->id.'-'.$year.'.png';
152}
153else
154{
155 $filename_avg = $dir.'/receptionsaverage-'.$year.'.png';
156}
157
158$px3 = new DolGraph();
159$mesg = $px3->isGraphKo();
160if (! $mesg)
161{
162 $px3->SetData($data);
163 $i=$startyear;$legend=array();
164 while ($i <= $endyear)
165 {
166 $legend[]=$i;
167 $i++;
168 }
169 $px3->SetLegend($legend);
170 $px3->SetYLabel($langs->trans("AmountAverage"));
171 $px3->SetMaxValue($px3->GetCeilMaxValue());
172 $px3->SetMinValue($px3->GetFloorMinValue());
173 $px3->SetWidth($WIDTH);
174 $px3->SetHeight($HEIGHT);
175 $px3->SetShading(3);
176 $px3->SetHorizTickIncrement(1);
177 $px3->mode='depth';
178 $px3->SetTitle($langs->trans("AmountAverage"));
179
180 $px3->draw($filename_avg,$fileurl_avg);
181}
182*/
183
184
185// Show array
186$data = $stats->getAllByYear();
187$arrayyears = array();
188foreach ($data as $val) {
189 if (!empty($val['year'])) {
190 $arrayyears[$val['year']] = $val['year'];
191 }
192}
193if (!count($arrayyears)) {
194 $arrayyears[$nowyear] = $nowyear;
195}
196
197$h = 0;
198$head = array();
199$head[$h][0] = DOL_URL_ROOT.'/reception/stats/index.php';
200$head[$h][1] = $langs->trans("ByMonthYear");
201$head[$h][2] = 'byyear';
202$h++;
203
204$type = 'reception_stats';
205
206complete_head_from_modules($conf, $langs, null, $head, $h, $type);
207
208print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
209
210
211print '<div class="fichecenter"><div class="fichethirdleft">';
212
213
214// Show filter box
215print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
216print '<input type="hidden" name="token" value="'.newToken().'">';
217
218print '<table class="noborder centpercent">';
219print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
220// Company
221print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
222print img_picto('', 'company', 'class="pictofixedwidth"');
223print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
224print '</td></tr>';
225// User
226print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
227print img_picto('', 'user', 'class="pictofixedwidth"');
228print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
229print '</td></tr>';
230// Year
231print '<tr><td>'.$langs->trans("Year").'</td><td>';
232if (!in_array($year, $arrayyears)) {
233 $arrayyears[$year] = $year;
234}
235if (!in_array($nowyear, $arrayyears)) {
236 $arrayyears[$nowyear] = $nowyear;
237}
238arsort($arrayyears);
239print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
240print '</td></tr>';
241print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
242print '</table>';
243print '</form>';
244print '<br><br>';
245
246print '<table class="noborder centpercent">';
247print '<tr class="liste_titre" height="24">';
248print '<td class="center">'.$langs->trans("Year").'</td>';
249print '<td class="right">'.$langs->trans("NbOfReceptions").'</td>';
250/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
251print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
252print '</tr>';
253
254$oldyear = 0;
255foreach ($data as $val) {
256 $year = $val['year'];
257 while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
258 $oldyear--;
259
260
261 print '<tr class="oddeven" height="24">';
262 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
263
264 print '<td class="right">0</td>';
265 /*print '<td class="right">0</td>';
266 print '<td class="right">0</td>';*/
267 print '</tr>';
268 }
269
270 print '<tr class="oddeven" height="24">';
271 print '<td class="center">';
272 if ($year) {
273 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
274 } else {
275 print $langs->trans("ValidationDateNotDefinedEvenIfReceptionValidated");
276 }
277 print '</td>';
278 print '<td class="right">'.$val['nb'].'</td>';
279 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
280 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
281 print '</tr>';
282 $oldyear = $year;
283}
284
285print '</table>';
286
287
288print '</div><div class="fichetwothirdright">';
289
290
291// Show graphs
292print '<table class="border centpercent"><tr valign="top"><td class="center">';
293if ($mesg) {
294 print $mesg;
295} else {
296 print $px1->show();
297 print "<br>\n";
298 /*print $px2->show();
299 print "<br>\n";
300 print $px3->show();*/
301}
302print '</td></tr></table>';
303
304
305print '</div></div>';
306print '<div class="clearboth"></div>';
307
308print dol_get_fiche_end();
309
310
311
312// TODO USe code similar to commande/stats/index.php instead of this one.
313/*
314print '<table class="border centpercent">';
315print '<tr><td class="center">'.$langs->trans("Year").'</td>';
316print '<td width="40%" class="center">'.$langs->trans("NbOfReceptions").'</td></tr>';
317
318$sql = "SELECT count(*) as nb, date_format(date_reception,'%Y') as dm";
319$sql.= " FROM ".MAIN_DB_PREFIX."reception";
320$sql.= " WHERE fk_statut > 0";
321$sql.= " AND entity = ".$conf->entity;
322$sql.= " GROUP BY dm DESC";
323
324$resql=$db->query($sql);
325if ($resql)
326{
327 $num = $db->num_rows($resql);
328 $i = 0;
329 while ($i < $num)
330 {
331 $row = $db->fetch_row($resql);
332 $nbproduct = $row[0];
333 $year = $row[1];
334 print "<tr>";
335 print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
336 $i++;
337 }
338}
339$db->free($resql);
340
341print '</table>';
342*/
343
344print '<br>';
345print '<i class="opacitymedium">'.$langs->trans("StatsOnReceptionsOnlyValidated").'</i>';
346
347llxFooter();
348
349$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 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.