<div class="modal fade" id="add-edit-emp-opening-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">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('add_emp_opening'); ?></h5>
                <h5 class="edit-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('edit_emp_opening'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="emp_opening_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='entry_id' id='entry_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('emp_opening_alert'); ?>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('Employee'); ?></label>
                            <span class="red-star">*</span>
                            <input class="full-width" id="employee_id" name="employee_id" type="hidden" required  />
                        </div>
                    </div> 
                    <div class="row form-group">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('Date'); ?></label>
                            <span class="red-star">*</span>
                            <input class="form-control" id="to_date" name="to_date" type="text" required  />
                        </div>
                    </div> 
                    <div class="row form-group">
                        <div class="col-md-12 ">
                            <label><?php print CommonLanguage::getMessage('total_salary'); ?></label>
                            <span class="red-star">*</span>
                            <input class="form-control" id="total_salary" name="total_salary" type="number" min="0" required />
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12 ">
                            <label><?php print CommonLanguage::getMessage('allowance'); ?></label>
                            <span class="red-star">*</span>
                            <input class="form-control" id="total_allowance" name="total_allowance" type="number" min="0" required />
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12 ">
                            <label><?php print CommonLanguage::getMessage('tax'); ?></label>
                            <span class="red-star">*</span>
                            <input class="form-control" id="total_tax" name="total_tax" type="number" min="0" required />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button style="color:white !important;" class="btn bg-success text-white" id="submit_emp_opening"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('empOpeningLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function(){
        $('#to_date').datepicker({autoclose:true})
        build_select2($("#employee_id"), "xhr/employeeSearch");
        $("#tableWithSearch").on("click", ".edit_emp_opening", function () {
            var entry_value = $(this).attr('data-id');
            $("#entry_id").val(entry_value);
            $("#add-edit-emp-opening-modal .edit-label").removeClass('hidden');
            CommonViewById('common_ajax/ViewByEntryId', {table:'employee_opening_list' ,entry_value:entry_value,entry_id: 'entry_id'},'#empOpeningLoader', function (response) {
                $('#total_allowance').val(response[0].total_allowance)
                $('#total_tax').val(response[0].total_tax)
                $('#total_salary').val(response[0].total_salary)
                $('#to_date').val(response[0].to_date)
                $('#employee_id').val(response[0].employee_id).attr('data-select-name',response[0].emp)
                 build_select2($("#employee_id"), "xhr/employeeSearch");
            });
        });
        $("#new_emp_opening").on("click", function () {
            $("#entry_id").val(0);
            $("#add-edit-emp-opening-modal .add-label").removeClass('hidden');
        });
        $("#submit_emp_opening").on("click", function () {
            if (!$("#emp_opening_form").valid())
                return;
            var Data = new FormData(document.getElementById("emp_opening_form"));
            $("#empOpeningLoader").removeClass('hidden');
            $.ajax({
                url: "HRMAjax/submitEmpOpening",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            hideModalAlert('add-edit-emp-opening-modal', 'emp_opening_alert');
                           RebuildDataTable($('.panel-heading .panel-title').html(), [0,1,2], 'HRMAjax/getEmployeeOpening');
                        }
                        AddAlert("#emp_opening_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#empOpeningLoader").addClass('hidden');
                }
            });
        });  
    });
</script>