{% extends "base.html" %} {% from "_macros.html" import state_badge, pay_badge, attachments_card with context %} {% set list_title = {'out_invoice': 'Customer Invoices', 'out_refund': 'Credit Notes', 'in_invoice': 'Vendor Bills', 'in_refund': 'Vendor Refunds'}[kind] %} {% block title %}{{ inv.number or t('Draft') }}{% endblock %} {% block content %} {% set cur = inv.currency or branch.currency %}
{{ t(list_title) }} · {{ t(doc_title[0]) }}

{{ inv.number or t('Draft') }} {{ state_badge(inv.state) }} {{ pay_badge(pay_state) }}

{% if inv.state != 'draft' or inv.number %}{{ t('Print') }} PDF{% endif %} {% if can_write and inv.state == 'posted' %}{{ t('Email') }}{% endif %} {{ t('Statement') }} {% if can_write %}{{ t('Duplicate') }}{% endif %} {% if inv.move_id %}{{ t('Journal Entry') }}{% endif %} {% if order %}{{ order.number }}{% endif %} {% if origin %}{{ t('Original') }}: {{ origin.number }}{% endif %} {% for r in refunds %}{{ r.number or t('Draft') }}{% endfor %} {% for r in debit_notes %}{{ t('Debit Note') }} {{ r.number or t('Draft') }}{% endfor %} {% if proforma %}{{ t('Proforma') }} {{ proforma.number }}{% endif %} {% if converted %}{{ t('Tax invoice') }} {{ converted.number or t('Draft') }}{% endif %} {% for pk in pickings %}{{ pk.number }}{% endfor %} {% if can_write and inv.state == 'posted' and has('prepaid') %} {{ t('Spread over months') }}{% endif %} {% if can_write and inv.state == 'posted' and kind == 'in_invoice' and has('assets') %} {{ t('Register Asset') }}{% endif %} {% if can_write and needs_picking and has('inventory') %}
{% endif %} {% if can_write %} {% if inv.invoice_type == 'proforma' and inv.state in ('draft', 'proforma') %} {% if inv.state == 'draft' %}{{ t('Edit') }}
{% endif %}
{% if inv.state == 'draft' and not inv.number %}
{% else %}
{% endif %} {% elif inv.state == 'draft' %} {{ t('Edit') }}
{% if not inv.number %}
{% else %}
{% endif %} {% elif inv.state == 'posted' %} {% if residual > 0 %}{{ t('Register Payment') }} {% if not inv.currency and kind in ('out_invoice', 'in_invoice') %}{{ t('Pay by cheque') }}{% endif %}{% endif %} {% if kind in ('out_invoice', 'in_invoice') %}{{ t('Make recurring') }}{% endif %} {% if kind == 'out_invoice' and inv.invoice_type not in ('advance', 'proforma') %}
{% endif %} {% if kind in ('out_invoice', 'in_invoice') %}
{% endif %} {% if not einv or einv.status == 'rejected' %}
{% endif %} {% elif inv.state == 'cancelled' %}
{% endif %} {% endif %}
{% if inv.kind == 'out_invoice' and inv.state == 'draft' %}{% set ci = credit_issues(inv.partner_id, (inv.amount_total * inv.rate)|int, branch.currency) %} {% if ci %}
{{ icon('shield') }}{{ t('Credit control') }}: {{ ci|join('; ') }}.{% if company.credit_policy == 'block' or 'hold' in ci|join %} {{ t('This invoice cannot be posted until that is resolved.') }}{% endif %}
{% endif %}{% endif %} {% if einv %}{% set es = {'cleared': ('ok', 'Cleared by ZATCA'), 'reported': ('ok', 'Reported to ZATCA'), 'pending': ('warn', 'Waiting to be sent to ZATCA'), 'rejected': ('bad', 'Rejected by ZATCA')}[einv.status] %}
{{ einv_qr|safe }}
{{ t(es[1]) }} {{ t('ZATCA e-invoice') }} · {{ t('Standard (B2B)') if einv.subtype == 'standard' else t('Simplified (B2C)') }}
UUID
{{ einv.uuid }}
{{ t('Invoice counter') }}
{{ einv.icv }}
{{ t('Signed at') }}
{{ einv.issued_at|replace('T', ' ') }}
{% if einv.sent_at %}
{{ t('Sent at') }}
{{ einv.sent_at|replace('T', ' ') }}
{% endif %}
{{ t('Hash') }}
{{ einv.hash }}
{% if einv_msgs.errors %}
{{ icon('alert') }}{{ einv_msgs.errors|join('; ') }}
{% endif %} {% if einv_msgs.warnings %}
{{ einv_msgs.warnings|length }} {{ t('warning(s) from ZATCA') }}
    {% for w in einv_msgs.warnings %}
  • {{ w }}
  • {% endfor %}
{% endif %}
{{ t('Download XML') }} {% if einv.status == 'pending' and can_write %}
{% endif %} {% if einv.status == 'rejected' %}{{ t('Correct the problem (Reset to Draft, edit, Post) to issue it again.') }}{% endif %}
{% endif %}
{{ t('Customer') if info.partner_type == 'customer' else t('Vendor') }}
{{ nm({'name_en': inv.pname_en, 'name_ar': inv.pname_ar}) }}{% if inv.pvat %}
{{ t('VAT') }}: {{ inv.pvat }}{% endif %}
{{ t('Branch') }}
{{ branch.code }} — {{ nm(branch) }}
{% if inv.currency %}
{{ t('Currency') }}
{{ inv.currency }} · 1 {{ inv.currency }} = {{ inv.rate }} {{ branch.currency }}
{% endif %}
{{ t('Journal') }}
{{ inv.jcode }}
{{ t('Date') }}
{{ inv.date }}
{{ t('Due Date') }}
{{ inv.due_date or '—' }}
{{ t('Vendor credit note no.' if kind == 'in_refund' else 'Vendor invoice no.' if kind == 'in_invoice' else 'Customer reference') }}
{{ inv.ref or '—' }}
{% if kind == 'out_invoice' and inv.invoice_type != 'standard' %}
{{ t('Invoice type') }}
{{ t(doc_title[0]) }}
{% endif %} {% if inv.invoice_type == 'debit_note' %}
{{ t('Original invoice') }}
{% if origin %}{{ origin.number }}{% else %}—{% endif %}
{{ t('Reason') }}
{{ inv.note_reason or '—' }}
{% endif %} {% if has('projects') and inv.project_id %}
{{ t('Project') }}
{{ inv.pj_code }} — {{ nm({'name_en': inv.pj_en, 'name_ar': inv.pj_ar}) }}{% if inv.project_billing %}
{{ t('Progress invoice') if inv.project_billing == 'progress' else t('Retention release') }}{% endif %}
{% endif %}
{% for l in lines %} {% endfor %}
{{ t('Description') }}{{ t('Account') }}{{ t('Qty') }}{{ t('Unit Price') }} {{ t('Tax') }}{{ t('Subtotal') }}
{% if l.product_id %}{{ l.pcode or '' }} {{ nm({'name_en': l.prname_en, 'name_ar': l.prname_ar}) }}
{% endif %}{{ l.description or '' }}
{{ l.code }} {{ nm({'name_en': l.aname_en, 'name_ar': l.aname_ar}) }}{% if l.cc_code %} {{ l.cc_code }}{% endif %} {{ '%g' % l.quantity }}{{ l.price_unit|money(cur) }} {{ nm({'name_en': l.tname_en, 'name_ar': l.tname_ar}) if l.tname_en else '' }}{{ l.subtotal|money(cur) }}
{% for p in payments if p.state == 'posted' %} {% endfor %} {% if inv.state == 'posted' %}{% endif %} {% if inv.currency %}{% endif %}
{{ t('Untaxed Amount') }}{{ inv.amount_untaxed|money(cur) }}
{{ t('VAT') }}{{ inv.amount_tax|money(cur) }}
{{ t('Total') }} ({{ cur }}){{ inv.amount_total|money(cur) }}
{{ t('Paid on') }} {{ p.date }}− {{ p.amount|money(cur) }}
{{ t('Amount Due') }}{{ residual|money(cur) }}
{{ t('Booked in') }} {{ branch.currency }}{{ (inv.amount_total_base or (inv.amount_total * inv.rate)|round|int)|money(branch.currency) }}
{% if inv.notes %}

{{ t('Notes') }}

{{ inv.notes }}
{% endif %} {% if inv.terms %}

{{ t('Terms & Conditions') }}

{{ inv.terms }}
{% endif %} {% if inv.invoice_type == 'advance' and inv.state == 'posted' %}

{{ t('Advance deducted on') }}

{% for u in used_by %}{{ u.number or t('Draft') }} ({{ t(u.state|capitalize) }}) {% else %}{{ t('Not deducted yet.') }}{% endfor %}
{% endif %} {% if kind == 'out_invoice' and inv.state == 'draft' and (advances or deductions) and can_write %}

{{ t('Advances to deduct') }}

{{ t('Deducting an advance reverses its VAT on this invoice: Dr Advances from Customers, the customer pays the balance.') }}

{% for dd in deductions %}
{{ dd.description }}: {{ (-dd.subtotal)|money(cur) }} + {{ t('VAT') }} {{ (-dd.tax_amount)|money(cur) }}
{% endfor %} {% if advances %}
{% endif %}
{% endif %} {{ attachments_card('invoice', inv.id) }} {% endblock %}