$(document).ready(function () {
    $('body').on('change', '.monthno, .yearno', getdata);
    $('body').on('click', '.caltick', getTrandata);
    $('body').on('click', '.ts-entry', getConsultData);
    $('body').on('click', '.treatdet', getTreatDet);

    getdata();
    getTrandata();
 
    
    $(".detailModal").on("hidden.bs.modal", function () {
        $(".detTreatModal").modal("hide");
    });

    function getConsultData() {
        var tr = $(this).closest("tr"),
                vouchno = tr.find(".vouchno").val(),
                acttype = tr.find(".acttype").val();
        $.post("getDetailsCust2.php", {vouchno: vouchno, acttype: acttype}, function (data) {
            $(".detailpatient").html(data);
            $(".detailModal").modal({
                backdrop: "static",
                keyboard: false,
                show:true,
            });
            // $(".detailModal").modal("show");
            
        })


    }

    function getTreatDet() {
        var tr = $(this).closest("tr"),
                vouchno = $(".vouchno").val(),
                vouchdt = $(".vouchdt").val(),
                accode = $(".accode").val(),
                addflg = $(".addflg").val(),
                scheddate = tr.find(".scheddate").val(),
                treatment = tr.find(".streatment").val();
        $.post(
                "getTreatDet2.php",
                {
                    vouchno: vouchno,
                    vouchdt: vouchdt,
                    accode: accode,
                    scheddate: scheddate,
                    treatment: treatment,
                    addflg: addflg,
                },
                function (data) {
                    $(".dettreatment").html(data);

                    $(".detTreatModal").modal("show");
                }
        );
    }


    function getdata() {
        var monthno = $(".monthno").val(),
                yearno = $(".yearno").val();
        $.post('get_calendarnew.php', {yearno: yearno, monthno: monthno}, function (data) {
            $(".tbody").html(data);
        });
    }
    function getTrandata() {
        var id = $(this).attr("id"),
                sid = "";
        if (id == undefined) {
            sid = "today";
        } else {
            sid = id;
        }
        $.post('get_calendartran.php', {sid: sid}, function (data) {
            $(".apointtbody").html(data);
        });
    }
//        function getday() {
//            var dt = $(".vouchdt").val();
//            $.post('getday.php', {date: dt}, function (data) {
//                var dtt = data.dte;
//                $("#day").val(dtt);
////                if(dtt == "Saturday"){
////                    $("#day").css("color","red");
////                }
//            });
//        }

});