Skip to content

Commit 5d41f04

Browse files
committed
Add 'Accounting' section to stats area on dashboard
This is primarily to show the number of payments received for the program and also the total amount paid so far. See #229.
1 parent 7e32bdd commit 5d41f04

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

esp/esp/program/modules/handlers/jsondatamodule.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
from esp.users.models import UserAvailability
5757
from esp.utils.decorators import cached_module_view, json_response
5858
from esp.utils.no_autocookie import disable_csrf_cookie_update
59-
from esp.accounting.controllers import IndividualAccountingController
59+
from esp.accounting.controllers import ProgramAccountingController, IndividualAccountingController
60+
from esp.accounting.models import Transfer
6061

6162
from decimal import Decimal
6263

@@ -762,6 +763,15 @@ def student_max_count(clslist):
762763
}
763764
dictOut["stats"].append({"id": "splashinfo", "data": splashinfo_data})
764765

766+
# Add accounting stats
767+
lt = ProgramAccountingController(prog).default_payments_lineitemtype()
768+
payments = Transfer.objects.filter(line_item=lt)
769+
accounting_data = {
770+
'num_payments': payments.count(),
771+
'total_payments': payments.aggregate(total=Sum('amount_dec'))['total'],
772+
}
773+
dictOut["stats"].append({"id": "accounting", "data": accounting_data})
774+
765775
return dictOut
766776
stats.cached_function.depend_on_row(ClassSubject, lambda cls: {'prog': cls.parent_program})
767777
stats.cached_function.depend_on_row(SplashInfo, lambda si: {'prog': si.program})

esp/public/media/scripts/program/modules/adminvitals.js

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function fillStats(data)
99
grades = stats.grades;
1010
shirtnum = stats.shirtnum;
1111
splashinfo = stats.splashinfo;
12+
accounting = stats.accounting;
1213

1314
// Fill in student num data
1415
$studentnum = $j("#stats_students > .module_group_body");
@@ -158,6 +159,11 @@ function fillStats(data)
158159
}
159160
else
160161
$splashinfo.html("SplashInfo module is not enabled -- no statistics");
162+
163+
// Fill in the accounting table
164+
$accounting = $j("#stats_accounting > .module_group_body");
165+
$accounting.html("<strong>Number of credit card payments</strong>: " + accounting.data.num_payments + "<br />");
166+
$accounting.append("<strong>Total amount of credit card payments</strong>: $" + accounting.data.total_payments.toFixed(2));
161167
}
162168

163169
function getStats()

esp/templates/program/modules/adminvitals/vitals.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
.add("#stats_hours")
1717
.add("#stats_timeslots")
1818
.add("#stats_tshirts")
19-
.add("#stats_splashinfo");
19+
.add("#stats_splashinfo")
20+
.add("#stats_accounting");
2021
$module_group_headers = $module_groups.children(".module_group_header");
2122
$module_group_headers.click(getStats);
2223
});
@@ -86,6 +87,12 @@
8687
Loading data...
8788
</div>
8889
</div>
90+
<div class="module_group" id="stats_accounting">
91+
<div class="module_group_header module_group_expandable">Accounting <span class="expand_collapse_text">(click to expand)</span></div>
92+
<div class="module_group_body" style="display:none">
93+
Loading data...
94+
</div>
95+
</div>
8996
</div> <!-- div#program_vitals_wrapper -->
9097
</div>
9198
</div> <!-- div#program_form -->

0 commit comments

Comments
 (0)