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-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.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.'/don/class/don.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.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  $action = '';
40  $socid = $user->socid;
41 }
42 
43 $nowyear = strftime("%Y", dol_now());
44 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
45 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
46 $endyear = $year;
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array("companies", "other", "sendings"));
50 
51 
52 /*
53  * View
54  */
55 
56 $form = new Form($db);
57 
58 llxHeader();
59 
60 print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg);
61 
62 
63 dol_mkdir($dir);
64 
65 $stats = new DonationStats($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.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
75 } else {
76  $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
77 }
78 
79 $px1 = new DolGraph();
80 $mesg = $px1->isGraphKo();
81 if (!$mesg) {
82  $px1->SetData($data);
83  $i = $startyear; $legend = array();
84  while ($i <= $endyear) {
85  $legend[] = $i;
86  $i++;
87  }
88  $px1->SetLegend($legend);
89  $px1->SetMaxValue($px1->GetCeilMaxValue());
90  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
91  $px1->SetWidth($WIDTH);
92  $px1->SetHeight($HEIGHT);
93  $px1->SetYLabel($langs->trans("NbOfSendings"));
94  $px1->SetShading(3);
95  $px1->SetHorizTickIncrement(1);
96  $px1->mode = 'depth';
97  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
98 
99  $px1->draw($filenamenb, $fileurlnb);
100 }
101 
102 // Build graphic amount of object
103 /*
104 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
105 //var_dump($data);
106 // $data = array(array('Lib',val1,val2,val3),...)
107 
108 if (empty($user->rights->societe->client->voir) || $user->socid)
109 {
110  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
111 }
112 else
113 {
114  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
115 }
116 
117 $px2 = new DolGraph();
118 $mesg = $px2->isGraphKo();
119 if (! $mesg)
120 {
121  $px2->SetData($data);
122  $i=$startyear;$legend=array();
123  while ($i <= $endyear)
124  {
125  $legend[]=$i;
126  $i++;
127  }
128  $px2->SetLegend($legend);
129  $px2->SetMaxValue($px2->GetCeilMaxValue());
130  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
131  $px2->SetWidth($WIDTH);
132  $px2->SetHeight($HEIGHT);
133  $px2->SetYLabel($langs->trans("AmountOfShipments"));
134  $px2->SetShading(3);
135  $px2->SetHorizTickIncrement(1);
136  $px2->mode='depth';
137  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
138 
139  $px2->draw($filenameamount,$fileurlamount);
140 }
141 */
142 
143 /*
144 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
145 
146 if (empty($user->rights->societe->client->voir) || $user->socid)
147 {
148  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
149 }
150 else
151 {
152  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
153 }
154 
155 $px3 = new DolGraph();
156 $mesg = $px3->isGraphKo();
157 if (! $mesg)
158 {
159  $px3->SetData($data);
160  $i=$startyear;$legend=array();
161  while ($i <= $endyear)
162  {
163  $legend[]=$i;
164  $i++;
165  }
166  $px3->SetLegend($legend);
167  $px3->SetYLabel($langs->trans("AmountAverage"));
168  $px3->SetMaxValue($px3->GetCeilMaxValue());
169  $px3->SetMinValue($px3->GetFloorMinValue());
170  $px3->SetWidth($WIDTH);
171  $px3->SetHeight($HEIGHT);
172  $px3->SetShading(3);
173  $px3->SetHorizTickIncrement(1);
174  $px3->mode='depth';
175  $px3->SetTitle($langs->trans("AmountAverage"));
176 
177  $px3->draw($filename_avg,$fileurl_avg);
178 }
179 */
180 
181 
182 // Show array
183 $data = $stats->getAllByYear();
184 $arrayyears = array();
185 foreach ($data as $val) {
186  if (!empty($val['year'])) {
187  $arrayyears[$val['year']] = $val['year'];
188  }
189 }
190 if (!count($arrayyears)) {
191  $arrayyears[$nowyear] = $nowyear;
192 }
193 
194 $h = 0;
195 $head = array();
196 $head[$h][0] = DOL_URL_ROOT.'/don/stats/index.php';
197 $head[$h][1] = $langs->trans("ByMonthYear");
198 $head[$h][2] = 'byyear';
199 $h++;
200 
201 $type = 'donation_stats';
202 
203 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
204 
205 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
206 
207 
208 print '<div class="fichecenter"><div class="fichethirdleft">';
209 
210 
211 // Show filter box
212 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
213 print '<input type="hidden" name="token" value="'.newToken().'">';
214 
215 print '<table class="border centpercent">';
216 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
217 // Company
218 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
219 print img_picto('', 'company', 'class="pictofixedwidth"');
220 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
221 print '</td></tr>';
222 // User
223 print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
224 print img_picto('', 'user', 'class="pictofixedwidth"');
225 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
226 print '</td></tr>';
227 // Year
228 print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
229 if (!in_array($year, $arrayyears)) {
230  $arrayyears[$year] = $year;
231 }
232 if (!in_array($nowyear, $arrayyears)) {
233  $arrayyears[$nowyear] = $nowyear;
234 }
235 arsort($arrayyears);
236 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
237 print '</td></tr>';
238 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
239 print '</table>';
240 print '</form>';
241 print '<br><br>';
242 
243 print '<div class="div-table-responsive-no-min">';
244 print '<table class="border centpercent">';
245 print '<tr height="24">';
246 print '<td class="center">'.$langs->trans("Year").'</td>';
247 print '<td class="center">'.$langs->trans("NbOfSendings").'</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  print '<tr height="24">';
258  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
259 
260  print '<td class="right">0</td>';
261  /*print '<td class="right">0</td>';
262  print '<td class="right">0</td>';*/
263  print '</tr>';
264  }
265 
266  print '<tr height="24">';
267  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
268  print '<td class="right">'.$val['nb'].'</td>';
269  /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
270  print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
271  print '</tr>';
272  $oldyear = $year;
273 }
274 
275 print '</table>';
276 print '</div>';
277 
278 
279 print '</div><div class="fichetwothirdright">';
280 
281 
282 // Show graphs
283 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
284 if ($mesg) {
285  print $mesg;
286 } else {
287  print $px1->show();
288  print "<br>\n";
289  /*print $px2->show();
290  print "<br>\n";
291  print $px3->show();*/
292 }
293 print '</td></tr></table>';
294 
295 
296 print '</div></div>';
297 print '<div style="clear:both"></div>';
298 
299 print dol_get_fiche_end();
300 
301 
302 
303 // TODO USe code similar to commande/stats/index.php instead of this one.
304 /*
305 print '<table class="border centpercent">';
306 print '<tr><td class="center">'.$langs->trans("Year").'</td>';
307 print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
308 
309 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
310 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
311 $sql.= " WHERE fk_statut > 0";
312 $sql.= " AND entity = ".$conf->entity;
313 $sql.= " GROUP BY dm DESC";
314 
315 $resql=$db->query($sql);
316 if ($resql)
317 {
318  $num = $db->num_rows($resql);
319  $i = 0;
320  while ($i < $num)
321  {
322  $row = $db->fetch_row($resql);
323  $nbproduct = $row[0];
324  $year = $row[1];
325  print "<tr>";
326  print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
327  $i++;
328  }
329 }
330 $db->free($resql);
331 
332 print '</table>';
333 */
334 
335 print '<br>';
336 print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
337 
338 llxFooter();
339 
340 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1539
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
DonationStats
Class to manage donations statistics.
Definition: donstats.class.php:35
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603