{% extends 'base.html' %}
{% load i18n %}

{% block title %}{% trans "Supplier Payments" %} | {{ site_settings.business_name }}{% endblock %}

{% block content %}
<div class="container-fluid px-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="fw-bold mb-0">{% trans "Supplier Payments" %}</h2>
            <p class="text-muted small mb-0">{% trans "History of payments made to suppliers" %}</p>
        </div>
        <a href="{% url 'purchases' %}" class="btn btn-primary rounded-3 px-4 shadow-sm">
            <i class="bi bi-list-ul me-2"></i>{% trans "Purchase Invoices" %}
        </a>
    </div>

    <div class="card border-0 shadow-sm rounded-4">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4">{% trans "Date" %}</th>
                            <th>{% trans "Purchase #" %}</th>
                            <th>{% trans "Supplier" %}</th>
                            <th>{% trans "Amount" %}</th>
                            <th>{% trans "Method" %}</th>
                            <th>{% trans "User" %}</th>
                            <th class="pe-4">{% trans "Notes" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for payment in payments %}
                        <tr>
                            <td class="ps-4">{{ payment.payment_date|date:"Y-m-d" }}</td>
                            <td>
                                <a href="{% url 'purchase_detail' payment.purchase.id %}" class="fw-bold text-decoration-none">
                                    {{ payment.purchase.invoice_number|default:payment.purchase.id }}
                                </a>
                            </td>
                            <td>{{ payment.purchase.supplier.name|default:"-" }}</td>
                            <td class="fw-bold text-dark">{{ site_settings.currency_symbol }}{{ payment.amount|floatformat:3 }}</td>
                            <td>
                                <span class="badge bg-light text-dark border rounded-pill px-3">
                                    {{ payment.payment_method_name }}
                                </span>
                            </td>
                            <td>
                                <span class="text-muted small">
                                    <i class="bi bi-person me-1"></i>{{ payment.created_by.username|default:"System" }}
                                </span>
                            </td>
                            <td class="pe-4">
                                <span class="small text-muted">{{ payment.notes|default:"-" }}</span>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="7" class="text-center py-5">
                                <img src="https://illustrations.popsy.co/gray/payments.svg" alt="Empty" style="width: 200px;" class="mb-3">
                                <p class="text-muted">{% trans "No purchase payments found." %}</p>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% include "core/pagination.html" with page_obj=payments %}
        </div>
    </div>
</div>
{% endblock %}
