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

  <!-- Header — "ОВО НИЈЕ ФИСКАЛНИ РАЧУН" must render at 2× size on
       Копија/Предрачун/Обука per PDF rule P10 (page 7). -->
  <group if="isNonFiscal">
    <text align="center" bold="true" size="2">ОВО НИЈЕ ФИСКАЛНИ РАЧУН</text>
  </group>
  <group if="!isNonFiscal">
    <text align="center" bold="true">= ФИСКАЛНИ РАЧУН =</text>
  </group>

  <!-- 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 block -->
  <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 -->
  <text align="center">Артикли:</text>
  <divider style="="/>

  <table>
    <column width="22%" align="left">Назив</column>
    <column width="26%" align="right">Јед. цена</column>
    <column width="20%" align="right">Кол.</column>
    <column width="32%" align="right">Укупно</column>
    <row each=".items">
      <cell>{{.name}} ({{range $i, $l := .labels}}{{if $i}},{{end}}{{$l}}{{end}})/{{.unit}}</cell>
      <cell>{{fmtAmount .unitPrice}}</cell>
      <cell>{{fmtQty .quantity}}</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>

  <group if="isAdvance">
    <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="="/>

  <group if="isNonFiscal">
    <text align="center" bold="true" size="2">ОВО НИЈЕ ФИСКАЛНИ РАЧУН</text>
    <divider style="="/>
  </group>

  <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 code -->
  <feed lines="1"/>
  <qrcode>{{if .verificationUrl}}{{.verificationUrl}}{{else}}{{.verificationQRCode}}{{end}}</qrcode>

  <!-- Customer signature line (only on Копија Рефундација, per PDF page 25) -->
  <group if="isCopy">
    <group if="isRefund">
      <feed lines="1"/>
      <text>Потпис купца: ________________________</text>
    </group>
  </group>

  <!-- Footer -->
  <group if="isCopy">
    <text align="center" bold="true" size="2">ОВО НИЈЕ ФИСКАЛНИ РАЧУН</text>
  </group>
  <group if="!isCopy">
    <group if="isNonFiscal">
      <text align="center" bold="true" size="2">ОВО НИЈЕ ФИСКАЛНИ РАЧУН</text>
    </group>
    <group if="!isNonFiscal">
      <text align="center" bold="true">= КРАЈ ФИСКАЛНОГ РАЧУНА =</text>
    </group>
  </group>

  <!-- Custom footer lines -->
  <text each=".footerLines">{{.}}</text>

  <feed lines="1"/>
  <text align="center">www.harmonypos.io</text>
  <feed lines="1"/>
</receipt>
