changing on fee payments

This commit is contained in:
Flatlogic Bot 2026-01-24 03:36:59 +00:00
parent 9726a81f0c
commit 04660926d3
11 changed files with 111 additions and 8 deletions

View File

@ -95,7 +95,9 @@ class AppSettingAdmin(admin.ModelAdmin):
(None, {'fields': ('app_name', 'logo', 'slogan')}),
(_('Contact Information'), {'fields': ('contact_phone', 'contact_email', 'contact_address')}),
(_('Legal'), {'fields': ('registration_number', 'tax_number', 'terms_of_service', 'privacy_policy')}),
(_('Subscription'), {'fields': ('subscription_enabled', 'monthly_fee', 'annual_fee')}),
(_('Subscription Status'), {'fields': ('subscription_enabled',)}),
(_('Shipper Subscription Fees'), {'fields': ('shipper_monthly_fee', 'shipper_annual_fee')}),
(_('Truck Owner Subscription Fees'), {'fields': ('truck_owner_monthly_fee', 'truck_owner_annual_fee')}),
)
def has_add_permission(self, request):

View File

@ -33,9 +33,10 @@ class UserRegistrationForm(UserCreationForm):
app_settings = AppSetting.objects.first()
if app_settings and app_settings.subscription_enabled:
# We will update these labels via JS based on selected role to show the correct fee
self.fields['subscription_plan'].choices = [
('MONTHLY', _('Monthly (%(fee)s)') % {'fee': app_settings.monthly_fee}),
('ANNUAL', _('Annual (%(fee)s)') % {'fee': app_settings.annual_fee}),
('MONTHLY', _('Monthly Plan')),
('ANNUAL', _('Annual Plan')),
]
self.fields['subscription_plan'].required = True
else:

View File

@ -0,0 +1,41 @@
# Generated by Django 5.2.7 on 2026-01-24 03:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0017_appsetting_annual_fee_appsetting_monthly_fee_and_more'),
]
operations = [
migrations.RemoveField(
model_name='appsetting',
name='annual_fee',
),
migrations.RemoveField(
model_name='appsetting',
name='monthly_fee',
),
migrations.AddField(
model_name='appsetting',
name='shipper_annual_fee',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, verbose_name='Shipper Annual Fee'),
),
migrations.AddField(
model_name='appsetting',
name='shipper_monthly_fee',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, verbose_name='Shipper Monthly Fee'),
),
migrations.AddField(
model_name='appsetting',
name='truck_owner_annual_fee',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, verbose_name='Truck Owner Annual Fee'),
),
migrations.AddField(
model_name='appsetting',
name='truck_owner_monthly_fee',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, verbose_name='Truck Owner Monthly Fee'),
),
]

View File

@ -249,8 +249,14 @@ class AppSetting(models.Model):
terms_of_service = models.TextField(_('Terms of Service'), blank=True)
privacy_policy = models.TextField(_('Privacy Policy'), blank=True)
subscription_enabled = models.BooleanField(_('Enable Subscription Fee'), default=False)
monthly_fee = models.DecimalField(_('Monthly Fee'), max_digits=10, decimal_places=2, default=0.00)
annual_fee = models.DecimalField(_('Annual Fee'), max_digits=10, decimal_places=2, default=0.00)
# Shipper Fees
shipper_monthly_fee = models.DecimalField(_('Shipper Monthly Fee'), max_digits=10, decimal_places=2, default=0.00)
shipper_annual_fee = models.DecimalField(_('Shipper Annual Fee'), max_digits=10, decimal_places=2, default=0.00)
# Truck Owner Fees
truck_owner_monthly_fee = models.DecimalField(_('Truck Owner Monthly Fee'), max_digits=10, decimal_places=2, default=0.00)
truck_owner_annual_fee = models.DecimalField(_('Truck Owner Annual Fee'), max_digits=10, decimal_places=2, default=0.00)
class Meta:
verbose_name = _('App Setting')

View File

@ -15,7 +15,7 @@
<div class="card-body p-5">
<h2 class="text-center mb-4">{% trans "Create your account" %}</h2>
<form method="post" novalidate>
<form method="post" novalidate id="registrationForm">
{% csrf_token %}
{% if form.non_field_errors %}
@ -101,4 +101,38 @@
</div>
</div>
</section>
{% if subscription_enabled %}
<script>
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 monthlyLabel = "{% trans 'Monthly' %}";
const annualLabel = "{% trans 'Annual' %}";
function updateFees() {
const role = roleSelect.value;
const roleFees = fees[role];
if (roleFees) {
for (let option of planSelect.options) {
if (option.value === 'MONTHLY') {
option.text = `${monthlyLabel} (${roleFees.MONTHLY})`;
} else if (option.value === 'ANNUAL') {
option.text = `${annualLabel} (${roleFees.ANNUAL})`;
}
}
}
}
if (roleSelect && planSelect) {
roleSelect.addEventListener('change', updateFees);
updateFees(); // Initialize
}
});
</script>
{% endif %}
{% endblock %}

View File

@ -10,6 +10,7 @@ from django.db.models import Q
from django.contrib.auth.models import User
from .whatsapp import send_whatsapp_message
from django.contrib.auth.forms import AuthenticationForm
import json
def home(request):
"""Render the landing screen for MASAR CARGO."""
@ -25,6 +26,19 @@ def home(request):
def register(request):
app_settings = AppSetting.objects.first()
subscription_enabled = app_settings.subscription_enabled if app_settings else False
# Fees for JS
fees = {
'SHIPPER': {
'MONTHLY': str(app_settings.shipper_monthly_fee) if app_settings else "0.00",
'ANNUAL': str(app_settings.shipper_annual_fee) if app_settings else "0.00",
},
'TRUCK_OWNER': {
'MONTHLY': str(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",
}
}
if request.method == 'POST':
form = UserRegistrationForm(request.POST)
if form.is_valid():
@ -53,7 +67,12 @@ def register(request):
messages.error(request, _("Please correct the errors below."))
else:
form = UserRegistrationForm()
return render(request, 'registration/register.html', {'form': form, 'subscription_enabled': subscription_enabled})
return render(request, 'registration/register.html', {
'form': form,
'subscription_enabled': subscription_enabled,
'fees_json': json.dumps(fees)
})
def verify_otp_registration(request):
registration_data = request.session.get('registration_data')
@ -407,4 +426,4 @@ def terms_of_service(request):
'content': app_settings.terms_of_service if app_settings else _("Terms of service are coming soon.")
}
}
return render(request, 'core/article_detail.html', context)
return render(request, 'core/article_detail.html', context)