<html>
<head>
    <meta charset="utf-8">

    <style>
        .receipt {
            font-family: Arial;
            font-size: 17px;
            width: 90mm;
            font-smooth: never;
            -webkit-font-smoothing: none;
        }

        .print-header {
            margin-bottom: 10px;
            margin-top: 10px;
        }

        .price {
            text-align: right;
        }

        .item-row {
            margin-bottom: 10px;
        }

        .item-row div {
            line-height: initial;
        }

        table {
            width: 100%;
            font-size: 17px;
        }

        table th {
            text-align: right;
            font-weight: normal;
        }

        @media print {
            @page {
                margin: 10mm 9mm 0mm 4mm !important;
                padding: 0;
                width: 80mm;
            }
        }
    </style>

</head>
<body>
{block "full-invoice"}
    {$full_invoice = !$order.total_price_array.value_with_vat->lowerThan(toDecimal(10000))}
{/block}

{function computePrice}
    {if !$discount->isZero()}
        {$price->removeDiscount($discount)|format_price:"ceil=false"}
    {else}
        {$price|format_price:"ceil=false"}
    {/if}
{/function}
<div class="receipt">
    <div class="seller-info">
        <div style="text-align: center;">
            {$dbcfg.shop_title} <br/>
            {$dbcfg.shop_firm_owner} <br/>
            {$dbcfg.shop_address} <br/>
            IČ: {$dbcfg.shop_ico}, DIČ: {$dbcfg.shop_dic}<br/>
           {$id_delivery = $order->getDeliveryType()->id_delivery}
           {if $dbcfg.eet.pos.$id_delivery.address}
              Provozovna: {$dbcfg.eet.pos.$id_delivery.address}
           {/if}
        </div>
    </div>

    <div class="print-header">
       <div style="text-align: center">
         Daňový doklad
       </div>
       <div>
         Nákup č.: <strong>{$order->getInvoiceNo()}</strong><br/>
         {*Pokladna: <strong>{$adminName}</strong>*}
       </div>
       {if $order.date_created != null}
         <div style="float:left">
         Vytvořeno: {$order.date_created|date_format:'d.m.Y H:i:s'}
         </div>
       {/if}
       {if $order.date_handle != null}
         <div style="float:left">
         Vyřízeno: {$order.date_handle|date_format:'d.m.Y H:i:s'}
         </div>
       {/if}
    </div>

    <hr width="100%">

    {$sum = DecimalConstants::zero()}
    {foreach $order.items as $item}
    <div class="item-row">
            {$sum = $sum->add($item.total_price.value_with_vat)}
            <div >
                <div style="float:left; width:70%">
                    <strong>{$item.descr}</strong>
                </div>
                <div class="price">
                    {computePrice price=$item.total_price.value_with_vat discount=$item.discount}
                </div>
            </div>
            <div style="clear:both;" > </div>
            <div style="margin-left:10%">
                <div style="width:20%; float:left; text-align: right; padding-right:10px;">
                    {$item.pieces}
                </div>
                <div>
                    * {computePrice price=$item.piece_price.value_with_vat discount=$item.discount}
                </div>
            </div>
            <div style="clear:both;" > </div>

            {if $full_invoice}
                <div style="margin-left:10%">
                        DPH {$item.vat}%
                        &nbsp;&nbsp;
                        {computePrice price=$item.value_vat->mul(toDecimal($item.pieces)) discount=$item.discount}
                </div>
            {/if}

            {if !$item.discount->isZero()}
                <div style="margin-left:16%">
                    <div style="float: left; width:60%">
                        <div style="float:left; text-align: right; padding-right:10px;">
                            sleva
                        </div>
                        <div style="margin-left:55%">
                              {$item.discount->printFloatValue(0)} %
                        </div>
                    </div>
                    <div class="price">
                        - {$item.total_price.value_with_vat->removeDiscount($item.discount)->sub($item.total_price.value_with_vat)|format_price:"ceil=false"}
                    </div>
                </div>
                <div style="clear:both;" > </div>
            {/if}
            {$itemInfo = $order->getItemInfo($item)}
            {foreach $itemInfo as $key => $print_note}
                {if $key == 'event_data'}
                   <div style="margin-left:16%">
                      <div style="float: left; width:60%">
                         <div style="float:left; text-align: right; padding-right:10px;">
                            sleva
                         </div>
                         <div style="margin-left:55%">
                            {$print_note.totalDiscountPerc} %
                         </div>
                      </div>
                      <div class="price">
                         - {$print_note.totalDiscount}
                      </div>
                   </div>
                   <div style="clear:both;" > </div>
                {/if}
            {/foreach}

            {block 'custom_data_item'}{/block}
        </div>
    {/foreach}
    {block "discounts"}
      {get_order_items_discounts order=$order assign='itemsDiscounts'}
      {if $itemsDiscounts}
         <hr width="100%">
         <table cellspacing="0">
            <tr>
               <td align="left">
                  <strong>Aplikované slevy</strong>
               </td>
               <td align="right">
                  <span class="price"><strong>s DPH</strong></span>
               </td>
            </tr>
            {$totalDiscounts = DecimalConstants::zero()}
            {foreach $itemsDiscounts as $discount}
               <tr>
                  <td align="left">
                      &nbsp; {$discount.name}
                  </td>
                  <td align="right">
                     <span class="price">{$discount.totalPrice|format_price:"ceil=no;decimal=dynamic"}</span>
                  </td>
               </tr>
               {$totalDiscounts = $totalDiscounts->add($discount.totalPrice)}
            {/foreach}
            <tr>
               <td align="left">
                  <strong>Celkem jste ušetřili</strong>
               </td>
               <td align="right">
                  <span class="price"><strong>{$totalDiscounts|format_price:"ceil=no;decimal=dynamic"}</strong></span>
               </td>
            </tr>
         </table>
      {/if}
    {/block}
    <div style="clear:both;" > </div>

            <div>
                <hr width="100%">

                <table cellspacing="0">
                    <tr>
                        <td align="right">
                            Zaokrouhlení
                        </td>
                        <td align="right">
                            <span class="price">{{$order.total_price_array.value_with_vat->sub($sum)}|format_price:"ceil=false"}</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <strong>Celkem</strong>
                        </td>
                        <td align="right">
                            <span class="price"><strong>{$order.total_price_array.value_with_vat|format_price:"ceil=false"}</strong></span>
                        </td>
                    </tr>
                </table>

                <hr width="90%">

                <table cellspacing="0">
                    <tr>
                        <th>&nbsp;</th>
                        <th width="30%" align="right">Základ</th>
                        <th width="30%" align="right">DPH</th>
                    </tr>
                    {foreach $order.vats as $key => $vat}
                        <tr>
                            <td align="left">{$key} % DPH</td>
                            <td align="right">{$vat.tax.value_without_vat|format_price:"ceil=no"}</td>
                            <td align="right">{$vat.tax.value_vat|format_price:"ceil=no"}</td>
                        </tr>
                    {/foreach}
                </table>

               {ifmodule NEW_POS__TERMINAL}
                  {get_terminal_transactions order=$order}
               {/ifmodule}

                <hr width="100%">

                <div class="additional-info">
                    {ifmodule SKEET}
                       {get_skeet_data id_order=$order.id assign='skeetData'}

                       {if $skeetData}
                          {foreach $skeetData as $skeet}
                             <p>
                                <br>
                                UID: {$skeet['uid']}
                                <br>
                                OKP: {$skeet['okp']}
                                <br>
                                Datum platby: {$skeet['date_sent']|format_date:'d.m.Y H:i:m'}
                             </p>
                         {/foreach}
                       {/if}
                   {/ifmodule}
                </div>

                <div style="text-align: center;">Zpracováno pokladním modulem wpjshop</div>
            </div>
</body>
</html>
