﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #222222; }
/* Przeglądarka: komórki do góry, jak w PDF (Qt nie tworzy tbody, a atrybut valign psuje eksport ODT) */
tbody > tr > td { vertical-align: top; }
.title { font-size: 20pt; font-weight: bold; color: #1f3a5f; }
.subtitle { font-size: 12pt; color: #1f3a5f; }
.label { font-size: 8pt; font-weight: bold; color: #5a6b80; }
.muted { color: #5a6b80; }
.party { border-top: 2px solid #1f3a5f; padding-top: 4px; }
.items th { background-color: #e6ecf3; color: #1f3a5f; font-size: 8pt; border: 1px solid #b3bfcc; padding: 4px; }
.items td { font-size: 8.5pt; border: 1px solid #c7d0da; padding: 4px; }
.nowrap { white-space: nowrap; }
.sum td { background-color: #e6ecf3; font-weight: bold; }
.total { background-color: #e6ecf3; font-size: 13pt; font-weight: bold; color: #1f3a5f; padding: 6px; }
.sign { border-top: 1px dotted #5a6b80; padding-top: 4px; font-size: 8pt; color: #5a6b80; }
</style>
</head>
<body>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
  <td>
    <span class="title">FAKTURA</span><br/>
    <span class="subtitle">nr <b>{{ invoice.id }}</b></span>
  </td>
  <td align="right">
    <span class="muted">Miejsce wystawienia:</span> {{ translator.city }}<br/>
    <span class="muted">Data wystawienia:</span> {{ invoice.invoice_date }}<br/>
    <span class="muted">Data dostawy:</span> {{ invoice.delivery_date }}<br/>
    <span class="muted">Termin płatności:</span> <b>{{ invoice.payment_date }}</b>
  </td>
</tr>
</table>
<br/>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
  <td width="50%" class="party">
    <span class="label">SPRZEDAWCA</span><br/>
    <b>{{ translator.name }}</b><br/>
    {% if translator.street %}{{ translator.street }}<br/>{% endif %}
    {{ translator.code }} {{ translator.city }}<br/>
    {% if translator.NIP %}NIP: {{ translator.NIP }}<br/>{% endif %}
  </td>
  <td width="50%" class="party">
    <span class="label">NABYWCA</span><br/>
    <b>{{ customer.name }}</b><br/>
    {% if customer.street %}{{ customer.street }}<br/>{% endif %}
    {{ customer.code }} {{ customer.city }}<br/>
    {% if customer.country and customer.country != 'Polska' %}{{ customer.country }}<br/>{% endif %}
    {% if customer.NIP %}NIP: {{ customer.prefix_UE }}{{ customer.NIP }}<br/>{% endif %}
    {% if customer.payer_name %}
    <br/><span class="label">PŁATNIK</span><br/>
    <b>{{ customer.payer_name }}</b><br/>
    {% if customer.payer_street %}{{ customer.payer_street }}<br/>{% endif %}
    {{ customer.payer_code }} {{ customer.payer_city }}<br/>
    {% if customer.payer_country and customer.payer_country != 'Polska' %}{{ customer.payer_country }}<br/>{% endif %}
    {% if customer.payer_NIP %}NIP: {{ customer.payer_prefix_UE }}{{ customer.payer_NIP }}<br/>{% endif %}
    {% endif %}
  </td>
</tr>
</table>
<br/>

<table class="items" width="100%" cellspacing="0" cellpadding="4" style="border-collapse: collapse">
<tr>
  <th width="4%" class="nowrap">Lp.</th>
  <th width="29%">Nazwa towaru lub usługi</th>
  <th width="10%">PKWiU</th>
  <th width="6%" class="nowrap">Ilość</th>
  <th width="5%" class="nowrap">J.m.</th>
  <th width="10%">Cena netto</th>
  <th width="10%">Wartość netto</th>
  <th width="6%" class="nowrap">VAT</th>
  <th width="9%">Kwota VAT</th>
  <th width="11%">Wartość brutto</th>
</tr>
{% set lp = namespace(value=0) %}
{% for translation in translations %}
{% set lp.value = lp.value + 1 %}
{% set rate = translation.VAT|float * 0.01 %}
{% if translation.count_type == 'Godzin' %}
  {% set unit = "godz." %}
{% elif translation.count_type == 'Stron' %}
  {% set unit = "str." %}
{% elif translation.count_type == 'Dokumenty' %}
  {% set unit = "dok." %}
{% else %}
  {% set unit = "blok" %}
{% endif %}
{% set netto = translation.page_price|float * translation.page_count|float %}
<tr>
  <td align="center" class="nowrap">{{ lp.value }}</td>
  <td>{% if translation.translation_type == 'Poświadczenie' %}{{ translation.translation_type }} tłumaczenia{% else %}{{ translation.translation_type }} tłumaczenie{% endif %} {{ translation.translation_comb }}: {{ translation.document_type }}</td>
  <td align="center" class="nowrap">{{ translation.pkwiu }}</td>
  <td align="right" class="nowrap">{{ translation.page_count|number }}</td>
  <td align="center" class="nowrap">{{ unit }}</td>
  <td align="right" class="nowrap">{{ translation.page_price|currency }}</td>
  <td align="right" class="nowrap">{{ netto|currency }}</td>
  <td align="center" class="nowrap">{{ translation.VAT ~ ' %' if translation.VAT else 'zw' }}</td>
  <td align="right" class="nowrap">{{ (netto * rate)|currency }}</td>
  <td align="right" class="nowrap">{{ (netto * (1 + rate))|currency }}</td>
</tr>
{% if translation.copies|float > 0 %}
{% set lp.value = lp.value + 1 %}
{% set copies = translation.copies|float * translation.page_count|float %}
{% set netto = translation.page_copy_price|float * copies %}
<tr>
  <td align="center" class="nowrap">{{ lp.value }}</td>
  <td>Poświadczona kopia tłumaczenia: {{ translation.document_type }}</td>
  <td align="center" class="nowrap">{{ translation.pkwiu }}</td>
  <td align="right" class="nowrap">{{ copies|number }}</td>
  <td align="center" class="nowrap">{{ unit }}</td>
  <td align="right" class="nowrap">{{ translation.page_copy_price|currency }}</td>
  <td align="right" class="nowrap">{{ netto|currency }}</td>
  <td align="center" class="nowrap">{{ translation.VAT ~ ' %' if translation.VAT else 'zw' }}</td>
  <td align="right" class="nowrap">{{ (netto * rate)|currency }}</td>
  <td align="right" class="nowrap">{{ (netto * (1 + rate))|currency }}</td>
</tr>
{% endif %}
{% if translation.delivery_on_bill == 'TAK' %}
{% set lp.value = lp.value + 1 %}
{% set netto = translation.delivery_price|float %}
<tr>
  <td align="center" class="nowrap">{{ lp.value }}</td>
  <td>Przesyłka</td>
  <td></td>
  <td align="right" class="nowrap">1</td>
  <td align="center" class="nowrap">szt.</td>
  <td align="right" class="nowrap">{{ netto|currency }}</td>
  <td align="right" class="nowrap">{{ netto|currency }}</td>
  <td align="center" class="nowrap">{{ translation.VAT ~ ' %' if translation.VAT else 'zw' }}</td>
  <td align="right" class="nowrap">{{ (netto * rate)|currency }}</td>
  <td align="right" class="nowrap">{{ (netto * (1 + rate))|currency }}</td>
</tr>
{% endif %}
{% endfor %}
{% set netto = invoice.summary|sum(attribute='netto') %}
<tr class="sum">
  <td colspan="6" align="right">Razem</td>
  <td align="right" class="nowrap">{{ netto|currency }}</td>
  <td></td>
  <td align="right" class="nowrap">{{ (invoice.final_price - netto)|currency }}</td>
  <td align="right" class="nowrap">{{ invoice.final_price|currency }}</td>
</tr>
{% for summary in invoice.summary %}
<tr>
  <td colspan="6" align="right" class="muted">w tym</td>
  <td align="right" class="nowrap">{{ summary.netto|currency }}</td>
  <td align="center" class="nowrap">{{ summary.rate }}</td>
  <td align="right" class="nowrap">{{ (summary.brutto - summary.netto)|currency }}</td>
  <td align="right" class="nowrap">{{ summary.brutto|currency }}</td>
</tr>
{% endfor %}
</table>
<br/>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
  <td class="total">Do zapłaty: {{ invoice.final_price|currency }} {{ invoice.currency }}</td>
</tr>
</table>
<p>
<span class="muted">Słownie:</span> {{ invoice.final_price_words }}<br/>
<span class="muted">Forma płatności:</span> {{ invoice.payment_type }}<br/>
{% if invoice.payment_type == 'przelew' %}
<span class="muted">Numer konta:</span> <b>{{ translator.account_number1 }}</b>{% if translator.bank_name %} ({{ translator.bank_name }}){% endif %}<br/>
{% endif %}
</p>
{% if invoice.summary.0.rate == 'zw' %}
<p><span class="muted">Podstawa zwolnienia z VAT:</span> {{ translator.vat_exemption_basis }}</p>
{% endif %}
<br/><br/>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
  <td width="40%" align="center"></td>
  <td width="20%"></td>
  <td width="40%" align="center">{{ translator.name }}</td>
</tr>
<tr>
  <td align="center" class="sign">Faktura bez podpisu odbiorcy</td>
  <td></td>
  <td align="center" class="sign">Wystawca faktury</td>
</tr>
</table>
</body>
</html>
