235 lines
12 KiB
HTML
235 lines
12 KiB
HTML
{% extends "module_base.html" %}
|
|
{% load static %}
|
|
{% load indonesian_filters %}
|
|
|
|
{% block title %}Sales Report{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h4 class="card-title mb-0">
|
|
<i class="fas fa-shopping-cart me-2"></i>Sales Report
|
|
</h4>
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- Report Filters -->
|
|
<form method="get" class="row mb-4 g-3">
|
|
<div class="col-md-3">
|
|
<label for="date_from" class="form-label">Date From</label>
|
|
<input type="date" class="form-control" id="date_from" name="date_from" value="{{ date_from }}">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label for="date_to" class="form-label">Date To</label>
|
|
<input type="date" class="form-control" id="date_to" name="date_to" value="{{ date_to }}">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label for="customer" class="form-label">Customer</label>
|
|
<select class="form-select" id="customer" name="customer">
|
|
<option value="">All Customers</option>
|
|
{% for customer in customers %}
|
|
<option value="{{ customer.id }}" {% if customer.id|stringformat:"s" == request.GET.customer %}selected{% endif %}>{{ customer.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status">
|
|
<option value="">All Statuses</option>
|
|
<option value="processing" {% if request.GET.status == 'processing' %}selected{% endif %}>Processing</option>
|
|
<option value="completed" {% if request.GET.status == 'completed' %}selected{% endif %}>Completed</option>
|
|
<option value="cancelled" {% if request.GET.status == 'cancelled' %}selected{% endif %}>Cancelled</option>
|
|
</select>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- Summary Cards -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-3">
|
|
<div class="card bg-success text-white">
|
|
<div class="card-body text-center">
|
|
<h5 class="card-title">Total Orders</h5>
|
|
<h3>{{ total_orders|default:0 }}</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card bg-primary text-white">
|
|
<div class="card-body text-center">
|
|
<h5 class="card-title">Total Revenue</h5>
|
|
<h3>{{ total_revenue|format_rupiah }}</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card bg-warning text-white">
|
|
<div class="card-body text-center">
|
|
<h5 class="card-title">Avg Order Value</h5>
|
|
<h3>{{ avg_order_value|format_rupiah }}</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card bg-info text-white">
|
|
<div class="card-body text-center">
|
|
<h5 class="card-title">Pending Orders</h5>
|
|
<h3>{{ pending_orders|default:0 }}</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sales Orders Table -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Sales Orders</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped" id="sales_table">
|
|
<thead>
|
|
<tr>
|
|
<th>Order Number</th>
|
|
<th>Customer</th>
|
|
<th>Order Date</th>
|
|
<th>Expected Delivery</th>
|
|
<th>Status</th>
|
|
<th>Items</th>
|
|
<th>Total Amount</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for order in sales_orders %}
|
|
<tr>
|
|
<td>{{ order.so_number }}</td>
|
|
<td>{{ order.customer.name }}</td>
|
|
<td>{{ order.order_date|date:"d M Y" }}</td>
|
|
<td>{{ order.expected_delivery_date|date:"d M Y" }}</td>
|
|
<td>
|
|
{% if order.status == 'processing' %}
|
|
<span class="badge bg-warning">Processing</span>
|
|
{% elif order.status == 'completed' %}
|
|
<span class="badge bg-success">Completed</span>
|
|
{% elif order.status == 'cancelled' %}
|
|
<span class="badge bg-danger">Cancelled</span>
|
|
{% endif %}
|
|
</td>
|
|
<td>{{ order.items.count }}</td>
|
|
<td>{{ order.total_amount|format_rupiah }}</td>
|
|
</tr>
|
|
{% empty %}
|
|
<tr>
|
|
<td colspan="7" class="text-center text-muted">
|
|
No sales orders found for the selected period.
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Top Products -->
|
|
<div class="card mt-4">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Top Products</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Product</th>
|
|
<th>Quantity Sold</th>
|
|
<th>Total Revenue</th>
|
|
<th>% of Total Sales</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for product in top_products %}
|
|
<tr>
|
|
<td>{{ product.name }}</td>
|
|
<td>{{ product.total_quantity }}</td>
|
|
<td>{{ product.total_revenue|format_rupiah }}</td>
|
|
<td>{{ product.percentage }}%</td>
|
|
</tr>
|
|
{% empty %}
|
|
<tr>
|
|
<td colspan="4" class="text-center text-muted">
|
|
No product sales data available.
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Export Options -->
|
|
<div class="mt-4 text-center">
|
|
<div class="btn-group">
|
|
<a href="{% url 'reports:sales_report' %}?export=excel" class="btn btn-outline-primary">
|
|
<i class="fas fa-file-excel me-2"></i>Export to Excel
|
|
</a>
|
|
<button class="btn btn-outline-danger" onclick="exportToPDF()">
|
|
<i class="fas fa-file-pdf me-2"></i>Export to PDF
|
|
</button>
|
|
<button class="btn btn-outline-secondary" onclick="printReport()">
|
|
<i class="fas fa-print me-2"></i>Print Report
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Set default date range (last 30 days)
|
|
const today = new Date();
|
|
const thirtyDaysAgo = new Date();
|
|
thirtyDaysAgo.setDate(today.getDate() - 30);
|
|
|
|
const dateFromInput = document.getElementById('date_from');
|
|
const dateToInput = document.getElementById('date_to');
|
|
|
|
if (dateFromInput && !dateFromInput.value) {
|
|
dateFromInput.value = thirtyDaysAgo.toISOString().split('T')[0];
|
|
}
|
|
if (dateToInput && !dateToInput.value) {
|
|
dateToInput.value = today.toISOString().split('T')[0];
|
|
}
|
|
|
|
// Auto-submit form when filters change
|
|
document.querySelectorAll('select').forEach(select => {
|
|
select.addEventListener('change', function() {
|
|
this.closest('form').submit();
|
|
});
|
|
});
|
|
});
|
|
|
|
function exportToExcel() {
|
|
// Get current filter parameters
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
urlParams.set('export', 'excel');
|
|
|
|
// Create export URL with current filters
|
|
const exportUrl = window.location.pathname + '?' + urlParams.toString();
|
|
window.location.href = exportUrl;
|
|
}
|
|
|
|
function exportToPDF() {
|
|
alert('PDF export functionality would be implemented here');
|
|
}
|
|
|
|
function printReport() {
|
|
window.print();
|
|
}
|
|
</script>
|
|
{% endblock %} |