{extends 'export/orders_pohoda.tpl'}

{block customParts}
   <inv:invoiceDetail>
      {foreach $order->fetchItems() as $key => $item}
         <inv:invoiceItem>
            <inv:code>{$item.code}</inv:code>
            {if $item.id_product and ($item.code or $item.ean)}
               <inv:stockItem>
                  <typ:stockItem>
                     {if $item.ean}
                        <typ:EAN>{$item.ean}</typ:EAN>
                     {else}
                        <typ:ids>{$item.code}</typ:ids>
                     {/if}
                  </typ:stockItem>
               </inv:stockItem>
            {/if}
            <inv:text>{$item.descr|substr:0:80}</inv:text>
            <inv:note>{$item.descr|substr:0:80}</inv:note>
            <inv:quantity>{$item.pieces}</inv:quantity>
            <inv:payVAT>true</inv:payVAT>
            {if !isset($order->currency) or $order->currency == 'CZK'}
               {switch $item.vat}
               {case 21}
                  <inv:rateVAT>high</inv:rateVAT>
               {/case}
               {case 15}
                  <inv:rateVAT>low</inv:rateVAT>
               {/case}
               {case 12}
                  <inv:rateVAT>low</inv:rateVAT>
               {/case}
               {case 10}
                  <inv:rateVAT>third</inv:rateVAT>
               {/case}
               {case 0}
                  <inv:rateVAT>none</inv:rateVAT>
               {/case}
               {default}
                  <inv:rateVAT>historyHigh</inv:rateVAT>
                  <inv:percentVAT>{$item.vat}</inv:percentVAT>
               {/switch}
               <inv:homeCurrency>
                  {if $order.status_storno == 0}
                     <typ:unitPrice>{$item.piece_price.value_with_vat->printFloatValue(2)}</typ:unitPrice>
                     <typ:price>{$item.total_price.value_with_vat->printFloatValue(2)}</typ:price>
                  {else}
                     <typ:unitPrice>0</typ:unitPrice>
                     <typ:price>0</typ:price>
                  {/if}
               </inv:homeCurrency>
            {else}
               <inv:rateVAT>{pohoda_get_vat_level order=$order item=$item}</inv:rateVAT>
               <inv:percentVAT>{$item.vat}</inv:percentVAT>
               <inv:foreignCurrency>
                  {if $order.status_storno == 0}
                     <typ:unitPrice>{$item.piece_price.value_with_vat->printFloatValue(2)}</typ:unitPrice>
                     <typ:price>{$item.total_price.value_with_vat->printFloatValue(2)}</typ:price>

                  {else}
                     <typ:unitPrice>0</typ:unitPrice>
                     <typ:price>0</typ:price>

                  {/if}
               </inv:foreignCurrency>
               {if $oss}
                  <inv:typeServiceMOSS>
                     <typ:ids>GD</typ:ids>
                  </inv:typeServiceMOSS>
               {/if}
            {/if}
         </inv:invoiceItem>
      {/foreach}
   </inv:invoiceDetail>
{/block}
{block invoiceSummary}
     {if isset($order->currency) and $order->currency != 'CZK'}
         <inv:invoiceSummary>
              {get_contexts currency=true assign='contexts'}
              {if $contexts.currency->getDefaultId() == 'EUR'}
                 {$currencyRate = toDecimal(1/$order->currency_rate)}
              {else}
                 {$currencyRate = toDecimal($order->currency_rate)}
              {/if}
              <inv:foreignCurrency>
                  <typ:currency>
                      <typ:ids>{$order->currency}</typ:ids>
                  </typ:currency>
                  <typ:rate>{$currencyRate->printFloatValue(3)}</typ:rate>
                  <typ:amount>1</typ:amount>
              </inv:foreignCurrency>
         </inv:invoiceSummary>
     {/if}
{/block}
