<div style="display: none;">
    <div id="orderConvertContent">
        <div class="popup-header toolbar-header">
            <div class="popup-title">Convert Order Type</div>
            <div class="popup-close-btn" onclick="zamanEposPopupcloser()"><span class="icon icon-cancel"></span></div>
        </div>
        <input type="hidden" id="covertedOrderId">
        <input type="hidden" id="covertedOrderType">
        <div class="popup-content">
            <div class="order-new-order">
                <?php if ((in_array('table', $this->session->userdata('userApps')) && array_key_exists('table', $services)) || $this->session->userdata('group') == '2'): ?>   
                    <div class="tab-group keypad epos-convert-type" id="tableOrderConvert">
                        <div class="tab-item zaman-epos-nav quantity-digit new-order-type table-bg" onclick="eposConvertOrder('table')">
                            <img class="table-icon" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAA1JREFUeNpjYBgF1AQAAVAAATS4OtkAAAAASUVORK5CYII=">
                            <span><?php echo $this->lang->line('table') ?></span>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ((in_array('waiting', $this->session->userdata('userApps')) && array_key_exists('waiting', $services)) || $this->session->userdata('group') == '2'): ?>   
                    <div class="tab-group keypad epos-convert-type" id="waitingOrderConvert">
                        <div class="tab-item zaman-epos-nav quantity-digit new-order-type waiting-bg" onclick="eposConvertOrder('waiting')">
                            <img class="waiting-icon" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAA1JREFUeNpjYBgF1AQAAVAAATS4OtkAAAAASUVORK5CYII=">
                            <span><?php echo $this->lang->line('waiting') ?></span>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ((in_array('bar', $this->session->userdata('userApps')) && array_key_exists('bar', $services)) || $this->session->userdata('group') == '2'): ?>   
                    <div class="tab-group keypad epos-convert-type" id="barOrderConvert">
                        <div class="tab-item zaman-epos-nav quantity-digit new-order-type bar-bg" onclick="eposConvertOrder('bar')">
                            <img class="bar-icon" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAvAQMAAABJ6QHvAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAA1JREFUeNpjYBgFVAEAAUkAAf+U2WcAAAAASUVORK5CYII=">
                            <span><?php echo $this->lang->line('bar') ?></span>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ((in_array('collection', $this->session->userdata('userApps')) && array_key_exists('collection', $services)) || $this->session->userdata('group') == '2'): ?>   
                    <div class="tab-group keypad epos-convert-type" id="collectionOrderConvert">
                        <div class="tab-item zaman-epos-nav quantity-digit new-order-type collection-bg" onclick="eposConvertOrder('collection')">
                            <img class="collection-icon" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAA1JREFUeNpjYBgF1AQAAVAAATS4OtkAAAAASUVORK5CYII=">
                            <span><?php echo $this->lang->line('collection') ?></span>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ((in_array('booking', $this->session->userdata('userApps')) && array_key_exists('booking', $services)) || $this->session->userdata('group') == '2'): ?>   
                    <div class="tab-group keypad epos-convert-type" id="deliveryOrderConvert">
                        <div class="tab-item zaman-epos-nav quantity-digit new-order-type delivery-bg" onclick="eposConvertOrder('delivery')">
                            <img class="delivery-icon" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAA1JREFUeNpjYBgF1AQAAVAAATS4OtkAAAAASUVORK5CYII=">
                            <span><?php echo $this->lang->line('delivery') ?></span>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function zamanOrderCovertControllerPopup(orderId, type) {
        zamanEposDb.epos_order.get({orderId: Number(orderId)}).then(function (anOrder) {
            if (typeof (anOrder) !== 'undefined') {
                if (Number(anOrder.isPaid) === 3) {
                    orderPaymentPreProcessor(anOrder);
                } else {
                    $.colorbox({
                        inline: true,
                        scrolling: false,
                        href: "#orderConvertContent",
                        width: '290px',
                        maxWidth: "100%",
                        height: 'auto',
                        open: true,
                        closeButton: false,
                        transition: 'none',
                        overlayClose: false,
                        className: 'transparent-overlay',
                        onOpen: function () {
                            playBeepSound();
                            $('#colorbox').colorbox.resize();
                        },
                        onLoad: function () {
                            $('.epos-convert-type').show();
                            $('#' + type + 'OrderConvert').hide();
                        },
                        onComplete: function () {
                            $('.epos-convert-type').show();
                            $('#' + type + 'OrderConvert').hide();
                            $('#covertedOrderId').val(orderId);
                            $('#covertedOrderType').val(type);
                        },
                        onCleanup: function () {
                        },
                        onClosed: function () {
                            $('#covertedOrderId').val('');
                            $('#covertedOrderType').val('');
                            $('.epos-convert-type').show();
                        }
                    });
                }
            } else {
                warning('<?php echo $this->lang->line('warning') ?>', '<?php echo $this->lang->line('load_order_in_cart') ?>', '<?php echo $this->lang->line('ok') ?>');
            }
        });
    }
    function eposConvertOrder(to) {
        var orderId = $('#covertedOrderId').val();
        var convertedOrderType = $('#covertedOrderType').val();
        zamanEposDb.epos_order.get({orderId: Number(orderId)}).then(function (theOrder) {
            if ((convertedOrderType === 'table' || convertedOrderType === 'bar') && (to === 'bar' || to === 'table')) {
                if (to === 'bar') {
                    zamanPlaceBarOrder(theOrder.orderId, '', '', 'yes', '');
                } else {
                    zamanPlaceTableOrder(theOrder.orderId, '', '', 'yes', '');
                }
            } else {
                if ((convertedOrderType === 'waiting' || convertedOrderType === 'collection' || convertedOrderType === 'delivery') && (to === 'waiting' || to === 'collection' || to === 'delivery')) {
                    if (to === 'waiting') {
                        zamanPlaceWaitingOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, 'yes', '');
                    }
                    if (to === 'collection') {
                        zamanPlaceCollectionOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, '', 'yes', '');
                    }
                    if (to === 'delivery') {
                        zamanPlaceDeliveryOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, '', '', '', '', '', '', '', '', '', '', '', 'yes', '');
                    }
                } else {
                    if (to === 'table' || to === 'bar') {
                        if (to === 'bar') {
                            zamanPlaceBarOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, 'yes', 'in');
                        } else {
                            zamanPlaceTableOrder(theOrder.orderId, '', '', 'yes', 'in');
                        }
                    } else {
                        if (to === 'waiting') {
                            if (theOrder.orderInfo.name) {
                                zamanPlaceWaitingOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, 'yes', 'out');
                            } else {
                                zamanPlaceWaitingOrder(theOrder.orderId, '', '', 'yes', 'out');
                            }
                        }
                        if (to === 'collection') {
                            if (theOrder.orderInfo.name) {
                                zamanPlaceCollectionOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, '', 'yes', 'out');
                            } else {
                                zamanPlaceCollectionOrder(theOrder.orderId, '', '', '', 'yes', 'out');
                            }
                        }
                        if (to === 'delivery') {
                            if (theOrder.orderInfo.name) {
                                zamanPlaceDeliveryOrder(theOrder.orderId, theOrder.orderInfo.name, theOrder.orderInfo.phone, '', '', '', '', '', '', '', '', '', '', '', 'yes', 'out');
                            } else {
                                zamanPlaceDeliveryOrder(theOrder.orderId, '', '', '', '', '', '', '', '', '', '', '', '', '', 'yes', 'out');
                            }

                        }
                    }
                }
            }
        });
    }
</script>