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