Django_Basic_Manufacturing_3/templates/reports/purchasing_report.html
2025-08-22 17:05:22 +07:00

235 lines
12 KiB
HTML

{% extends "module_base.html" %}
{% load static %}
{% load indonesian_filters %}
{% block title %}Purchasing 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>Purchasing 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="supplier" class="form-label">Supplier</label>
<select class="form-select" id="supplier" name="supplier">
<option value="">All Suppliers</option>
{% for supplier in suppliers %}
<option value="{{ supplier.id }}" {% if supplier.id|stringformat:"s" == request.GET.supplier %}selected{% endif %}>{{ supplier.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="ordered" {% if request.GET.status == 'ordered' %}selected{% endif %}>Ordered</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 Cost</h5>
<h3>{{ total_cost|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>
<!-- Purchase Orders Table -->
<div class="card">
<div class="card-header">
<h5 class="mb-0">Purchase Orders</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped" id="purchasing_table">
<thead>
<tr>
<th>PO Number</th>
<th>Supplier</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 purchase_orders %}
<tr>
<td>{{ order.po_number }}</td>
<td>{{ order.supplier.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 == 'ordered' %}
<span class="badge bg-warning">Ordered</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 purchase 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 Purchased Products</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Product</th>
<th>Quantity Purchased</th>
<th>Total Cost</th>
<th>% of Total Purchases</th>
</tr>
</thead>
<tbody>
{% for product in top_products %}
<tr>
<td>{{ product.product__name }}</td>
<td>{{ product.total_quantity }}</td>
<td>{{ product.total_cost|format_rupiah }}</td>
<td>{{ product.percentage }}%</td>
</tr>
{% empty %}
<tr>
<td colspan="4" class="text-center text-muted">
No product purchasing 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:purchasing_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 %}