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

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <script src="../../App_Themes/mis_db/JavaScript/jquery-3.3.1.min.js"></script>
    <script>
        var OrgGroupId = 0;
        var Count = 0;
        var drpOrgGroup = '';
        var drpBatch = '';
        var OrgBatchId = 0;
        var StatusId;
        var DeptRole1;
        var CommonOrgGroupBatchId = 0
        $(document).ready(function () {
            var myurl = window.location.href;
            var url = decodeURIComponent(myurl);
            console.log(url);
            var keyval = myurl.split('?')[1].split('&');
            var click = "", sourcetypeId = "";
            OrgGroupId = parseInt(keyval[0].split('=')[1].toString());
            CommonOrgGroupBatchId = parseInt(keyval[1].split('=')[1].toString());
            TypeWiseTransportSummaryDataBind();

            //$(document).on("change", "#drpDeptRole", function (e) {
            //    DeptRole($("#hdnclick").val(), OrgGroupId, $("#hdnSource").val())
            //});
        });

        function OrgGroupNameGet() {
            var OrgGroup = {};
            OrgGroup.attend = [];
            $.ajax({
                type: "POST",
                url: "ConsolidateReceiptDetailsDashBoard.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: "ConsolidateReceiptDetailsDashBoard.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);


                    //alert(OrgBatchId);

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

        function TypeWiseTransportSummaryDataBind() {
            $.ajax({
                //async: false,
                type: "POST",
                url: "SummariseTransportSummaryDashBoard.aspx/TypeWiseTransportSummaryDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "CommonOrgGroupBatchId": parseInt(CommonOrgGroupBatchId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblTypeWiseDashBoardSummary = "";
                    var total = 0;
                    var itemname = "";
                    debugger;
                    if (obj != "") {
                        tblTypeWiseDashBoardSummary += "<tr><th>Route Name</th><th>Student Count</th></tr>";
                        $.each(obj, function (i, item) {
                            if (item.Transport != itemname) {
                                tblTypeWiseDashBoardSummary += "<tr><td colspan='2' style='font-weight:bold' align='Center'>" + item.Transport + "</td></tr>";
                                itemname = item.Transport;
                            }
                            
                            tblTypeWiseDashBoardSummary += "<tr><td><a onclick='BusRouteTransportDashBoardSummary(" + item.BusRouteID + ",\"" + OrgGroupId + "\",\"" + CommonOrgGroupBatchId + "\")'>" + item.Route + "</a></td><td><a onclick='StudentDetailTransportDashBoardSummary(" + item.BusRouteID + ",\"" + OrgGroupId + "\",\"" + CommonOrgGroupBatchId + "\")'>" + item.StudentCount + "</a></td></tr>";
                            total += parseInt(item.StudentCount);
                        });
                        tblTypeWiseDashBoardSummary += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else {
                        tblTypeWiseDashBoardSummary += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>";
                    }
                    document.getElementById("tblTypeWiseDashBoardSummary").innerHTML = tblTypeWiseDashBoardSummary;
                },
                complete: function () {
                    $("#UserSummaryLoader").hide();
                    $("#LoaderDiv1").hide();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    $("#LoaderDiv1").hide();
                    $("#UserSummaryLoader").hide();
                }
            });
        }


        function BusRouteTransportDashBoardSummary(BusRouteId, OrgGroupID, CommonOrgGroupBatchId) {
            $.ajax({
                type: "POST",
                url: "SummariseTransportSummaryDashBoard.aspx/TypeDetailsTransportSummaryDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "CommonOrgGroupBatchId": parseInt(CommonOrgGroupBatchId), "BusRouteId": parseInt(BusRouteId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",

                success: function (result) {
                    debugger;
                    var obj = (result.d);
                    var tblDetailsTransportSummary = "";
                    if (obj != "") {
                        $.each(obj, function (i, item) {
                            tblDetailsTransportSummary +=
                                "<tr><td>Bus Route</td><td>" + item.Route + "</td></tr> " +
                                "<tr><td>Vehicle</td><td>" + item.Vehicle +
                                "</tr><tr></td><td>Registration Number</td><td>" + item.RegistrationNumber +
                                "</tr><tr></td><td>Driver Name</td><td>" + item.DriverName +
                                "</tr><tr></td><td>Driver Mobile No</td><td>" + item.DriverNo +
                                "</tr><tr></td><td>Conductor Name </td><td>" + item.ConductorName +
                                "</tr><tr></td><td>Conductor Mobile No</td><td>" + item.ConductorNo + "</td></tr>";

                        });
                    }


                    else {
                        tblDetailsTransportSummary += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>";
                    }
                    document.getElementById("tblBusRouteDashBoardSummary").innerHTML = tblDetailsTransportSummary;                    
                    document.getElementById("TypeWiseUserSummaryHead").style.display = "none";
                    document.getElementById("TypeBusRouteSummaryHead").style.display = "block";
                    BusRouteDetailTransportDashBoardSummary(BusRouteId, OrgGroupID, CommonOrgGroupBatchId);                    
                    // $("#LoaderDiv1").hide();
                    // console.log(Header);

                    //if (obj != "") {
                    //    $.each(obj, function (i, item) {
                    //        tblDetailsTransportSummary += "<tr><td>Bus Route</td><td>Vehicle</td><td>Registration Number</td><td>Driver Name</td><td>Driver Mobile No</td><td>Conductor Name </td><td>Conductor Mobile No</td></tr>";
                    //        tblDetailsTransportSummary += "<tr><td>" + item.Route + "</td><td>" + item.Vehicle + "</td><td>" + item.RegistrationNumber +
                    //                "</td><td>" + item.DriverName + "</td><td>" + item.DriverNo + "</td><td>" + item.ConductorName + "</td><td>" + item.ConductorNo + "</td></tr>";

                    //    });
                    //}
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    // $("#LoaderDiv1").hide();
                }
            });
        }

        function BusRouteDetailTransportDashBoardSummary(BusRouteId, OrgGroupID, CommonOrgGroupBatchId) {
            $.ajax({
                type: "POST",
                url: "SummariseTransportSummaryDashBoard.aspx/BusRouteDetailsTransportSummaryDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "CommonOrgGroupBatchId": parseInt(CommonOrgGroupBatchId), "BusRouteId": parseInt(BusRouteId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",

                success: function (result) {
                    debugger;
                    var obj = (result.d);
                    var tblDetailsTransportSummary = "";
                    if (obj != "") {
                        tblDetailsTransportSummary += "<tr><th>Bus Route Point</th><th>Pickup Time</th><th>Drop Time</th></tr>";
                        $.each(obj, function (i, item) {
                            tblDetailsTransportSummary += "<tr><td>" + item.Route + "</td><td>" + item.PickupTime + "</td><td>" + item.DropTime + "</td></tr>";
                        });
                    }
                    else {
                        tblDetailsTransportSummary += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>";
                    }
                    
                    document.getElementById("tblBusRouteDetailDashBoardSummary").innerHTML = tblDetailsTransportSummary;                    
                    document.getElementById("TypeBusRouteDetailSummaryHead").style.display = "block";
                    document.getElementById("TypeBusRouteSummaryHead").style.display = "block";                    
                    document.getElementById("TypeWiseUserSummaryHead").style.display = "none";
                    StatusId = 1;
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);                    
                }
            });
        }

        function StudentDetailTransportDashBoardSummary(BusRouteId, OrgGroupID, CommonOrgGroupBatchId) {
            debugger;
            $.ajax({
                type: "POST",
                url: "SummariseTransportSummaryDashBoard.aspx/StudentDetailsTransportSummaryDataBind",
                data: JSON.stringify({ "OrgGroupId": parseInt(OrgGroupId), "CommonOrgGroupBatchId": parseInt(CommonOrgGroupBatchId), "BusRouteId": parseInt(BusRouteId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",

                success: function (result) {
                    debugger;
                    var obj = (result.d);
                    var tblDetailsTransportSummary = "";
                    if (obj != "") {
                        tblDetailsTransportSummary += "<tr><th>Org Name</th><th>Student Id</th><th>Class</th><th>Student Name</th><th>Contact No.</th><th>Pickup</th><th>Drop</th></tr>";
                        $.each(obj, function (i, item) {
                            tblDetailsTransportSummary += "<tr><td>" + item.OrgName + "</td><td>" + item.id + "</td><td>" + item.Class +
                                "</td><td>" + item.StudentName + "</td><td>" + item.Contact + "</td><td>" + item.PickupTime +
                                "</td><td>" + item.DropTime + "</td></tr>";
                        });
                    }
                    else {
                        tblDetailsTransportSummary += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>";
                    }
                    StatusId = 1;
                    document.getElementById("tblstudent").innerHTML = tblDetailsTransportSummary;
                    document.getElementById("StudentHead").style.display = "block";
                    document.getElementById("TypeBusRouteSummaryHead").style.display = "none";                    
                    document.getElementById("TypeWiseUserSummaryHead").style.display = "none";
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }

        function BackOrgFunction() {
            if (StatusId == 1) {
                document.getElementById("TypeWiseUserSummaryHead").style.display = "block";                
                document.getElementById("TypeBusRouteSummaryHead").style.display = "none";
                document.getElementById("TypeBusRouteDetailSummaryHead").style.display = "none";
                document.getElementById("StudentHead").style.display = "none";
                StatusId--;
            }
            
            else { window.location.href = "../MobileView/SummariseDashBoard.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">Transport DashBoard</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="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="TypeWiseUserSummaryHead">
                            <h3 class="table-topic">Type Wise Transport Summary</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <input type="hidden" id="hdnclick" />
                                    <input type="hidden" id="hdnSource" />
                                    <table id='tblTypeWiseDashBoardSummary' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                            <div class="se-pre-con" id="LoaderDiv1" style="display: none"></div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="TypeBusRouteSummaryHead" style="display: none">
                            <h3 class="table-topic">Bus Route Summary</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblBusRouteDashBoardSummary' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="TypeBusRouteDetailSummaryHead" style="display: none">
                            <h3 class="table-topic">Bus Route Detail Summary</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblBusRouteDetailDashBoardSummary' 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>                            
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblstudent' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>



        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>
