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