<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
?>


<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="role-mode" id="add_employee_deduction_note" aria-hidden="true" style="display: none;     width: 40%;
     margin: 0 auto;">
    <div class="modal-dialog">
        <div class="modal-content">
            <?php echo Forms::ModalLoader('addIsBusy') ?>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel"> <?php print CommonLanguage::getMessage('add_employee_deduction_note'); ?></h4>
                <br>
                <div id="EmployeeValidationAlert"></div>
            </div>
            <div class="modal-body">
                <div class="col-md-12 form-group">
                    <div class="col-md-6">
                        <label><?php echo CommonLanguage::getMessage('employee') ?></label><span class="red-star">*</span>
                        <input type="hidden" required  class="full-width Employee_ID" name="Employee_ID" id="Employee_ID" required/>
                    </div>
                    <div class="col-md-6">
                        <label><?php echo CommonLanguage::getMessage('duration_in_min') ?></label><span class="red-star">*</span>
                        <input type="text" class="form-control TimeDuration" name="TimeDuration" id="TimeDuration" required/>
                    </div>


                </div>

                <div class="col-md-12 form-group">
                    <div class="col-md-6">

                        <div class="radio radio-success " id="Employee_IS_Deduction">
                            <input type="radio" value="1" name="Employee_IS_Deduction"  id="Deduction">
                            <label for="Deduction"> <?php print CommonLanguage::getMessage('deduction_nb'); ?></label><br/>
                            <input type="radio" checked="checked" value="0" name="Employee_IS_Deduction"  id="Bonus">
                            <label for="Bonus"><?php print CommonLanguage::getMessage('bonus'); ?></label>
                        </div>
                    </div>
                    <div class="col-md-6 ">
                        <label><?php echo CommonLanguage::getMessage('note') ?></label><span class="red-star">*</span>
                        <textarea class="form-control Employee_Note" Placeholder="<?php echo CommonLanguage::getMessage('note') ?>" id="Employee_Note" required></textarea>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="CloseAdd" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button type="submit" class="btn btn-success " id="SubmitAdd"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>;
    $(function () {

        build_select2($('.Employee_ID'), 'xhr/employeesearch?is_actual='+is_actual);



        $('#SubmitAdd').on('click', function () {


            if ($(".Employee_Note").val() == '' || $('.TimeDuration').val() == '' || $('#Employee_ID').val() == '') {
                $("#EmployeeValidationAlert").attr("class", "alert alert-danger").empty().html(Required_Fields);
                return;
            }
            $("#addIsBusy").removeClass('hidden');
            var Data = {
                Employee_ID: $('#Employee_ID').val(),
                Employee_Name: $.trim($('.Employee_ID').text()),
                TimeDuration: $('#TimeDuration').val(),
                Employee_IS_Deduction: $('input[name=Employee_IS_Deduction]:checked', '#Employee_IS_Deduction').val(),
                Employee_Note: $('#Employee_Note').val(),
                is_actual: is_actual
            }
            $.ajax({
                url: "HRMAjax/add_employee_deduction_note",
                type: "POST",
                data: Data,
                complete: function (v, vv) {
                    if (vv == 'success' && v.responseText == 'ok') {
                        RebuildDataTable(title, [0, 1, 2, 3, 4], 'HRMAjax/viewEmployeeDeductionNote',{is_actual :is_actual});
                        $("#EmployeeValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                        setTimeout(function () {
                            $("#add_employee_deduction_note").modal('hide')
                        }, 1500)
                        setTimeout(function () {
                            $("#EmployeeValidationAlert").addClass('hidden')
                        }, 1500)
                    } else {
                        $("#EmployeeValidationAlert").attr("class", "alert alert-danger").empty().html(Failed_Submit);
                    }
                    $("#addIsBusy").addClass('hidden');

                }
            })



        })

























    })
</script>