dolibarr 19.0.4
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
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
30require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.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// Security check
39if ($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 - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('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// Security check
53$result = restrictedArea($user, 'don');
54
55
56/*
57 * View
58 */
59
60$form = new Form($db);
61
62llxHeader();
63
64print load_fiche_titre($langs->trans("StatisticsOfDonations"), $mesg);
65
66
67dol_mkdir($dir);
68
69$stats = new DonationStats($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
77if (!$user->hasRight('societe', 'client', 'voir') || $user->socid) {
78 $filenamenb = $dir.'/donationnbinyear-'.$user->id.'-'.$year.'.png';
79} else {
80 $filenamenb = $dir.'/donationnbinyear-'.$year.'.png';
81}
82
83$px1 = new DolGraph();
84$mesg = $px1->isGraphKo();
85if (!$mesg) {
86 $px1->SetData($data);
87 $i = $startyear;
88 $legend = array();
89 while ($i <= $endyear) {
90 $legend[] = $i;
91 $i++;
92 }
93 $px1->SetLegend($legend);
94 $px1->SetMaxValue($px1->GetCeilMaxValue());
95 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
96 $px1->SetWidth($WIDTH);
97 $px1->SetHeight($HEIGHT);
98 $px1->SetYLabel($langs->trans("NbOfDonations"));
99 $px1->SetShading(3);
100 $px1->SetHorizTickIncrement(1);
101 $px1->mode = 'depth';
102 $px1->SetTitle($langs->trans("NumberOfDonationsByMonth"));
103
104 $px1->draw($filenamenb, $fileurlnb);
105}
106
107// Build graphic amount of object
108/*
109$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
110//var_dump($data);
111// $data = array(array('Lib',val1,val2,val3),...)
112
113if (empty($user->rights->societe->client->voir) || $user->socid)
114{
115 $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
116}
117else
118{
119 $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
120}
121
122$px2 = new DolGraph();
123$mesg = $px2->isGraphKo();
124if (! $mesg)
125{
126 $px2->SetData($data);
127 $i=$startyear;$legend=array();
128 while ($i <= $endyear)
129 {
130 $legend[]=$i;
131 $i++;
132 }
133 $px2->SetLegend($legend);
134 $px2->SetMaxValue($px2->GetCeilMaxValue());
135 $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
136 $px2->SetWidth($WIDTH);
137 $px2->SetHeight($HEIGHT);
138 $px2->SetYLabel($langs->trans("AmountOfShipments"));
139 $px2->SetShading(3);
140 $px2->SetHorizTickIncrement(1);
141 $px2->mode='depth';
142 $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
143
144 $px2->draw($filenameamount,$fileurlamount);
145}
146*/
147
148/*
149$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
150
151if (empty($user->rights->societe->client->voir) || $user->socid)
152{
153 $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
154}
155else
156{
157 $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
158}
159
160$px3 = new DolGraph();
161$mesg = $px3->isGraphKo();
162if (! $mesg)
163{
164 $px3->SetData($data);
165 $i=$startyear;$legend=array();
166 while ($i <= $endyear)
167 {
168 $legend[]=$i;
169 $i++;
170 }
171 $px3->SetLegend($legend);
172 $px3->SetYLabel($langs->trans("AmountAverage"));
173 $px3->SetMaxValue($px3->GetCeilMaxValue());
174 $px3->SetMinValue($px3->GetFloorMinValue());
175 $px3->SetWidth($WIDTH);
176 $px3->SetHeight($HEIGHT);
177 $px3->SetShading(3);
178 $px3->SetHorizTickIncrement(1);
179 $px3->mode='depth';
180 $px3->SetTitle($langs->trans("AmountAverage"));
181
182 $px3->draw($filename_avg,$fileurl_avg);
183}
184*/
185
186
187// Show array
188$data = $stats->getAllByYear();
189$arrayyears = array();
190foreach ($data as $val) {
191 if (!empty($val['year'])) {
192 $arrayyears[$val['year']] = $val['year'];
193 }
194}
195if (!count($arrayyears)) {
196 $arrayyears[$nowyear] = $nowyear;
197}
198
199$h = 0;
200$head = array();
201$head[$h][0] = DOL_URL_ROOT.'/don/stats/index.php';
202$head[$h][1] = $langs->trans("ByMonthYear");
203$head[$h][2] = 'byyear';
204$h++;
205
206$type = 'donation_stats';
207
208complete_head_from_modules($conf, $langs, null, $head, $h, $type);
209
210print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
211
212
213print '<div class="fichecenter"><div class="fichethirdleft">';
214
215
216// Show filter box
217print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
218print '<input type="hidden" name="token" value="'.newToken().'">';
219
220print '<table class="border centpercent">';
221print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
222// Company
223print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
224print img_picto('', 'company', 'class="pictofixedwidth"');
225print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
226print '</td></tr>';
227// User
228print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
229print img_picto('', 'user', 'class="pictofixedwidth"');
230print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
231print '</td></tr>';
232// Year
233print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
234if (!in_array($year, $arrayyears)) {
235 $arrayyears[$year] = $year;
236}
237if (!in_array($nowyear, $arrayyears)) {
238 $arrayyears[$nowyear] = $nowyear;
239}
240arsort($arrayyears);
241print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
242print '</td></tr>';
243print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
244print '</table>';
245print '</form>';
246print '<br><br>';
247
248print '<div class="div-table-responsive-no-min">';
249print '<table class="border centpercent">';
250print '<tr height="24">';
251print '<td class="center">'.$langs->trans("Year").'</td>';
252print '<td class="right">'.$langs->trans("NbOfDonations").'</td>';
253/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
254print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
255print '</tr>';
256
257$oldyear = 0;
258foreach ($data as $val) {
259 $year = $val['year'];
260 while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
261 $oldyear--;
262 print '<tr 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 height="24">';
272 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
273 print '<td class="right">'.$val['nb'].'</td>';
274 /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
275 print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
276 print '</tr>';
277 $oldyear = $year;
278}
279
280print '</table>';
281print '</div>';
282
283
284print '</div><div class="fichetwothirdright">';
285
286
287// Show graphs
288print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
289if ($mesg) {
290 print $mesg;
291} else {
292 print $px1->show();
293 print "<br>\n";
294 /*print $px2->show();
295 print "<br>\n";
296 print $px3->show();*/
297}
298print '</td></tr></table>';
299
300
301print '</div></div>';
302print '<div class="clearboth"></div>';
303
304print dol_get_fiche_end();
305
306
307
308// TODO USe code similar to commande/stats/index.php instead of this one.
309/*
310print '<table class="border centpercent">';
311print '<tr><td class="center">'.$langs->trans("Year").'</td>';
312print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
313
314$sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
315$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
316$sql.= " WHERE fk_statut > 0";
317$sql.= " AND entity = ".$conf->entity;
318$sql.= " GROUP BY dm DESC";
319
320$resql=$db->query($sql);
321if ($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
337print '</table>';
338*/
339
340print '<br>';
341print '<i>'.$langs->trans("StatsOnDonationsOnlyValidated").'</i>';
342
343llxFooter();
344
345$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.