dolibarr 18.0.6
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 - (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
59llxHeader();
60
61print load_fiche_titre($langs->trans("StatisticsOfDonations"), $mesg);
62
63
64dol_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
74if (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();
82if (!$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
109if (empty($user->rights->societe->client->voir) || $user->socid)
110{
111 $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
112}
113else
114{
115 $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
116}
117
118$px2 = new DolGraph();
119$mesg = $px2->isGraphKo();
120if (! $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
147if (empty($user->rights->societe->client->voir) || $user->socid)
148{
149 $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
150}
151else
152{
153 $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
154}
155
156$px3 = new DolGraph();
157$mesg = $px3->isGraphKo();
158if (! $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();
186foreach ($data as $val) {
187 if (!empty($val['year'])) {
188 $arrayyears[$val['year']] = $val['year'];
189 }
190}
191if (!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
204complete_head_from_modules($conf, $langs, null, $head, $h, $type);
205
206print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
207
208
209print '<div class="fichecenter"><div class="fichethirdleft">';
210
211
212// Show filter box
213print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
214print '<input type="hidden" name="token" value="'.newToken().'">';
215
216print '<table class="border centpercent">';
217print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
218// Company
219print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
220print img_picto('', 'company', 'class="pictofixedwidth"');
221print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
222print '</td></tr>';
223// User
224print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
225print img_picto('', 'user', 'class="pictofixedwidth"');
226print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
227print '</td></tr>';
228// Year
229print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
230if (!in_array($year, $arrayyears)) {
231 $arrayyears[$year] = $year;
232}
233if (!in_array($nowyear, $arrayyears)) {
234 $arrayyears[$nowyear] = $nowyear;
235}
236arsort($arrayyears);
237print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
238print '</td></tr>';
239print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
240print '</table>';
241print '</form>';
242print '<br><br>';
243
244print '<div class="div-table-responsive-no-min">';
245print '<table class="border centpercent">';
246print '<tr height="24">';
247print '<td class="center">'.$langs->trans("Year").'</td>';
248print '<td class="right">'.$langs->trans("NbOfDonations").'</td>';
249/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
250print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
251print '</tr>';
252
253$oldyear = 0;
254foreach ($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
276print '</table>';
277print '</div>';
278
279
280print '</div><div class="fichetwothirdright">';
281
282
283// Show graphs
284print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
285if ($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}
294print '</td></tr></table>';
295
296
297print '</div></div>';
298print '<div class="clearboth"></div>';
299
300print dol_get_fiche_end();
301
302
303
304// TODO USe code similar to commande/stats/index.php instead of this one.
305/*
306print '<table class="border centpercent">';
307print '<tr><td class="center">'.$langs->trans("Year").'</td>';
308print '<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);
317if ($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
333print '</table>';
334*/
335
336print '<br>';
337print '<i>'.$langs->trans("StatsOnDonationsOnlyValidated").'</i>';
338
339llxFooter();
340
341$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)