dolibarr  19.0.0-dev
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 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
32 
34 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
35 
36 $userid = GETPOST('userid', 'int');
37 $socid = GETPOST('socid', 'int');
38 // Security check
39 if ($user->socid > 0) {
40  $action = '';
41  $socid = $user->socid;
42 }
43 
44 $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
45 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
46 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
47 $endyear = $year;
48 
49 // Load translation files required by the page
50 $langs->loadLangs(array("companies", "other", "sendings"));
51 
52 
53 /*
54  * View
55  */
56 
57 $form = new Form($db);
58 
59 llxHeader();
60 
61 print load_fiche_titre($langs->trans("StatisticsOfDonations"), $mesg);
62 
63 
64 dol_mkdir($dir);
65 
66 $stats = new DonationStats($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 
74 if (empty($user->rights->societe->client->voir) || $user->socid) {
75  $filenamenb = $dir.'/donationnbinyear-'.$user->id.'-'.$year.'.png';
76 } else {
77  $filenamenb = $dir.'/donationnbinyear-'.$year.'.png';
78 }
79 
80 $px1 = new DolGraph();
81 $mesg = $px1->isGraphKo();
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("NbOfDonations"));
95  $px1->SetShading(3);
96  $px1->SetHorizTickIncrement(1);
97  $px1->mode = 'depth';
98  $px1->SetTitle($langs->trans("NumberOfDonationsByMonth"));
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.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
112 }
113 else
114 {
115  $filenameamount = $dir.'/shipmentsamountinyear-'.$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("AmountOfShipments"));
135  $px2->SetShading(3);
136  $px2->SetHorizTickIncrement(1);
137  $px2->mode='depth';
138  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
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.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
150 }
151 else
152 {
153  $filename_avg = $dir.'/shipmentsaverage-'.$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.'/don/stats/index.php';
198 $head[$h][1] = $langs->trans("ByMonthYear");
199 $head[$h][2] = 'byyear';
200 $h++;
201 
202 $type = 'donation_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="border centpercent">';
217 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
218 // Company
219 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
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 class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
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 class="left">'.$langs->trans("Year").'</td><td class="left">';
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 '<div class="div-table-responsive-no-min">';
245 print '<table class="border centpercent">';
246 print '<tr height="24">';
247 print '<td class="center">'.$langs->trans("Year").'</td>';
248 print '<td class="right">'.$langs->trans("NbOfDonations").'</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  $year = $val['year'];
256  while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
257  $oldyear--;
258  print '<tr height="24">';
259  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
260 
261  print '<td class="right">0</td>';
262  /*print '<td class="right">0</td>';
263  print '<td class="right">0</td>';*/
264  print '</tr>';
265  }
266 
267  print '<tr height="24">';
268  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
269  print '<td class="right">'.$val['nb'].'</td>';
270  /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
271  print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
272  print '</tr>';
273  $oldyear = $year;
274 }
275 
276 print '</table>';
277 print '</div>';
278 
279 
280 print '</div><div class="fichetwothirdright">';
281 
282 
283 // Show graphs
284 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
285 if ($mesg) {
286  print $mesg;
287 } else {
288  print $px1->show();
289  print "<br>\n";
290  /*print $px2->show();
291  print "<br>\n";
292  print $px3->show();*/
293 }
294 print '</td></tr></table>';
295 
296 
297 print '</div></div>';
298 print '<div class="clearboth"></div>';
299 
300 print dol_get_fiche_end();
301 
302 
303 
304 // TODO USe code similar to commande/stats/index.php instead of this one.
305 /*
306 print '<table class="border centpercent">';
307 print '<tr><td class="center">'.$langs->trans("Year").'</td>';
308 print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
309 
310 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
311 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
312 $sql.= " WHERE fk_statut > 0";
313 $sql.= " AND entity = ".$conf->entity;
314 $sql.= " GROUP BY dm DESC";
315 
316 $resql=$db->query($sql);
317 if ($resql)
318 {
319  $num = $db->num_rows($resql);
320  $i = 0;
321  while ($i < $num)
322  {
323  $row = $db->fetch_row($resql);
324  $nbproduct = $row[0];
325  $year = $row[1];
326  print "<tr>";
327  print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
328  $i++;
329  }
330 }
331 $db->free($resql);
332 
333 print '</table>';
334 */
335 
336 print '<br>';
337 print '<i>'.$langs->trans("StatsOnDonationsOnlyValidated").'</i>';
338 
339 llxFooter();
340 
341 $db->close();
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage donations statistics.
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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)
llxFooter()
Footer empty.
Definition: index.php:71
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