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