<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;
    }
</style>
<body style="" onload="window.print()">
    <?php
    if (empty($data_filter['is_day'])) {
        $data = array(0 => $data);
        $totals = array(0 => $totals);
    }
	else{
		//here if all specific date is with same currency or unit then put it at header not at each row
		$data_uniq = $data['data_uniq'];
		unset($data['data_uniq']);
	}
	foreach ($data as $date => $data_date) {
        ?>
        <div class="myDivToPrint">
            <div style="text-align: center;" id="headerDiv">

                <h3><?php echo smc_session()['org_detail']['Organization_Name']; ?></h3>
                <span><?php echo smc_session()['org_detail']['Org_Address']; ?></span><br/>
                <span><?php echo smc_session()['org_detail']['Organization_Phone']; ?></span>
                <br/><span>M.O.F #: <?php echo smc_session()['org_detail']['Organization_Commercial_Registry'] ?></span>


                <br/>
                <span><?php echo CommonLanguage::getMessage('range_date') . ': ' . ($date === 0 ? (!empty($data_filter['fromToDateinvoice']) ? $data_filter['fromToDateinvoice'] : $data_filter['fromToDate']) :  $date); ?></span>
                <?php if (!empty($data_filter['users'])) { ?>
                    <br><span><?php echo CommonLanguage::getMessage('users') . ': ' . $data_filter['users']; ?></span>
                <?php } if ($data_filter['return'] == 1) { ?>
                    <br><span><?php echo CommonLanguage::getMessage('return'); ?></span>
                <?php } if (!empty($data_filter['customer_name'])) { ?>
                    <br><span><?php echo CommonLanguage::getMessage('customer_name') . ': ' . $data_filter['customer_name']; ?></span>
    <?php } ?>

                <hr>
                <table class="first "  cellspacing='' style="width:100%;">
                    <thead>
                        <tr>
                            <th><?php print CommonLanguage::getMessage('Name') ?></th>
                            <th style='text-align:left;'><?php print CommonLanguage::getMessage('Quantity') . (empty($data_uniq[$date]['uom']) ? '' : " ({$data_uniq[$date]['uom']})"); ?></th>
                            <th style='text-align:left;'><?php print CommonLanguage::getMessage('Price') . (empty($data_uniq[$date]['curr']) ? '' : " ({$data_uniq[$date]['curr']})"); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($data_date as $row) {
                            ?>
                            <tr>
                                <td ><?php echo $row['Item_Name'] ?></td>
                                <td style='text-align:left;'><?php echo CommonFunctions::formatNumber($row['total_qty']) . (empty($data_uniq[$date]['uom']) ? " {$row['UOM_Name']}" : ''); ?></td>
                                <td style='text-align:left;'><?php echo CommonFunctions::formatNumber($row['total_price']) . (empty($data_uniq[$date]['curr']) ? " {$row['Currency_Symbol']}" : ''); ?></td>
                            </tr>
    <?php } ?>
                    </tbody>
                </table>
                <hr>
                <table class="secondTbl">
                    <thead>
                        <tr class="second">
                            <th ></th>
                            <th ></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong><?php echo CommonLanguage::getMessage('Quantity') ?></strong> </td>
                            <td><strong><?php echo $totals[$date]['total_quantity']; ?></strong></td>
                        </tr>
                        <tr>
                            <td><strong><?php echo CommonLanguage::getMessage('subtotal') ?></strong> </td>
                            <td><strong><?php echo $totals[$date]['sub_total'] . ' ' . smc_session()['local_currency_symbol']; ?></strong></td>
                        </tr>
                        <tr>
                            <td><strong><?php echo CommonLanguage::getMessage('vat') ?></strong> </td>
                            <td><strong><?php echo $totals[$date]['vat_total'] . ' ' . smc_session()['local_currency_symbol']; ?></strong></td>
                        </tr>
                        <tr>
                            <td><strong><?php echo CommonLanguage::getMessage('total') ?> </strong></td>
                            <td><strong><?php echo $totals[$date]['total'] . ' ' . smc_session()['local_currency_symbol']; ?></strong></td>
                        </tr>
                    </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>
