0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.223.205.151


Current Path : /var/www/html/oums/js/
Upload File :
Current File : /var/www/html/oums/js/employees.js

var curr_fold_name = window.location.pathname.substring(
    0,
    window.location.pathname.lastIndexOf('/')
)
var curr_fold_path = document.URL.substr(0, document.URL.lastIndexOf('/'))

function load_page() {
    load_page_data(
        window.location.href.substr(window.location.href.lastIndexOf('/') + 1)
    )
    cncl_data()
}

function cncl_data() {
    $('#page-container-body').load('employees_grid.php', function () {
        $('#btn_addn').show()
        $('#btn_save').hide()
        $('#btn_cncl').hide()
        load_grid_data(20, 1)
    })
}

function load_grid_data(page_limt, page_numb) {
    $.ajax({
        type: 'POST',
        url: 'src/employees.php',
        data: {
            load_data: 'grid_data',
            page_limt: page_limt,
            page_numb: page_numb,
            dept_code: document.getElementById('seldeptcode').value,
            empl_desn: document.getElementById('selempldesn').value,
            empl_stat: document.getElementById('selemplstat').value,
            find_data: document.getElementById('txtemplfind').value,
        },
        cache: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            hide_process()
            $('#page-container-grid').html(data)
        },
        error: function (data) {
            hide_process()
            $('#page-container-grid').html('Error: ' + data)
        },
    })
}

function load_page_limt(page_limt) {
    load_grid_data(page_limt, 1)
}

function clrs_data() {
    $('#btn_addn').hide()
    $('#btn_save').show()
    $('#btn_cncl').show()
    $(function () {
        $('#txtemplbday').datepicker({ dateFormat: 'dd/mm/yy' })
    })
    $(function () {
        $('#txtjoindate').datepicker({ dateFormat: 'dd/mm/yy' })
    })
    $(function () {
        $('#txttermdate').datepicker({ dateFormat: 'dd/mm/yy' })
    })
    document.getElementById('imgemplphot').src = 'img-empl/blank.png'
}

function addn_data() {
    $('#page-container-body').load('employees_form.php', function () {
        clrs_data()
        document.getElementById('lblpagemode').innerHTML = 'Add'
        document.getElementById('txtpagemode').value = 'add'
        document.getElementById('txtemplcode').value = '<<AUTO>>'
        document.getElementById('txtemplname').focus()
    })
}

function edit_data(prim_data) {
    $('#page-container-body').load('employees_form.php', function () {
        clrs_data()
        document.getElementById('lblpagemode').innerHTML = 'Edit'
        document.getElementById('txtpagemode').value = 'edit'
        document.getElementById('txtemplname').focus()
        $.ajax({
            type: 'POST',
            url: 'src/employees.php',
            data: {
                load_data: 'disp_data',
                empl_code: prim_data,
            },
            cache: false,
            beforeSend: function () {
                show_process()
            },
            success: function (data) {
                var data = JSON.parse(data)
                if (data.femplphot == '') {
                    document.getElementById('imgemplphot').src =
                        'img-empl/blank.png'
                    document.getElementById('txtemplphot').value = ''
                } else {
                    document.getElementById('imgemplphot').src =
                        'img-empl/' + data.femplphot
                    document.getElementById('txtemplphot').value =
                        data.femplphot
                }
                $.ajax({
                    url: curr_fold_path + '/img-empl/' + data.femplphot,
                    type: 'HEAD',
                    error: function () {
                        document.getElementById('imgemplphot').src =
                            'img-empl/blank.png'
                        document.getElementById('txtemplphot').value = ''
                    },
                    success: function () {
                        document.getElementById('imgemplphot').src =
                            'img-empl/' + data.femplphot
                        document.getElementById('txtemplphot').value =
                            data.femplphot
                    },
                })

                load_desn_data(data.fdeptcode)
                document.getElementById('txtemplcode').value = data.femplcode
                document.getElementById('txtemplname').value = data.femplname
                document.getElementById('txtdeptcode').value = data.fdeptcode
                document.getElementById('txtempldesn').value = data.fempldesn
                document.getElementById('txtempltype').value = data.fempltype
                document.getElementById('txtworkplce').value = data.fworkplce
                document.getElementById('txtrepthead').value = data.frepthead
                document.getElementById('txtemplstat').value = data.femplstat
                document.getElementById('txtemplgend').value = data.femplgend
                document.getElementById('txtemplbday').value = get_format_date(
                    data.fbrthdate
                )
                document.getElementById('txtemplmobl').value = data.femplmobl
                document.getElementById('txtempladhr').value = data.fadhrnumb
                document.getElementById('txtemplpanc').value = data.fpancnumb
                document.getElementById('txtemplmail').value = data.femplmail
                document.getElementById('txtempladd1').value = data.fpermadd1
                document.getElementById('txtempladd2').value = data.fpermadd2
                document.getElementById('txtempladd3').value = data.fpermadd3
                document.getElementById('txtempladd4').value = data.fpermadd4
                document.getElementById('txtexpnentr').value = data.fexpnentr
                document.getElementById('txtattnentr').value = data.fattnentr
                document.getElementById('txtworkentr').value = data.fworkentr
                document.getElementById('txtsalrcomp').value = data.fsalrcomp
                document.getElementById('txtsalrhead').value = data.fsalrhead
                document.getElementById('txtsalrtype').value = data.fsalrtype
                document.getElementById('txtsalrbase').value = data.fsalrbase
                document.getElementById('txtsalrdays').value = data.fsalrdays
                document.getElementById('txtsalrhour').value = data.fsalrhour
                document.getElementById('txtsalrappr').value = data.fsalrappr
                document.getElementById('txttotlcasl').value = data.ftotlleav
                document.getElementById('txtavlbcasl').value = data.favlbleav
                document.getElementById('txttotlextl').value = data.ftotlextl
                document.getElementById('txtavlbextl').value = data.favlbextl
                document.getElementById('txtacntname').value = data.facntname
                document.getElementById('txtacntnumb').value = data.facntnumb
                document.getElementById('txtbankcode').value = data.fbankcode
                document.getElementById('txtbankifsc').value = data.fifsccode
                document.getElementById('txtjoindate').value = get_format_date(
                    data.fjoindate
                )
                document.getElementById('txttermdate').value = get_format_date(
                    data.ftermdate
                )
                document.getElementById('txtemplremk').value = data.femplremk
                hide_process()
            },
            error: function (data) {
                hide_process()
                $('#page-container-form').html('Error: ' + data)
            },
        })
    })
}

function view_data(prim_data) {
    alert('Not available')
    // if (r == true) {
    //     $.ajax({
    //         type: 'POST',
    //         url: 'src/employees.php',
    //         data: {
    //             load_data: 'view_data',
    //             prim_code: prim_data,
    //         },
    //         success: function (data) {
    //             load_grid_data(20, 1)
    //         },
    //     })
    // }
}

function dele_data(prim_data) {
    var r = confirm('Delete Record?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/employees.php',
            data: {
                load_data: 'dele_data',
                prim_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function dele_dvid(prim_data) {
    var r = confirm('Reset device ID?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/employees.php',
            data: {
                load_data: 'dele_dvid',
                prim_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function prnt_card(prim_data) {
    $.ajax({
        type: 'POST',
        url: 'src/employees_print_id_card.php',
        dataType: "json",
        data: {
            prim_code: prim_data,
        },
        cache: false,
        beforeSend: function () {
            show_process();
        },
        success: function (data) {
            hide_process();
            if (data.stat != "F") {
                window.open("src/" + data.file,'_blank');
            } else {
                alert(data.mesg);
            }
        },
        error: function (data) {
            hide_process();
        },
    })
}
function prnt_ndaf(prim_data) {
    $.ajax({
    type: 'POST',
    url: 'src/employees_print_nda_form.php',
    dataType: "json",
    data: {
        prim_code: prim_data,
    },
    cache: false,
    beforeSend: function () {
        show_process();
    },
    success: function (data) {
        hide_process();
        if (data.stat != "F") {
            window.open("src/" + data.file,'_blank');
        } else {
            alert(data.mesg);
        }
    },
    error: function (data) {
        hide_process();
    },
    })

}

function salary_days() {
    var xsalr_mnth = document.getElementById('txtsalrbase').value
    var xsalr_days = Math.round(xsalr_mnth / 30)
    document.getElementById('txtsalrdays').value = xsalr_days
    salary_hour()
}

function salary_hour() {
    var xsalr_days = document.getElementById('txtsalrdays').value
    var xsalr_hour = Math.round(xsalr_days / 8)
    document.getElementById('txtsalrhour').value = xsalr_hour
}

function load_dept_data() {
    $.ajax({
        type: 'POST',
        url: 'src/employees.php',
        data: {
            load_data: 'dept_data',
        },
        cache: false,
        success: function (data) {
            $('#txtdeptcode').html(data)
        },
    })
}

function load_desn_data(dept_code) {
    $.ajax({
        type: 'POST',
        url: 'src/employees.php',
        async: false,
        data: {
            load_data: 'desn_data',
            dept_code: dept_code,
        },
        cache: false,
        success: function (data) {
            $('#txtempldesn').html(data)
        },
    })
}

function load_bank_data() {
    $.ajax({
        type: 'POST',
        url: 'src/employees.php',
        data: {
            load_data: 'bank_data',
        },
        cache: false,
        success: function (data) {
            $('#txtbankcode').html(data)
        },
    })
}

function actv_empl(prim_data) {
    var r = confirm('Activate Employee?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/employees.php',
            data: {
                load_data: 'actv_empl',
                prim_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function inac_empl(prim_data) {
    var r = confirm('Deactivate Employee?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/employees.php',
            data: {
                load_data: 'inac_empl',
                prim_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function benf_name() {
    if (document.getElementById('txtacntname').value == '') {
        document.getElementById('txtacntname').value =
            document.getElementById('txtemplname').value
    }
}

function sele_bank_code() {
    $bank_code = document.getElementById('txtbankifsc').value.substr(0, 4)
    $bank_code = $bank_code.toUpperCase()
    if ($bank_code == '') {
        $bank_code = 0
    }
    document.getElementById('txtbankcode').value = $bank_code
}

function save_data() {
    if (document.getElementById('txtemplname').value == '') {
        alert('Please enter employee name!')
        txtemplname.focus()
        return false
    }

    if (document.getElementById('txtdeptcode').value == '') {
        alert('Please select cleint!')
        txtdeptcode.focus()
        return false
    }

    if (document.getElementById('txtempldesn').value == '') {
        alert('Please select designation!')
        txtempldesn.focus()
        return false
    }

    if (document.getElementById('txtempltype').value == '') {
        alert('Please select employee type!')
        txtempltype.focus()
        return false
    }

    if (document.getElementById('txtworkplce').value == '') {
        alert('Please select working place!')
        txtworkplce.focus()
        return false
    }

    if (document.getElementById('txtrepthead').value == '') {
        alert('Please select your reporting head!')
        txtrepthead.focus()
        return false
    }

    if (document.getElementById('txtemplstat').value == '') {
        alert('Please select status!')
        txtemplstat.focus()
        return false
    }

    if (document.getElementById('txtemplgend').value == '') {
        alert('Please select gender!')
        txtemplgend.focus()
        return false
    }

    if (
        document.getElementById('txtemplbday').value == '' ||
        document.getElementById('txtemplbday').value == '0000-00-00' ||
        document.getElementById('txtemplbday').value == '00-00-0000' ||
        document.getElementById('txtemplbday').value == '0000/00/00' ||
        document.getElementById('txtemplbday').value == '00/00/0000'
    ) {
        alert('Please enter date of birth!')
        txtemplbday.focus()
        return false
    }

    if (
        document.getElementById('txtjoindate').value == '' ||
        document.getElementById('txtjoindate').value == '0000-00-00' ||
        document.getElementById('txtjoindate').value == '00-00-0000' ||
        document.getElementById('txtjoindate').value == '0000/00/00' ||
        document.getElementById('txtjoindate').value == '00/00/0000'
    ) {
        alert('Please enter joning date!')
        txtjoindate.focus()
        return false
    }

    if (validate_mobile('txtemplmobl', $('#txtemplmobl').val()) == false) {
        $('#txtemplmobl').focus()
        return false
    }

    if (validate_aadhar('txtempladhr', $('#txtempladhr').val()) == false) {
        $('#txtempladhr').focus()
        return false
    }

    if (validate_pan('txtemplpanc', $('#txtemplpanc').val()) == false) {
        $('#txtemplpanc').focus()
        return false
    }

    if (validate_email('txtemplmail', $('#txtemplmail').val()) == false) {
        $('#txtemplmail').focus()
        return false
    }
    if (document.getElementById('txtempladd1').value == '') {
        alert('Please enter address #1!')
        txtempladd1.focus()
        return false
    }
    if (document.getElementById('txtempladd2').value == '') {
        alert('Please enter address #12')
        txtempladd2.focus()
        return false
    }
    if (document.getElementById('txtempladd3').value == '') {
        alert('Please enter address #3!')
        txtempladd3.focus()
        return false
    }
    if (document.getElementById('txtempladd4').value == '') {
        alert('Please enter address #4!')
        txtempladd4.focus()
        return false
    }

    // if (document.getElementById("txtsalrcomp").value == "") {
    // 	alert("Please select salary computation!");
    // 	txtsalrcomp.focus();
    // 	return false;
    // }

    if (document.getElementById('txtsalrhead').value == '') {
        alert('Please select salary head!')
        txtsalrhead.focus()
        return false
    }

    if (document.getElementById('txtsalrtype').value == '') {
        alert('Please select salary type!')
        txtsalrtype.focus()
        return false
    }

    if (
        document.getElementById('txtsalrbase').value == 0 ||
        document.getElementById('txtsalrbase').value == ''
    ) {
        alert('Please enter salary per month!')
        txtsalrbase.focus()
        return false
    }

    if (
        document.getElementById('txtsalrdays').value == 0 ||
        document.getElementById('txtsalrdays').value == ''
    ) {
        alert('Please enter salary per day!')
        txtsalrdays.focus()
        return false
    }

    if (
        document.getElementById('txtsalrhour').value == 0 ||
        document.getElementById('txtsalrhour').value == ''
    ) {
        alert('Please enter salary per hour!')
        txtsalrhour.focus()
        return false
    }

    if (document.getElementById('txtsalrappr').value == '') {
        alert('Please select next salary apprisal month!')
        txtsalrappr.focus()
        return false
    }

    if (document.getElementById('txtacntname').value == '') {
        alert('Please enter benificiary name!')
        txtacntname.focus()
        return false
    }

    if (document.getElementById('txtacntnumb').value == '') {
        alert('Please enter bank account number!')
        txtacntnumb.focus()
        return false
    }

    if (document.getElementById('txtbankifsc').value == '') {
        alert('Please enter bank IFSC Code!')
        txtbankifsc.focus()
        return false
    }

    if (document.getElementById('txtemplphot').value == '') {
        alert('Please upload photo!')
        txtemplphot.focus()
        return false
    }

    // if (document.getElementById("txtemplstat").value == "T") {
    // 	document.getElementById("txttermdate").value = "";
    // }

    if (document.getElementById('txtemplstat').value == 'F') {
        if (
            document.getElementById('txttermdate').value == '' ||
            document.getElementById('txttermdate').value == '0000-00-00' ||
            document.getElementById('txttermdate').value == '00-00-0000' ||
            document.getElementById('txttermdate').value == '0000/00/00' ||
            document.getElementById('txttermdate').value == '00/00/0000'
        ) {
            alert('Please enter the relieve date!')
            txttermdate.focus()
            return false
        }
    }

    if ($('#filemplphot').val() != '') {
        empl_phot = $('#txtemplphot').val()
        empl_phot = empl_phot.replace(/^.*[\\\/]/, '')
        empl_phot =
            document.getElementById('txtemplname').value + '_' + empl_phot
        empl_phot = empl_phot.split(' ').join('_')
        empl_phot = empl_phot.toLowerCase()
    } else {
        empl_phot = document.getElementById('txtemplphot').value
    }

    var file_data = $('#filemplphot').prop('files')[0]
    var file_text = empl_phot
    var form_data = new FormData()
    form_data.append('load_data', 'save_data')
    form_data.append('file', file_data)
    form_data.append('empl_phot', empl_phot)
    form_data.append('page_mode', document.getElementById('txtpagemode').value)
    form_data.append('empl_code', document.getElementById('txtemplcode').value)
    form_data.append('empl_name', document.getElementById('txtemplname').value)
    form_data.append('dept_code', document.getElementById('txtdeptcode').value)
    form_data.append('empl_desn', document.getElementById('txtempldesn').value)
    form_data.append('empl_type', document.getElementById('txtempltype').value)
    form_data.append('work_plce', document.getElementById('txtworkplce').value)
    form_data.append('rept_head', document.getElementById('txtrepthead').value)
    form_data.append('empl_gend', document.getElementById('txtemplgend').value)
    form_data.append('empl_bday', document.getElementById('txtemplbday').value)
    form_data.append('empl_mobl', document.getElementById('txtemplmobl').value)
    form_data.append('empl_mail', document.getElementById('txtemplmail').value)
    form_data.append('empl_add1', document.getElementById('txtempladd1').value)
    form_data.append('empl_add2', document.getElementById('txtempladd2').value)
    form_data.append('empl_add3', document.getElementById('txtempladd3').value)
    form_data.append('empl_add4', document.getElementById('txtempladd4').value)
    form_data.append('salr_comp', document.getElementById('txtsalrcomp').value)
    form_data.append('salr_head', document.getElementById('txtsalrhead').value)
    form_data.append('salr_type', document.getElementById('txtsalrtype').value)
    form_data.append('salr_base', document.getElementById('txtsalrbase').value)
    form_data.append('salr_days', document.getElementById('txtsalrdays').value)
    form_data.append('salr_hour', document.getElementById('txtsalrhour').value)
    form_data.append('salr_appr', document.getElementById('txtsalrappr').value)
    form_data.append('totl_casl', document.getElementById('txttotlcasl').value)
    form_data.append('join_date', document.getElementById('txtjoindate').value)
    form_data.append('term_date', document.getElementById('txttermdate').value)
    form_data.append('empl_stat', document.getElementById('txtemplstat').value)
    form_data.append('expn_entr', document.getElementById('txtexpnentr').value)
    form_data.append('attn_entr', document.getElementById('txtattnentr').value)
    form_data.append('work_entr', document.getElementById('txtworkentr').value)
    form_data.append('empl_remk', document.getElementById('txtemplremk').value)
    form_data.append('empl_adhr', document.getElementById('txtempladhr').value)
    form_data.append('empl_panc', document.getElementById('txtemplpanc').value)
    form_data.append('acnt_name', document.getElementById('txtacntname').value)
    form_data.append('bank_acnt', document.getElementById('txtacntnumb').value)
    form_data.append('bank_ifsc', document.getElementById('txtbankifsc').value)
    form_data.append('bank_code', document.getElementById('txtbankcode').value)

    $.ajax({
        type: 'POST',
        url: 'src/employees.php',
        data: form_data,
        dataType: 'json',
        cache: false,
        contentType: false,
        processData: false,
        cache: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            hide_process()
            if (data.errs == 'T') {
                alert(data.mesg)
            } else {
                alert(data.mesg)
                cncl_data()
                load_grid_data(20, 1)
            }
        },
        error: function (data) {
            $('#page-container-form').html('Error: ' + data)
        },
    })
}

function show_brow_file() {
    $('#filemplphot').trigger('click')
}

function chck_file_path(input) {
    var phot_file = $('#filemplphot').val()
    var file_extn = phot_file.split('.').pop()
    file_extn = file_extn.toLowerCase()
    if (
        file_extn == 'jpeg' ||
        file_extn == 'jpg' ||
        file_extn == 'png' ||
        file_extn == 'bmp'
    ) {
    } else {
        alert('JPEG, JPG, PNG and BMP files are allowed!')
        return false
    }
    var file_size = $('#filemplphot')[0].files[0].size
    if (file_size > 5000000) {
        alert('Upload files with size less then 5MB!')
        return false
    }
    document.getElementById('txtemplphot').value =
        document.getElementById('filemplphot').value

    if (input.files && input.files[0]) {
        var reader = new FileReader()
        reader.onload = function (e) {
            $('#imgemplphot').attr('src', e.target.result)
        }
        reader.readAsDataURL(input.files[0])
    }
}