$(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);
    function getTreatDet() {
        var tr = $(this).closest("tr"),
                vouchno = tr.find(".vouchno").val(),
                accode = tr.find(".accode").val(),
                addflg = '5',
                scheddate = tr.find(".scheddate").val(),
                treatment = tr.find(".treatment").val();
        $.post(
                "getTreatDet.php",
                {
                    vouchno: vouchno,
//                    vouchdt: vouchdt,
                    accode: accode,
                    scheddate: scheddate,
                    treatment: treatment,
                    addflg: addflg, 
                },
                function (data) {
                    $(".dettreatment").html("");

                    $(".dettreatment").html(data);
//                    $(".detTreatModal").modal("show");
                }
        );
    }
    getdata();
    getTrandata();


    function getConsultData() {
        var tr = $(this).closest("tr"),
                accode = tr.find(".accod").val(),
                vouchno = tr.find(".vouchno").val(),
                acttype = tr.find(".acttype").val();
        if (acttype == "P") {
            $.post("getDetailsCust.php", {vouchno: vouchno, acttype: acttype}, function (data) {
                $(".detailpatient").html(data);
                $(".detailModal").modal("show");
            })
        } else {
            window.open("patient.php?mode=edit&ajpara=C&accode=" + accode, "_blank");
        }
    }
    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");
////                }
//            });
//        }

});