<?php $existing_type = $currentOrderObj->order_type ?>
<a class='orderConversion' href="#orderConversion" style="display:none"></a>
<div style="display:none">
    <div id="orderConversion" class="popupouter">
        <div class="popup-header row">
            <div id="orderConversionHeader" class="warningPopupHeader col-lg-10 col-md-10 col-sm-10 col-xs-10 pull-left text-uppercase"><?php echo $existing_type . "&nbsp;" . $this->lang->line('gkpos_convert_to') ?></div>
            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pull-left closeServiceChargePopup text-center times">&times;</div>
        </div>
        <div class="popup-body row">
            <div id="orderConversionContent" class="warningPopupContent col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <?php echo form_open('gkpos/orders/convert', array('id' => 'conversion_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?>

                <div class="form-group">	
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="stylish">

                            <span>
                                <input onclick="$(this).closest('div').find('select').slideToggle(110)" class="form-control" type="text" name="new_order_type" readonly="1" id="new_order_type"  placeholder="<?php echo $this->lang->line('gkpos_order_type') ?>"  style="width: 320px; margin: 0 auto; " />
                                <br>
                                <select size=15 onclick="$(this).hide().closest('div').find('input').val($(this).find('option:selected').val());" style="width: 320px; min-height:180px; margin: 0 auto; left:24px; margin-top: -20px">
                                    <?php if ($existing_type != 'collection' && $this->config->item('gk_order_collection') == 'yes'): ?>
                                        <option value="collection" class="btn btn-default btn-lg btn-block text-lowercase"><?php echo $this->lang->line('gkpos_collection') ?></option>
                                    <?php endif; ?>
                                    <?php if ($existing_type != 'delivery' && $this->config->item('gk_order_delivery') == 'yes'): ?>   
                                        <option value="delivery" class="btn btn-default btn-lg btn-block text-lowercase"><?php echo $this->lang->line('gkpos_delivery') ?></option>
                                    <?php endif; ?>
                                    <?php if ($existing_type != 'waiting' && $this->config->item('gk_order_waiting') == 'yes'): ?>   
                                        <option value="waiting" class="btn btn-default btn-lg btn-block text-lowercase"><?php echo $this->lang->line('gkpos_waiting') ?></option>
                                    <?php endif; ?>
                                    <?php if ($existing_type != 'table' && $this->config->item('gk_order_table') == 'yes'): ?>  
                                        <option value="table" class="btn btn-default btn-lg btn-block text-lowercase"><?php echo $this->lang->line('gkpos_table') ?></option>
                                    <?php endif; ?>
                                </select>
                            </span>
                        </div>
                    </div>
                </div>
                <ul id="conversion_form_error_message_box" class="error_message_box"></ul>
                <div class="form-group form-group-md">	
                    <div class="col-md-12">
                        <input type="hidden" name="existing_order_type" id="existing_order_type" class="form-control" readonly="true">
                        <input type="hidden" id="ConvertingOrderId" name="order_id" value="<?php isset($order_id) ? print $order_id : print $this->Orders_Model->get_current_orderid() ?>">
                        <input class="form-submit-button mainsystembg2 waiting-bg img-responsive delivery-info-submit-btn" type="submit" name="submit_form" value="<?php echo $this->lang->line('gkpos_numpad_key_enter') ?>" onclick="convert()" style="width: 320px; margin: 0 auto">
                    </div>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div>
    </div>
</div>
<script>
    function OrderConversion(order_id, order_type) {
        
        var isConversion = $('#showConversion').val();
        if (isConversion == 'yes') {
            if (!order_id && !order_type) {
                jQuery('#cartWarningHeader').text("<?php echo $this->lang->line('gkpos_cart_warning') ?>");
                jQuery('#cartWarningContent').text("<?php echo $this->lang->line('gkpos_make_order_sure') ?>");
                jQuery(".cartWarning").colorbox({inline: true, slideshow: false, scrolling: false, height: "250px", open: true, width: '100%', maxWidth: '400px', 'left': '30%'});
                return false;
            } else {
                $('#existing_order_type').val(order_type);
                $('#ConvertingOrderId').val(order_id);
                jQuery(".orderConversion").colorbox({inline: true, slideshow: false, scrolling: false, height: "300px", open: true, width: '100%', maxWidth: '400px', left: "30%"});
                return false;
            }
        } else {
            $('#showConversion').val('yes');
            getBaseAjaxPage('<?php echo site_url('gkpos/orders/indexajax/') ?>' + order_id)
        }
    }

    function convert() {
        
        $('#conversion_form').validate({
            submitHandler: function () {
                var myform = document.getElementById('conversion_form');
                var formdata = new FormData(myform);
                $.ajax({
                    url: $('#conversion_form').attr('action'),
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    success: function (response) {
                        jQuery.colorbox.close();
                        $('#showConversion').val('no');
                        $('.order-menu-list').html(response);
                    },
                });
            },
            errorClass: "has-error",
            errorLabelContainer: "#conversion_form_error_message_box",
            wrapper: "li",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
            },
            rules: {
                new_order_type: "required"
            },
            messages: {
                new_order_type: "Please select type to convert"
            }
        });
    }
</script>