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

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <script>
        var Id;
        var OrgId;
        var OrgGroupId;
        var Group;
        var BatchId;
        var statusId;
        var Header = [];
        var ReHeader;
        $(document).ready(function () {
            var myurl = window.location.href;
            var keyval = myurl.split('?')[1].split('&');
            OrgId = parseInt(keyval[0].split('=')[1].toString());
            Id = OrgId = parseInt(keyval[0].split('=')[1].toString());
            Group = keyval[1].split('=')[1].toString();
            BatchId = parseInt(keyval[2].split('=')[1].toString());
            $.ajax({
                type: "POST",
                url: "FeePending.aspx/GetOrgId",
                data: JSON.stringify({ "Id": Id, "Group": Group }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    if (Group == "OrgId") {
                        Header[0] = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>"+
                         " <h5 class='page-title' ><a href='#' onclick='PageName()'>Fee Pending</a></h5>";
                        $("#HeaderLabel").text("MIS DashBoard");
                    }
                    else {
                        Header[0] = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>"+
                         " <h5 class='page-title' ><a href='#' onclick='PageName()'>Fee Pending</a></h5>";
                        $("#HeaderLabel").text("EIS DashBoard");
                    }

                    document.getElementById("HeaderTitle").innerHTML = Header;
                    ReHeader = document.getElementById("HeaderTitle").innerHTML;
                }
            });
            if (Group == "OrgId")
            { ReceiptBookDataBind(); }
            else { OrganizationGet(); }
           
        });

        function HeaderDisplay(id) {
            if (id == 1) {
                document.getElementById("ReceiptHead").style.display = "Block";
                document.getElementById("DivisionHead").style.display = "none";
                document.getElementById("StudentHead").style.display = "none";
                $("#ReceiptBook").hide();
                $("#DivisionClass").hide();
                document.getElementById("HeaderTitle").innerHTML = ReHeader;
                Header = [];
            }
            else if (id == 2) {
                document.getElementById("ReceiptHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "Block";
                document.getElementById("StudentHead").style.display = "none";
                $("#ReceiptBook").show();
                $("#DivisionClass").hide();

            }
        }

        function dashboardpage() {
            if (Group == "OrgId") {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + Id;
            }
            else {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id;
            }
        }
        function PageName() {
            if (Group == "OrgId") {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + Id;
            }
            else {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id;
            }
        }
        function OrganizationGet() {
            $.ajax({
                type: "POST",
                url: "FeePending.aspx/OrganizationGet",
                data: JSON.stringify({ "OrgId": OrgId, "BatchId": parseInt(BatchId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblOrg = "";
                    var total = 0;
                    if (obj != "") {
                        tblOrg += "<tr><th>Organization Name</th><th>Count</th></tr>";
                        $.each(obj, function (i, item) {

                            tblOrg += "<tr><td><a onclick='ReceiptBookDataBind(" + item.OrgId + ")'>" + item.OrganizationName + "</a></td><td>" + item.PendingAmount + "</td></tr>";
                            total += parseInt(item.PendingAmount);
                        });
                        tblOrg += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                        // Header += " <h5 class='page-title' style='display:Block' id='ClassName'><a href='#' onclick='HeaderDisplay(1)'>" + ClassName + "</a></h5>";
                    }
                    else { tblOrg += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblOrg").innerHTML = tblOrg;
                    document.getElementById("ReceiptHead").style.display = "none";
                    document.getElementById("OrgHead").style.display = "block";
                    // document.getElementById("HeaderTitle").innerHTML = Header;
                    statusId = 0;
                }
            });
        }
        function ReceiptBookDataBind(Id) {
            if (Group == "OrgId")
            { OrgGroupId = 0; }
            else { OrgGroupId = OrgId;; OrgId = Id; }
            $.ajax({
                type: "POST",
                url: "FeePending.aspx/ReceiptBookDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblReceipt = "";
                    var total = 0;
                    if (obj != "")
                    {
                        tblReceipt += "<tr><th>Receipt Book</th><th>Pending Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            // alert(item.DepartmentName);
                            tblReceipt += "<tr><td><a onclick='DivisionBookDataBind(" + item.ReceiptBookId + ",\"" + item.ReceiptBook + " \")'>" + item.ReceiptBook + "</a></td><td>" + item.PendingAmount + "</td></tr>";
                            total += parseInt(item.PendingAmount);
                        });
                        tblReceipt += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblReceipt += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                  
                    // alert(obj);
                    document.getElementById("tblReceipt").innerHTML = tblReceipt;
                    document.getElementById("ReceiptHead").style.display = "block";
                    document.getElementById("OrgHead").style.display = "none";
                }
            });
        }

        function DivisionBookDataBind(ReceiptBookId, ReceiptBook) {
           
            $.ajax({
                type: "POST",
                url: "FeePending.aspx/DivisionBookDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "ReceiptBookId": parseInt(ReceiptBookId), "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblDivision = "";
                    var total = 0;
                    Header[0] = ReHeader;
                    if (obj != "")
                    {
                        tblDivision += "<tr><th>Division Class</th><th>Pending Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            // alert(item.DepartmentName);
                            tblDivision += "<tr><td><a onclick='StudentDataBind(" + item.DivisionId + "," + ReceiptBookId + ",\"" + item.DivisionClass + "\")'>" + item.DivisionClass + "</a></td><td>" + item.PendingAmount + "</td></tr>";
                            total += parseInt(item.PendingAmount);
                        });
                        tblDivision += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                        Header [1]= " <h5 class='page-title'  id='ReceiptBook'><a href='#' onclick='HeaderDisplay(1)'>" + ReceiptBook + "</a></h5>";
                    }
                    else { tblDivision += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblDivision").innerHTML = tblDivision;
                    document.getElementById("HeaderTitle").innerHTML = '';
                    $.each(Header, function (i, item) {
                        // alert('' + Header[i]    );
                        document.getElementById("HeaderTitle").innerHTML += Header[i];

                    });
                    document.getElementById("ReceiptHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "Block";
                    statusId = 1;
                }
            });
        }
        function StudentDataBind(DivisionId, ReceiptBookId, DivisionClass) {
           
            $.ajax({
                type: "POST",
                url: "FeePending.aspx/StudentDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "DivisionId": parseInt(DivisionId), "ReceiptBookId": parseInt(ReceiptBookId), "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblStudent = "";
                    var total = 0;
                    if (obj != "")
                    {
                        tblStudent += "<tr><th>Student Code</th><th>Student Name</th><th>Pending Amount</th></tr>";
                        $.each(obj, function (i, item) {
                            // alert(item.DepartmentName);
                            tblStudent += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td><td style=' text-align: right'>" + item.PendingAmount + "</td></tr>";
                            total += parseInt(item.PendingAmount);
                        });
                        tblStudent += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold; text-align: right' colspan='2'>" + total + "</td></tr>";
                        Header [2]= " <h5 class='page-title' id='DivisionClass'><a href='#' onclick='HeaderDisplay(2)'>" + DivisionClass + "</a></h5>";
                    }
                    else { tblStudent += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblStudent").innerHTML = tblStudent;
                    document.getElementById("HeaderTitle").innerHTML = '';
                    $.each(Header, function (i, item) {
                        // alert('' + Header[i]    );
                        document.getElementById("HeaderTitle").innerHTML += Header[i];

                    });
                    document.getElementById("ReceiptHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "none";
                    document.getElementById("StudentHead").style.display = "Block";
                    statusId = 2;
                }
            });
        }
        function BackOrgFunction()
        {
            if (statusId == 0)
            {
                document.getElementById("ReceiptHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "none";
                document.getElementById("StudentHead").style.display = "none";
                document.getElementById("OrgHead").style.display = "block";
                statusId--;
            }
            else if( statusId == 2)
            {
                document.getElementById("ReceiptHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "Block";
                document.getElementById("StudentHead").style.display = "none";
                $("#ReceiptBook").show();
                $("#DivisionClass").hide();
                statusId--;
            }
           else if (statusId == 1) {
                document.getElementById("ReceiptHead").style.display = "Block";
                document.getElementById("DivisionHead").style.display = "none";
                document.getElementById("StudentHead").style.display = "none";
                $("#ReceiptBook").hide();
                $("#DivisionClass").hide();
                document.getElementById("HeaderTitle").innerHTML = ReHeader;
                Header = [];
                statusId--;
           }
           else
           {
               if (Group == "OrgId")
               { window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + OrgId; }
               else { window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id; }
           }
        }
        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
    <asp:UpdatePanel ID="DoctorScheduleUpdatePanel" runat="server">
        <ContentTemplate>
          <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"></label>
                </div>
                <input type="button" value="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" />
            </div>
            <div class="page-header row mb20">
                <div class="col-xl-12 col-sm-12 col-xs-12 border-bottom-inline xs-padd0">
                    <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">
                           <div class="himssuHeader1WireBox col-md-12 pTop5" id="OrgHead" style="display:block">
                                        <h3 class="table-topic">Organization</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblOrg' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                                    <div class="himssuHeader1WireBox col-md-12 pTop5" id="ReceiptHead" style="display:none">
                                        <h3 class="table-topic">Receipt Book</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblReceipt' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                         <div class="himssuHeader1WireBox col-md-12 pTop5" id="DivisionHead" style="display:none">
                                        <h3 class="table-topic">Division Class</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblDivision' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                            <div class="himssuHeader1WireBox col-md-12 pTop5" id="StudentHead" style="display:none">
                                        <h3 class="table-topic">Student List</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblStudent' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                    
                    </div>
                </div>
            </div>
            <script>
                function openNav() {
                    document.getElementById("mySidenav").style.width = "344px";
                }

                function closeNav() {
                    document.getElementById("mySidenav").style.width = "0";
                }
            </script>
          
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
