{% extends '_base.html' %}
{% load humanize %}

{% block content %}
<div class="container py-4">
  <div class="mb-4 d-flex justify-content-between align-items-center">
    <div>
      <h4 class="mb-1">فاکتور نهایی</h4>
      <small class="text-muted">کد درخواست: {{ instance.code }}</small>
    </div>
    <div>
      <!-- Placeholders for logo/signature -->
      <div class="text-end">لوگو</div>
    </div>
  </div>
  <div class="table-responsive">
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>آیتم</th>
          <th>تعداد</th>
          <th>قیمت واحد</th>
          <th>قیمت کل</th>
        </tr>
      </thead>
      <tbody>
        {% for it in items %}
        <tr>
          <td>{{ it.item.name }}</td>
          <td>{{ it.quantity }}</td>
          <td>{{ it.unit_price|floatformat:0|intcomma:False }}</td>
          <td>{{ it.total_price|floatformat:0|intcomma:False }}</td>
        </tr>
        {% empty %}
        <tr><td colspan="4" class="text-center text-muted">آیتمی ندارد</td></tr>
        {% endfor %}
      </tbody>
      <tfoot>
        <tr><th colspan="3" class="text-end">مبلغ کل</th><th>{{ invoice.total_amount|floatformat:0|intcomma:False }}</th></tr>
        <tr><th colspan="3" class="text-end">تخفیف</th><th>{{ invoice.discount_amount|floatformat:0|intcomma:False }}</th></tr>
        <tr><th colspan="3" class="text-end">مبلغ نهایی</th><th>{{ invoice.final_amount|floatformat:0|intcomma:False }}</th></tr>
        <tr><th colspan="3" class="text-end">پرداختی‌ها</th><th>{{ invoice.paid_amount|floatformat:0|intcomma:False }}</th></tr>
        <tr><th colspan="3" class="text-end">مانده</th><th>{{ invoice.remaining_amount|floatformat:0|intcomma:False }}</th></tr>
      </tfoot>
    </table>
  </div>
  <div class="mt-5 d-flex justify-content-between">
    <div>امضا مشتری</div>
    <div>امضا شرکت</div>
  </div>
</div>
<script>window.print()</script>
{% endblock %}


