Skip to content

Commit 9a9cf13

Browse files
Merge pull request #1559 from learning-unlimited/cc-payment-display
Credit card payment display
2 parents 89afd5e + a79aa8a commit 9a9cf13

File tree

6 files changed

+51
-3
lines changed

6 files changed

+51
-3
lines changed

esp/esp/accounting/controllers.py

+7
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ def remove_pending_transfers(self, users):
278278
we shouldn't be expecting their money. """
279279
self.all_transfers().filter(user__in=users, executed=False).delete()
280280

281+
def payments_summary(self):
282+
""" Return a tuple with the number and total dollar amount of payments
283+
that have been made so far. """
284+
payment_li_type = self.default_payments_lineitemtype()
285+
payments = Transfer.objects.filter(line_item=payment_li_type)
286+
return (payments.count(), payments.aggregate(total=Sum('amount_dec'))['total'])
287+
281288
class IndividualAccountingController(ProgramAccountingController):
282289
def __init__(self, program, user, *args, **kwargs):
283290
super(IndividualAccountingController, self).__init__(program, *args, **kwargs)

esp/esp/program/modules/handlers/creditcardviewer_cybersource.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
from esp.web.util import render_to_response
3838
from datetime import datetime
3939
from django.db.models.query import Q
40+
from django.db.models import Sum
4041
from esp.users.models import User, ESPUser
42+
from esp.accounting.models import Transfer
4143
from esp.accounting.controllers import ProgramAccountingController, IndividualAccountingController
4244
from esp.middleware import ESPError
4345

@@ -58,11 +60,21 @@ def viewpay_cybersource(self, request, tl, one, two, module, extra, prog):
5860
student_list = list(pac.all_students())
5961
payment_table = []
6062

63+
# Fetch detailed information for every student associated with the program
6164
for student in student_list:
6265
iac = IndividualAccountingController(prog, student)
6366
payment_table.append((student, iac.get_transfers(), iac.amount_requested(), iac.amount_due()))
6467

65-
context = { 'program': prog, 'payment_table': payment_table }
68+
# Also fetch summary information about the payments
69+
(num_payments, total_payment) = pac.payments_summary()
70+
71+
context = {
72+
'program': prog,
73+
'payment_table': payment_table,
74+
'num_students': len(student_list),
75+
'num_payments': num_payments,
76+
'total_payment': total_payment,
77+
}
6678

6779
return render_to_response(self.baseDir() + 'viewpay_cybersource.html', request, context)
6880

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

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

6061
from decimal import Decimal
6162

@@ -775,6 +776,15 @@ def student_max_count(clslist):
775776
}
776777
dictOut["stats"].append({"id": "splashinfo", "data": splashinfo_data})
777778

779+
# Add accounting stats
780+
pac = ProgramAccountingController(prog)
781+
(num_payments, total_payment) = pac.payments_summary()
782+
accounting_data = {
783+
'num_payments': num_payments,
784+
'total_payments': total_payment,
785+
}
786+
dictOut["stats"].append({"id": "accounting", "data": accounting_data})
787+
778788
return dictOut
779789
stats.cached_function.depend_on_row(ClassSubject, lambda cls: {'prog': cls.parent_program})
780790
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 -->

esp/templates/program/modules/creditcardviewer_cybersource/viewpay_cybersource.html

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
{% block content %}
3232
<h1>Credit Card Payments</h1>
3333

34+
<ul>
35+
<li>Total number of students: {{ num_students }}</li>
36+
<li>Number of credit card payments so far: {{ num_payments }}</li>
37+
<li>Amount of credit card payments so far: ${{ total_payment|floatformat:2 }}</li>
38+
</ul>
39+
3440
<div id="program_form">
3541
<table>
3642

0 commit comments

Comments
 (0)