getQuery=(name)=>{
    return document.querySelectorAll(name);
}
let requiredFeild = getQuery(".required");
let requiredInput = getQuery("input");
let validateButton = getId("ValidationButton");
let cashPay=getId("cashPay");
    let bankPay=getId("bankPay");
    let advancePay=getId("advancePay");
    let pendingAmount =getId("pendingAmount");
    let advanceLimit = getId("advanceValue");
    let paymentMethod=getId("paymentMethod");
    let chequeNo=getId("chequeNo");
handleCalculation=(e)=>{
    console.log(e);
    let total = Number(cashPay.value)+Number(bankPay.value)+Number(advancePay.value);
    console.log(total);
    if(paymentMethod.value !="advance")
    {
        if(Number(pendingAmount.value)<Number(total))
        {
            alert();
            e.target.value="";
        }
    }
    if(paymentMethod.value== "advance")
    {
        if(Number(advanceLimit.innerHTML)<Number(advancePay.value)){
            alert("advance Exceed");
            e.target.value="";
        }
        if(Number(pendingAmount.value)<Number(total))
        {
            alert();
            e.target.value="";
        }
    }
}
handlePaymentMethod=()=>{   
    console.log(paymentMethod);
    if (paymentMethod.value=="cash")
    {
        cashPay.readOnly=false;
        advancePay.readOnly=true;
        bankPay.readOnly = true;
        chequeNo.readOnly=true;
        advancePay.value=0;
        bankPay.value=0;
        chequeNo.value="-";
        cashPay.focus();
    }
    if (paymentMethod.value=="bank")
    {
        cashPay.readOnly=true;
        advancePay.readOnly=true;
        bankPay.readOnly = false;
        chequeNo.readOnly=false;
        advancePay.value=0;
        cashPay.value=0;
        chequeNo.value="";
        bankPay.focus();
    }
    if (paymentMethod.value=="advance")
    {
        cashPay.readOnly=true;
        advancePay.readOnly=false;
        bankPay.readOnly = true;
        chequeNo.readOnly=true;
        cashPay.value=0;
        chequeNo.value="-";
        bankPay.value=0;
        advancePay.focus();
    }
    if (paymentMethod.value=="all")
    {
        cashPay.readOnly=false;
        advancePay.readOnly=false;
        bankPay.readOnly = false;
        chequeNo.readOnly=false;
        advancePay.value="";
        cashPay.value="";
        chequeNo.value="";
        bankPay.value="";
        cashPay.focus();
    }
    feildValidate();
}
advancePay.addEventListener("keyup",function(e){
    handleCalculation(e);
});
cashPay.addEventListener("keyup",function(){
    handleCalculation(e);
});
bankPay.addEventListener("keyup",function(){
    handleCalculation(e);
});
feildValidate=()=>{
    let validateFunction=true;
requiredFeild.forEach((data)=>{
    if(data.value==""){
        data.classList.remove("required");
        data.classList.add("requiredvalue");
        validateFunction=false;
        console.log(data);
    }
    else{
        data.classList.remove("requiredvalue");
        data.classList.add("required");
    }
});
console.log(validateFunction);
return validateFunction;
}
requiredInput.forEach((data)=>{
    data.addEventListener("focus",function(){
        data.classList.remove("requiredvalue");
        data.classList.add("required");
    })
    data.addEventListener("keyup",function(){
        data.classList.remove("requiredvalue");
        data.classList.add("required");
    })
    data.addEventListener("change",function(){
        data.classList.remove("requiredvalue");
        data.classList.add("required");
    })
});
validateButton.addEventListener("click",function(){
    if(!feildValidate())
    {
        return;
    }
    console.log("yes");
    getId("submitButton").click();
});