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

    <script type="text/javascript" src="./static/js/qwebchannel.js?v4"></script>
    <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: 5px;
        }

        .write-field {
            margin: 5px 0;
            border-bottom: 2px dashed black;
            height: 50px;
        }

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

        table {
            font-size: 17px;
            width: 80mm;
        }

        table td {
            border: 1px solid black;
        }

        table th {
            text-align: left;
            font-weight: normal;
            border: 2px solid black;
        }

        @media print {
            @page {
                margin: 10mm 9mm 0mm 4mm !important;
                padding: 0;
                font-family: Arial;
                font-size: 17px;
                width: 90mm;
                font-smooth: never;
                -webkit-font-smoothing: none;

            }

            table {
                font-size: 20px;
            }
        }
    </style>
</head>
<body>
{block "full-invoice"}
    {$full_invoice = !$order.total_price_array.value_with_vat->lowerThan(toDecimal(10000))}
{/block}
{block content}
<div class="receipt">
    <div class="seller-info">
        <div style="text-align: center;">
            {$dbcfg.shop_title} <br/>
            {$dbcfg.shop_address} <br/>
            IČ: {$dbcfg.shop_ico}, DIČ: {$dbcfg.shop_dic}<br/>

        </div>
    </div>

    <div class="print-header">
        <div style="text-align: center">
            <strong>Výdejka</strong>
        </div>
        <div>
            Objednávka: <strong>{$order->order_no}</strong>
        </div>
        <div>
            <div class="row">
                <div class="col-md-3 control-label">
                    <label>Odběratel:</label>
                </div>
            </div>
            <div style="font-size:14px;">
               {if !$order.invoice_ico or !$order.invoice_firm}
                <div class="row">
                    <div class="col-md-12">
                        {$order.invoice_name} {$order.invoice_surname}
                    </div>
                </div>
               {/if}
                <div class="row">
                    <div class="col-md-12">
                        {$order.invoice_firm}
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div>
                            {$order.delivery_street}, {$order.delivery_zip} {$order.delivery_city}
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div>
                            IČO: {$order.invoice_ico} &nbsp;
                            DIČ: {$order.invoice_dic}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <table>
        <tr>
            <th width="80%">Zboží</th>
            <th width="20%">Ks</th>
        </tr>
        {get_today_selled_items items=$order.items assign=items}
        {foreach $items as $item}
            <tr>
                <td>
                    {$item.descr}
                </td>
                <td align="center">
                    {$item.pieces}
                </td>
            </tr>
        {/foreach}
    </table>

    <div>
        <div style="text-align: left">
            <strong>Datum</strong>: {$smarty.now|date_format:"d.m.Y H:i:s"}
        </div>

        <div class="row">
            <div class="col-md-10 control-label write-field">
                <label>Převzal</label>
            </div>
        </div>

        <div class="row">
            <div class="col-md-10 control-label write-field">
                <label>Vydal</label>
            </div>
        </div>
    </div>
    <div>
        <hr width="90%">

        <div style="text-align: center; font-size:13px">Zpracováno systémem wpjshop</div>
    </div>
</div>
{/block}

    <script type='text/javascript'>
        /*
         WEBCHANNELS
         */
        {if $smarty.get.now}
            window.onload = function () {
               let triedsReconnect = false;

               function connectSocket(url){
                  let socket = new WebSocket(url);

                  socket.onclose = function () {
                     console.error("web channel closed");
                  };
                  socket.onerror = function (error) {
                     if (!triedsReconnect) {
                        socket = null;
                        triedsReconnect = true;
                        connectSocket("ws://localhost:12345");
                        return;
                     }
                     console.error("web channel error: " + error);
                  };
                  socket.onopen = function () {
                     new QWebChannel(socket, function (channel) {
                        // make dialog object accessible globally
                        window.codereader = channel.objects.codereader;
                        codereader.printOrderRequest("{$cfg.Addr.full}admin/launch.php?s=printCenter.php&type=order&set=POS&ID={$order.id}&template=POSVydejka");
                        window.close();
                     });
                  }
               }

               connectSocket("ws://localhost:13458");
            };
        //END SETUP
        {/if}

        setTimeout(function () {
           PrintInvoice();
        }, 600);

        function PrintInvoice() {
           if (typeof codereader === 'undefined') {
              window.print();
              var isChrome = !!window.chrome;
              if (!isChrome)
                 window.close();

           }
        }
    </script>
</body>
</html>
