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 : 3.22.27.41


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

function load_page() {
    load_page_data(
        window.location.href.substr(window.location.href.lastIndexOf('/') + 1)
    )
    clrs_data()
    load_empl_data()
    document.getElementById('txtexpndate').value = get_today_date()
}

function clrs_data() {
    $('#btn_save').hide()
    $(function () {
        $('#txtexpndate').datepicker({ dateFormat: 'dd/mm/yy' })
    })
    document.getElementById('txtemplcode').focus()
    $('#page-container-grid').html('')
}

function load_empl_data() {
    $.ajax({
        type: 'POST',
        url: 'src/expense.php',
        data: {
            load_data: 'empl_data',
        },
        cache: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            $('#txtemplcode').html(data)
            load_dept_data()
            hide_process()
        },
        error: function (data) {
            $('#txtemplcode').html('Error: ' + data)
        },
    })
}

function load_dept_data() {
    $.ajax({
        type: 'POST',
        url: 'src/expense.php',
        data: {
            load_data: 'dept_data',
            empl_code: document.getElementById('txtemplcode').value,
        },
        cache: false,
        success: function (data) {
            $('#txtdeptcode').html(data)
        },
        error: function (data) {
            $('#txtdeptcode').html('Error: ' + data)
        },
    })
}

function view_data() {
    if (document.getElementById('txtemplcode').value == 0) {
        alert('Please select employee!')
        txtemplcode.focus()
        return false
    }

    if (document.getElementById('txtacnttype').value == 0) {
        alert('Please select account type!')
        txtacnttype.focus()
        return false
    }

    $host = 'oums'
    $.ajax({
        type: 'POST',
        url: 'src/expense.php',
        data: {
            load_data: 'disp_data',
            dept_code: document.getElementById('txtdeptcode').value,
            empl_code: document.getElementById('txtemplcode').value,
            acnt_type: document.getElementById('txtacnttype').value,
            expn_date: document.getElementById('txtexpndate').value,
        },
        cache: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            $('#page-container-grid').html(data)
            $('#btn_save').show()
            hide_process()
        },
        error: function (data) {
            hide_process()
            $('#page-container-grid').html('Error: ' + data)
        },
    })
}

function validate_row(r) {
    var row_index = r.parentNode.parentNode.rowIndex
    var arr_index = row_index - 1

    //Validate for expense head selection
    var arr_input = document.getElementsByName('txtheaddesc[]')
    if (arr_input[arr_index].value == '0') {
        alert('Please select description!')
        arr_input[arr_index].focus()
        return false
    }

    //Validate for expense amount
    var arr_input = document.getElementsByName('txtexpnamnt[]')
    if (
        arr_input[arr_index].value == '0.00' ||
        arr_input[arr_index].value <= '0'
    ) {
        alert('Please enter amount!')
        arr_input[arr_index].focus()
        return false
    }

    //Validate for expense head selection
    var arr_input = document.getElementsByName('txtclntcode[]')
    if (arr_input[arr_index].value == '0') {
        alert('Please select client!')
        arr_input[arr_index].focus()
        return false
    }

    //Load the element and values
    var table = document.getElementById('dataTable')
    var row_count = table.rows.length
    if (row_index + 1 == row_count) {
        var row = table.insertRow(row_count)
        row.insertCell(0).innerHTML =
            '<input type="text" id="txtslnolist[]" name="txtslnolist[]" class="form-control" disabled="disabled" value=' +
            row_count +
            ' style="text-align:center;">'
        row.insertCell(1).innerHTML = table.rows[1].cells[1].innerHTML
        row.insertCell(2).innerHTML =
            '<input type="text" id="txtexpnamnt[]" name="txtexpnamnt[]" class="form-control" value="0.00" style="text-align:right;"/>'
        row.insertCell(3).innerHTML = table.rows[1].cells[3].innerHTML
        row.insertCell(4).innerHTML =
            '<input type="text" id="txtexpnremk[]" name="txtexpnremk[]" class="form-control" value="" onBlur="validate_row(this)"/>'
        row.insertCell(5).innerHTML = table.rows[1].cells[5].innerHTML
    }
}

function deleteRow(r) {
    var row_index = r.parentNode.parentNode.rowIndex
    var arr_index = row_index - 1
    if (row_index == 1) {
        document.getElementById('txtheaddesc[]').selectedIndex = '0'
        document.getElementById('txtexpnamnt[]').value = '0.00'
        document.getElementById('txtexpnremk[]').value = ''
    } else {
        document.getElementById('dataTable').deleteRow(row_index)
    }
}

function save_data() {
    if (document.getElementById('txtdeptcode').value == 0) {
        alert('Please select client!')
        txtdeptcode.focus()
        return false
    }

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

    if (document.getElementById('txtacnttype').value == 0) {
        alert('Please select account type!')
        txtacnttype.focus()
        return false
    }

    var rowcount = $('#dataTable tr').length
    if (rowcount == 0) {
        alert('No details to save!')
        cmdview.focus()
        return false
    }

    var totl_rows = $('#dataTable tr').length - 1

    var head_desc = []
    var head_desc1 = document.getElementsByName('txtheaddesc[]')

    var expn_amnt = []
    var expn_amnt1 = document.getElementsByName('txtexpnamnt[]')

    var clnt_code = []
    var clnt_code1 = document.getElementsByName('txtclntcode[]')

    var expn_remk = []
    var expn_remk1 = document.getElementsByName('txtexpnremk[]')

    for (var i = 0; i < totl_rows; i++) {
        head_desc[i] = head_desc1[i].value
        expn_amnt[i] = expn_amnt1[i].value
        clnt_code[i] = clnt_code1[i].value
        expn_remk[i] = expn_remk1[i].value
    }

    $.ajax({
        type: 'POST',
        url: 'src/expense.php',
        dataType: 'json',
        data: {
            load_data: 'save_data',
            empl_code: document.getElementById('txtemplcode').value,
            dept_code: document.getElementById('txtdeptcode').value,
            acnt_type: document.getElementById('txtacnttype').value,
            expn_date: document.getElementById('txtexpndate').value,
            head_desc: head_desc,
            expn_amnt: expn_amnt,
            clnt_code: clnt_code,
            expn_remk: expn_remk,
        },
        cache: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            hide_process()
            clrs_data()
            alert(data.mesg)
        },
        error: function (data) {
            hide_process()
            $('#page-container-grid').html('Error: ' + data)
        },
    })
}