$(document).ready(function () {
    $("body").on("change", ".monthno,.billperiod", ChangeMon);
    ChangeMon();
    function ChangeMon() {

        var month = $(".monthno").val();
        var billperiod = $(".billperiod").val();
        var billperiod = $(".billperiod").val();
        var st = '', lt = '', sdate = '', ltdate = '';
        var fryear = $(".fryear").val();
        var toyear = $(".toyear").val();
        var date = new Date();
        st = '01';
//            lt = '31';
        sdate = new Date([toyear, month, "01"].join("-"));
        ltdate = new Date(toyear, sdate.getMonth() + 1, 0);
        lt = ("0" + ltdate.getDate()).slice(-2);
        var dd = '';


        var fdate = '';
        var tdate = '';
        if (month != '') {
            if (month <= 3) {
                fdate = [toyear, month, st].join("-");
                var adate = new Date([toyear, month, "01"].join("-"));
//                var lastdate = new Date(toyear, adate.getMonth() + 1, 0);
//                tdate = [toyear, month, ("0" + lastdate.getDate()).slice(-2)].join("-");
                tdate = [toyear, month, lt].join("-");
            } else {
                fdate = [fryear, month, st].join("-");
                var adate = new Date([fryear, month, st].join("-"));
//                var lastdate = new Date(fryear, adate.getMonth() + 1, 0);
                tdate = [fryear, month, lt].join("-");
            }
            $(".fdate").val(fdate);
            $(".tdate").val(tdate);
            $(".invdate").val(tdate);
        }
    }
});