getId=(idName)=>{
    return document.getElementById(idName);
}
handlePaymentMethodEdit=()=>{   
    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;
        cashPay.focus();
    }
    feildValidate();
}
$(document).ready(function(){
    let customer = $("#customerAdd").val();
    $.ajax({
        type:'POST',
        url:'ajaxpath1/fetch_amount_details_debit.php',
        data:{customer:customer},
        success:function(data){
        var output = data.split("||");
        var total = Number(cashPay.value)+Number(bankPay.value)+Number(advancePay.value)+Number(output[1]);
        $("#totalAmount").val(output[0]);
        $("#pendingAmount").val(total);
        $("#advanceText").hide();
        $("#advanceValue").hide();
        feildValidate();
        handlePaymentMethodEdit();
                    }
       });  
    $("#advanceText").hide();
    $("#advanceValue").hide();
    $("#customerAdd").on("change",function(){
       
        $.ajax({
            type:'POST',
            url:'ajaxpath1/fetch_amount_details_debit.php',
            data:{customer:customer},
            success:function(data){
            var output = data.split("||");
            $("#totalAmount").val(output[0]);
            $("#pendingAmount").val(output[1]);
            $("#paymentMethod").trigger('change').val(null);
            $("#advanceText").hide();
            $("#advanceValue").hide();
            feildValidate();
                        }
           });  
    });
    $("#paymentMethod").on("change",function(){
        handlePaymentMethod();
        $("#advanceText").hide();
    $("#advanceValue").hide();
        let customer = $("#customerAdd").val();
        let paymentMethod = $("#paymentMethod").val();
        if(paymentMethod=="advance"||paymentMethod=="all"){
        $.ajax({
            type:'POST',
            url:'ajaxpath1/fetch_advance_amount.php',
            data:{customer:customer,payment:paymentMethod},
            success:function(data){
            $("#advanceText").show();
            $("#advanceValue").show();
            $("#advanceValue").html(data);
                        }
           });
        }  
    });
});