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';
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');
80$title = $langs->trans(
"Donations");
81$dir =
$conf->don->dir_temp;
83llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-don page-stats');
89$massactionbutton =
'';
91$nbtotalofrecords = $langs->trans(
"Statistics");
94$urlnew = DOL_URL_ROOT.
'/don/card.php?action=create';
96 $urlnew .=
'&socid='.$socid;
100$newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/don/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
101$newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/don/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
102$newcardbutton .=
dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/don/stats/index.php',
'', 2, array(
'morecss' =>
'reposition'));
104$newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewDonation'),
'',
'fa fa-plus-circle', DOL_URL_ROOT.
'/don/card.php?action=create',
'', $user->hasRight(
'don',
'write'));
106print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
110$stats =
new DonationStats(
$db, $socid,
'', ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($status > 0 ? $status : 4));
112if (is_array($custcats) && !empty($custcats)) {
113 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cat ON (d.fk_soc = cat.fk_soc)';
114 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $custcats)).
')';
118$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
120$filenamenb = $dir.
"/salariesnbinyear-".$year.
".png";
121$fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=donationStats&file=donationinyear-'.$year.
'.png';
124$mesg = $px1->isGraphKo();
126 $px1->SetData($data);
129 while ($i <= $endyear) {
133 $px1->SetLegend($legend);
134 $px1->SetMaxValue($px1->GetCeilMaxValue());
135 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
136 $px1->SetWidth($WIDTH);
137 $px1->SetHeight($HEIGHT);
138 $px1->SetYLabel($langs->trans(
"NbOfDonations"));
140 $px1->SetHorizTickIncrement(1);
141 $px1->mode =
'depth';
142 $px1->SetTitle($langs->trans(
"NumberByMonth"));
144 $px1->draw($filenamenb, $fileurlnb);
147$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
149$filenameamount = $dir.
"/donationamount-".$year.
".png";
150$fileurlamount =
dolBuildUrl(DOL_URL_ROOT.
'/viewimage.php', [
'modulepart' =>
'donationStats',
'file' =>
'donationamoutinyear-'.$year.
'.png']);
153$mesg = $px2->isGraphKo();
155 $px2->SetData($data);
158 while ($i <= $endyear) {
162 $px2->SetLegend($legend);
163 $px2->SetMaxValue($px2->GetCeilMaxValue());
164 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
165 $px2->SetWidth($WIDTH);
166 $px2->SetHeight($HEIGHT);
167 $px2->SetYLabel($langs->trans(
"Amount"));
169 $px2->SetHorizTickIncrement(1);
170 $px2->mode =
'depth';
171 $px2->SetTitle($langs->trans(
"AmountTotal"));
173 $px2->draw($filenameamount, $fileurlamount);
176$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
178$filename_avg = $dir.
"/donationaverage-".$year.
".png";
179$fileurl_avg =
dolBuildUrl(DOL_URL_ROOT.
'/viewimage.php', [
'modulepart' =>
'donationStats',
'file' =>
'donationaverageinyear-'.$year.
'.png']);
182$mesg = $px3->isGraphKo();
184 $px3->SetData($data);
187 while ($i <= $endyear) {
191 $px3->SetLegend($legend);
192 $px3->SetYLabel($langs->trans(
"AmountAverage"));
193 $px3->SetMaxValue($px3->GetCeilMaxValue());
194 $px3->SetMinValue((
int) $px3->GetFloorMinValue());
195 $px3->SetWidth($WIDTH);
196 $px3->SetHeight($HEIGHT);
198 $px3->SetHorizTickIncrement(1);
199 $px3->mode =
'depth';
200 $px3->SetTitle($langs->trans(
"AmountAverage"));
202 $px3->draw($filename_avg, $fileurl_avg);
206$data = $stats->getAllByYear();
207$arrayyears = array();
208foreach ($data as $val) {
209 if (!empty($val[
'year'])) {
210 $arrayyears[$val[
'year']] = $val[
'year'];
213if (!count($arrayyears)) {
214 $arrayyears[$nowyear] = $nowyear;
219$head[$h][0] = DOL_URL_ROOT.
'/don/stats/index.php';
220$head[$h][1] = $langs->trans(
"ByMonthYear");
221$head[$h][2] =
'byyear';
224$type =
'donation_stats';
231print
'<div class="fichecenter"><div class="fichethirdleft">';
234print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
235print
'<input type="hidden" name="token" value="'.newToken().
'">';
237print
'<table class="noborder centpercent">';
238print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
242 print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
243 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
244 print $form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300',
'');
249print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
251print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
253 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
259 $cat_type = Categorie::TYPE_CUSTOMER;
260 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
261 print
'<tr><td>'.$cat_label.
'</td><td>';
262 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
263 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
264 if (is_array($cate_arbo)) {
265 print $form->multiselectarray(
'custcats', $cate_arbo,
GETPOST(
'custcats',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
271print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
272print
img_picto(
'',
'user',
'class="pictofixedwidth"');
273print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
277print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
279 '2' => $langs->trans(
"DonationStatusPaid"),
280 '0' => $langs->trans(
"DonationStatusPromiseNotValidated"),
281 '1' => $langs->trans(
"DonationStatusPromiseValidated"),
282 '3' => $langs->trans(
"Canceled")
284print $form->selectarray(
'status', $liststatus, 4, 1);
287print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
289print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
290print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
293print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
298print
'<div class="div-table-responsive-no-min">';
299print
'<table class="noborder centpercent">';
300print
'<tr class="liste_titre" height="24">';
301print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
302print
'<td class="right">'.$langs->trans(
"NbOfDonations").
'</td>';
303print
'<td class="right">%</td>';
304print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
305print
'<td class="right">%</td>';
306print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
307print
'<td class="right">%</td>';
311foreach ($data as $val) {
312 $year = $val[
'year'];
313 while (!empty($year) && $oldyear > (
int) $year + 1) {
315 print
'<tr class="oddeven" height="24">';
316 print
'<td class="center"><a href="'.dolBuildUrl($_SERVER[
"PHP_SELF"], [
'year' => $oldyear]).
'">'.$oldyear.
'</a></td>';
318 print
'<td class="right">0</td>';
319 print
'<td class="right"></td>';
320 print
'<td class="right amount">0</td>';
321 print
'<td class="right"></td>';
322 print
'<td class="right amount">0</td>';
323 print
'<td class="right"></td>';
327 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] >= 0);
328 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] >= 0);
329 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] >= 0);
331 print
'<tr class="oddeven" height="24">';
332 $query = [
'year' => $year,
'mode' => $mode];
334 $query += [
'socid' => $socid];
337 $query += [
'userid' => $userid];
339 print
'<td align="center"><a href="'.dolBuildUrl($_SERVER[
"PHP_SELF"], $query).
'">'.$year.
'</a></td>';
340 print
'<td class="right">'.$val[
'nb'].
'</td>';
341 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>';
342 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'total'],
'MT'), 1).
'</span></td>';
343 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>';
344 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</span></td>';
345 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>';
353print
'</div><div class="fichetwothirdright">';
356print
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
366print
'</td></tr></table>';
369print
'<div class="clearboth"></div>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
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)
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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)
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
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.