<div style="display:none">
    <div id="discountPopup" class="popupouter">
        <style>
            #custom_discount_form .payment-pin-calculatorbg ul li {
                font-size: 13px;
                line-height: 50px;
                padding: 12px 24px;
            }
        </style>
        <fieldset style="margin: 0 auto;padding: 0px">
            <div class="popup-body row">
                <div id="discountPopupContent" class="warningPopupContent col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <?php echo form_open('gkpos/orders/adddiscount/', array('id' => 'custom_discount_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?>
                    <div class="form-group form-group-sm"  style="margin: 0">	
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"  style="margin: 0">
                            <div class="pin-calculatorbg payment-pin-calculatorbg">
                                <?php $OrderDiscountData = $this->Orders_Model->get_discount($this->Orders_Model->get_current_orderid()); ?>
                                <input type="text" id="discount" name="number" value="<?php !empty($OrderDiscountData) ? print$OrderDiscountData['number'] : print '' ?>" class="form-control input-sm" style="width: 330px; margin: 0 auto;">
                                <div class="form-group form-group-sm" style="margin: 0px auto;">	
                                    <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-capitalize"><?php echo $this->lang->line('gkpos_function') ?></label>
                                    <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                                        <label class="radio-inline text-capitalize"><input type="radio" name="func" id="discount_func1" value="2" <?php (!empty($OrderDiscountData) && ( isset($OrderDiscountData['func']) && $OrderDiscountData['func'] == 2)) ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_fixed') ?></label>
                                        <label class="radio-inline text-capitalize"><input type="radio" name="func" id="discount_func2" value="1" <?php (!empty($OrderDiscountData) && (isset($OrderDiscountData['func']) && $OrderDiscountData['func'] == 1)) ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_percentage') ?></label>
                                    </div>
                                </div>
                                <div class="form-group form-group-sm" style="margin: 2px 0 5px 0;">	
                                    <?php echo form_label($this->lang->line('gkpos_discount_applied'), '', array('class' => 'text-capitalize control-label col-lg-4 col-md-4 col-sm-4 col-xs-4')); ?>
                                    <div class='col-lg-3 col-md-3 col-sm-3 col-xs-2 text-left text-capitalize'><?php echo form_checkbox(array('name' => 'food', 'class' => 'checkbox-inline', 'value' => 'yes', 'checked' => isset($OrderDiscountData['food']) ? $OrderDiscountData['food'] : false)); ?><span class="discount-lebel"><?php echo $this->lang->line('gkpos_food') ?></span></div>
                                    <div class='col-lg-4 col-md-4 col-sm-4 col-xs-3 text-left text-capitalize '><?php echo form_checkbox(array('name' => 'nonfood', 'class' => 'checkbox-inline', 'value' => 'yes', 'checked' => isset($OrderDiscountData['nonfood']) ? $OrderDiscountData['nonfood'] : false)); ?> <span class="discount-lebel"><?php echo $this->lang->line('gkpos_non_food') ?></span></div>
                                </div>
                                <ul>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key1') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key2') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key3') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key4') ?></li>
                                </ul>
                                <ul>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key5') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key6') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key7') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key8') ?></li>
                                </ul>
                                <ul>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key9') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key0') ?></li>
                                    <li class="numkey discountNumKey"><?php echo $this->lang->line('gkpos_numpad_key_dot') ?></li>
                                    <li class="btnPin discountBtnPin" style="padding: 12px 15px !important"><?php echo $this->lang->line('gkpos_numpad_key_del') ?></li>
                                </ul>
                                <ul>
                                    <li class="numkey discountNumKey" style=" padding: 12px 20px;">10</li>
                                    <li class="numkey discountNumKey" style=" padding: 12px 20px;">15</li>
                                    <li class="numkey discountNumKey" style=" padding: 12px 20px;">20</li>
                                    <li class="btnPin discountBtnPin" style="padding: 12px 15px !important"><?php echo $this->lang->line('gkpos_numpad_key_clr') ?></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <ul id="custom_discount_form_error_message_box" class="error_message_box text-center"></ul>
                    <div class="form-group form-group-md" style="margin: 0">	
                        <div class="col-md-12">
                            <input type="hidden" id="discountOrderId" 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="saveDiscount()" style="width: 330px; margin: 0 auto; padding: 20px 0px;">
                        </div>
                    </div>
                    <?php echo form_close(); ?>
                </div>
            </div>
        </fieldset>
    </div>
    <script>
        function addDiscount(order_id) {
            
            var orderId = $('#orderId').val();
            var CurrentOrderTotal = $('#CurrentOrderTotal').val();
            if ((!order_id || !orderId) && order_id != orderId) {
                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 {
                if (CurrentOrderTotal <= 0) {
                    jQuery('#cartWarningHeader').text("<?php echo $this->lang->line('gkpos_cart_warning') ?>");
                    jQuery('#cartWarningContent').text("<?php echo $this->lang->line('gkpos_put_item_on_cart') ?>");
                    jQuery(".cartWarning").colorbox({inline: true, slideshow: false, scrolling: false, height: "250px", open: true, width: '100%', maxWidth: '400px', 'left': '30%'});
                    return false;
                } else {
                    $('#discountOrderId').val(order_id);
                    $('#discountCurrentOrderTotal').val(CurrentOrderTotal);
                    var discountPopup = $("#discountPopup").html();
                    $('#categoryTitle').html('<p class="sidebar-heading text-capitalize"><?php echo $this->lang->line('gkpos_add_discount') ?></p>');
                    $('#menuListArea').html(discountPopup);
                    setDiscountNumKeys('discount');
                    return false;
                }
            }
        }
        function saveDiscount() {
            
            $('#custom_discount_form').validate({
                submitHandler: function () {
                    var myform = document.getElementById('custom_discount_form');
                    var formdata = new FormData(myform);
                    $.ajax({
                        url: $('#custom_discount_form').attr('action'),
                        data: formdata,
                        cache: false,
                        processData: false,
                        contentType: false,
                        type: 'POST',
                        dataType: 'json',
                        success: function (response) {
                            loadCart(response.order_id, 'discount');
                            $('#menuListArea').html('');
                            $('#categoryTitle').html('<p class="sidebar-heading text-capitalize"><?php echo $this->lang->line('gkpos_click_category_mesage') ?></p>');
                        }
                    });
                },
                errorClass: "has-error",
                errorLabelContainer: "#custom_discount_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: {
                    number: {number: true, required: true}
                },
                messages: {
                    number: "<?php echo $this->lang->line('gkpos_discount_amount_required'); ?>",
                }
            });
        }
        function setDiscountNumKeys(inputFiledId) {
            jQuery('.discountNumKey').click(function (event) {
                
                var numBox = document.getElementById(inputFiledId);
                numBox.value = numBox.value + this.innerHTML;
                event.stopPropagation();
            });
            $('.discountBtnPin').click(function (event) {
                
                if (this.innerHTML == 'DEL') {
                    var numBox = document.getElementById(inputFiledId);
                    if (numBox.value.length > 0) {
                        numBox.value = numBox.value.substring(0, numBox.value.length - 1);
                    }
                } else {
                    document.getElementById(inputFiledId).value = '';
                }
                event.stopPropagation();
            });
        }
    </script>
</div>