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';
51$langs->loadLangs(array(
"donations"));
56if ($user->socid > 0) {
58 $socid = $user->socid;
68$custcats =
GETPOST(
'custcats',
'array');
79llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-don page-stats_index');
81$dir =
$conf->don->dir_temp;
87$stats =
new DonationStats($db, $socid,
'', ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($status > 0 ? $status : 4));
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)).
')';
95$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
97$filenamenb = $dir.
"/salariesnbinyear-".$year.
".png";
98$fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=donationStats&file=donationinyear-'.$year.
'.png';
101$mesg = $px1->isGraphKo();
103 $px1->SetData($data);
106 while ($i <= $endyear) {
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"));
117 $px1->SetHorizTickIncrement(1);
118 $px1->mode =
'depth';
119 $px1->SetTitle($langs->trans(
"NumberByMonth"));
121 $px1->draw($filenamenb, $fileurlnb);
124$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
126$filenameamount = $dir.
"/donationamount-".$year.
".png";
127$fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=donationStats&file=donationamoutinyear-'.$year.
'.png';
130$mesg = $px2->isGraphKo();
132 $px2->SetData($data);
135 while ($i <= $endyear) {
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"));
146 $px2->SetHorizTickIncrement(1);
147 $px2->mode =
'depth';
148 $px2->SetTitle($langs->trans(
"AmountTotal"));
150 $px2->draw($filenameamount, $fileurlamount);
153$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
155$filename_avg = $dir.
"/donationaverage-".$year.
".png";
156$fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=donationStats&file=donationaverageinyear-'.$year.
'.png';
159$mesg = $px3->isGraphKo();
161 $px3->SetData($data);
164 while ($i <= $endyear) {
168 $px3->SetLegend($legend);
169 $px3->SetYLabel($langs->trans(
"AmountAverage"));
170 $px3->SetMaxValue($px3->GetCeilMaxValue());
171 $px3->SetMinValue($px3->GetFloorMinValue());
172 $px3->SetWidth($WIDTH);
173 $px3->SetHeight($HEIGHT);
175 $px3->SetHorizTickIncrement(1);
176 $px3->mode =
'depth';
177 $px3->SetTitle($langs->trans(
"AmountAverage"));
179 $px3->draw($filename_avg, $fileurl_avg);
183$data = $stats->getAllByYear();
184$arrayyears = array();
185foreach ($data as $val) {
186 if (!empty($val[
'year'])) {
187 $arrayyears[$val[
'year']] = $val[
'year'];
190if (!count($arrayyears)) {
191 $arrayyears[$nowyear] = $nowyear;
196$head[$h][0] = DOL_URL_ROOT.
'/don/stats/index.php';
197$head[$h][1] = $langs->trans(
"ByMonthYear");
198$head[$h][2] =
'byyear';
201$type =
'donation_stats';
208print
'<div class="fichecenter"><div class="fichethirdleft">';
211print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
212print
'<input type="hidden" name="token" value="'.newToken().
'">';
214print
'<table class="noborder centpercent">';
215print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
218if (empty(!
$conf->global->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',
'');
226print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
227$sortparam_typent = (empty(
$conf->global->SOCIETE_SORT_ON_TYPEENT) ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
228print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
230 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
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 print $form->multiselectarray(
'custcats', $cate_arbo,
GETPOST(
'custcats',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
246print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
247print
img_picto(
'',
'user',
'class="pictofixedwidth"');
248print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
252print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
254 '2' => $langs->trans(
"DonationStatusPaid"),
255 '0' => $langs->trans(
"DonationStatusPromiseNotValidated"),
256 '1' => $langs->trans(
"DonationStatusPromiseValidated"),
257 '3' => $langs->trans(
"Canceled")
259print $form->selectarray(
'status', $liststatus, 4, 1);
262print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
264print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
267print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
272print
'<div class="div-table-responsive-no-min">';
273print
'<table class="noborder centpercent">';
274print
'<tr class="liste_titre" height="24">';
275print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
276print
'<td class="right">'.$langs->trans(
"NbOfDonations").
'</td>';
277print
'<td class="right">%</td>';
278print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
279print
'<td class="right">%</td>';
280print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
281print
'<td class="right">%</td>';
285foreach ($data as $val) {
286 $year = $val[
'year'];
287 while (!empty($year) && $oldyear > (
int) $year + 1) {
289 print
'<tr class="oddeven" height="24">';
290 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'">'.$oldyear.
'</a></td>';
292 print
'<td class="right">0</td>';
293 print
'<td class="right"></td>';
294 print
'<td class="right amount">0</td>';
295 print
'<td class="right"></td>';
296 print
'<td class="right amount">0</td>';
297 print
'<td class="right"></td>';
301 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] >= 0);
302 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] >= 0);
303 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] >= 0);
305 print
'<tr class="oddeven" height="24">';
306 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
307 print
'<td class="right">'.$val[
'nb'].
'</td>';
308 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>';
309 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'total'],
'MT'), 1).
'</span></td>';
310 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>';
311 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</span></td>';
312 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>';
320print
'</div><div class="fichetwothirdright">';
323print
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
333print
'</td></tr></table>';
336print
'<div class="clearboth"></div>';
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.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage donations statistics.
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 a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.