diff --git a/spoken/views.py b/spoken/views.py index 30e387eca..d665bd428 100644 --- a/spoken/views.py +++ b/spoken/views.py @@ -962,9 +962,50 @@ def subscription(request): context = {} context["subscription_amount"] = settings.SUBSCRIPTION_AMOUNT template = 'spoken/templates/subscription.html' + + # Get user's past transactions + if user.is_authenticated: + # Get subscriptions for this user - try multiple matching strategies + # since existing data might not have user field properly set + user_subscriptions = AcademicSubscription.objects.filter( + Q(user=user) | Q(email=user.email) + ).select_related('transaction').prefetch_related('academic_details__academic').order_by('-created') + + # Prepare transaction data for template + transactions = [] + for subscription in user_subscriptions: + # Get academic details for this subscription + academic_details = subscription.academic_details.all() + + if academic_details.exists(): + for detail in academic_details: + transaction_data = { + 'payment_date': subscription.created.date(), + 'subscription_end_date': detail.subscription_end_date, + 'institute_name': detail.academic.institution_name, + 'gst_number': detail.gst_number or 'N/A', + } + + # Add transaction details if available + if subscription.transaction: + transaction_data.update({ + 'transaction_id': subscription.transaction.transaction_id or subscription.transaction.order_id, + 'order_status': subscription.transaction.order_status or 'PENDING' + }) + else: + transaction_data.update({ + 'transaction_id': 'N/A', + 'order_status': 'NO_TRANSACTION' + }) + + transactions.append(transaction_data) + + context['user_transactions'] = transactions + if request.method == 'GET': form = AcademicSubscriptionForm(user=user) context['form'] = form + return render(request, template, context=context) if request.method == 'POST': form = AcademicSubscriptionForm(request.POST, user=user) @@ -977,6 +1018,7 @@ def subscription(request): subscription_amount = settings.SUBSCRIPTION_AMOUNT * total_academic_centers email = form.cleaned_data.get('email') data = { + 'user': user, # Add the user to link subscription to logged-in user 'name': form.cleaned_data.get('name'), 'email': form.cleaned_data.get('email'), 'phone': form.cleaned_data.get('phone'), diff --git a/static/spoken/templates/subscription.html b/static/spoken/templates/subscription.html index acdd35e53..e2c227153 100644 --- a/static/spoken/templates/subscription.html +++ b/static/spoken/templates/subscription.html @@ -10,9 +10,61 @@ font-size: 1.2rem; } .is-invalid { - border-color: #dc3545 !important; - box-shadow: 0 0 4px #dc3545; -} + border-color: #dc3545 !important; + box-shadow: 0 0 4px #dc3545; + } + + /* Transaction history table styling */ + .table-responsive { + border: 1px solid #dee2e6; + border-radius: 5px; + margin-bottom: 20px; + } + + .thead-dark th { + background-color: #343a40; + color: #ffffff; + border-color: #454d55; + font-weight: 600; + font-size: 0.9rem; + } + + .table-striped tbody tr:nth-of-type(odd) { + background-color: rgba(0, 123, 255, 0.05); + } + + .table-hover tbody tr:hover { + background-color: rgba(0, 123, 255, 0.1); + } + + .badge { + font-size: 0.8rem; + padding: 0.4em 0.6em; + } + + .badge-success { + background-color: #28a745; + } + + .badge-warning { + background-color: #ffc107; + color: #212529; + } + + .badge-danger { + background-color: #dc3545; + } + + .badge-secondary { + background-color: #6c757d; + } + + .transaction-history h3 { + margin-bottom: 20px; + color: #495057; + border-bottom: 2px solid #007bff; + padding-bottom: 10px; + } {% endblock %} {% block heading %} @@ -103,6 +155,69 @@ + + {% if user.is_authenticated and user_transactions %} +
+
+

Your Transaction History

+
+ + + + + + + + + + + + + {% for transaction in user_transactions %} + + + + + + + + + {% endfor %} + +
Payment Date Transaction ID Subscription End Date Institute Name GST Number Status
{{ transaction.payment_date|date:"d M Y" }} + {{ transaction.transaction_id }} + {{ transaction.subscription_end_date|date:"d M Y" }}{{ transaction.institute_name }}{{ transaction.gst_number }} + {% if transaction.order_status == 'CHARGED' %} + + Paid + + {% elif transaction.order_status == 'PENDING' or transaction.order_status == 'PENDING_VBV' or transaction.order_status == 'AUTHORIZING' %} + + Pending + + {% elif transaction.order_status == 'NO_TRANSACTION' %} + + No Payment + + {% else %} + + Failed + + {% endif %} +
+
+
+
+ {% elif user.is_authenticated %} +
+
+
+ No transaction history found for your account. +
+
+
+ {% endif %} +