{% extends "base.html" %}
{% block title %}Customer Ledger - {{ customer.name }}{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4>Customer Ledger: {{ customer.name }}</h4>
            <form method="get" class="d-flex">
                <input type="date" name="start_date" value="{{ start_date|date:'Y-m-d' }}" class="form-control me-2">
                <input type="date" name="end_date" value="{{ end_date|date:'Y-m-d' }}" class="form-control me-2">
                <button type="submit" class="btn btn-primary">Filter</button>
            </form>
        </div>
        <div class="card-body">
            <p><strong>Opening Balance:</strong> {{ opening_balance|floatformat:2 }}</p>
            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead class="table-dark">
                        <tr>
                            <th>Date</th>
                            <th>Reference</th>
                            <th>Description</th>
                            <th class="text-end">Debit</th>
                            <th class="text-end">Credit</th>
                            <th class="text-end">Balance</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in ledger_entries %}
                        <tr>
                            <td>{{ entry.date|date:"Y-m-d" }}</td>
                            <td>{{ entry.reference }}</td>
                            <td>{{ entry.description }}</td>
                            <td class="text-end">{{ entry.debit|floatformat:2 }}</td>
                            <td class="text-end">{{ entry.credit|floatformat:2 }}</td>
                            <td class="text-end">{{ entry.balance|floatformat:2 }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                    <tfoot class="table-light">
                        <tr>
                            <td colspan="5" class="text-end"><strong>Closing Balance:</strong></td>
                            <td class="text-end"><strong>{{ final_balance|floatformat:2 }}</strong></td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
