Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion donate/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def get_display_transaction_details(transaction):
def get_academic_centers(request):
stateId = request.GET.get('stateId')
if stateId:
ac = AcademicCenter.objects.filter(state_id=stateId).order_by('institution_name').values('id', 'institution_name', 'academic_code')
ac = AcademicCenter.objects.filter(state_id=stateId).order_by('institution_name').values('id', 'institution_name', 'academic_code','institution_type_id' )
return JsonResponse(list(ac), safe=False)
return JsonResponse([])

Expand Down
30 changes: 23 additions & 7 deletions spoken/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ def subscription(request):
user = request.user
context = {}
context["subscription_amount"] = settings.SUBSCRIPTION_AMOUNT
context["SUBSCRIPTION_AMOUNT_COLLEGE"] = settings.SUBSCRIPTION_AMOUNT_COLLEGE
context["SUBSCRIPTION_INSTITUTE_TYPES"] = settings.SUBSCRIPTION_INSTITUTE_TYPES

template = 'spoken/templates/subscription.html'
if request.method == 'GET':
form = AcademicSubscriptionForm(user=user)
Expand All @@ -952,8 +955,13 @@ def subscription(request):
academic = form.cleaned_data.get('institute')
expiry_date = date.today() + timedelta(days=365)
state = form.cleaned_data.get('state')
total_academic_centers = len(academic)
subscription_amount = settings.SUBSCRIPTION_AMOUNT * total_academic_centers
subscription_amount = 0

for ac in academic:
if ac.institute_type_id in settings.SUBSCRIPTION_INSTITUTE_TYPES:
subscription_amount += settings.SUBSCRIPTION_AMOUNT_COLLEGE
else:
subscription_amount += settings.SUBSCRIPTION_AMOUNT
email = form.cleaned_data.get('email')
data = {
'name': form.cleaned_data.get('name'),
Expand All @@ -971,13 +979,20 @@ def subscription(request):
for ac in academic:
gst_no = request.POST.get(f"gst_no_{ac.id}")
gst_name = request.POST.get(f"gst_name_{ac.id}")
if ac.institute_type_id in settings.SUBSCRIPTION_INSTITUTE_TYPES:
amount = settings.SUBSCRIPTION_AMOUNT_COLLEGE
else:
amount = settings.SUBSCRIPTION_AMOUNT

AcademicSubscriptionDetail.objects.create(
subscription = subscription,
academic = ac,
subscription_end_date = expiry_date, # Default to expiry_date,
gst_number = gst_no.strip(),
gst_name = gst_name.strip()
subscription=subscription,
academic=ac,
subscription_end_date=expiry_date,
gst_number=gst_no.strip() if gst_no else None,
gst_name=gst_name.strip() if gst_name else None,
amount=amount
)

else:
messages.add_message(request, messages.ERROR, "Please see below errors.")
return render(request, template, context=context)
Expand Down Expand Up @@ -1007,6 +1022,7 @@ def subscription(request):
subscription.save()
messages.add_message(request, messages.ERROR, "An error occurred. Please try later")
return render(request, template, context=context)


@csrf_exempt
def payment_callback(request):
Expand Down
41 changes: 34 additions & 7 deletions static/spoken/templates/subscription.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
<script src="{% static 'spoken/js/events.js' %}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<script>
window.SUBSCRIPTION_AMOUNT = {{ subscription_amount }};
window.SUBSCRIPTION_AMOUNT_COLLEGE = {{ SUBSCRIPTION_AMOUNT_COLLEGE }};
window.SUBSCRIPTION_INSTITUTE_TYPES = {{ SUBSCRIPTION_INSTITUTE_TYPES|safe }};
</script>


<script>
$(document).ready(function() {
Expand All @@ -134,20 +140,41 @@
.then(data => {
academicSelect.html('<option value="">-- Select Academic Center --</option>'); // reset
data.forEach(item => {
academicSelect.append(new Option(`${item.academic_code} - ${item.institution_name}`, item.id))
});
const option = new Option(
`${item.academic_code} - ${item.institution_name}`,
item.id
);
option.dataset.type = item.institution_type_id; // ✅ THIS IS THE LINE YOU ASKED ABOUT
academicSelect.append(option);
});
academicSelect.prop('disabled', false); // enable after loading
document.getElementById("ac_info").style.display = "none";
})
.catch(error =>alert('An error occurred. Please try later.'))
}
});

$('#id_academic').on('select2:select select2:unselect', function (e) {
var selectedCount = $(this).val() ? $(this).val().length : 0;
let total_amount = {{subscription_amount}} * selectedCount;
$("#id_amount").val(total_amount);
});
// $('#id_academic').on('select2:select select2:unselect', function (e) {
// var selectedCount = $(this).val() ? $(this).val().length : 0;
// let total_amount = {{subscription_amount}} * selectedCount;
// $("#id_amount").val(total_amount);
// });
$('#id_academic').on('change', function () {
let total_amount = 0;

$('#id_academic option:selected').each(function () {
const typeId = parseInt($(this).data('type'), 10);

if (SUBSCRIPTION_INSTITUTE_TYPES.includes(typeId)) {
total_amount += SUBSCRIPTION_AMOUNT_COLLEGE;
} else {
total_amount += SUBSCRIPTION_AMOUNT;
}
});

$('#id_amount').val(total_amount);
});


//GST fields
// Trigger on page load and on selection change
Expand Down