$(document).ready(function () {

    $("body").on("change", '.expense', getItemDt);

    $("body").on("change blur", '.vouchdt, .expense', getEntryList);

    getEntryList();

    function getEntryList() {
        var vouchdt = $(".vouchdt").val();

        $.post('ShowEntryList.php', { vouchdt: vouchdt }, function (data) {
            $(".tbodyy").html(data);
        });
    }


    getItemDt();

    function getItemDt() {
        var item = $(".expense").val();

        $.post('getItemDt.php', { item: item }, function (data) {
            $(".txtunit").text(data);
            $(".unit").val(data);
        });
    }

    $("form").on("submit", function (e) {
        var amount = parseFloat($(".amount").val());
        var paidby = $(".paidby").val();

        if (paidby != 'R') {
            if (isNaN(amount) || amount === 0) {
                alert("Amount cannot be zero.");
                e.preventDefault(); // Stop form submission
                return false;
            }
        }
    });

});