<?xml version="1.0" encoding="UTF-8"?>
<receipt>
  <feed lines="1"/>

  <!-- Header -->
  <text align="center" bold="true">= ФИСКАЛНИ РАЧУН =</text>

  <!-- Business info -->
  <text align="center">{{.tin}}</text>
  <text align="center">{{.businessName}}</text>
  <text align="center">{{.locationName}}</text>
  <text align="center">{{.address}}</text>
  <text if="district" align="center">{{.district}}</text>
  <feed lines="1"/>

  <!-- Cashier / ESIR -->
  <line>
    <text width="50%">Касир:</text>
    <text width="50%">{{.cashier}}</text>
  </line>
  <line if="buyerId">
    <text width="50%">ИД купца:</text>
    <text width="50%">{{.buyerId}}</text>
  </line>
  <line if="buyerCostCenterId">
    <text width="50%">Опционо поље купца:</text>
    <text width="50%">{{.buyerCostCenterId}}</text>
  </line>
  <line>
    <text width="50%">ЕСИР број:</text>
    <text width="50%">{{.esirNumber}}</text>
  </line>
  <line if="esirTime">
    <text width="50%">ЕСИР време:</text>
    <text width="50%">{{.esirTime}}</text>
  </line>
  <line if="referentDocumentNumber">
    <text width="50%">Реф. број:</text>
    <text width="50%">{{.referentDocumentNumber}}</text>
  </line>
  <line if="referentDocumentDT">
    <text width="50%">Реф. време:</text>
    <text width="50%">{{.referentDocumentDT}}</text>
  </line>

  <!-- Transaction label -->
  <divider style="-"/>
  <text align="center" bold="true">{{.transactionLabel}}</text>
  <divider style="-"/>

  <!-- Items (tax-label-grouped; name already carries "N: Аванс (Label)") -->
  <text align="center">Артикли:</text>
  <divider style="="/>

  <table>
    <column width="50%" align="left">Назив</column>
    <column width="50%" align="right">Укупно</column>
    <row each=".items">
      <cell>{{.name}}</cell>
      <cell>{{fmtAmount .totalAmount}}</cell>
    </row>
  </table>

  <!-- Payments -->
  <divider style="-"/>
  <line>
    <text width="50%">За уплату:</text>
    <text width="50%">{{fmtAmount .totalAmount}}</text>
  </line>
  <line each=".payments">
    <text width="50%">Уплаћено – {{.label}}:</text>
    <text width="50%">{{fmtAmount .amount}}</text>
  </line>

  <!-- Advance-paid block (only on non-refund advance) -->
  <group if="!isRefund">
    <line>
      <text width="50%">Плаћено авансом:</text>
      <text width="50%">{{fmtAmount .advancePaidAmount}}</text>
    </line>
    <line>
      <text width="50%">ПДВ на аванс:</text>
      <text width="50%">{{fmtAmount .advancePaidVAT}}</text>
    </line>
  </group>

  <!-- Tax breakdown -->
  <divider style="="/>
  <table>
    <column width="20%" align="left">Ознака</column>
    <column width="25%" align="left">Име</column>
    <column width="25%" align="left">Стопа</column>
    <column width="30%" align="right">Порез</column>
    <row each=".taxItems">
      <cell>{{.label}}</cell>
      <cell>{{.categoryName}}</cell>
      <cell>{{fmtRate .rate}}</cell>
      <cell>{{fmtAmount .amount}}</cell>
    </row>
  </table>
  <divider style="-"/>
  <line>
    <text width="50%">Укупан износ пореза:</text>
    <text width="50%">{{fmtAmount .totalTax}}</text>
  </line>
  <divider style="="/>

  <!-- PFR info -->
  <line>
    <text width="50%">ПФР време:</text>
    <text width="50%">{{.sdcDateTime}}</text>
  </line>
  <line>
    <text width="50%">ПФР број:</text>
    <text width="50%">{{.invoiceNumber}}</text>
  </line>
  <line>
    <text width="50%">Бројач рачуна:</text>
    <text width="50%">{{.invoiceCounter}}{{.invoiceCounterExtension}}</text>
  </line>
  <divider style="="/>

  <!-- QR -->
  <feed lines="1"/>
  <qrcode>{{if .verificationUrl}}{{.verificationUrl}}{{else}}{{.verificationQRCode}}{{end}}</qrcode>

  <!-- Footer -->
  <text align="center" bold="true">= КРАЈ ФИСКАЛНОГ РАЧУНА =</text>
  <feed lines="1"/>
  <text align="center">www.harmonypos.io</text>
  <feed lines="1"/>
</receipt>
