{% extends "base.html" %}
{% block title %}Purchase Order{% endblock %}
{% block breadcrumb %}Pengadaan / Purchase Order{% endblock %}
{% block page_title %}Purchase Order{% endblock %}
{% block topbar_actions %}<a href="{{ url_for('procurement.po_create') }}" class="btn btn-primary">+ Buat PO</a>{% endblock %}
{% block content %}
<div class="flex gap-2 mb-4">
    {% for s, label in [('all','Semua'),('draft','Draft'),('sent','Dikirim'),('partial','Sebagian Diterima'),('received','Diterima'),('cancelled','Dibatalkan')] %}
    <a href="?status={{ s }}" class="btn {% if current_status == s %}btn-primary{% else %}btn-secondary{% endif %} btn-sm">{{ label }}</a>
    {% endfor %}
</div>
<div class="card">
    <div class="table-wrap">
        <table>
            <thead><tr><th>No. PO</th><th>Proyek</th><th>Vendor</th><th>Tgl Order</th><th class="text-right">Subtotal</th><th class="text-right">PPN</th><th class="text-right">Total</th><th>Status</th><th>Aksi</th></tr></thead>
            <tbody>
            {% for po in pos %}
            <tr>
                <td><a href="{{ url_for('procurement.po_detail', id=po.id) }}" class="text-accent font-mono fw-600">{{ po.po_number }}</a></td>
                <td class="fs-13">{{ po.project.project_code }}</td>
                <td class="fs-13">{{ po.vendor.vendor_name[:30] }}</td>
                <td class="fs-13">{{ po.order_date.strftime('%d %b %Y') }}</td>
                <td class="font-mono text-right fs-13">Rp {{ "{:,.0f}".format(po.subtotal) }}</td>
                <td class="font-mono text-right fs-13">Rp {{ "{:,.0f}".format(po.tax_amount) }}</td>
                <td class="font-mono text-right fw-600">Rp {{ "{:,.0f}".format(po.total_amount) }}</td>
                <td>
                    {% if po.status == 'draft' %}<span class="badge badge-secondary">Draft</span>
                    {% elif po.status == 'sent' %}<span class="badge badge-info">Dikirim</span>
                    {% elif po.status == 'partial' %}<span class="badge badge-warning">Sebagian</span>
                    {% elif po.status == 'received' %}<span class="badge badge-success">Diterima</span>
                    {% elif po.status == 'cancelled' %}<span class="badge badge-danger">Batal</span>{% endif %}
                </td>
                <td><a href="{{ url_for('procurement.po_detail', id=po.id) }}" class="btn btn-secondary btn-sm">Detail</a></td>
            </tr>
            {% else %}
            <tr><td colspan="9" style="text-align:center;padding:40px;color:var(--text-muted)">Belum ada Purchase Order</td></tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
