Skip to content

Commit a109e01

Browse files
committed
added transaction history table to the subscription page under profile
1 parent 71148ee commit a109e01

2 files changed

Lines changed: 160 additions & 3 deletions

File tree

spoken/views.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,50 @@ def subscription(request):
962962
context = {}
963963
context["subscription_amount"] = settings.SUBSCRIPTION_AMOUNT
964964
template = 'spoken/templates/subscription.html'
965+
966+
# Get user's past transactions
967+
if user.is_authenticated:
968+
# Get subscriptions for this user - try multiple matching strategies
969+
# since existing data might not have user field properly set
970+
user_subscriptions = AcademicSubscription.objects.filter(
971+
Q(user=user) | Q(email=user.email)
972+
).select_related('transaction').prefetch_related('academic_details__academic').order_by('-created')
973+
974+
# Prepare transaction data for template
975+
transactions = []
976+
for subscription in user_subscriptions:
977+
# Get academic details for this subscription
978+
academic_details = subscription.academic_details.all()
979+
980+
if academic_details.exists():
981+
for detail in academic_details:
982+
transaction_data = {
983+
'payment_date': subscription.created.date(),
984+
'subscription_end_date': detail.subscription_end_date,
985+
'institute_name': detail.academic.institution_name,
986+
'gst_number': detail.gst_number or 'N/A',
987+
}
988+
989+
# Add transaction details if available
990+
if subscription.transaction:
991+
transaction_data.update({
992+
'transaction_id': subscription.transaction.transaction_id or subscription.transaction.order_id,
993+
'order_status': subscription.transaction.order_status or 'PENDING'
994+
})
995+
else:
996+
transaction_data.update({
997+
'transaction_id': 'N/A',
998+
'order_status': 'NO_TRANSACTION'
999+
})
1000+
1001+
transactions.append(transaction_data)
1002+
1003+
context['user_transactions'] = transactions
1004+
9651005
if request.method == 'GET':
9661006
form = AcademicSubscriptionForm(user=user)
9671007
context['form'] = form
1008+
9681009
return render(request, template, context=context)
9691010
if request.method == 'POST':
9701011
form = AcademicSubscriptionForm(request.POST, user=user)
@@ -977,6 +1018,7 @@ def subscription(request):
9771018
subscription_amount = settings.SUBSCRIPTION_AMOUNT * total_academic_centers
9781019
email = form.cleaned_data.get('email')
9791020
data = {
1021+
'user': user, # Add the user to link subscription to logged-in user
9801022
'name': form.cleaned_data.get('name'),
9811023
'email': form.cleaned_data.get('email'),
9821024
'phone': form.cleaned_data.get('phone'),

static/spoken/templates/subscription.html

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,61 @@
1010
font-size: 1.2rem;
1111
}
1212
.is-invalid {
13-
border-color: #dc3545 !important;
14-
box-shadow: 0 0 4px #dc3545;
15-
}
13+
border-color: #dc3545 !important;
14+
box-shadow: 0 0 4px #dc3545;
15+
}
16+
17+
/* Transaction history table styling */
18+
.table-responsive {
19+
border: 1px solid #dee2e6;
20+
border-radius: 5px;
21+
margin-bottom: 20px;
22+
}
23+
24+
.thead-dark th {
25+
background-color: #343a40;
26+
color: #ffffff;
27+
border-color: #454d55;
28+
font-weight: 600;
29+
font-size: 0.9rem;
30+
}
31+
32+
.table-striped tbody tr:nth-of-type(odd) {
33+
background-color: rgba(0, 123, 255, 0.05);
34+
}
35+
36+
.table-hover tbody tr:hover {
37+
background-color: rgba(0, 123, 255, 0.1);
38+
}
39+
40+
.badge {
41+
font-size: 0.8rem;
42+
padding: 0.4em 0.6em;
43+
}
44+
45+
.badge-success {
46+
background-color: #28a745;
47+
}
48+
49+
.badge-warning {
50+
background-color: #ffc107;
51+
color: #212529;
52+
}
53+
54+
.badge-danger {
55+
background-color: #dc3545;
56+
}
57+
58+
.badge-secondary {
59+
background-color: #6c757d;
60+
}
61+
62+
.transaction-history h3 {
63+
margin-bottom: 20px;
64+
color: #495057;
65+
border-bottom: 2px solid #007bff;
66+
padding-bottom: 10px;
67+
}
1668
</style>
1769
{% endblock %}
1870
{% block heading %}
@@ -103,6 +155,69 @@
103155
</div>
104156
</form>
105157

158+
<!-- User Transaction History -->
159+
{% if user.is_authenticated and user_transactions %}
160+
<div class="row transaction-history" style="margin-top: 30px;">
161+
<div class="col-sm-12">
162+
<h3><i class="fa fa-history"></i> Your Transaction History</h3>
163+
<div class="table-responsive">
164+
<table class="table table-striped table-hover">
165+
<thead class="thead-dark">
166+
<tr>
167+
<th><i class="fa fa-calendar"></i> Payment Date</th>
168+
<th><i class="fa fa-receipt"></i> Transaction ID</th>
169+
<th><i class="fa fa-calendar-check"></i> Subscription End Date</th>
170+
<th><i class="fa fa-university"></i> Institute Name</th>
171+
<th><i class="fa fa-file-text"></i> GST Number</th>
172+
<th><i class="fa fa-info-circle"></i> Status</th>
173+
</tr>
174+
</thead>
175+
<tbody>
176+
{% for transaction in user_transactions %}
177+
<tr>
178+
<td>{{ transaction.payment_date|date:"d M Y" }}</td>
179+
<td>
180+
<small class="text-muted">{{ transaction.transaction_id }}</small>
181+
</td>
182+
<td>{{ transaction.subscription_end_date|date:"d M Y" }}</td>
183+
<td>{{ transaction.institute_name }}</td>
184+
<td>{{ transaction.gst_number }}</td>
185+
<td>
186+
{% if transaction.order_status == 'CHARGED' %}
187+
<span class="badge badge-success">
188+
<i class="fa fa-check"></i> Paid
189+
</span>
190+
{% elif transaction.order_status == 'PENDING' or transaction.order_status == 'PENDING_VBV' or transaction.order_status == 'AUTHORIZING' %}
191+
<span class="badge badge-warning">
192+
<i class="fa fa-clock-o"></i> Pending
193+
</span>
194+
{% elif transaction.order_status == 'NO_TRANSACTION' %}
195+
<span class="badge badge-secondary">
196+
<i class="fa fa-exclamation"></i> No Payment
197+
</span>
198+
{% else %}
199+
<span class="badge badge-danger">
200+
<i class="fa fa-times"></i> Failed
201+
</span>
202+
{% endif %}
203+
</td>
204+
</tr>
205+
{% endfor %}
206+
</tbody>
207+
</table>
208+
</div>
209+
</div>
210+
</div>
211+
{% elif user.is_authenticated %}
212+
<div class="row" style="margin-top: 30px;">
213+
<div class="col-sm-12">
214+
<div class="alert alert-info">
215+
<i class="fa fa-info-circle"></i> No transaction history found for your account.
216+
</div>
217+
</div>
218+
</div>
219+
{% endif %}
220+
106221
<div id="paymentMsg">
107222

108223
</div>

0 commit comments

Comments
 (0)