<%@ page language="C#" autoeventwireup="true" inherits="Pages_MobileView_Default, App_Web_3jc1dqf5" masterpagefile="~/Pages/Common/MasterPages/MobileViewMasterPage.master" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <script>
        var OrgGroupId = 0;
        var Count = 0;
        var drpOrgGroup = '';
        var drpBatch = '';
        var OrgBatchId = 0;
        var OrgName = '';
        var StatusId;
        var SourceTypeId = 0;
        var UserId = 0;
        var CommonOrgGroupBatchId = 0;
        var ValReceiptBookId = 0;
        var ValCollectionId = 0;
        var SyncData = 0;
        //var FromDate = '';
        //var ToDate = '';

        $(document).ready(function () {
            debugger;
            var myurl = window.location.href;
            var keyval = myurl.split('?')[1].split('&');
            OrgName = keyval[0].split('=')[0].toString();
            OrgGroupId = parseInt(keyval[0].split('=')[1].toString());
            Count = parseInt(keyval[1].split('=')[1].toString());
            CommonOrgGroupBatchId = parseInt(keyval[2].split('=')[1].toString());
            //FromDate = keyval[3].split('=')[1].toString();
           // ToDate = keyval[4].split('=')[1].toString();
            //CommonOrgGroupBatchId = parseInt(keyval[2].split('=')[1].toString());
            //SourceTypeId = 95;
            //UserId = 1101000000088;
            // OrgGroupNameGet();
            if (Count == 1 || Count == 2)
            { PaidAndUnpaidClassWiseDataBind(); }
            else { ReceiptBookCollectionDataBind(); }

            //CurrentBatchGet();
            var tblDropdown = "<tr><th><select id='drpOrganization' onchange='OrganizationFunction()'><option value='0'>Select</option></select></th><th><select id='drpBatch' onchange='BatchFunction()'><option value='0'>Select</option></select></th></tr>";
            //  document.getElementById("tblDropdown").innerHTML = tblDropdown;



            // ReceiptBookCollectionDataBind();


        });
        function OrgGroupNameGet() {
            var OrgGroup = {};
            OrgGroup.attend = [];
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/GetOrgDropDownList",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    drpOrgGroup = (result.d);
                    $("#drpOrganization").html(drpOrgGroup);
                    CurrentBatchGet();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function OrganizationFunction() {

            OrgGroupId = $("#drpOrganization").val();
            // $("#drpOrganization").val(OrgGroupId);
            CurrentBatchGet();
        }
        function CurrentBatchGet() {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/GetBatch",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    drpBatch = (result.d);
                    // OrgBatchId = $("#drpBatch").val();

                    $("#drpBatch").html(drpBatch);
                    OrgBatchId = $("#drpBatch").val();
                    PaidAndUnpaidDataBind();

                    //alert(OrgBatchId);

                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function BatchFunction() {

            OrgBatchId = $("#drpBatch").val();
            // $("#drpBatch").val(OrgBatchId);
            PaidAndUnpaidDataBind();
        }
        function PaidAndUnpaidClassWiseDataBind() {
            $("#LoaderAttndLoader").css("display", "block");
            var OrgGroup = {};
            OrgGroup.attend = [];
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/PaidAndUnpaidClassWiseDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "OrgName": OrgName, "Count": parseInt(Count), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblPaidUnpaidClassWise = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        if (Count == 1) { tblPaidUnpaidClassWise += "<tr><th>Class</th><th>StudentCount</th><th>Paid Amount</th></tr>"; }
                        if (Count == 2) { tblPaidUnpaidClassWise += "<tr><th>Class</th><th>StudentCount</th><th>Pending Amount</th></tr>"; };
                        $.each(obj, function (i, item1) {
                            if (alreadyAdded.indexOf(item1.OrgGroupId) >= 0)
                            { }
                            else
                            {
                                tblPaidUnpaidClassWise += "<tr><th colspan='9'><b>" + item1.OrgGroupName + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.OrgGroupId === item1.OrgGroupId) {
                                        if (Count == 1)
                                        { tblPaidUnpaidClassWise += "<tr><td>" + item.ClassDivision + "</a></td><td>" + item.StudentCount + "</td><td><a onclick='PaidAndUnpaidDataBind(" + item.ClassId + ")'>" + item.PaidAmount + "</a></td></tr>"; }
                                        else if (Count == 2)
                                        { tblPaidUnpaidClassWise += "<tr><td>" + item.ClassDivision + "</a></td><td>" + item.StudentCount + "</td><td><a onclick='PaidAndUnpaidDataBind(" + item.ClassId + ")'>" + item.PendingAmount + "</a></td></tr>"; }
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.OrgGroupId);
                            }
                        });
                    }
                    else { tblPaidUnpaidClassWise += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblPaidUnpaidClassWise").innerHTML = tblPaidUnpaidClassWise;
                    document.getElementById("PaidAndUnpaidHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("PaidAndUnpaidHeadClassWise").style.display = "block";
                    
                    $("#LoaderAttndLoader").css("display", "none");
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }

        function PaidAndUnpaidDataBind(ClassId) {
            $("#LoaderAttndLoader").css("display", "block");
            var OrgGroup = {};
            OrgGroup.attend = [];
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/PaidAndUnpaidDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "OrgName": OrgName, "Count": parseInt(Count), "CommonOrgGroupBatchId": CommonOrgGroupBatchId, "ClassId": parseInt(ClassId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblPaidUnpaid = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        if (Count == 1) { tblPaidUnpaid += "<tr><th>Code</th><th>Name</th><th>Contact</th><th>Paid Amount</th></tr>"; }
                        if (Count == 2) { tblPaidUnpaid += "<tr><th>Code</th><th>Name</th><th>Contact</th><th>Pending Amount</th></tr>"; };
                        $.each(obj, function (i, item1) {
                            if (alreadyAdded.indexOf(item1.DivisionId) >= 0)
                            { }
                            else
                            {
                                tblPaidUnpaid += "<tr><th colspan='9'><b>" + item1.ClassDivision + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.DivisionId === item1.DivisionId) {
                                        if (Count == 1)
                                        { tblPaidUnpaid += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PaidAmount + "</td></tr>"; }
                                        else if (Count == 2)
                                        { tblPaidUnpaid += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PendingAmount + "</td></tr>"; }
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.DivisionId);
                            }
                           

                        });
                    }
                    else { tblPaidUnpaid += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblPaidUnpaid").innerHTML = tblPaidUnpaid;
                    document.getElementById("PaidAndUnpaidHead").style.display = "block";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("PaidAndUnpaidHeadClassWise").style.display = "none";
                    StatusId = 1
                    $("#LoaderAttndLoader").css("display", "none");
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }

        function SyncDataFunction() {
            SyncData = 1;
            ReceiptBookCollectionDataBind();
            location.reload();
        }

        function ReceiptBookCollectionDataBind() {
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidDetilsDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId, "SyncData": parseInt(SyncData) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                //async: false,
                success: function (result) {
                    var obj = (result.d);
                    var total = 0;
                    var finaltotal = 0;
                    var tblTotalCountDetail = "";

                    document.getElementById("tblTotalCountDetail").innerHTML = result.d;
                    document.getElementById("PaidAndUnpaidHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("PaidAndUnpaidHeadClassWise").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalCountDetailHead").style.display = "block";
                    $("#LoaderAttndLoader").css("display", "none");
                   // document.getElementById("CreateDate").innerHTML = obj[0].LastUpdatedDate;
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    //console.log(err.Message);
                    $("#LoaderDiv1").hide();
                }
            });
        }
        function ReceiptBookCollectionGroupDetailDataBind(ReceiptBookId, CollectionGroupId) {
            //$("#LoaderDiv").show();
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/ReceiptBookCollectionGroupDetailDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "OrgBatchId": parseInt(OrgBatchId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionGroupId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblReceiptDetail = "";
                    ///  var total = 0;
                    if (obj != "") {
                        tblReceiptDetail += "<tr><th>Receipt No</th><th>Code</th><th>Name</th><th>Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            if (Count == 1 || Count == 2)
                            { tblReceiptDetail += "<tr><td>" + item.ReceiptNumber + "</td><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ReceiptAmount + "</td></tr>"; }
                            else if (Count == 3)
                            { tblReceiptDetail += "<tr><td>" + item.ReceiptNumber + "</td><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ReceiptAmount + "</td></tr>"; }

                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblReceiptDetail += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblReceiptDetail").innerHTML = tblReceiptDetail;
                    document.getElementById("ReceiptCollectionHead").style.display = "none";
                    document.getElementById("ReceiptDetailHead").style.display = "block";
                    StatusId = 1
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function TotalPaidCount(ReceiptBookId, CollectionId) {
            ValReceiptBookId = ReceiptBookId;
            ValCollectionId = CollectionId;
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPaid = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        tblTotalPaid += "<tr><th>Class Name</th><th>Student Count</th><th>Paid Amount</th></tr>";
                        $.each(obj, function (j, item1) {

                            if (alreadyAdded.indexOf(item1.OrgGroupId) >= 0)
                            { }
                            else
                            {
                                tblTotalPaid += "<tr><th colspan='9'>" + item1.OrgGroupName + "</th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.OrgGroupId === item1.OrgGroupId) {
                                        //$("#drpClassAndMonthWiseFunction").on("change ", function () {
                                        //    alert($(this).val());
                                        //});
                                        tblTotalPaid += "<tr><td>" + item.ClassDivision + "</td><td>" + item.StudentCount + "</td><td><a onclick='PaidCountSubDetails(" + ReceiptBookId + ",\"" + CollectionId + "\",\"" + item.ClassId + "\")'>" + item.PaidAmount + "</a></td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.OrgGroupId);
                            }
                            
                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalPaid += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblTotalPaid").innerHTML = tblTotalPaid;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "block";
                    StatusId = 1
                    $("#LoaderAttndLoader").css("display", "none");
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }

        function ClassAndMonthWiseFunction()
        {
            //alert(ValReceiptBookId);
            //alert(ValCollectionId);
            var ClassAndMonthWise = $('#drpClassAndMonthWiseFunction').val();
            if (ClassAndMonthWise == 1)
            {
                $.ajax({
                    type: "POST",
                    url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidDataBindMonthWise",
                    data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ValReceiptBookId), "CollectionGroupId": parseInt(ValCollectionId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        //alert(result.d);
                        var obj = (result.d);
                        var tblTotalPaid = "";
                        ///  var total = 0;
                        var alreadyAdded = [];
                        if (obj != "") {
                             tblTotalPaid += "<tr><th>Month</th><th>Paid Amount</th></tr>"; 
                            $.each(obj, function (j, item1) {

                                if (alreadyAdded.indexOf(item1.OrgGroupId) >= 0)
                                { }
                                else
                                {
                                    tblTotalPaid += "<tr><th colspan='9'>" + item1.OrgGroupName + "</th></tr>";
                                    $.each(obj, function (i, item) {
                                        if (item.OrgGroupId === item1.OrgGroupId) {
                                            tblTotalPaid += "<tr><td>" + item.MonthName + "</td><td><a onclick='PaidCountSubDetailsMonthWise(" + ValReceiptBookId + ",\"" + ValCollectionId + "\",\"" + item.Month + "\")'>" + item.PaidAmount + "</a></td></tr>";
                                        }
                                        else {
                                        }
                                    });
                                    alreadyAdded.push(item1.OrgGroupId);
                                }

                                //total += parseInt(item.StudentCount);
                            });
                            //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                        }
                        else { tblTotalPaid += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                        document.getElementById("tblTotalPaid").innerHTML = tblTotalPaid;
                        document.getElementById("TotalCountDetailHead").style.display = "none";
                        document.getElementById("TotalPaidHead").style.display = "block";
                        StatusId = 1
                        $("#LoaderAttndLoader").css("display", "none");
                        // console.log(Header);
                    },
                    error: function (xhr, status, error) {
                        var err = eval("(" + xhr.responseText + ")");
                        console.log(err.Message);
                        // $("#LoaderDiv1").hide();
                    }
                });
            }
            else
            {
                TotalPaidCount(ValReceiptBookId, ValCollectionId);
            }
               
        }

        function PaidCountSubDetailsMonthWise(ReceiptBookId, CollectionId, Month)
        {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidSubDetailsDataBindMonthWise",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "Month": parseInt(Month), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPaidSubDetails = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        tblTotalPaidSubDetails += "<tr><th>Code</th><th> Name</th><th>Contact</th><th>Paid Amount</th></tr>";
                        $.each(obj, function (i, item1) {
                            if (alreadyAdded.indexOf(item1.DivisionId) >= 0)
                            { }
                            else
                            {
                                tblTotalPaidSubDetails += "<tr><th colspan='9'><b>" + item1.ClassDivision + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.DivisionId === item1.DivisionId) {
                                        tblTotalPaidSubDetails += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PaidAmount + "</a></td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.DivisionId);
                                // alert(item.ClassId);
                            }

                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalPaidSubDetails += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblTotalPaidSubDetails").innerHTML = tblTotalPaidSubDetails;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPaidSubDetailsHead").style.display = "block";
                    StatusId = 2
                    $("#LoaderAttndLoader").css("display", "none");
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function TotalPendingCount(ReceiptBookId, CollectionId) {
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPendingDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPending = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        tblTotalPending += "<tr><th>Class Name</th><th>Class Name</th><th>Pending Amount</th></tr>";
                        $.each(obj, function (i, item1) {

                            if (alreadyAdded.indexOf(item1.OrgGroupId) >= 0)
                            { }
                            else
                            {
                                tblTotalPending += "<tr><th colspan='9'><b>" + item1.OrgGroupName + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.OrgGroupId === item1.OrgGroupId) {
                                        tblTotalPending += "<tr><td>" + item.ClassDivision + "</td><td>" + item.StudentCount + "</td><td><a onclick='PendingCountSubDetails(" + ReceiptBookId + ",\"" + CollectionId + "\",\"" + item.ClassId + "\")'>" + item.PendingAmount + "</td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.OrgGroupId);
                            }
                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalPending += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblTotalPending").innerHTML = tblTotalPending;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "block";
                    //$("#LoaderDiv3").hide();
                    $("#LoaderAttndLoader").css("display", "none");
                    // console.log(Header);
                    StatusId = 1;
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function PendingCountSubDetails(ReceiptBookId, CollectionId, ClassId) {
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/PendingCountSubDetails",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "ClassId": parseInt(ClassId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tbPendingSubDetails = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        tbPendingSubDetails += "<tr><th>Code</th><th> Name</th><th>Contact</th><th>Pending Amount</th></tr>";
                        $.each(obj, function (i, item1) {

                            if (alreadyAdded.indexOf(item1.DivisionId) >= 0)
                            { }
                            else
                            {
                                tbPendingSubDetails += "<tr><th colspan='9'><b>" + item1.ClassDivision + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.DivisionId === item1.DivisionId) {
                                        tbPendingSubDetails += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PendingAmount + "</a></td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.DivisionId);
                                // alert(item.ClassId);
                            }
                                //total += parseInt(item.StudentCount);
                            });
                        
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalCountSubDetails += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tbPendingSubDetails").innerHTML = tbPendingSubDetails;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("TotalCountSubDetailsHead").style.display = "none";
                    document.getElementById("PendingSubDetailsHead").style.display = "block";
                    StatusId = 4;
                    $("#LoaderAttndLoader").css("display", "none");
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function TotalCount(ReceiptBookId, CollectionId) {
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalCountDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalSub = "";
                    var alreadyAdded = [];
                    var alreadyAdded1 = [];
                    ///  var total = 0;
                    if (obj != "") {
                        tblTotalSub += "<tr><th>Class Name</th><th>Student Count</th><th>Total Amount</th></tr>";
                        $.each(obj, function (j, item1) {
                            if (alreadyAdded.indexOf(item1.OrgGroupId) >= 0)
                            { }
                            else
                            {
                                tblTotalSub += "<tr><th colspan='9'>" + item1.OrgGroupName + "</th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.OrgGroupId === item1.OrgGroupId) {
                                        tblTotalSub += "<tr><td>" + item.ClassDivision + "</td><td>" + item.StudentCount + "</td><td><a onclick='TotalCountSubDetails(" + ReceiptBookId + ",\"" + CollectionId + "\",\"" + item.ClassId + "\")'>" + item.TotalAmount + "</td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.OrgGroupId);
                            }
                            
                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalSub += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblTotalSub").innerHTML = tblTotalSub;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "block";
                    StatusId = 1
                    $("#LoaderAttndLoader").css("display", "none");
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function TotalCountSubDetails(ReceiptBookId, CollectionId, ClassId) {
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalCountSubDetailsDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "ClassId": parseInt(ClassId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalCountSubDetails = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        tblTotalCountSubDetails += "<tr><th>Code</th><th> Name</th><th>Contact</th><th>Total Amount</th></tr>";
                        $.each(obj, function (i, item1) {
                            if (alreadyAdded.indexOf(item1.DivisionId) >= 0)
                            { }
                            else
                            {
                                tblTotalCountSubDetails += "<tr><th colspan='9'><b>" + item1.ClassDivision + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.DivisionId === item1.DivisionId) {
                                        tblTotalCountSubDetails += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.TotalAmount + "</a></td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.DivisionId);
                                // alert(item.ClassId);
                            }                           
                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalCountSubDetails += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblTotalCountSubDetails").innerHTML = tblTotalCountSubDetails;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalCountSubDetailsHead").style.display = "block";
                    StatusId = 3;
                    $("#LoaderAttndLoader").css("display", "none");
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function PaidCountSubDetails(ReceiptBookId, CollectionId, ClassId) {
            $("#LoaderAttndLoader").css("display", "block");
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidSubDetailsDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "ClassId": parseInt(ClassId), "CommonOrgGroupBatchId": CommonOrgGroupBatchId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPaidSubDetails = "";
                    ///  var total = 0;
                    var alreadyAdded = [];
                    if (obj != "") {
                        tblTotalPaidSubDetails += "<tr><th>Code</th><th> Name</th><th>Contact</th><th>Paid Amount</th></tr>";
                        $.each(obj, function (i, item1) {
                            if (alreadyAdded.indexOf(item1.DivisionId) >= 0)
                            { }
                            else
                            {
                                tblTotalPaidSubDetails += "<tr><th colspan='9'><b>" + item1.ClassDivision + "</b></th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.DivisionId === item1.DivisionId) {
                                        tblTotalPaidSubDetails += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PaidAmount + "</a></td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.DivisionId);
                                // alert(item.ClassId);
                            }
                            
                            //total += parseInt(item.StudentCount);
                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblTotalPaidSubDetails += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblTotalPaidSubDetails").innerHTML = tblTotalPaidSubDetails;
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPaidSubDetailsHead").style.display = "block";
                    StatusId = 2
                    $("#LoaderAttndLoader").css("display", "none");
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }
        function BackOrgFunction() {
            if (Count == 1 || Count == 2) {
                if(StatusId == 1)
                {
                    document.getElementById("PaidAndUnpaidHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("PaidAndUnpaidHeadClassWise").style.display = "block";
                    StatusId--;
                }
                else { if (OrgName == 'OrgGroupId' ? window.location.href = "../MobileView/ConsolidateDashBoard.aspx" : window.location.href = "../MobileView/MISConsolidateDashBoard.aspx"); }

            } else if (StatusId == 4) {
                document.getElementById("TotalCountDetailHead").style.display = "none";
                document.getElementById("TotalPaidHead").style.display = "none";
                document.getElementById("TotalPendingHead").style.display = "block";
                document.getElementById("TotalSubHead").style.display = "none";
                document.getElementById("TotalCountSubDetailsHead").style.display = "none";
                document.getElementById("PendingSubDetailsHead").style.display = "none";
                StatusId = 1;
            } else if (StatusId == 3) {
                document.getElementById("TotalCountDetailHead").style.display = "none";
                document.getElementById("TotalPaidHead").style.display = "none";
                document.getElementById("TotalPendingHead").style.display = "none";
                document.getElementById("TotalSubHead").style.display = "block";
                document.getElementById("TotalCountSubDetailsHead").style.display = "none";
                StatusId =1;
            } else if (StatusId == 1) {
                document.getElementById("TotalCountDetailHead").style.display = "block";
                document.getElementById("TotalPaidHead").style.display = "none";
                document.getElementById("TotalPendingHead").style.display = "none";
                document.getElementById("TotalSubHead").style.display = "none";
                StatusId--;
            }
            else {
                if (StatusId == 2) {
                    document.getElementById("TotalCountDetailHead").style.display = "none";
                    document.getElementById("TotalPaidHead").style.display = "block";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    document.getElementById("TotalPaidSubDetailsHead").style.display = "none";
                    StatusId--;
                }
                else if (StatusId == 1) {
                    document.getElementById("TotalCountDetailHead").style.display = "block";
                    document.getElementById("TotalPaidHead").style.display = "none";
                    document.getElementById("TotalPendingHead").style.display = "none";
                    document.getElementById("TotalSubHead").style.display = "none";
                    StatusId--;
                } else { window.location.href = "../MobileView/ConsolidateDashBoard.aspx"; }
            }
        }
        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
    <asp:UpdatePanel ID="DoctorScheduleUpdatePanel" runat="server">
        <ContentTemplate>
            <div class="page-header row mb20">
                <div class="col-xl-12 col-sm-12 col-xs-12 border-bottom-inline padd-0">
                    <div class="col-md-12 ptb12 d-inline-flex">
                        <span class='btn btn-home btn-icon' onclick='DashBoard()' title='home'><span><i class='material-icons'>home</i></span></span>
                        <div class="d-inline-flex w-100">
                            <label class="header-topic justify-content-center" id="HeaderLabel">Consolidate DashBoard</label>
                        </div>
                        <input type="button" value="&#8635;" id="btnUpdate" onclick="SyncDataFunction()" skinid="0" class="float-right btn btn-back btn-icon fas"/>
                        <input type="button" value="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" />
                    </div>
                    <div class="main-topic inner" id="HeaderTitle">
                    </div>
                </div>
            </div>
            
            <div id="LoaderAttndLoader" style="display: none; position: absolute; left: 0; top: 0px; width: 100%; height: 100%; z-index: 99;">
                <div class="se-pre-con1"></div>
            </div>
            <div class="bg-white row center-block">
                <div class="container-fluid">
                    <div class="gutters-tiny push js-appear-enabled animated fadeIn overflow-hidden" data-toggle="appear">
                        <%--<input type="button" value="Back" id="bntBack1" onclick="BackFunction1()" style="display:none" />
                        <input type="button" value="Back" id="bntBack2" onclick="BackFunction2()" style="display:none" />--%>
                       <div class="himssuHeader1WireBox col-md-12 pTop5" id="PaidAndUnpaidHeadClassWise">
                            <h3 class="table-topic">Paid And Unpaid Class Wise</h3>
                           
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <%--    <table id='tblDropdown' class='table table-striped table-bordered'>
                                    </table>--%>
                                    <table id='tblPaidUnpaidClassWise' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>

                        </div>
                          <div class="himssuHeader1WireBox col-md-12 pTop5" id="PaidAndUnpaidHead" style="display: none">
                            <h3 class="table-topic">Paid And Unpaid Amount</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <%--    <table id='tblDropdown' class='table table-striped table-bordered'>
                                    </table>--%>
                                    <table id='tblPaidUnpaid' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>

                        </div>
                        <div class="himssuHeader1WireBox col-md-12 padd-0" id="TotalCountDetailHead" style="display: none">
                            <h3 class="table-topic">Total Count Detail</h3>
                              <%--<span class="table-topic date-topic" id="CreateDate"></span>--%>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent table-responsive'>
                                <div class="zui-wrapper">
                                    <div class="zui-scroller">
                                        <table id='tblTotalCountDetail' class='table table-striped consolidate zui-table'>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv1" style="display: none"></div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="TotalPaidHead" style="display: none">
                            <h3 class="table-topic">Total Paid Amount</h3><br />
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                             <select id='drpClassAndMonthWiseFunction' onchange="ClassAndMonthWiseFunction()">
                                    <option selected="selected" value='0'>Class</option> 
                                 <option  value='1'>Month</option> 
                                </select><br />
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblTotalPaid' class='table table-striped'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv2" style="display: none"></div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="TotalPendingHead" style="display: none">
                            <h3 class="table-topic">Total Pending</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblTotalPending' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv3" style="display: none"></div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="PendingSubDetailsHead" style="display: none">
                            <h3 class="table-topic">Total PaidSub Details </h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tbPendingSubDetails' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv7" style="display: none"></div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="TotalSubHead" style="display: none">
                            <h3 class="table-topic">Total Sub </h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblTotalSub' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv4" style="display: none"></div>
                        </div>
                          <div class="himssuHeader1WireBox col-md-12 pTop5" id="TotalCountSubDetailsHead" style="display: none">
                            <h3 class="table-topic">Total PaidSub Details </h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblTotalCountSubDetails' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv6" style="display: none"></div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="TotalPaidSubDetailsHead" style="display: none">
                            <h3 class="table-topic">Total PaidSub Details </h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblTotalPaidSubDetails' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv5" style="display: none"></div>
                        </div>
                        <%--   <input type="hidden" id="Departmentid" runat="server" />
                         <input type="hidden" id="ClassHiddenId" runat="server" />
                         <input type="hidden" id="DivisionHiddenId" runat="server" />--%>
                    </div>
                </div>
            </div>



        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>
