haikal/templates/ledger/reports/car_sale_report.html
2025-09-11 17:42:05 +03:00

362 lines
20 KiB
HTML

{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load tenhal_tag %}
{% block title %}
{{ _("Car Sale Report")|capfirst }}
{% endblock title %}
{% block content %}
<style>
.summary-card {
border: 1px solid var(--card-border);
border-radius: .5rem;
box-shadow: var(--card-shadow);
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.summary-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}
.summary-card .card-body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.summary-card .card-title {
font-size: 1rem;
font-weight: 500;
color: var(--secondary-color) !important;
}
.summary-card .card-text {
font-size: 2.25rem;
font-weight: 700;
}
</style>
<div class="container-fluid report-container">
<header class="report-header text-center">
<h1 class="display-4">
{% trans 'Car Sale Report' %} <span class="fas fa-chart-line mx-2 text-primary"></span>
</h1>
<p class="lead text-muted">
<strong>{{ dealer }}</strong>
</p>
<p class="text-muted">{% trans 'Report Date' %}: {{ current_time }}</p>
</header>
<main>
<section id="filters" class="mb-5 p-4 rounded border border-primary">
<h2 class="section-heading mb-4">
{% trans 'Filters' %} <i class="fas fa-sliders-h ms-2"></i>
</h2>
<form method="GET" class="row g-3 align-items-end" data-filter-url="{% url 'get_filtered_choices' dealer_slug=dealer.slug %}">
<div class="col-md-6">
<label for="start_date" class="form-label">{% trans 'Start Date' %}</label>
<input type="date" class="form-control" id="start_date" name="start_date" value="{{ start_date }}">
</div>
<div class="col-md-6">
<label for="end_date" class="form-label">{% trans 'End Date' %}</label>
<input type="date" class="form-control" id="end_date" name="end_date" value="{{ end_date }}">
</div>
<div class="col-md-2">
<label for="make-select" class="form-label">{% trans 'Make' %}</label>
<select id="make-select" name="make" class="form-select">
<option value="">{% trans 'All Makes' %}</option>
{% for make in makes %}
<option value="{{ make }}" {% if make == selected_make %}selected{% endif %}>{{ make }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<label for="model-select" class="form-label">{% trans 'Model' %}</label>
<select id="model-select" name="model" class="form-select">
<option value="">{% trans 'All Models' %}</option>
{% if selected_model %}
<option value="{{ selected_model }}" selected>{{ selected_model }}</option>
{% endif %}
</select>
</div>
<div class="col-md-2">
<label for="serie-select" class="form-label">{% trans 'Serie' %}</label>
<select id="serie-select" name="serie" class="form-select">
<option value="">{% trans 'All Series' %}</option>
{% if selected_serie %}
<option value="{{ selected_serie }}" selected>{{ selected_serie }}</option>
{% endif %}
</select>
</div>
<div class="col-md-2">
<label for="year-select" class="form-label">{% trans 'Year' %}</label>
<select id="year-select" name="year" class="form-select">
<option value="">{% trans 'All Years' %}</option>
{% if selected_year %}
<option value="{{ selected_year }}" selected>{{ selected_year }}</option>
{% endif %}
</select>
</div>
<div class="col-md-2">
<label for="stock_type-select" class="form-label">{% trans 'Stock Types' %}</label>
<select id="stock_type-select" name="stock_type" class="form-select">
<option value="">{% trans 'All Stock Types' %}</option>
{% if selected_stock_type %}
<option value="{{ selected_stock_type }}" selected>{{ selected_stock_type }}</option>
{% endif %}
</select>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-filter me-2"></i>{% trans 'Filter' %}
</button>
</div>
</form>
</section>
<section id="summary" class="mb-5">
<h2 class="section-heading mb-4 border-start border-5 border-primary p-2">{% trans 'Report Summary' %}</h2>
<div class="row g-4">
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
<span>{% trans 'Total Revenue from Cars' %}<span class="icon-saudi_riyal"></span></span>
</h5>
<p class="card-text">
<span>{{ total_revenue_from_cars|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
<span>{% trans 'Total Revenue from Services' %}<span class="icon-saudi_riyal"></span></span>
</h5>
<p class="card-text">
<span>{{ total_revenue_from_additonals|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
<span>{% trans 'Total Revenue' %}<span class="icon-saudi_riyal"></span></span>
</h5>
<p class="card-text">
<span>{{ total_revenue_collected|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
{% trans 'Total VAT from Cars' %}<i class="fas fa-percent ms-2"></i>
</h5>
<p class="card-text">
<span>{{ total_vat_on_cars|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
{% trans 'Total VAT from Services' %}<i class="fas fa-percent ms-2"></i>
</h5>
<p class="card-text">
<span>{{ total_vat_from_additonals|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
{% trans 'Total VAT' %}<i class="fas fa-percent ms-2"></i>
</h5>
<p class="card-text">
<span>{{ total_vat_collected|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
{% trans 'Total Discount Amount' %}<i class="fas fa-tag ms-2"></i>
</h5>
<p class="card-text">
<span>{{ total_discount|floatformat:'2g' }} <span class="icon-saudi_riyal"></span></span>
</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card summary-card">
<div class="card-body">
<h5 class="card-title">
{% trans 'Total Cars Sold' %}<i class="fas fa-car ms-2"></i>
</h5>
<p class="card-text">{{ total_cars_sold }}</p>
</div>
</div>
</div>
</div>
</section>
<section id="sale-details" class="mb-3">
<h2 class="section-heading border-start border-5 border-primary p-2">{% trans 'Detailed Sale List' %}</h2>
<div class="d-flex justify-content-end mb-3 d-print-none">
<a href="{% url 'car-sale-report-csv-export' dealer.slug %}"
class="btn btn-phoenix-primary">
<i class="bi bi-download me-2"></i>{% trans 'Download as CSV' %}
</a>
</div>
<div class="table-responsive table-container">
<table class="table table-striped table-hover table-bordered table-sm">
<thead>
<tr>
<th class="fs-9">{% trans 'VIN' %}</th>
<th class="fs-9">{% trans 'Make' %}</th>
<th class="fs-9">{% trans 'Model' %}</th>
<th class="fs-9">{% trans 'Year' %}</th>
<th class="fs-9">{% trans 'Serie' %}</th>
<th class="fs-9">{% trans 'Trim' %}</th>
<th class="fs-9">{% trans 'Mileage' %}</th>
<th class="fs-9">{% trans 'Stock Type' %}</th>
<th class="fs-9">{% trans 'Created Date' %}</th>
<th class="fs-9">{% trans 'Sold Date' %}</th>
<th class="fs-9">{% trans 'Cost Price' %}</th>
<th class="fs-9">{% trans 'Marked Price' %}</th>
<th class="fs-9">{% trans 'Discount Amount' %}</th>
<th class="fs-9">{% trans 'Selling Price' %}</th>
<th class="fs-9">{% trans 'VAT on Car' %}</th>
<th class="fs-9">{% trans 'Services Price' %}</th>
<th class="fs-9">{% trans 'VAT on Services' %}</th>
<th class="fs-9">{% trans 'Final Total' %}</th>
<th class="fs-9">{% trans 'Invoice Number' %}</th>
</tr>
</thead>
<tbody>
{% for car in cars_sold %}
<tr>
<td class="ps-1 fs-9">{{ car.vin }}</td>
<td class="fs-9">{{ car.id_car_make.name }}</td>
<td class="fs-9">{{ car.id_car_model.name }}</td>
<td class="fs-9">{{ car.year }}</td>
<td class="fs-9">{{ car.id_car_serie.name }}</td>
<td class="fs-9">{{ car.id_car_trim.name }}</td>
<td class="fs-9">{{ car.mileage }}</td>
<td class="fs-9">{{ car.stock_type|capfirst }}</td>
<td class="fs-9">{{ car.created_at|date }}</td>
<td class="fs-9">{{ car.invoice.sale_orders.first.order_date|date|default_if_none:"-" }}</td>
<td class="fs-9 text-nowrap">
<span>{{ car.cost_price }}<span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.marked_price }} <span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.discount }} <span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.final_price }} <span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.vat_amount|floatformat:2 }} <span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.get_additional_services.total|floatformat:2 }} <span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.get_additional_services.services_vat|floatformat:2 }}<span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9 text-nowrap">
<span>{{ car.final_price_plus_services_plus_vat|floatformat:2 }}<span class="icon-saudi_riyal"></span></span>
</td>
<td class="fs-9">
<span>{{ car.invoice.invoice_number }}</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
</main>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const makeSelect = document.getElementById('make-select');
const modelSelect = document.getElementById('model-select');
const serieSelect = document.getElementById('serie-select');
const yearSelect = document.getElementById('year-select');
const stockTypeSelect = document.getElementById('stock_type-select');
const startDateInput = document.getElementById('start_date');
const endDateInput = document.getElementById('end_date');
const form = document.querySelector('form');
const baseUrl = form.dataset.filterUrl;
function updateOptions(selectElement, options, currentValue) {
const name = selectElement.name.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
selectElement.innerHTML = `<option value="">All ${name}s</option>`;
options.forEach(option => {
const newOption = document.createElement('option');
newOption.value = option;
newOption.textContent = option;
if (String(option) === String(currentValue)) {
newOption.selected = true;
}
selectElement.appendChild(newOption);
});
}
function fetchAndUpdateDropdowns() {
const make = makeSelect.value;
const model = modelSelect.value;
const serie = serieSelect.value;
const start_date = startDateInput.value;
const end_date = endDateInput.value;
// Corrected: Include start_date and end_date in the AJAX URL
const url = `${baseUrl}?make=${make}&model=${model}&serie=${serie}&start_date=${start_date}&end_date=${end_date}`;
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
updateOptions(modelSelect, data.models, model);
updateOptions(serieSelect, data.series, serie);
updateOptions(yearSelect, data.years, yearSelect.value);
updateOptions(stockTypeSelect, data.stock_types, stockTypeSelect.value);
})
.catch(error => console.error('Error fetching filtered choices:', error));
}
// Event listeners for all filter elements
makeSelect.addEventListener('change', fetchAndUpdateDropdowns);
modelSelect.addEventListener('change', fetchAndUpdateDropdowns);
serieSelect.addEventListener('change', fetchAndUpdateDropdowns);
yearSelect.addEventListener('change', fetchAndUpdateDropdowns);
stockTypeSelect.addEventListener('change', fetchAndUpdateDropdowns);
startDateInput.addEventListener('change', fetchAndUpdateDropdowns);
endDateInput.addEventListener('change', fetchAndUpdateDropdowns);
// Initial call to populate other dropdowns on page load
fetchAndUpdateDropdowns();
});
</script>
{% endblock %}