Compare commits

...

6 Commits

Author SHA1 Message Date
0859bb3255 update3 2025-06-18 14:47:16 +03:00
91db23e063 Merge branch 'main' of http://10.10.1.136:3000/ismail/haikal into frontend 2025-06-18 13:21:38 +03:00
b75534b601 update1 2025-06-18 13:21:25 +03:00
55a7ec1158 reformat html templates 2025-06-18 13:20:58 +03:00
0c81022e7c update on the bulk update 2025-06-18 13:13:50 +03:00
2c0e40598a Merge pull request 'New Update' (#75) from frontend into main
Reviewed-on: #75
Reviewed-by: ismail <ismail.mosa.ibrahim@gmail.com>
2025-06-18 13:13:21 +03:00
87 changed files with 5310 additions and 5262 deletions

View File

@ -279,6 +279,11 @@ urlpatterns = [
views.CarFinanceUpdateView.as_view(), views.CarFinanceUpdateView.as_view(),
name="car_finance_update", name="car_finance_update",
), ),
path(
"htmx/cars/bulk_update_car_price/",
views.bulk_update_car_price,
name="bulk_update_car_price",
),
path("ajax/", views.AjaxHandlerView.as_view(), name="ajax_handler"), path("ajax/", views.AjaxHandlerView.as_view(), name="ajax_handler"),
path( path(
"cars/<slug:slug>/add-color/", views.CarColorCreate.as_view(), name="add_color" "cars/<slug:slug>/add-color/", views.CarColorCreate.as_view(), name="add_color"

View File

@ -23,6 +23,7 @@ from inventory.models import Status as LeadStatus
from django.db import IntegrityError from django.db import IntegrityError
from background_task.models import Task from background_task.models import Task
from django.views.generic import FormView from django.views.generic import FormView
from django.views.decorators.http import require_http_methods
from django.db.models.deletion import RestrictedError from django.db.models.deletion import RestrictedError
from django.http.response import StreamingHttpResponse from django.http.response import StreamingHttpResponse
from django.core.exceptions import ImproperlyConfigured, ValidationError from django.core.exceptions import ImproperlyConfigured, ValidationError
@ -9288,3 +9289,26 @@ def upload_cars(request,pk=None):
return render(request, 'csv_upload.html',{"make_data":models.CarMake.objects.all(),"form":form,"item":item}) return render(request, 'csv_upload.html',{"make_data":models.CarMake.objects.all(),"form":form,"item":item})
############################################################### ###############################################################
############################################################### ###############################################################
@require_http_methods(["POST"])
def bulk_update_car_price(request):
if request.method == "POST":
cars = request.POST.getlist('car')
price = request.POST.get('price')
if not price or int(price) <= 0:
messages.error(request, "Please enter a valid price")
elif not cars:
messages.error(request, "No cars selected for price update")
else:
for car_pk in cars:
car_finance , created = models.CarFinance.objects.get_or_create(car__pk=car_pk, cost_price=Decimal(price),selling_price=0)
if not created:
car_finance.cost_price = Decimal(price)
car_finance.selling_price = 0
car_finance.save()
messages.success(request, "Price updated successfully")
response = HttpResponse()
response['HX-Redirect'] = reverse('car_list')
return response

View File

@ -152,7 +152,7 @@
<th class="sort white-space-nowrap align-middle " scope="col">{% trans 'PO' %}</th> <th class="sort white-space-nowrap align-middle " scope="col">{% trans 'PO' %}</th>
</tr> </tr>
</thead> </thead>
<tbody class="list" id="project-list-table-body"> <tbody class="list fs-9" id="project-list-table-body">
{% for bill_item in itemtxs_qs %} {% for bill_item in itemtxs_qs %}
<tr> <tr>
<td class="align-middle white-space-nowrap"> <td class="align-middle white-space-nowrap">
@ -171,7 +171,7 @@
</td> </td>
<td class="align-middle white-space-nowrap"> <td class="align-middle white-space-nowrap">
<span class="text-xs font-weight-bold"> <span class="text-xs font-weight-bold">
{% currency_symbol %}{{ bill_item.unit_cost | currency_format }} {{ bill_item.unit_cost | currency_format }}
</span> </span>
</td> </td>
<td class="align-middle white-space-nowrap"> <td class="align-middle white-space-nowrap">
@ -179,7 +179,7 @@
</td> </td>
<td class="align-middle white-space-nowrap"> <td class="align-middle white-space-nowrap">
<span class="text-xs font-weight-bold"> <span class="text-xs font-weight-bold">
{% currency_symbol %}{{ bill_item.total_amount | currency_format }} {{ bill_item.total_amount | currency_format }}
</span> </span>
</td> </td>
<td class="align-middle white-space-nowrap pe-2"> <td class="align-middle white-space-nowrap pe-2">

View File

@ -2,6 +2,7 @@
{% load django_ledger %} {% load django_ledger %}
{% if style == 'detail' %} {% if style == 'detail' %}
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-hover"> <table class="table table-hover">
<thead > <thead >
@ -15,24 +16,24 @@
<th class="sort white-space-nowrap align-middle" scope="col">{% trans 'Description' %}</th> <th class="sort white-space-nowrap align-middle" scope="col">{% trans 'Description' %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody class="fs-9">
{% for transaction_model in transaction_model_qs %} {% for transaction_model in transaction_model_qs %}
<tr> <tr>
<td class="sort white-space-nowrap align-middle ps-1" scope="col" >{{ transaction_model.timestamp }}</td> <td class=" white-space-nowrap align-middle ps-2" scope="col" >{{ transaction_model.timestamp }}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{{ transaction_model.account_code }}</td> <td class=" white-space-nowrap align-middle" scope="col">{{ transaction_model.account_code }}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{{ transaction_model.account_name }}</td> <td class=" white-space-nowrap align-middle" scope="col">{{ transaction_model.account_name }}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{% if transaction_model.entity_unit_name %}{{ transaction_model.entity_unit_name }}{% endif %}</td> <td class=" white-space-nowrap align-middle" scope="col">{% if transaction_model.entity_unit_name %}{{ transaction_model.entity_unit_name }}{% endif %}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{% if transaction_model.is_credit %}${{ transaction_model.amount | currency_format }}{% endif %}</td> <td class=" white-space-nowrap align-middle" scope="col">{% if transaction_model.is_credit %}{{ transaction_model.amount | currency_format }}{% endif %}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{% if transaction_model.is_debit %}${{ transaction_model.amount | currency_format }}{% endif %}</td> <td class=" white-space-nowrap align-middle" scope="col">{% if transaction_model.is_debit %}{{ transaction_model.amount | currency_format }}{% endif %}</td>
<td class="sort white-space-nowrap align-middle pe-1" scope="col">{% if transaction_model.description %}{{ transaction_model.description }}{% endif %}</td> <td class=" white-space-nowrap align-middle pe-2" scope="col">{% if transaction_model.description %}{{ transaction_model.description }}{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr class="fw-bold"> <tr class="fw-bold">
<td class="sort white-space-nowrap align-middle" colspan="3"></td> <td class=" white-space-nowrap align-middle" colspan="3"></td>
<td class="class="sort white-space-nowrap align-middle" " scope="col">{% trans 'Total' %}</td> <td class=" white-space-nowrap align-middle" scope="col">{% trans 'Total' %}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{% currency_symbol %}{{ total_credits | currency_format }}</td> <td class=" white-space-nowrap align-middle" scope="col">{% currency_symbol %}{{ total_credits | currency_format }}</td>
<td class="sort white-space-nowrap align-middle" scope="col">{% currency_symbol %}{{ total_debits | currency_format }}</td> <td class=" white-space-nowrap align-middle" scope="col">{% currency_symbol %}{{ total_debits | currency_format }}</td>
<td class="sort white-space-nowrap align-middle" scope="col"></td> <td class=" white-space-nowrap align-middle" scope="col"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -42,29 +43,28 @@
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
<tr class="bg-body-highlight"> <tr class="bg-body-highlight">
<th>{% trans 'Account' %}</th> <th class="sort white-space-nowrap align-middle">{% trans 'Account Name' %}</th>
<th>{% trans 'Account Name' %}</th> <th class="sort white-space-nowrap align-middle">{% trans 'Credit' %}</th>
<th>{% trans 'Credit' %}</th> <th class="sort white-space-nowrap align-middle">{% trans 'Debit' %}</th>
<th>{% trans 'Debit' %}</th> <th class="sort white-space-nowrap align-middle">{% trans 'Description' %}</th>
<th>{% trans 'Description' %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody class="fs-9">
{% for transaction_model in transaction_model_qs %} {% for transaction_model in transaction_model_qs %}
<tr> <tr>
<td>{{ transaction_model.account_code }}</td> <td class=" white-space-nowrap align-middle ps-2">{{ transaction_model.account_code }}</td>
<td>{{ transaction_model.account_name }}</td> <td class=" white-space-nowrap align-middle">{{ transaction_model.account_name }}</td>
<td>{% if transaction_model.is_credit %}${{ transaction_model.amount | currency_format }}{% endif %}</td> <td class=" white-space-nowrap align-middle">{% if transaction_model.is_credit %}{{ transaction_model.amount | currency_format }}{% endif %}</td>
<td>{% if transaction_model.is_debit %}${{ transaction_model.amount | currency_format }}{% endif %}</td> <td class=" white-space-nowrap align-middle">{% if transaction_model.is_debit %}{{ transaction_model.amount | currency_format }}{% endif %}</td>
<td>{% if transaction_model.description %}{{ transaction_model.description }}{% endif %}</td> <td class=" white-space-nowrap align-middle pe-2">{% if transaction_model.description %}{{ transaction_model.description }}{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr class="fw-bold"> <tr class="fw-bold">
<td colspan="1"></td> <td class=" white-space-nowrap align-middle" colspan="1"></td>
<td class="text-end">{% trans 'Total' %}</td> <td class=" white-space-nowrap align-middle text-end">{% trans 'Total' %}</td>
<td>{% currency_symbol %}{{ total_credits | currency_format }}</td> <td class="white-space-nowrap align-middle">{% currency_symbol %}{{ total_credits | currency_format }}</td>
<td>{% currency_symbol %}{{ total_debits | currency_format }}</td> <td class=" white-space-nowrap align-middle">{% currency_symbol %}{{ total_debits | currency_format }}</td>
<td></td> <td class="white-space-nowrap align-middle"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -145,8 +145,14 @@
hx-on::after-request="filter_after_request()">{{ _("Search") }}</button> hx-on::after-request="filter_after_request()">{{ _("Search") }}</button>
</div> </div>
<div class="row"> <div class="row">
<form class="update-price-form d-flex flex-row align-items-center ms-auto w-25 d-none" action="" method="post" style="float:right;"> <form hx-boost='true' action="{% url 'bulk_update_car_price' %}" method="post"
<input class="form-control me-2" type="number" placeholder='{{ _("Search") }}' name="price" aria-label="Price"> hx-include=".car-checkbox"
class="update-price-form d-flex flex-row align-items-center ms-auto w-25 d-none" style="float:right;">
{% csrf_token %}
<div class="form-floating me-2">
<input class="form-control" type="number" placeholder='{{ _("Search") }}' name="price" aria-label="Price" id="price">
<label for="price">{{ _("Price") }}</label>
</div>
<button class="btn btn-outline-primary" type="submit">{{ _("Search") }}</button> <button class="btn btn-outline-primary" type="submit">{{ _("Search") }}</button>
</form> </form>
<div class="table-responsive scrollbar transition"> <div class="table-responsive scrollbar transition">
@ -186,7 +192,7 @@
<tr class="position-static"> <tr class="position-static">
<td class="align-middle white-space-nowrap"> <td class="align-middle white-space-nowrap">
<div class="form-check"> <div class="form-check">
<input class="form-check-input car-checkbox" type="checkbox" name="car" id="car-{{car.pk}}"> <input class="form-check-input car-checkbox" type="checkbox" name="car" value="{{ car.pk }}" id="car-{{car.pk}}">
</div> </div>
</td> </td>
<td class="align-middle white-space-nowrap ps-1"> <td class="align-middle white-space-nowrap ps-1">
@ -313,18 +319,31 @@
document.getElementById('select-all').addEventListener('change', function() { document.getElementById('select-all').addEventListener('change', function() {
const checkboxes = document.querySelectorAll('#project-list-table-body input[type="checkbox"]'); const checkboxes = document.querySelectorAll('#project-list-table-body input[type="checkbox"]');
checkboxes.forEach(checkbox => {
checkbox.checked = this.checked;
});
});
document.getElementById('car-checkbox').addEventListener('change', function() {
const form = document.querySelector('.update-price-form');
if (this.checked) { if (this.checked) {
checkboxes.forEach(checkbox => checkbox.checked = true);
} else {
checkboxes.forEach(checkbox => checkbox.checked = false);
}
updateFormVisibility();
});
const cbox = document.querySelectorAll('.car-checkbox');
cbox.forEach(checkbox => {
checkbox.addEventListener('change', function() {
updateFormVisibility();
});
});
function updateFormVisibility() {
const form = document.querySelector('.update-price-form');
const checkedCount = document.querySelectorAll('.car-checkbox:checked').length;
const submitButton = form.querySelector('button[type="submit"]');
if (checkedCount > 0) {
form.classList.remove('d-none'); form.classList.remove('d-none');
submitButton.textContent = `Update Cost Price (${checkedCount})`;
} else { } else {
form.classList.add('d-none'); form.classList.add('d-none');
} }
}); }
</script> </script>
{% endblock customJS %} {% endblock customJS %}

View File

@ -10,7 +10,7 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="row"> <div class="row mt-4">
<div class="row"> <div class="row">
<div class="col-xl-9"> <div class="col-xl-9">
<div class="d-sm-flex justify-content-between"> <div class="d-sm-flex justify-content-between">