dolibarr 23.0.3
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
32require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35if (isModEnabled('category')) {
36 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
37}
38
49
50// Load translation files required by the page
51$langs->loadLangs(array("donations"));
52
53$userid = GETPOSTINT('userid');
54$socid = GETPOSTINT('socid');
55// Security check
56if ($user->socid > 0) {
57 $action = '';
58 $socid = $user->socid;
59}
60
61$status = GETPOSTINT('status');
62$nowyear = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
63$typent_id = GETPOSTINT('typent_id');
64$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
65$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
66$endyear = $year;
67$mode = GETPOST("mode") ? GETPOST("mode") : 'customer';
68$custcats = GETPOST('custcats', 'array');
69
70// Security check
71$result = restrictedArea($user, 'don');
72
73/*
74 * View
75 */
76$form = new Form($db);
77$formcompany = new FormCompany($db);
78
79llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-don page-stats_index');
80
81$dir = $conf->don->dir_temp;
82
83print load_fiche_titre($langs->trans("DonationsStatistics"), '', 'donation');
84
85dol_mkdir($dir);
86
87$stats = new DonationStats($db, $socid, '', ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($status > 0 ? $status : 4));
88
89if (is_array($custcats) && !empty($custcats)) {
90 $stats->from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cat ON (d.fk_soc = cat.fk_soc)';
91 $stats->where .= ' AND cat.fk_categorie IN ('.$db->sanitize(implode(',', $custcats)).')';
92}
93
94// Build graphic number of object
95$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
96
97$filenamenb = $dir."/salariesnbinyear-".$year.".png";
98$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=donationStats&amp;file=donationinyear-'.$year.'.png';
99
100$px1 = new DolGraph();
101$mesg = $px1->isGraphKo();
102if (!$mesg) {
103 $px1->SetData($data);
104 $i = $startyear;
105 $legend = array();
106 while ($i <= $endyear) {
107 $legend[] = $i;
108 $i++;
109 }
110 $px1->SetLegend($legend);
111 $px1->SetMaxValue($px1->GetCeilMaxValue());
112 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
113 $px1->SetWidth($WIDTH);
114 $px1->SetHeight($HEIGHT);
115 $px1->SetYLabel($langs->trans("NbOfDonations"));
116 $px1->SetShading(3);
117 $px1->SetHorizTickIncrement(1);
118 $px1->mode = 'depth';
119 $px1->SetTitle($langs->trans("NumberByMonth"));
120
121 $px1->draw($filenamenb, $fileurlnb);
122}
123
124$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
125
126$filenameamount = $dir."/donationamount-".$year.".png";
127$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=donationStats&amp;file=donationamoutinyear-'.$year.'.png';
128
129$px2 = new DolGraph();
130$mesg = $px2->isGraphKo();
131if (!$mesg) {
132 $px2->SetData($data);
133 $i = $startyear;
134 $legend = array();
135 while ($i <= $endyear) {
136 $legend[] = $i;
137 $i++;
138 }
139 $px2->SetLegend($legend);
140 $px2->SetMaxValue($px2->GetCeilMaxValue());
141 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
142 $px2->SetWidth($WIDTH);
143 $px2->SetHeight($HEIGHT);
144 $px2->SetYLabel($langs->trans("Amount"));
145 $px2->SetShading(3);
146 $px2->SetHorizTickIncrement(1);
147 $px2->mode = 'depth';
148 $px2->SetTitle($langs->trans("AmountTotal"));
149
150 $px2->draw($filenameamount, $fileurlamount);
151}
152
153$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
154
155$filename_avg = $dir."/donationaverage-".$year.".png";
156$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=donationStats&file=donationaverageinyear-'.$year.'.png';
157
158$px3 = new DolGraph();
159$mesg = $px3->isGraphKo();
160if (!$mesg) {
161 $px3->SetData($data);
162 $i = $startyear;
163 $legend = array();
164 while ($i <= $endyear) {
165 $legend[] = $i;
166 $i++;
167 }
168 $px3->SetLegend($legend);
169 $px3->SetYLabel($langs->trans("AmountAverage"));
170 $px3->SetMaxValue($px3->GetCeilMaxValue());
171 $px3->SetMinValue((int) $px3->GetFloorMinValue());
172 $px3->SetWidth($WIDTH);
173 $px3->SetHeight($HEIGHT);
174 $px3->SetShading(3);
175 $px3->SetHorizTickIncrement(1);
176 $px3->mode = 'depth';
177 $px3->SetTitle($langs->trans("AmountAverage"));
178
179 $px3->draw($filename_avg, $fileurl_avg);
180}
181
182// Show array
183$data = $stats->getAllByYear();
184$arrayyears = array();
185foreach ($data as $val) {
186 if (!empty($val['year'])) {
187 $arrayyears[$val['year']] = $val['year'];
188 }
189}
190if (!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
203complete_head_from_modules($conf, $langs, null, $head, $h, $type);
204
205print dol_get_fiche_head($head, 'byyear', '', -1);
206
207
208print '<div class="fichecenter"><div class="fichethirdleft">';
209
210// Show filter box
211print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
212print '<input type="hidden" name="token" value="'.newToken().'">';
213
214print '<table class="noborder centpercent">';
215print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
216
217// Company
218if (getDolGlobalString('DONATION_USE_THIRDPARTIES')) {
219 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
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}
224
225// ThirdParty Type
226print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
227$sortparam_typent = getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC');
228print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
229if ($user->admin) {
230 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
231}
232print '</td></tr>';
233
234// Category
235if (isModEnabled('category')) {
236 $cat_type = Categorie::TYPE_CUSTOMER;
237 $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
238 print '<tr><td>'.$cat_label.'</td><td>';
239 $cate_arbo = $form->select_all_categories($cat_type, '', 'parent', 0, 0, 1);
240 print img_picto('', 'category', 'class="pictofixedwidth"');
241 if (is_array($cate_arbo)) {
242 print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), 0, 0, 'widthcentpercentminusx maxwidth300');
243 }
244 print '</td></tr>';
245}
246
247// User
248print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
249print img_picto('', 'user', 'class="pictofixedwidth"');
250print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
251print '</td></tr>';
252
253// Status
254print '<tr><td>'.$langs->trans("Status").'</td><td>';
255$liststatus = array(
256 '2' => $langs->trans("DonationStatusPaid"),
257 '0' => $langs->trans("DonationStatusPromiseNotValidated"),
258 '1' => $langs->trans("DonationStatusPromiseValidated"),
259 '3' => $langs->trans("Canceled")
260);
261print $form->selectarray('status', $liststatus, 4, 1);
262
263// Year
264print '<tr><td>'.$langs->trans("Year").'</td><td>';
265arsort($arrayyears);
266print img_picto('', 'calendar', 'class="pictofixedwidth"');
267print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
268
269print '</td></tr>';
270print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
271print '</table>';
272print '</form>';
273print '<br><br>';
274
275print '<div class="div-table-responsive-no-min">';
276print '<table class="noborder centpercent">';
277print '<tr class="liste_titre" height="24">';
278print '<td class="center">'.$langs->trans("Year").'</td>';
279print '<td class="right">'.$langs->trans("NbOfDonations").'</td>';
280print '<td class="right">%</td>';
281print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
282print '<td class="right">%</td>';
283print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
284print '<td class="right">%</td>';
285print '</tr>';
286
287$oldyear = 0;
288foreach ($data as $val) {
289 $year = $val['year'];
290 while (!empty($year) && $oldyear > (int) $year + 1) {
291 $oldyear--;
292 print '<tr class="oddeven" height="24">';
293 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
294
295 print '<td class="right">0</td>';
296 print '<td class="right"></td>';
297 print '<td class="right amount">0</td>';
298 print '<td class="right"></td>';
299 print '<td class="right amount">0</td>';
300 print '<td class="right"></td>';
301 print '</tr>';
302 }
303
304 $greennb = (empty($val['nb_diff']) || $val['nb_diff'] >= 0);
305 $greentotal = (empty($val['total_diff']) || $val['total_diff'] >= 0);
306 $greenavg = (empty($val['avg_diff']) || $val['avg_diff'] >= 0);
307
308 print '<tr class="oddeven" height="24">';
309 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>';
310 print '<td class="right">'.$val['nb'].'</td>';
311 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>';
312 print '<td class="right"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
313 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>';
314 print '<td class="right"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
315 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>';
316 print '</tr>';
317 $oldyear = $year;
318}
319
320print '</table>';
321print '</div>';
322
323print '</div><div class="fichetwothirdright">';
324
325// Show graphs
326print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
327if ($mesg) {
328 print $mesg;
329} else {
330 print $px1->show();
331 print "<br>\n";
332 print $px2->show();
333 print "<br>\n";
334 print $px3->show();
335}
336print '</td></tr></table>';
337
338print '</div></div>';
339print '<div class="clearboth"></div>';
340
341print dol_get_fiche_end();
342
343llxFooter();
344$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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, $morecssdiv='')
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.