<?php
$time_lang = CommonLanguage::getMessage('time', 'ar');
?>

<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:12px;}
    #headerDiv h3{
        margin-bottom: 0px;
    }
    table.first{
        border-spacing: 0px;
    }
    table.first thead tr th{
        border-bottom: 1px solid black;
    }
    table.first,table.secondTbl {color: #000;font-family: aealarabiya; font-size: 12px;}
    th,td{
        font-size:12px;text-align: center;}
    tr th:first-child,tr td:first-child{
        font-size:12px;text-align: left;}
    .second{display:none;}
    .pay-title{
        text-align: center !important;
        border-bottom: 1px solid black;
        border-top: 1px solid black;
    }

    .total_cash td{
        border-top: 1px solid black;
        font-weight: bold;
        font-size:14px !important;
    }
    body{
        margin:0;
    }</style>
<body  onload="window.print()">
    <div id="myDivToPrint">

        <div style="text-align: center;" id="headerDiv">
            <h3><?php echo !empty($template_title) ? $template_title : CommonLanguage::getMessage('end_shift_report') ?></h3>
            <br><span><?php echo CommonLanguage::getMessage('From') . ': ' . $current_date_from; ?></span>
            <br><span><?php echo CommonLanguage::getMessage('To') . ': ' . $current_date_to; ?></span>
            <?php
    foreach ($all_data as $data) {
        if (!empty($data['data'])) {
            $user_name = $data['user_name'];
            $data = $data['data'];
            ?>
            <hr>
            <div class='row'>
                <span style="font-weight: bold;font-size:16px;"><?php echo $user_name ?></span>
            </div>
            <?php if($data['total_count']['total_nb_persons'] !=0 || $data['total_count']['total_tables'] !=0 || $data['total_count']['total_void_invoices'] !=0 || $data['total_count']['total_void_items'] !=0 ) {?>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th  style="width:30%"><?php echo CommonLanguage::getMessage('title') ?></th>
                        <th  style="width:30%"><?php echo CommonLanguage::getMessage('total') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                foreach ($data['total_count'] as $key => $row) {
                    $name = CommonLanguage::getMessage($key);
                    if($row != 0){
                    ?>
                    <tr class="<?php echo $key ?> ">
                        <td style="font-weight: bold"><?php echo $name ?></td>
                        <td ><?php echo CommonFunctions::public_round_number($row) ?></td>
                    </tr>
                    <?php } } ?>
                </tbody>
            </table>
            <hr>
            <?php }if($data['total_amounts']['total_amount_tables'] !=0 || $data['total_amounts']['total_amount_delivery'] !=0 || $data['total_amounts']['total_amount_takeaway'] !=0 || $data['total_amounts']['total_amount_void_invoices'] !=0 || $data['total_amounts']['total_amount_void_items'] !=0 || $data['total_amounts']['average_amount_on_person'] !=0) {?>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th  style="width:30%"><?php echo CommonLanguage::getMessage('title') ?></th>
                        <th  style="width:30%"><?php echo CommonLanguage::getMessage('total') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                foreach ($data['total_amounts'] as $key => $row) {
                    $name = CommonLanguage::getMessage($key);
                    if($row != 0){
                    ?>
                    <tr class="<?php echo $key ?> ">
                        <td style="font-weight: bold"><?php echo $name ?></td>
                        <td ><?php echo CommonFunctions::public_round_number($row) ?></td>
                    </tr>
                    <?php } } ?>
                </tbody>
            </table>
            <hr>
            <?php }?>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th  style="width:30%"><?php echo CommonLanguage::getMessage('title') ?></th>
                        <th  style="width:30%"><?php echo CommonLanguage::getMessage('total_in') . ' ' . $data['currency_symbol'] ?></th>
                        <?php if (smc_session()['local_currency'] != $data['currency_id']) { ?>
                        <th style="width:30%" ><?php echo CommonLanguage::getMessage('total_in') . ' ' . smc_session()['local_currency_symbol'] ?></th>
                        <?php } ?>
                    </tr>
                </thead>
                <tbody>
                    <?php
            foreach ($data['totals'] as $key => $row) {
                $name = CommonLanguage::getMessage($key);
                if ($key == 'deposit') {
                    ?>
                    <tr>
                        <td class="pay-title" colspan=" <?php echo (smc_session()['local_currency'] != $data['currency_id']) ? 3 : 2 ?>" style="font-weight: bold"><?php echo CommonLanguage::getMessage('payments') ?></td>
                    </tr>
                    <?php }  ?>
                    <tr class="<?php echo $key ?> ">
                        <td style="font-weight: bold"><?php echo $name ?></td>
                        <td ><?php echo CommonFunctions::public_round_number($row['amount']) ?></td>
                        <?php if (smc_session()['local_currency'] != $data['currency_id']) { ?>
                        <td ><?php echo CommonFunctions::public_round_number($row['local_amount']) ?></td>
                        <?php } ?>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <?php }
    } ?>
            <hr>
            <?php if (!empty($with_inv)) { ?>
            <h5>Invoices</h5>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th>#</th>
                        <th><?php print CommonLanguage::getMessage('customer_name') ?></th>
                        <th><?php print CommonLanguage::getMessage('Date') ?></th>
                        <th><?php print CommonLanguage::getMessage('total') ?></th>
                        <th><?php print CommonLanguage::getMessage('Type') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
    foreach ($data_inv as $row) {
        //                            print_r($row);
                    ?>
                    <tr>
                        <td><?php echo $row['id'] ?></td>
                        <td><?php echo $row['customer_name'] ?></td>
                        <td ><?php echo $row['date_created']; ?></td>
                        <td ><?php echo CommonFunctions::formatNumber($row['total'] * $row['current_rate']) . ' ' . smc_session()['local_currency_symbol']; ?></td>
                        <td ><?php echo $row['type'] == 'Invoice' ? 'I' : 'R'; ?></td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <hr>
            <?php }if(!empty($category_data)){?>
            <h5>Total Per Category</h5>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th><?php print CommonLanguage::getMessage('Category') ?></th>
                        <th><?php print CommonLanguage::getMessage('total') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($category_data as $row) { ?>
                    <tr>
                        <td><?php echo $row['Cat_Name'] ?></td>
                        <td><?php echo CommonFunctions::formatNumber($row['total_category_amount']) . ' ' . smc_session()['local_currency_symbol']; ?></td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <hr>
            <?php }if(!empty($total_sold_items_data)){?>
            <h5>Total Sold Items</h5>
            <table class="first "  cellspacing='' style="width:100%;">
                <thead>
                    <tr>
                        <th><?php print CommonLanguage::getMessage('Name') ?></th>
                        <th><?php print CommonLanguage::getMessage('Quantity') ?></th>
                        <th><?php print CommonLanguage::getMessage('Price') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
    foreach ($total_sold_items_data['items'] as $row) {
                    ?>
                    <tr>
                        <td ><?php echo $row['Item_Name'] ?></td>
                        <td ><?php echo $row['total_qty'] . ' ' . $row['UOM_Name']; ?></td>
                        <td ><?php echo CommonFunctions::formatNumber($row['total_price']).' '.$row['Currency_Symbol']; ?></td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <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 CommonFunctions::formatNumber($total_sold_items_data['total_quantity']); ?></strong></td>
                    </tr>
                    <tr>
                        <td><strong><?php echo CommonLanguage::getMessage('subtotal') ?></strong> </td>
                        <td><strong><?php echo CommonFunctions::formatNumber($total_sold_items_data['sub_total']) . ' ' . smc_session()['local_currency_symbol']; ?></strong></td>
                    </tr>
                    <tr>
                        <td><strong><?php echo CommonLanguage::getMessage('vat') ?></strong> </td>
                        <td><strong><?php echo CommonFunctions::formatNumber($total_sold_items_data['vat_total']) . ' ' . smc_session()['local_currency_symbol']; ?></strong></td>
                    </tr>
                    <tr>
                        <td><strong><?php echo CommonLanguage::getMessage('total') ?> </strong></td>
                        <td><strong><?php echo CommonFunctions::formatNumber($total_sold_items_data['total']). ' ' . smc_session()['local_currency_symbol']; ?></strong></td>
                    </tr>
                </tbody>
            </table>
            <hr>
            <?php }
            if(!empty($with_inv) || !empty($with_user)){?>
            <table class="secondTbl">
                <thead>
                    <tr class="second">
                        <th ></th>
                        <th ></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><?php echo CommonLanguage::getMessage('total') ?> </td>
                        <td> <?php echo CommonFunctions::formatNumber($totals['total']) . ' ' . smc_session()['local_currency_symbol']; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo CommonLanguage::getMessage('cash') ?> </td>
                        <td> <?php echo CommonFunctions::formatNumber($totals['total_cash']) . ' ' . smc_session()['local_currency_symbol']; ?> </td>
                    </tr>
                    <tr>
                        <td><?php echo CommonLanguage::getMessage('debit') ?></td>
                        <td> <?php echo CommonFunctions::formatNumber($totals['total'] - $totals['total_cash']) . ' ' . smc_session()['local_currency_symbol']; ?> </td>
                    </tr> 
                    <tr>
                        <td><?php echo CommonLanguage::getMessage('discount') ?></td>
                        <td><?php echo CommonFunctions::formatNumber($totals['discount']) . ' ' . smc_session()['local_currency_symbol']; ?>  </td>
                    </tr>
                </tbody>
            </table>
            <?php }  if(empty($with_user) && !empty($total_credit)) {?>
            <table class="secondTbl">
                <thead>
                    <tr class="second">
                        <th ></th>
                        <th ></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><?php echo CommonLanguage::getMessage('credit_card') ?> </td>
                        <td> <?php echo CommonFunctions::formatNumber($total_credit['total_credit']) . ' ' . smc_session()['local_currency_symbol']; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo CommonLanguage::getMessage('cash') ?> </td>
                        <td> <?php echo CommonFunctions::formatNumber($total_credit['total_cash']) . ' ' . smc_session()['local_currency_symbol']; ?> </td>
                    </tr>
                </tbody>
            </table>
            <?php }?>
            <hr>
            <span><?php echo CommonLanguage::getMessage('print_time') . ': ' . date('y-m-d h:i:s a'); ?></span>
        </div>
    </div>
    <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>

