<div class="container-fluid menuselection body">
    <div class="row">
        <input type="hidden" id="currentPage" value="<?php (isset($current_page) && ($current_page != '' || $current_page != null )) ? print $current_page : print'false' ?>">
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 left-item">
            <div style="padding-top: 8px; ">
                <div class="category-listing" id="listCategory">    <?php echo $showcategory ?></div>
                <div class="category-navigation">
                    <div class="main-arrowbg text-center">
                        <ul id="catPagination">
                            <li><div class="prevbtng catPrebtn off-click" id="prevBtn" value="0" onclick="listingCategory(this.value)"><a href="javascript:void(0)"><img src="<?php echo ASSETS_GKPOS_PATH ?>images/prevbtnbg.png" class="img-responsive"/></a></div></li>
                            <li><div class="cat-pages off-click" id="catPages"></div></li>
                            <li><div class="nextbtng catNextBtn off-click" id="nextBtn"value="0" onclick="listingCategory(this.value)"><a href="javascript:void(0)"><img src="<?php echo ASSETS_GKPOS_PATH ?>images/nextbtnbg.png" class="img-responsive" /></a></div></li>
                        </ul>
                    </div>
                </div>
            </div> 
        </div>
        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 bodyitem">
            <div id="listingMenus">
                <?php echo $this->load->view('gkpos/orders/listmenus') ?>
            </div>
            <div class="action-button">
                <div class="main-arrowbg col-md-offset-3 col-md-6 col-md-offset-3 text-center">
                    <ul id="menuPagination">
                        <li><div class="prevbtng menuPrevBtn catPrebtn off-click" id="menuPrevBtn" onclick="menuNavigation('prev')"><a href="javascript:void(0)"><img src="<?php echo ASSETS_GKPOS_PATH ?>images/prevbtnbg.png" width="75" height="46" /></a></div></li>
                        <li><div class="cat-pages off-click" id="MenuSegmentPlusPages"></div></li>
                        <li><div class="nextbtng menuNextBtn catNextBtn off-click" id="menuNextBtn" onclick="menuNavigation('next')"><a href="javascript:void(0)"><img src="<?php echo ASSETS_GKPOS_PATH ?>images/nextbtnbg.png" width="75" height="46" /></a></div></li>
                    </ul>

                </div>
                <div class="clearfix"></div>
                <a href="javascript:void(0)" class="off-click" onclick="addDiscount('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><div class="mainsystembg2 collection-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4" ><?php echo $this->lang->line('gkpos_promotion') ?></div></a>
                <a href="javascript:void(0)" class="off-click" onclick="addQuantity('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><div class="mainsystembg2 delivery-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4" ><?php echo $this->lang->line('gkpos_quantity') ?></div></a>
                <a href="javascript:void(0)" class="off-click" onclick="addServiceCharge('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><div class="mainsystembg2 collection-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4" ><?php echo $this->lang->line('gkpos_add_service_charge') ?></div></a>
                <a href="javascript:void(0)" class="off-click" onclick="addMisc('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><div class="mainsystembg2 delivery-bg-color  img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_add_misc') ?></div></a>
                <a href="javascript:void(0)" class="off-click" onclick="addSpecial('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><div class="mainsystembg2 waiting-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_special_modify') ?></div></a>
                <a href="javascript:void(0)" class="off-click" onclick="showItemDescription()"><div class="mainsystembg2 delivery-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_item_description') ?></div></a>
                <?php if ($this->config->item('gk_guest_bill_from_browser') == 'yes'): ?>
                    <a href="javascript:void(0)" onclick="printGuestBillServer('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>', 3)"><div class="mainsystembg2 waiting-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_print_guest_bill'); ?></div></a>
                <?php else: ?>
                    <a href="javascript:void(0)" onclick="printGuestBill('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>', 3)"><div class="mainsystembg2 waiting-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_print_guest_bill'); ?></div></a>
                <?php endif ?>
                <a href="javascript:void(0)" onclick="orderExit('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><div class="mainsystembg2 collection-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_exit') ?></div></a>
                <a href="javascript:void(0)" class="off-click" onclick="OrderConversion('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>', '<?php echo $currentOrderObj->order_type ?>')"><div class="mainsystembg2 waiting-bg-color img-responsive col-lg-4 col-md-4 col-sm-4 col-xs-4"><?php echo $this->lang->line('gkpos_convert') ?></div></a>
                <div class="col-sm-6 no-padding">
                    <button class="btn btn-block btn-sm btn-success gradient" onclick="addToppings('<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>')"><span class="glyphicon glyphicon-plus"></span>&nbsp;Add Toppings</button>
                </div>
                <div class="col-sm-6 no-padding">
                    <button class="btn btn-block btn-sm btn-primary gradient" onclick="RefreshPage('<?php echo site_url("gkpos/orders/indexajax/" . $this->Orders_Model->get_current_orderid()) ?>')"><span class="glyphicon glyphicon-refresh"></span>&nbsp;<?php echo $this->lang->line('gkpos_refresh') ?></button>
                </div>

            </div>
        </div>
        <div id="cartBody"><?php echo $this->load->view('gkpos/orders/cart') ?></div>
        <input type="hidden" id="popUpQuantity">
        <input type="hidden" id="showItemDescription" value="no">
        <input type="hidden" id="showConversion" value="yes">
    </div>
</div>

<?php echo $this->load->view('gkpos/orders/popups/servicecharge') ?>
<?php echo $this->load->view('gkpos/orders/popups/discount') ?>
<?php echo $this->load->view('gkpos/orders/popups/quantity') ?>
<?php echo $this->load->view('gkpos/orders/popups/special') ?>
<?php echo $this->load->view('gkpos/orders/popups/toppings') ?>
<?php echo $this->load->view('gkpos/orders/popups/addmisc') ?>
<?php echo $this->load->view('gkpos/orders/popups/convert') ?>
<?php echo $this->load->view('gkpos/orders/popups/payandclose') ?>
<?php echo $this->load->view('gkpos/orders/popups/cart_warning') ?>
<script>
    listingCategory(0);
    var order_id = '<?php $this->Orders_Model->get_current_orderid() ? print $this->Orders_Model->get_current_orderid() : $this->uri->segment(4) ?>'
    loadCart(order_id);
    $(document).ready(function () {
        jQuery(".closeServiceChargePopup").click(function () {

            jQuery.colorbox.close();
            return false;
        });
        $('#popUpQuantity').val('');
        manageCategoryListingHeight();
        manageMenuAreaHeight();
    });
    function listingCategory(offset) {
        $.ajax({
            url: base_url + 'gkpos/orders/listcategory/' + offset, type: 'POST', success: function (output) {
                $('#listCategory').html(output);
            }
        });
    }
    function loadCart(order_id, line) {
        $.ajax({
            url: '<?php echo site_url("gkpos/orders/loadcart") ?>',
            data: {
                order_id: order_id
            },
            type: "POST",
            success: function (output) {
                $('#cartBody').html(output);
                if (line) {
                    $('.line-' + line).removeClass('alert-success alert-warning').addClass('alert-success');
                    $('#selectedRow').val(line);
                    $('#orderId').val(order_id);
                }
                $('#popUpQuantity').val('');
                manageCartAreaHeight();
            }
        });
    }
    function selectRow(line, orderId) {

        $('#selectedRow').val('');
        $('#orderId').val('');
        $('.line').removeClass('alert-success');
        if ($('.line-' + line).hasClass('alert-warning')) {
            $('.db-row').addClass('alert-warning');
            $('.line-' + line).removeClass('alert-warning').addClass('alert-success');
        } else {
            $('.line-' + line).addClass('alert-success');
        }
        $('#selectedRow').val(line);
        $('#orderId').val(orderId);
    }
    function updatecart(action, quantity, isCartEmty, isDbcEmpty) {

        var line = $('#selectedRow').val();
        var order_id = $('#orderId').val();
        ALERT_TITLE = "<?php echo $this->lang->line('gkpos_cart_warning') ?>";
        if (!order_id) {
            alert('<?php echo $this->lang->line('gkpos_make_order_sure') ?>');
        } else if (isCartEmty && isDbcEmpty) {
            alert('<?php echo $this->lang->line('gkpos_put_item_on_cart') ?>');
        } else {
            if (!line) {
                alert('<?php echo $this->lang->line('gkpos_select_item_row_to_change_quantity') ?>');
            } else {
                $.ajax({
                    url: '<?php echo site_url("gkpos/orders/updatecart") ?>',
                    data: {
                        line: parseInt(line),
                        action: action,
                        order_id: order_id,
                        quantity: quantity
                    },
                    type: "POST", dataType: "json", success: function (output) {
                        if (output.not_allowed) {
                            alert('<?php echo $this->lang->line('gkpos_not_allowed_to_update') ?>');
                        } else {
                            loadCart(output.order_id, output.line);
                        }

                    }
                });
            }
        }
    }
    function submitCart(order_id, min, isCartEmty, isDbcEmpty, hasNew, hasUpdate) {

        ALERT_TITLE = "<?php echo $this->lang->line('gkpos_cart_warning') ?>";
        if (order_id == null || order_id == '') {
            alert('<?php echo $this->lang->line('gkpos_make_order_sure') ?>');
        } else if (hasNew == 'no' && min == 'minNo') {
            alert('<?php echo $this->lang->line('gkpos_put_item_on_cart') ?>');
        } else if (hasNew == 'no' && min == 'minYes') {
            alert('<?php echo $this->lang->line('gkpos_meet_delivery_condition') ?>');
        } else if (hasNew == 'no' && !min) {
            alert('<?php echo $this->lang->line('gkpos_meet_delivery_condition') ?>');
        } else {
            if (!isDbcEmpty) {
                $.confirm({
                    'title': 'Sending Warning',
                    'message': 'Choose option to send items to kitchen',
                    'buttons': {
                        'Sent All': {
                            'class': 'btn btn-success',
                            'action': function () {
                                $.ajax({
                                    url: "<?php echo site_url('gkpos/orders/save_order') ?>",
                                    data: {
                                        order_id: order_id,
                                        sent: 'all'
                                    },
                                    type: "POST", dataType: "json", success: function (output) {
                                        loadCart(output.order_id, 0);
                                    }
                                });
                            }
                        },
                        'Sent New': {
                            'class': 'btn btn-warning',
                            'action': function () {
                                $.ajax({
                                    url: "<?php echo site_url('gkpos/orders/save_order') ?>",
                                    data: {
                                        order_id: order_id,
                                        sent: 'new'
                                    },
                                    type: "POST", dataType: "json", success: function (output) {
                                        loadCart(output.order_id, 0);
                                    }
                                });
                            }
                        },
                        'close': {
                            'class': 'btn btn-danger',
                            'action': function () {
                            }
                        }
                    }
                });
            } else {
                $.ajax({
                    url: "<?php echo site_url('gkpos/orders/save_order') ?>",
                    data: {
                        order_id: order_id,
                        sent: 'all'
                    },
                    type: "POST", dataType: "json", success: function (output) {
                        loadCart(output.order_id, 0);
                    }
                });
            }
        }
    }

    function printGuestBill(order_id, status) {

        var hasUpdate = $('#hasUpdate').val();
        var hasNew = $('#hasNew').val();
        var isDbcEmpty = $('#isDbcEmpty').val();
        if (hasUpdate === 'yes' || hasNew === 'yes' || isDbcEmpty === 'yes') {
            $.confirm({
                'title': '<?php echo $this->lang->line('gkpos_alert_title_warning') ?>',
                'message': 'Please do necessary update before printing guest bill',
                'buttons': {
                    'Ok': {
                        'class': 'btn btn-danger',
                        'action': function () {
                        }
                    }
                }
            });
        } else {
            $.ajax({
                url: "<?php echo site_url('gkpos/orders/print_guest_bill'); ?>",
                data: {
                    order_id: order_id,
                    status: status
                },
                type: "POST", dataType: "json", success: function (output) {
                    if (output.success) {
                        ALERT_TITLE = "<?php echo $this->lang->line('gkpos_alert_title_success') ?>";
                        alert(output.message);
                    }
                    alert(output.success);
                }
            });
        }
    }
    function printGuestBillServer(order_id, status) {

        var hasUpdate = $('#hasUpdate').val();
        var hasNew = $('#hasNew').val();
        var isDbcEmpty = $('#isDbcEmpty').val();
        if (hasUpdate === 'yes' || hasNew === 'yes' || isDbcEmpty === 'yes') {
            $.confirm({
                'title': '<?php echo $this->lang->line('gkpos_alert_title_warning') ?>',
                'message': 'Please do necessary update before printing guest bill',
                'buttons': {
                    'Ok': {
                        'class': 'btn btn-danger',
                        'action': function () {
                        }
                    }
                }
            });
        } else {
            $.ajax({
                url: "<?php echo site_url('gkpos/orders/update_guest_bill_status'); ?>",
                data: {
                    order_id: order_id,
                    status: status
                },
                type: "POST", dataType: "json", success: function (output) {
                    if (output.success) {
                        ALERT_TITLE = "Success";
                    }
                    alert(output.message);
                }
            });
            $("#guestBill_" + order_id).printThis();
        }

    }
    function sleep(milliseconds) {
        var start = new Date().getTime();
        for (var i = 0; i < 1e7; i++) {
            if ((new Date().getTime() - start) > milliseconds) {
                break;
            }
        }
    }
</script>
<style>
    .item-btn:active{
        background: #ffffff;
    }
</style>