update fee5
This commit is contained in:
parent
0106833e47
commit
b70c6b10e0
Binary file not shown.
@ -105,32 +105,42 @@
|
|||||||
{% if subscription_enabled %}
|
{% if subscription_enabled %}
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const roleSelect = document.querySelector('select[name="role"]');
|
|
||||||
const planSelect = document.querySelector('select[name="subscription_plan"]');
|
|
||||||
const fees = {{ fees_json|safe }};
|
const fees = {{ fees_json|safe }};
|
||||||
|
|
||||||
const monthlyLabel = "{% trans 'Monthly Plan' %}";
|
const monthlyLabel = "{% trans 'Monthly Plan' %}";
|
||||||
const annualLabel = "{% trans 'Annual Plan' %}";
|
const annualLabel = "{% trans 'Annual Plan' %}";
|
||||||
|
|
||||||
function updateFees() {
|
function updateFees() {
|
||||||
|
// Try multiple ways to find the elements to be extremely robust
|
||||||
|
const roleSelect = document.getElementById('id_role') || document.querySelector('[name="role"]');
|
||||||
|
const planSelect = document.getElementById('id_subscription_plan') || document.querySelector('[name="subscription_plan"]');
|
||||||
|
|
||||||
|
if (!roleSelect || !planSelect) return;
|
||||||
|
|
||||||
const role = roleSelect.value;
|
const role = roleSelect.value;
|
||||||
const roleFees = fees[role];
|
// Use case-insensitive match just in case
|
||||||
|
const roleKey = Object.keys(fees).find(k => k.toUpperCase() === role.toUpperCase());
|
||||||
|
const roleFees = fees[roleKey];
|
||||||
|
|
||||||
if (roleFees) {
|
if (roleFees) {
|
||||||
for (let option of planSelect.options) {
|
for (let i = 0; i < planSelect.options.length; i++) {
|
||||||
|
const option = planSelect.options[i];
|
||||||
if (option.value === 'MONTHLY') {
|
if (option.value === 'MONTHLY') {
|
||||||
option.text = `${monthlyLabel} (${roleFees.MONTHLY})`;
|
option.text = monthlyLabel + " (" + roleFees.MONTHLY + ")";
|
||||||
} else if (option.value === 'ANNUAL') {
|
} else if (option.value === 'ANNUAL') {
|
||||||
option.text = `${annualLabel} (${roleFees.ANNUAL})`;
|
option.text = annualLabel + " (" + roleFees.ANNUAL + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roleSelect && planSelect) {
|
const roleField = document.getElementById('id_role') || document.querySelector('[name="role"]');
|
||||||
roleSelect.addEventListener('change', updateFees);
|
if (roleField) {
|
||||||
updateFees(); // Initialize
|
roleField.addEventListener('change', updateFees);
|
||||||
|
updateFees(); // Run once on load
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// As a final fallback, try to run after a small delay in case of dynamic rendering issues
|
||||||
|
setTimeout(updateFees, 500);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@ -27,15 +27,15 @@ def register(request):
|
|||||||
app_settings = AppSetting.objects.first()
|
app_settings = AppSetting.objects.first()
|
||||||
subscription_enabled = app_settings.subscription_enabled if app_settings else False
|
subscription_enabled = app_settings.subscription_enabled if app_settings else False
|
||||||
|
|
||||||
# Fees for JS
|
# Fees for JS - using float for cleaner JSON and explicit formatting
|
||||||
fees = {
|
fees = {
|
||||||
'SHIPPER': {
|
'SHIPPER': {
|
||||||
'MONTHLY': str(app_settings.shipper_monthly_fee) if app_settings else "0.00",
|
'MONTHLY': "{:.2f}".format(app_settings.shipper_monthly_fee) if app_settings else "0.00",
|
||||||
'ANNUAL': str(app_settings.shipper_annual_fee) if app_settings else "0.00",
|
'ANNUAL': "{:.2f}".format(app_settings.shipper_annual_fee) if app_settings else "0.00",
|
||||||
},
|
},
|
||||||
'TRUCK_OWNER': {
|
'TRUCK_OWNER': {
|
||||||
'MONTHLY': str(app_settings.truck_owner_monthly_fee) if app_settings else "0.00",
|
'MONTHLY': "{:.2f}".format(app_settings.truck_owner_monthly_fee) if app_settings else "0.00",
|
||||||
'ANNUAL': str(app_settings.truck_owner_annual_fee) if app_settings else "0.00",
|
'ANNUAL': "{:.2f}".format(app_settings.truck_owner_annual_fee) if app_settings else "0.00",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user