<%@ page language="C#" autoeventwireup="true" inherits="Pages_MobileView_MobileConsolidateFeeStatusDashBoard, App_Web_3socqsrv" 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 StatusId;
        $(document).ready(function () {
            var myurl = window.location.href;
            var keyval = myurl.split('?')[1].split('&');
            OrgGroupId = parseInt(keyval[0].split('=')[1].toString());
            Count = parseInt(keyval[1].split('=')[1].toString());
            SourceTypeId = parseInt(keyval[2].split('=')[1].toString());
            UserSourceId = parseInt(keyval[3].split('=')[1].toString());
         
            // OrgGroupNameGet();
            if (Count == 1 || Count == 2)
            { PaidAndUnpaidDataBind(); }
            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 PaidAndUnpaidDataBind() {
            var OrgGroup = {};
            OrgGroup.attend = [];
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/PaidAndUnpaidDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "Count": parseInt(Count) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblPaidUnpaid = "";
                    ///  var total = 0;
                    if (obj != "") {
                        if (Count == 1) { tblPaidUnpaid += "<tr><th>Org Id</th><th>Class</th><th>Code</th><th>Name</th><th>Contact</th><th>Paid Amount</th></tr>"; }
                        if (Count == 2) { tblPaidUnpaid += "<tr><th>Org Id</th><th>Class</th><th>Code</th><th>Name</th><th>Contact</th><th>Pending Amount</th></tr>"; };
                        $.each(obj, function (i, item) {
                            if (Count == 1)
                            { tblPaidUnpaid += "<tr><td>" + item.OrgGroupId + "</td><td>" + item.ClassDivision + "</td><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.OrgGroupId + "</td><td>" + item.ClassDivision + "</td><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PendingAmount + "</td></tr>"; }

                        });
                    }
                    else { tblPaidUnpaid += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblPaidUnpaid").innerHTML = tblPaidUnpaid;
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }

        function ReceiptBookCollectionDataBind() {
            $("#bntBackOrg").hide();
            $("#LoaderDiv1").show();
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidDetilsDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "SourceTypeId": parseInt(SourceTypeId), "UserId": parseInt(UserSourceId) }),
                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("TotalSubHead").style.display = "none";
                    document.getElementById("TotalCountDetailHead").style.display = "block";
                    $("#LoaderDiv1").hide();
                },
                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) {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPaid = "";
                    ///  var total = 0;
                    if (obj != "") {
                        tblTotalPaid += "<tr><th>Org Id</th><th>Class Name</th><th>Paid Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            tblTotalPaid += "<tr><td>" + item.OrgGroupId + "</td><td>" + item.ClassDivision + "</td><td><a onclick='PaidCountSubDetails(" + ReceiptBookId + ",\"" + CollectionId + "\",\"" + item.DivisionId + "\")'>" + item.PaidAmount + "</a></td></tr>";
                            //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
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                    $("#bntBackOrg").show();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    $("#bntBackOrg").hide();
                    // $("#LoaderDiv1").hide();
                }
            });
        }

        function TotalPendingCount(ReceiptBookId, CollectionId) {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPendingDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPending = "";
                    ///  var total = 0;
                    if (obj != "") {
                        tblTotalPending += "<tr><th>Org Id</th><th>Class Name</th><th>Pending Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            tblTotalPending += "<tr><td>" + item.OrgGroupId + "</td><td>" + item.ClassDivision + "</td><td>" + item.PendingAmount + "</td></tr>";
                            //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";
                    StatusId = 1
                    $("#bntBackOrg").show();
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                    $("#bntBackOrg").hide();
                }
            });
        }

        function TotalCount(ReceiptBookId, CollectionId) {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalCountDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalSub = "";
                    ///  var total = 0;
                    if (obj != "") {
                        tblTotalSub += "<tr><th>Org Id</th><th>Class Name</th><th>Total Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            tblTotalSub += "<tr><td>" + item.OrgGroupId + "</td><td>" + item.ClassDivision + "</td><td>" + item.TotalAmount + "</td></tr>";
                            //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
                   $("#bntBackOrg").show();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    $("#bntBackOrg").hide();
                    // $("#LoaderDiv1").hide();
                }
            });
        }

        function PaidCountSubDetails(ReceiptBookId, CollectionId, DivisionId) {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeStatusDashBoard.aspx/TotalPaidSubDetailsDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "ReceiptBookId": parseInt(ReceiptBookId), "CollectionGroupId": parseInt(CollectionId), "DivisionId": parseInt(DivisionId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    var obj = (result.d);
                    var tblTotalPaidSubDetails = "";
                    ///  var total = 0;
                    if (obj != "") {
                        tblTotalPaidSubDetails += "<tr><th>Code</th><th> Name</th><th>Contact</th><th>Paid Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            // alert(item.ClassId);
                            tblTotalPaidSubDetails += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td>" + item.ParentContactNo + "</td><td>" + item.PaidAmount + "</a></td></tr>";
                            //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
                    $("#bntBackOrg").show();
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                    $("#bntBackOrg").hides();
                }
            });
        }
        function BackOrgFunction() {
            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) {
                $("#bntBackOrg").hide();
                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="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" style="display:none;"/>
                    </div>
                    <div class="main-topic inner" id="HeaderTitle">
                    </div>
                </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="PaidAndUnpaidHead">
                            <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>
                            <%-- <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>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblTotalPaid' class='table table-striped'>
                                    </table>
                                </div>
                            </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>
                        <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>
                        <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>
                        <%--   <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>
