<link href="<?php echo THEME_PATH; ?>css/style.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo THEME_PATH; ?>css/style-responsive.css" rel="stylesheet">
<link href="<?php echo THEME_PATH; ?>/css/bootstrap.rtl.css" rel="stylesheet">
<link href="<?php echo THEME_PATH; ?>/css/style.rtl.css" rel="stylesheet">
<link href="<?php echo THEME_PATH; ?>/plugins/bootstrap-datepicker/css/datepicker3.rtl.css" rel="stylesheet">
<style>
    #headerDiv span {font-size:15px;}
    #headerDiv h3{
        margin-bottom: 0px;
    }
    table.first,table.secondTbl {color: #000;font-family: aealarabiya; font-size: 15px;}
    th,td{
        font-size:15px;text-align: center;}
    .second{display:none;}
    body{
        margin:0;
    }
    .myDivToPrint{
        page-break-after:always;
    }
    .bg-gray{
        background-color: #e5e5e5 !important;
    }
</style>
<body style="" onload="window.print()">
    <?php
    foreach ($data['cat_prod'] as $date => $category) {
    ?>
    <div class="myDivToPrint">
        <div style="text-align: center;" id="headerDiv">
            <span><?php echo CommonLanguage::getMessage('Date') . ': '.$date; ?></span>
            <hr>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th class="text-left" style="width:10%"><?php print CommonLanguage::getMessage('Name') ?></th>
                        <th class="text-left" style="width:10%"><?php print CommonLanguage::getMessage('Quantity') ?></th>
                        <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('total') . ' (' . smc_session()['local_currency_symbol'] . ')' ?></th>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('vat') . ' (' . smc_session()['local_currency_symbol'] . ')'; ?></th>
                        <?php if (smc_session()['default_setting']['activate_second_vat'] == 1) { ?>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('vat2_amount') . ' (' . smc_session()['local_currency_symbol'] . ')'; ?></th>
                        <?php } ?>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('total_amount') . ' (' . smc_session()['local_currency_symbol'] . ')'; ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
        foreach ($category['cat'] as $key=>$category_row) {
                    ?>
                    <?php  if((empty($data_filter['type']) || $data_filter['type'] == 1) && !empty($category_row['total_with_vat'])){?>
                    <tr class="">
                        <td class="bg-gray"><?php echo $data['cat_arr'][$key]['name'];?></td>
                        <td class="bg-gray"></td>
                        <td class="bg-gray"><?php echo CommonFunctions::formatNumber($category_row['total']);?></td>
                        <td class="bg-gray"><?php echo CommonFunctions::formatNumber($category_row['vat1_total']);?></td>
                        <?php if (smc_session()['default_setting']['activate_second_vat'] == 1) { ?>
                        <td class="bg-gray"><?php echo CommonFunctions::formatNumber($category_row['vat2_total']);?></td>
                        <?php }?>
                        <td class="bg-gray"><?php echo CommonFunctions::formatNumber($category_row['total_with_vat']);?></td>
                    </tr>
                    <?php } foreach($category_row['items'] as $product_row){ 
                        if((empty($data_filter['type']) || $data_filter['type'] == 2) && !empty($product_row['total_with_vat'])){?>
                    <tr>
                        <td ><?php echo $product_row['name'] ?></td>
                        <td ><?php echo CommonFunctions::formatNumber($product_row['qty']); ?></td>
                        <td ><?php echo CommonFunctions::formatNumber($product_row['total']); ?></td>
                        <td ><?php echo CommonFunctions::formatNumber($product_row['vat1_total']); ?></td>
                        <?php if (smc_session()['default_setting']['activate_second_vat'] == 1) { ?>
                        <td ><?php echo CommonFunctions::formatNumber($product_row['vat2_total']); ?></td>
                        <?php }?>
                        <td ><?php echo CommonFunctions::formatNumber($product_row['total_with_vat']); ?></td>
                    </tr>
                    <?php } }
        } ?>
                </tbody>
            </table>
            <hr>
        </div>
    </div>
    <?php
    }
    ?>

    <script>
        function PrintElem(elem)
        {
            var mywindow = window.open('', 'PRINT', 'height=600,width=800');
            mywindow.document.write('<html><head><style>#headerDiv span {font-size:12px;} table.first,table.secondTbl {color: #000;font-family: aealarabiya; font-size: 12px;}th,td{' +
                                    'font-size:12px;}' +
                                    '.second{display:none;}</style>');
            mywindow.document.write('</head><body style="direction:rtl;">');
            mywindow.document.write(elem.html());
            mywindow.document.write('</body></html>');
            mywindow.document.close(); // necessary for IE >= 10
            mywindow.focus(); // necessary for IE >= 10*/
            mywindow.print();
            mywindow.close();
            return true;
        }
    </script>
</body>
