enableing disabling online payment

This commit is contained in:
Flatlogic Bot 2026-01-24 07:47:20 +00:00
parent cdda269c57
commit c5c799b7d6
11 changed files with 107 additions and 27 deletions

View File

@ -112,7 +112,7 @@ 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 Status'), {'fields': ('subscription_enabled',)}),
(_('Subscription Status'), {'fields': ('subscription_enabled', 'thawani_enabled')}),
(_('Shipper Subscription Fees'), {'fields': ('shipper_monthly_fee', 'shipper_annual_fee')}),
(_('Truck Owner Subscription Fees'), {'fields': ('truck_owner_monthly_fee', 'truck_owner_annual_fee')}),
)

View File

@ -0,0 +1,18 @@
# Generated by Django 5.2.7 on 2026-01-24 07:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0020_transaction_payment_status_transaction_session_id'),
]
operations = [
migrations.AddField(
model_name='appsetting',
name='thawani_enabled',
field=models.BooleanField(default=True, verbose_name='Enable Thawani Payment'),
),
]

View File

@ -261,6 +261,7 @@ 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)
thawani_enabled = models.BooleanField(_("Enable Thawani Payment"), default=True)
# Shipper Fees
shipper_monthly_fee = models.DecimalField(_('Shipper Monthly Fee'), max_digits=10, decimal_places=2, default=0.00)

View File

@ -46,35 +46,52 @@
<small class="text-muted">{% trans "Owner" %}: {{ truck.owner.username }} | {% trans "Plate" %}: {{ truck.plate_no }}</small>
</div>
</div>
<div class="mb-3">
<label class="form-label fw-bold">{{ form.required_truck_type_link.label }}</label>
{{ form.required_truck_type_link }}
{{ form.required_truck_type_link.errors }}
</div>
</div>
</div>
{% if form.errors %}
<div class="alert alert-danger">
<h6 class="alert-heading">{% trans "Please correct the following errors:" %}</h6>
<ul class="mb-0">
{% for field in form %}
{% for error in field.errors %}
<li><strong>{{ field.label }}:</strong> {{ error }}</li>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<form method="post" novalidate>
{% csrf_token %}
<h6 class="border-bottom pb-2 mb-3">{% trans "Shipment Details" %}</h6>
<div class="mb-3">
<label class="form-label fw-bold">{{ form.required_truck_type_link.label }}</label>
{{ form.required_truck_type_link }}
{% if form.required_truck_type_link.errors %}<div class="text-danger small">{{ form.required_truck_type_link.errors.0 }}</div>{% endif %}
</div>
<div class="mb-3">
<label class="form-label fw-bold">{{ form.description.label }}</label>
{{ form.description }}
{{ form.description.errors }}
{% if form.description.errors %}<div class="text-danger small">{{ form.description.errors.0 }}</div>{% endif %}
</div>
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label fw-bold">{{ form.weight.label }}</label>
{{ form.weight }}
{{ form.weight.errors }}
{% if form.weight.errors %}<div class="text-danger small">{{ form.weight.errors.0 }}</div>{% endif %}
</div>
<div class="col-md-6">
<label class="form-label fw-bold">{{ form.delivery_date.label }}</label>
{{ form.delivery_date }}
{{ form.delivery_date.errors }}
{% if form.delivery_date.errors %}<div class="text-danger small">{{ form.delivery_date.errors.0 }}</div>{% endif %}
</div>
</div>
@ -85,22 +102,22 @@
<label class="form-label small text-muted">{% trans "Origin" %}</label>
<div class="mb-2">
{{ form.origin_country }}
{{ form.origin_country.errors }}
{% if form.origin_country.errors %}<div class="text-danger small">{{ form.origin_country.errors.0 }}</div>{% endif %}
</div>
<div>
{{ form.origin_city }}
{{ form.origin_city.errors }}
{% if form.origin_city.errors %}<div class="text-danger small">{{ form.origin_city.errors.0 }}</div>{% endif %}
</div>
</div>
<div class="col-md-6">
<label class="form-label small text-muted">{% trans "Destination" %}</label>
<div class="mb-2">
{{ form.destination_country }}
{{ form.destination_country.errors }}
{% if form.destination_country.errors %}<div class="text-danger small">{{ form.destination_country.errors.0 }}</div>{% endif %}
</div>
<div>
{{ form.destination_city }}
{{ form.destination_city.errors }}
{% if form.destination_city.errors %}<div class="text-danger small">{{ form.destination_city.errors.0 }}</div>{% endif %}
</div>
</div>
</div>
@ -114,13 +131,13 @@
<span class="input-group-text">$</span>
{{ form.amount }}
</div>
{{ form.amount.errors }}
{% if form.amount.errors %}<div class="text-danger small">{{ form.amount.errors.0 }}</div>{% endif %}
</div>
<div class="mb-4">
<label class="form-label fw-bold">{{ form.comments.label }}</label>
{{ form.comments }}
{{ form.comments.errors }}
{% if form.comments.errors %}<div class="text-danger small">{{ form.comments.errors.0 }}</div>{% endif %}
</div>
<div class="d-grid gap-2">
@ -170,11 +187,16 @@ document.addEventListener('DOMContentLoaded', function() {
if (originCountry && originCity) {
originCountry.addEventListener('change', () => updateCities(originCountry, originCity));
updateCities(originCountry, originCity);
// Only run on load if there's no pre-existing selection (to avoid clearing initial filtered values)
if (!originCity.value || originCity.value === "") {
updateCities(originCountry, originCity);
}
}
if (destCountry && destCity) {
destCountry.addEventListener('change', () => updateCities(destCountry, destCity));
updateCities(destCountry, destCity);
if (!destCity.value || destCity.value === "") {
updateCities(destCountry, destCity);
}
}
});
</script>

View File

@ -30,30 +30,46 @@
<h2 class="mb-4">{% trans "Post a New Shipment" %}</h2>
<p class="text-muted mb-4">{% trans "Enter shipment details to receive bids or send as an offer." %}</p>
<form method="post" id="shipmentForm">
{% if form.errors %}
<div class="alert alert-danger">
<h6 class="alert-heading">{% trans "Please correct the following errors:" %}</h6>
<ul class="mb-0">
{% for field in form %}
{% for error in field.errors %}
<li><strong>{{ field.label }}:</strong> {{ error }}</li>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<form method="post" id="shipmentForm" novalidate>
{% csrf_token %}
<div class="mb-4">
<label class="form-label fw-bold">{% trans "Goods Description" %}</label>
{{ form.description }}
{% if form.description.errors %}<div class="text-danger small">{{ form.description.errors }}</div>{% endif %}
{% if form.description.errors %}<div class="text-danger small">{{ form.description.errors.0 }}</div>{% endif %}
</div>
<div class="row mb-4">
<div class="col-md-4">
<label class="form-label fw-bold">{% trans "Weight/Volume" %}</label>
{{ form.weight }}
{% if form.weight.errors %}<div class="text-danger small">{{ form.weight.errors }}</div>{% endif %}
{% if form.weight.errors %}<div class="text-danger small">{{ form.weight.errors.0 }}</div>{% endif %}
</div>
<div class="col-md-4">
<label class="form-label fw-bold">{% trans "Truck Type" %}</label>
{{ form.required_truck_type_link }}
{% if form.required_truck_type_link.errors %}<div class="text-danger small">{{ form.required_truck_type_link.errors }}</div>{% endif %}
{% if form.required_truck_type_link.errors %}<div class="text-danger small">{{ form.required_truck_type_link.errors.0 }}</div>{% endif %}
</div>
<div class="col-md-4">
<label class="form-label fw-bold">{% trans "Delivery Date" %}</label>
{{ form.delivery_date }}
{% if form.delivery_date.errors %}<div class="text-danger small">{{ form.delivery_date.errors }}</div>{% endif %}
{% if form.delivery_date.errors %}<div class="text-danger small">{{ form.delivery_date.errors.0 }}</div>{% endif %}
</div>
</div>
@ -66,18 +82,22 @@
<div class="card bg-light border-0 p-3 mb-3">
<label class="form-label fw-bold">{% trans "Origin Country" %}</label>
{{ form.origin_country }}
{% if form.origin_country.errors %}<div class="text-danger small">{{ form.origin_country.errors.0 }}</div>{% endif %}
<label class="form-label fw-bold mt-2">{% trans "Origin City" %}</label>
{{ form.origin_city }}
{% if form.origin_city.errors %}<div class="text-danger small">{{ form.origin_city.errors.0 }}</div>{% endif %}
</div>
</div>
<div class="col-md-6">
<div class="card bg-light border-0 p-3 mb-3">
<label class="form-label fw-bold">{% trans "Destination Country" %}</label>
{{ form.destination_country }}
{% if form.destination_country.errors %}<div class="text-danger small">{{ form.destination_country.errors.0 }}</div>{% endif %}
<label class="form-label fw-bold mt-2">{% trans "Destination City" %}</label>
{{ form.destination_city }}
{% if form.destination_city.errors %}<div class="text-danger small">{{ form.destination_city.errors.0 }}</div>{% endif %}
</div>
</div>
</div>
@ -128,13 +148,17 @@ document.addEventListener('DOMContentLoaded', function() {
if (originCountry && originCity) {
originCountry.addEventListener('change', () => updateCities(originCountry, originCity));
updateCities(originCountry, originCity);
if (!originCity.value || originCity.value === "") {
updateCities(originCountry, originCity);
}
}
if (destCountry && destCity) {
destCountry.addEventListener('change', () => updateCities(destCountry, destCity));
updateCities(destCountry, destCity);
if (!destCity.value || destCity.value === "") {
updateCities(destCountry, destCity);
}
}
});
</script>
{% endblock %}
{% endblock %}

View File

@ -42,9 +42,16 @@
</div>
<div class="d-grid">
{% if app_settings.thawani_enabled %}
<button type="submit" class="btn btn-primary btn-lg rounded-pill py-3">
<i class="bi bi-credit-card me-2"></i> {% trans "Renew Now" %}
</button>
{% else %}
<div class="alert alert-warning text-center border-0 rounded-3">
<i class="bi bi-info-circle me-2"></i>
{% trans "Online payment is currently disabled. Please contact support for renewal." %}
</div>
{% endif %}
</div>
</form>
</div>
@ -95,4 +102,4 @@
}
});
</script>
{% endblock %}
{% endblock %}

View File

@ -22,6 +22,9 @@ from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.contrib.sites.shortcuts import get_current_site
import json
import logging
logger = logging.getLogger(__name__)
def home(request):
"""Render the landing screen for MASAR CARGO."""
@ -36,7 +39,7 @@ def home(request):
def register(request):
app_settings = AppSetting.objects.first()
subscription_enabled = app_settings.subscription_enabled if app_settings else False
subscription_enabled = (app_settings.subscription_enabled and app_settings.thawani_enabled) if app_settings else False
# Simplified fees dictionary for JS
# Ensuring keys are exactly as they appear in Profile.ROLE_CHOICES
@ -325,6 +328,7 @@ def post_shipment(request):
messages.success(request, _("Shipment posted successfully! It is now open for bids or you can browse trucks to send it as an offer."))
return redirect('dashboard')
else:
logger.error(f"Post Shipment Form Errors: {form.errors}")
messages.error(request, _("Please correct the errors in the form."))
else:
form = ShipmentForm()
@ -382,6 +386,7 @@ def place_bid(request, truck_id):
messages.success(request, _("Offer sent successfully!"))
return redirect('dashboard')
else:
logger.error(f"Place Bid Form Errors: {form.errors}")
messages.error(request, _("Error sending offer. Please check the form."))
else:
form = ShipperOfferForm()
@ -498,6 +503,9 @@ def renew_subscription(request):
def thawani_checkout(request, plan):
profile = request.user.profile
app_settings = AppSetting.objects.first()
if app_settings and not app_settings.thawani_enabled:
messages.error(request, _("Online payment is currently disabled. Please contact support."))
return redirect("dashboard")
amount = 0
if profile.role == 'SHIPPER':