<?php
    $ci =& get_instance();
    $ci->load->helper('az_config');
    $ci->load->helper('az_core');
    $store_name = az_get_config('store_name');
    $store_description = az_get_config('store_description');
    $store_phone = az_get_config('store_phone');
?>
<html>
    <head>
        <title>
            Al Kasir - Cetak Laporan Penjualan
        </title>
        <style type="text/css">
            body {
                font-family: 'Helvetica';
                font-size: 12px;
            }
            .txt-center {
                text-align: center;
            }
            .txt-right {
                text-align: right;
            }
            .store-name {
                font-size: 18px;
                font-weight: bold;
            }
            .txt-report {
                font-weight: bold;
                margin-top:4px;
            }
            .txt-per {
                font-size: 10px;
            }
            .div-table-top {
                margin-top: 10px;
            }
            .table-top {
                width: 100%;
            }
            .td-left {
                width: 50px;
            }
            .td-sep {
                width: 5px;
            }
            .td-right {
                width: 400px;
            }
            .div-table-body {
                margin-top: 10px;
            }
            .table-body {
                width: 100%;
                border-collapse: collapse;
                font-size: 10px;
            }
                .table-body td {
                    padding-left: 3px;
                    padding-right: 3px;
                }
            .table-product {
                width: 100%;
                vertical-align: top;
            }
                .table-product td {
                    vertical-align: top;
                }
            .txt-total {
                margin-top: 10px;
                font-weight: bold;
                font-size: 14px;
            }
            table tbody td {
                vertical-align: top;
                font-size: 10px;
            }

        </style>
    </head>
    <body onload="window.print()">
        <div class='txt-center store-name'>
            <?php echo $store_name;?>
        </div>   
        <div class='txt-center store-desc'>
            <?php echo $store_description;?>
        </div>
        <div class='txt-center txt-report'>
            LAPORAN PENJUALAN <br>
        </div>
        <div class='txt-center txt-per'>
            PER <?php echo $transaction_date_1.' s/d '.$transaction_date_2;?>
        </div>

        </div>
        <div class='div-table-body'>
            <table class='table-body' border='1'>
                <tr>
                    <th style='width:20px'>
                        No
                    </th>
                    <th style='width:60px'>
                        Tanggal
                    </th>
                    <th style='width:100px'>
                        Nota
                    </th>
                    <th style='width:200px'>
                        Nama Barang
                    </th>
                    <th>
                        Kategori
                    </th>
                    <th>
                        Harga
                    </th>
                    <th>
                        Diskon
                    </th>
                    <th>
                        Grand Total
                    </th>
                    <th>
                        Pembeli
                    </th>
                    <th>
                        Kasir
                    </th>
                </tr>
                <?php 
                    $i = 0;
                    $total_all = 0;
                    foreach ($data as $key => $value) {
                        $i++;
                ?>
                <tr>
                    <td class='txt-center'>
                        <?php echo $i;?>
                    </td>
                    <td>
                        <?php echo Date('d-m-Y', strtotime(azarr($value, 'transaction_date')));?>
                    </td>
                    <td>
                        <?php echo azarr($value, 'code');?>
                    </td>
                    <td>
                        <table class='table-product' style="font-size:12px">
                        <?php 
                            foreach (azarr($value, 'product', array()) as $pkey => $pvalue) {
                        ?>
                                <tr>
                                    <td style='width:10px'>
                                        [<?php echo $pvalue['qty'];?>]
                                    </td>
                                    <td>
                                        <?php echo $pvalue['name'];?>
                                    </td>
                                    <td class='txt-right' style='width:50px'>
                                        <?php echo az_thousand_separator($pvalue['final_price']);?>
                                    </td>
                                </tr>
                        <?php        
                            }
                        ?>
                        </table>
                    </td>
                    <td>
                        <table class='table-product' style="font-size:12px">
                        <?php 
                            foreach (azarr($value, 'product', array()) as $pkey => $pvalue) {
                        ?>
                            <tr>
                                <td>
                                    <?php echo $pvalue['category_name'];?>
                                </td>
                            </tr>
                        <?php        
                            }
                        ?>
                        </table>
                    </td>
                    <td class='txt-right'>
                        <?php echo az_thousand_separator(azarr($value, 'total_sell_price'));?>
                    </td>
                    <td class='txt-right'>
                        <?php echo az_thousand_separator(azarr($value, 'total_discount'));?>
                    </td>
                    <td class='txt-right'>
                        <?php echo az_thousand_separator(azarr($value, 'total_final_price'));?>
                    </td>
                    <td>
                        <?php echo azarr($value, 'customer_name');?>
                    </td>
                    <td>
                        <?php echo azarr($value, 'cashier_name');?>
                    </td>
                <?php
                        $total_all += azarr($value, 'total_final_price');
                    }
                ?>
                </tr>
            </table>
        </div>
        <div class='txt-total'>
            TOTAL Rp. <?php echo az_thousand_separator($total_all);?>
        </div>
    </body>
</html>

<script type="text/javascript">
    document.body.onkeydown = function(e){
        location.href = "<?php echo app_url();?>" + "transaction_list";
    };
</script>