{% extends "base.html" %}

{% block title %}Fatura Arşivi - FaturaYol{% endblock %}
{% block page_title %}{{ firma.ad }}{% endblock %}

{% block content %}
<nav aria-label="breadcrumb" class="mb-4">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{% url 'fatura_arsivi' %}" class="text-decoration-none">Arşiv</a></li>
        <li class="breadcrumb-item active" aria-current="page">{{ firma.ad }}</li>
    </ol>
</nav>

<div class="card border-0 shadow-sm mb-4">
    <div class="card-header bg-white py-3">
        <div class="d-flex justify-content-between align-items-center">
            <h5 class="mb-0 fw-bold"><i class="bi bi-files me-2 text-primary"></i>Tüm Faturalar</h5>
            <div class="btn-group">
                <a href="{% url 'fatura_ekle' %}?firma={{ firma.pk }}" class="btn btn-sm btn-primary rounded-pill px-3"><i class="bi bi-plus-lg me-1"></i> Yeni PDF Yükle</a>
            </div>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-hover align-middle mb-0">
            <thead>
                <tr>
                    <th class="ps-4">Fatura No</th>
                    <th>Tarih</th>
                    <th>Ara Toplam</th>
                    <th>KDV</th>
                    <th>Genel Toplam</th>
                    <th>Durum</th>
                    <th class="text-end pe-4">İşlemler</th>
                </tr>
            </thead>
            <tbody>
                {% for fatura in faturalar %}
                <tr>
                    <td class="ps-4 fw-medium">{{ fatura.fatura_no }}</td>
                    <td>{{ fatura.tarih|date:"d.m.Y" }}</td>
                    <td>{{ fatura.ara_toplam }} ₺</td>
                    <td>{{ fatura.kdv_toplam }} ₺</td>
                    <td class="fw-bold text-primary">{{ fatura.genel_toplam }} ₺</td>
                    <td>
                        {% if fatura.islenmis %}
                        <span class="badge badge-soft-success px-2 py-1 rounded-pill">İşlendi</span>
                        {% else %}
                        <span class="badge bg-light text-dark px-2 py-1 rounded-pill border">Bekliyor</span>
                        {% endif %}
                    </td>
                    <td class="text-end pe-4">
                        <a href="{% url 'fatura_detay' fatura.pk %}" class="btn btn-sm btn-light rounded-circle me-1" title="Görüntüle">
                            <i class="bi bi-eye"></i>
                        </a>
                        {% if fatura.pdf_dosyasi %}
                        <a href="{{ fatura.pdf_dosyasi.url }}" target="_blank" class="btn btn-sm btn-light rounded-circle me-1" title="PDF İndir">
                            <i class="bi bi-download"></i>
                        </a>
                        {% endif %}
                        <a href="{% url 'fatura_sil' fatura.pk %}" class="btn btn-sm btn-light text-danger rounded-circle" title="Faturayı Sil">
                            <i class="bi bi-trash"></i>
                        </a>
                    </td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="7" class="text-center py-5 text-muted">
                        <p class="mb-0">Bu firmaya ait henüz fatura bulunamadı.</p>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
