
<style>
    .input-group-addon.complete {
        background-color:#4c0870;
        color: #ffffff;
    }
    .hidden{
        display: none;
    }
    #InputFile{
        /*        margin-left:128px;
                margin-top:10px;*/
        background-color:#4c0870 !important;
        color:#fff;
    }
    #InputFile > input{
        position:absolute;
        left:0px;
        top:0px;
        width:100%;
        height:100%;
        opacity:0.01;
        cursor:pointer;
    }
</style>
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="role-mode" id="CreateEmpTransferDay" 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_emp_trs_dys'); ?></h4>
                <br>
                <div id="EmployeeValidationAlert"></div>
                <input type='hidden' id="IsEdit" class="hidden" data-value='0' value="0" />


            </div>
            <div class="modal-body">
                <form id="AssignEmpAlertForm" method="POST" onsubmit="return false">
                    <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('Date') ?></label><span class="red-star">*</span>
                            <input type="text" class="form-control transfer_date" value="<?php echo $today ?>"name="transfer_date" id="transfer_date" required/>
                        </div>


                    </div>

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


                            <label><?php echo CommonLanguage::getMessage('days_nb') ?></label><span class="red-star">*</span>
                            <input type="number" min="1" value="1" class="form-control transfer_day_number" name="transfer_day_number" id="transfer_day_number" required/>

                        </div>
                        <div class="col-md-6 ">
                            <label><?php echo CommonLanguage::getMessage('note') ?></label><span class="red-star">*</span>
                            <textarea class="form-control transfer_day_note" Placeholder="<?php echo CommonLanguage::getMessage('note') ?>" id="transfer_day_note" required></textarea>
                        </div>
                    </div>

                </form>
            </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')); ?>,
            add = <?php echo json_encode(CommonLanguage::getMessage('add_emp_trs_dys')); ?>,
            edit = <?php echo json_encode(CommonLanguage::getMessage('edit_emp_trs_dys')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>;
    var entry_id, doc_id;
    $(function () {
        build_select2($('#Employee_ID'), 'xhr/employeesearch?is_actual='+is_actual);
        $('#transfer_date').datepicker({autoclose: true});
        $("#tableWithSearch").on("click", ".Action .Edit", function () {
            entry_id = $(this).parents("tr").find('.Action').attr('data-id');
            $('#myModalLabel').empty().html(edit);
            $('#CreateEmpTransferDay').modal('show');
            $("#IsEdit").attr('data-value', 1);
            $.ajax({
                url: 'HRMAjax/getEmpTransferDay?id=' + entry_id,
                dataType: 'JSON',
                complete: function (v1, v2) {
                    var Data = v1.responseJSON;
                    if (v2 == 'success') {
                        $('#transfer_date').val(Data['transfer_date']);
                        $('#transfer_day_note').val(Data['transfer_day_note']);
                        $('#Employee_ID').val(Data['employee_id']);
                        $('#transfer_day_number').val(Data['transfer_day_number']);
                        $('#Employee_ID').attr('data-select-name', Data['employee_name']);
                        build_select2($('#Employee_ID'), 'xhr/employeesearch?is_actual='+is_actual);
                    }
                }
            });
        });
        $('#SubmitAdd').on('click', function () {
            if ($("#transfer_day_note").val() == '' || $("#transfer_date").val() == '' || $('#Employee_ID').val() == '' || $('#transfer_day_number').val() == '') {
                $("#EmployeeValidationAlert").attr("class", "alert alert-danger").empty().html(Required_Fields);
                return;
            }
            $("#addIsBusy").removeClass('hidden');
            var Data = new FormData(document.getElementById("AssignEmpAlertForm"));
            Data.append("Employee_ID", $("#Employee_ID").val());
            Data.append("Employee_Name", $.trim($('.Employee_ID').text()));
            Data.append("transfer_date", $('#transfer_date').val());
            Data.append("transfer_day_number", $('#transfer_day_number').val());
            Data.append("transfer_day_note", ($('#transfer_day_note').val()));
            if (($("#IsEdit").attr('data-value') == 1)) {
                Data.append("entry_id", entry_id);
            }
            $.ajax({
                url: "HRMAjax/add_employee_transfer_date",
                processData: false,
                contentType: false,
                method: "POST",
                dataType: "json",
                data: Data,
                complete: function (v, vv) {
                    if (vv == 'success') {
                        if (v.responseJSON[0] == 'success') {
                            RebuildDataTable(title, [0, 1, 2, 3], 'HRMAjax/viewEmpTransferDay');
                            $("#EmployeeValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                            setTimeout(function () {
                                $("#CreateEmpTransferDay").modal('hide')
                            }, 1500)
                            setTimeout(function () {
                                $("#EmployeeValidationAlert").addClass('hidden')
                            }, 1500)
                        } else {
                            $("#EmployeeValidationAlert").attr("class", "alert alert-danger").empty().html(v.responseJSON[1]);
                        }
                        $("#addIsBusy").addClass('hidden');
                    } else {
                        $("#EmployeeValidationAlert").attr("class", "alert alert-danger").empty().html(Failed_Submit);
                    }
                }
            })
            $("#IsEdit").attr('data-value', 0);
            $('#myModalLabel').empty().html(add);
        })
    })

    $('#CloseAdd').on('click', function () {
        $("#IsEdit").attr('data-value', 0);
        $('#myModalLabel').empty().html(add);
    });


</script>