dolibarr 20.0.0
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';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33if (isModEnabled('category')) {
34 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
35}
38
39// Load translation files required by the page
40$langs->loadLangs("donations");
41
42$userid = GETPOSTINT('userid');
43$socid = GETPOSTINT('socid');
44// Security check
45if ($user->socid > 0) {
46 $action = '';
47 $socid = $user->socid;
48}
49
50$status = GETPOSTINT('status');
51$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
52$typent_id = GETPOSTINT('typent_id');
53$year = GETPOST('year') > 0 ? GETPOST('year') : $nowyear;
54$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
55$endyear = $year;
56$mode = GETPOST("mode") ? GETPOST("mode") : 'customer';
57$custcats = GETPOST('custcats', 'array');
58
59// Security check
60$result = restrictedArea($user, 'don');
61
62/*
63 * View
64 */
65$form = new Form($db);
66$formcompany = new FormCompany($db);
67
68llxHeader();
69
70$dir = $conf->don->dir_temp;
71
72print load_fiche_titre($langs->trans("DonationsStatistics"), '', 'donation');
73
74dol_mkdir($dir);
75
76$stats = new DonationStats($db, $socid, '', ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($status > 0 ? $status : 4));
77
78if (is_array($custcats) && !empty($custcats)) {
79 $stats->from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cat ON (d.fk_soc = cat.fk_soc)';
80 $stats->where .= ' AND cat.fk_categorie IN ('.$db->sanitize(implode(',', $custcats)).')';
81}
82
83// Build graphic number of object
84$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
85
86$filenamenb = $dir."/salariesnbinyear-".$year.".png";
87$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=donationStats&amp;file=donationinyear-'.$year.'.png';
88
89$px1 = new DolGraph();
90$mesg = $px1->isGraphKo();
91if (!$mesg) {
92 $px1->SetData($data);
93 $i = $startyear;
94 $legend = array();
95 while ($i <= $endyear) {
96 $legend[] = $i;
97 $i++;
98 }
99 $px1->SetLegend($legend);
100 $px1->SetMaxValue($px1->GetCeilMaxValue());
101 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
102 $px1->SetWidth($WIDTH);
103 $px1->SetHeight($HEIGHT);
104 $px1->SetYLabel($langs->trans("NbOfDonations"));
105 $px1->SetShading(3);
106 $px1->SetHorizTickIncrement(1);
107 $px1->mode = 'depth';
108 $px1->SetTitle($langs->trans("NumberByMonth"));
109
110 $px1->draw($filenamenb, $fileurlnb);
111}
112
113$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
114
115$filenameamount = $dir."/donationamount-".$year.".png";
116$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=donationStats&amp;file=donationamoutinyear-'.$year.'.png';
117
118$px2 = new DolGraph();
119$mesg = $px2->isGraphKo();
120if (!$mesg) {
121 $px2->SetData($data);
122 $i=$startyear;$legend=array();
123 while ($i <= $endyear) {
124 $legend[]=$i;
125 $i++;
126 }
127 $px2->SetLegend($legend);
128 $px2->SetMaxValue($px2->GetCeilMaxValue());
129 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
130 $px2->SetWidth($WIDTH);
131 $px2->SetHeight($HEIGHT);
132 $px2->SetYLabel($langs->trans("Amount"));
133 $px2->SetShading(3);
134 $px2->SetHorizTickIncrement(1);
135 $px2->mode='depth';
136 $px2->SetTitle($langs->trans("AmountTotal"));
137
138 $px2->draw($filenameamount, $fileurlamount);
139}
140
141$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
142
143$filename_avg = $dir."/donationaverage-".$year.".png";
144$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=donationStats&file=donationaverageinyear-'.$year.'.png';
145
146$px3 = new DolGraph();
147$mesg = $px3->isGraphKo();
148if (!$mesg) {
149 $px3->SetData($data);
150 $i = $startyear;
151 $legend = array();
152 while ($i <= $endyear) {
153 $legend[] = $i;
154 $i++;
155 }
156 $px3->SetLegend($legend);
157 $px3->SetYLabel($langs->trans("AmountAverage"));
158 $px3->SetMaxValue($px3->GetCeilMaxValue());
159 $px3->SetMinValue($px3->GetFloorMinValue());
160 $px3->SetWidth($WIDTH);
161 $px3->SetHeight($HEIGHT);
162 $px3->SetShading(3);
163 $px3->SetHorizTickIncrement(1);
164 $px3->mode = 'depth';
165 $px3->SetTitle($langs->trans("AmountAverage"));
166
167 $px3->draw($filename_avg, $fileurl_avg);
168}
169
170// Show array
171$data = $stats->getAllByYear();
172$arrayyears = array();
173foreach ($data as $val) {
174 if (!empty($val['year'])) {
175 $arrayyears[$val['year']] = $val['year'];
176 }
177}
178if (!count($arrayyears)) {
179 $arrayyears[$nowyear] = $nowyear;
180}
181
182$h = 0;
183$head = array();
184$head[$h][0] = DOL_URL_ROOT.'/don/stats/index.php';
185$head[$h][1] = $langs->trans("ByMonthYear");
186$head[$h][2] = 'byyear';
187$h++;
188
189$type = 'donation_stats';
190
191complete_head_from_modules($conf, $langs, null, $head, $h, $type);
192
193print dol_get_fiche_head($head, 'byyear', '', -1);
194
195
196print '<div class="fichecenter"><div class="fichethirdleft">';
197
198// Show filter box
199print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
200print '<input type="hidden" name="token" value="'.newToken().'">';
201
202print '<table class="noborder centpercent">';
203print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
204
205// Company
206if (empty(!$conf->global->DONATION_USE_THIRDPARTIES)) {
207 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
208 print img_picto('', 'company', 'class="pictofixedwidth"');
209 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
210 print '</td></tr>';
211}
212
213// ThirdParty Type
214print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
215$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
216print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
217if ($user->admin) {
218 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
219}
220print '</td></tr>';
221
222// Category
223if (isModEnabled('category')) {
224 $cat_type = Categorie::TYPE_CUSTOMER;
225 $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
226 print '<tr><td>'.$cat_label.'</td><td>';
227 $cate_arbo = $form->select_all_categories($cat_type, null, 'parent', null, null, 1);
228 print img_picto('', 'category', 'class="pictofixedwidth"');
229 print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), 0, 0, 'widthcentpercentminusx maxwidth300');
230 print '</td></tr>';
231}
232
233// User
234print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
235print img_picto('', 'user', 'class="pictofixedwidth"');
236print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
237print '</td></tr>';
238
239// Status
240print '<tr><td>'.$langs->trans("Status").'</td><td>';
241$liststatus = array(
242 '2' => $langs->trans("DonationStatusPaid"),
243 '0' => $langs->trans("DonationStatusPromiseNotValidated"),
244 '1' => $langs->trans("DonationStatusPromiseValidated"),
245 '3' => $langs->trans("Canceled")
246);
247print $form->selectarray('status', $liststatus, 4, 1);
248
249// Year
250print '<tr><td>'.$langs->trans("Year").'</td><td>';
251arsort($arrayyears);
252print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
253
254print '</td></tr>';
255print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
256print '</table>';
257print '</form>';
258print '<br><br>';
259
260print '<div class="div-table-responsive-no-min">';
261print '<table class="noborder centpercent">';
262print '<tr class="liste_titre" height="24">';
263print '<td class="center">'.$langs->trans("Year").'</td>';
264print '<td class="right">'.$langs->trans("NbOfDonations").'</td>';
265print '<td class="right">%</td>';
266print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
267print '<td class="right">%</td>';
268print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
269print '<td class="right">%</td>';
270print '</tr>';
271
272$oldyear = 0;
273foreach ($data as $val) {
274 $year = $val['year'];
275 while (!empty($year) && $oldyear > $year + 1) {
276 $oldyear--;
277 print '<tr class="oddeven" height="24">';
278 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
279
280 print '<td class="right">0</td>';
281 print '<td class="right"></td>';
282 print '<td class="right amount">0</td>';
283 print '<td class="right"></td>';
284 print '<td class="right amount">0</td>';
285 print '<td class="right"></td>';
286 print '</tr>';
287 }
288
289 $greennb = (empty($val['nb_diff']) || $val['nb_diff'] >= 0);
290 $greentotal = (empty($val['total_diff']) || $val['total_diff'] >= 0);
291 $greenavg = (empty($val['avg_diff']) || $val['avg_diff'] >= 0);
292
293 print '<tr class="oddeven" height="24">';
294 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
295 print '<td class="right">'.$val['nb'].'</td>';
296 print '<td class="right opacitylow" style="'.($greennb ? 'color: green;' : 'color: red;').'">'.(!empty($val['nb_diff']) && $val['nb_diff'] < 0 ? '' : '+').round(!empty($val['nb_diff']) ? $val['nb_diff'] : 0).'%</td>';
297 print '<td class="right"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
298 print '<td class="right opacitylow" style="'.($greentotal ? 'color: green;' : 'color: red;').'">'.( !empty($val['total_diff']) && $val['total_diff'] < 0 ? '' : '+').round(!empty($val['total_diff']) ? $val['total_diff'] : 0).'%</td>';
299 print '<td class="right"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
300 print '<td class="right opacitylow" style="'.($greenavg ? 'color: green;' : 'color: red;').'">'.(!empty($val['avg_diff']) && $val['avg_diff'] < 0 ? '' : '+').round(!empty($val['avg_diff']) ? $val['avg_diff'] : 0).'%</td>';
301 print '</tr>';
302 $oldyear = $year;
303}
304
305print '</table>';
306print '</div>';
307
308print '</div><div class="fichetwothirdright">';
309
310// Show graphs
311print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
312if ($mesg) {
313 print $mesg;
314} else {
315 print $px1->show();
316 print "<br>\n";
317 print $px2->show();
318 print "<br>\n";
319 print $px3->show();
320}
321print '</td></tr></table>';
322
323print '</div></div>';
324print '<div class="clearboth"></div>';
325
326print dol_get_fiche_end();
327
328llxFooter();
329$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 build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.