
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade" id="add_edit_void_reason_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header text-left">
                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="modal-title bold"> <?php echo CommonLanguage::getMessage('void_reason'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="void_reason_form" method="POST" onsubmit="return false">
                    <div class="row">
                        <?php echo Forms::AlertDiv('void_reason_alert'); ?>
                        <input type='hidden' name='reason_flag' id='reason_flag'/>
                        <input type='hidden' name='reason_id' id='reason_id'/>

                    </div>
                    <div class="row form-group m-t-10">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('reason_type'); ?></label>
                            <select id="reason_type" name="reason_type"  class="full-width " data-init-plugin="select2" required>
                                <option value="0"><?php print CommonLanguage::getMessage('both'); ?></option>
                                <option value="1"><?php print CommonLanguage::getMessage('Item'); ?></option>
                                <option value="2"><?php print CommonLanguage::getMessage('invoice'); ?></option>
                            </select>
                        </div>
                    </div>
                    <div class="row form-group m-t-10">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('reason_title'); ?></label>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('reason_title'); ?>" id="reason_title" name="reason_title" class="form-control " autocomplete="off" required>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary" id="submit_void_reason"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('VoidReasonDisabler'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".add_void_reason").on("click", function () {
            $("#reason_flag").val(0);
        });
        $("#tableWithSearch").on("click", ".edit", function () {
            var reason_id = $(this).parents('div.Action').attr('data-id');
            $("#reason_flag").val(1);
            $("#reason_id").val(reason_id);
            $("#reason_type").val($(this).attr('data-reason-type')).select2();
            $("#reason_title").val($(this).parents('tr').find('td:eq(0)').html());
        });
        $("#submit_void_reason").on("click", function () {
            if (!$("#void_reason_form").valid())
                return;
            $("#VoidReasonDisabler").removeClass('hidden');
            var Data = new FormData(document.getElementById("void_reason_form"));
            $.ajax({
                url: "RestaurantAjax/submitVoidReason",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable(title, [0], 'RestaurantAjax/void_reason_list');
                            hideModalAlert('add_edit_void_reason_modal', 'void_reason_alert');
                        }
                        AddAlert("#void_reason_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#VoidReasonDisabler").addClass('hidden');
                }
            });
        });
    });
</script>