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

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <link href="../../App_Themes/jquery-ui.css" rel="stylesheet" />
    <script src="../../JavaScript/rjs/lib/jquery-ui.min.js"></script>
    <script src="../../JavaScript/rjs/lib/1.11.4-jquery-ui.js"></script>
    <style>
        .table-topic.date-topic {
            float: right;
        }

        .table-topic.frst:after {
            /*width: 64pc;*/
            width: 62pc;
        }
        </style>
    <script>
        var statusId = 0;
        var CommonOrgGroupBatchId = 0;
        var OrgGroupId = 0;
        var TypeId = 0;

        $(document).ready(function () {
            var myurl = window.location.href;
            var keyval = myurl.split('?')[1].split('&');           
            //Id = OrgId = parseInt(keyval[0].split('=')[1].toString());
            //Group = keyval[1].split('=')[1].toString();
            OrgGroupId = parseInt(keyval[0].split('=')[1].toString());
            CommonOrgGroupBatchId = parseInt(keyval[1].split('=')[1].toString());

            var now = new Date();
            ReceiptStatusFromDatePickerDate = $.datepicker.formatDate('yy/mm/dd', new Date());
            ReceiptStatusToDatePickerDate = $.datepicker.formatDate('yy/mm/dd', new Date());


            $('#ReceiptStatusFromDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
            $('#ReceiptStatusToDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
            TypeId = $('#drpFeeCollectionType').val;
            GetCommonOrgGroupBatchList();
        });

        function GetCommonOrgGroupBatchList() {
            $.ajax({
                type: "POST",
                url: "ConsolidateFeeCollectionDashBoard.aspx/GetCommonOrgGroupBatchList",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    // debugger;
                    $("#drpFeeCommonOrgGroupBatch").html(result.d);
                    CommonOrgGroupBatchIdFee = $("#drpFeeCommonOrgGroupBatch").val();
                    //alert("hi");
                    FeeCollectionPayTypeDataBind();
                    //FeeStatusDataBind();
                    //GetExamId();
                    //GetAdmissionCount();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function FeeCommonOrgGroupBatchFunction() {
            CommonOrgGroupBatchId = $("#drpFeeCommonOrgGroupBatch").val();
            FeeCollectionPayTypeDataBind();
        }
        function FeeCollectionTypeFunction()
        {
            TypeId = $("#drpFeeCollectionType").val();
            FeeCollectionPayTypeDataBind();
        } 


        function FeeCollectionPayTypeDataBind() {
            $.ajax({
                async: false,
                type: "POST",
                url: "ConsolidateFeeCollectionDashBoard.aspx/CommonFeeCollectionDataBind",
                data: JSON.stringify({ "CommonOrgGroupBatchId": parseInt(CommonOrgGroupBatchIdFee),"TypeId":parseInt(TypeId), }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblFeeCollectionPayType = "";
                    if (obj != "") {
                        tblFeeCollectionPayType += "<tr><th>Organization Name</th><th>Total</th><th>By Bank</th><th>Cash</th><th>Cheque</th><th>Credit Card</th><th>DD</th><th>Netbanking</th></tr>";
                        $.each(obj, function (i, item) {
                            tblFeeCollectionPayType += "<tr><td><a href='../MobileView/ConsolidateFeeCollectionDashBoard.aspx?OrgGroupId=" + item.OrgGroupId + "&CommonOrgGroupBatchId=" + CommonOrgGroupBatchIdFee + "'>" + item.OrgGroupName + "</a></td><td>" + item.Total + "</td><td>" + item.ByBank + "</td><td>" + item.Cash + "</td><td>" + item.Cheque + "</td><td>" + item.CreditCard + "</td><td>" + item.DD + "</td><td>" + item.Netbanking + "</td></tr>";
                            //total += parseInt(item.StudentCount);

                        });
                        //tblFeeStatus += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblFeeCollectionPayType += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    //$("#FeeStatusLoader").hide();
                    document.getElementById("tblFeeCollectionPayType").innerHTML = tblFeeCollectionPayType;
                    // document.getElementById("CreateDate").innerHTML = obj[0].LastUpdatedDate;

                    //GetCommonOrgGroupBatchForReceipt(); alert(item.LastUpdatedDate);
                    // ReceiptDetailDataBind(ReceiptStatusFromDatePickerDate, ReceiptStatusToDatePickerDate);
                    // console.log(Header);
                },
                complete: function () {
                    $("#FeeStatusLoader").hide();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                    $("#LoaderDiv1").hide();
                }
            });

        }

        function ReceiptStatusFromDateFunction() {
            //alert("hi task");
            //  debugger;

            if ($('#ReceiptStatusFromDatePicker').val() == "") {
                //alert("From Date should not be blank");
                $('#ReceiptStatusFromDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
                //return;
            }
            if ($('#ReceiptStatusToDatePicker').val() == "") {
                // alert("To Date should not be blank");
                $('#ReceiptStatusToDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
                //return;
            }

            ReceiptStatusFromDatePickerDate = $('#ReceiptStatusFromDatePicker').val().split("/").reverse().join("-");
            ReceiptStatusToDatePickerDate = $('#ReceiptStatusToDatePicker').val().split("/").reverse().join("-");

            var FDate = new Date(ReceiptStatusFromDatePickerDate);
            var TDate = new Date(ReceiptStatusToDatePickerDate);

            if (FDate <= TDate) {
                // Do something

                // GetTaskData(FeeStatusFromDatePickerDate);

                ReceiptDetailDataBind(ReceiptStatusFromDatePickerDate, ReceiptStatusToDatePickerDate);
            }
            else {
                $('#ReceiptStatusFromDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
                alert("From Date should be greate than To Date");
            }

        }
        function ReceiptStatusToDateFunction() {
            //debugger;
            //alert("hi task");

            if ($('#ReceiptStatusFromDatePicker').val() == "") {
                //alert("From Date should not be blank");
                $('#ReceiptStatusFromDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
                //return;
            }
            if ($('#ReceiptStatusToDatePicker').val() == "") {
                //alert("To Date should not be blank");
                $('#ReceiptStatusToDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
                //return;
            }



            ReceiptStatusFromDatePickerDate = $('#ReceiptStatusFromDatePicker').val().split("/").reverse().join("-");
            ReceiptStatusToDatePickerDate = $('#ReceiptStatusToDatePicker').val().split("/").reverse().join("-");

            var FDate = new Date(ReceiptStatusFromDatePickerDate);
            var TDate = new Date(ReceiptStatusToDatePickerDate);

            if (FDate <= TDate) {
                // Do something

                // GetTaskData(FeeStatusFromDatePickerDate);

                ReceiptDetailDataBind(ReceiptStatusFromDatePickerDate, ReceiptStatusToDatePickerDate);
            }
            else {
                $('#ReceiptStatusToDatePicker').val($.datepicker.formatDate('dd/mm/yy', new Date()));
                alert("To Date should be less than To Date");
            }

        }
        function FeeHeadDataBind(ReceiptBookId, ReceiptBook) {
            $.ajax({
                type: "POST",
                url: "PaytypeReceiptCollection.aspx/FeeHeadDataBind",
                data: JSON.stringify({ "ReceiptBookId": parseInt(ReceiptBookId), "Day": Day, "BatchId": parseInt(BatchId), "OrgGroupId": parseInt(OrgId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    // alert(result.d);
                    var obj = (result.d);
                    var total = 0;
                    var finaltotal = 0;
                    var tblFeeHead = "";
                    Header[0] = ReHeader;
                    if (obj != "") {
                        var columnsIn = obj[0];
                        var newObj = {};
                        tblFeeHead += "<tr>";
                        for (var key in columnsIn) {
                            if (key !== "FeeHeadId") {
                                tblFeeHead += "<th>" + key + "</th>";
                                if (key === "FeeHead") {

                                    newObj[key] = "Total";
                                }
                                else {
                                    newObj[key] = 0;
                                }
                            }
                        }
                        //console.log(obj[0]);
                        tblFeeHead += "<th>Total</th></tr>";

                        $.each(obj, function (i, item) {

                            tblFeeHead += "<tr>";
                            for (var key in item) {
                                if (key !== "FeeHeadId") {

                                    if (key === "FeeHead") {

                                        if (item[key] !== "null" && item[key] !== undefined && item[key] !== null) {
                                            tblFeeHead += "<td><a onclick='FeeMasterDataBind(" + item.FeeHeadId + "," + ReceiptBookId + ",\"" + item.FeeHead + "\")'>" + item[key] + "</a></td>";
                                            // console.log(item.ReceiptBookId);
                                        }
                                    }
                                    // tblReceipt += "<td>" + item[key] + "</td>";

                                    if (key !== "FeeHead") {
                                        if (item[key] === null || item[key] === undefined)
                                        { item[key] = 0; }
                                        tblFeeHead += "<td>" + item[key] + "</td>";
                                        // console.log(item[key]);
                                        if (item[key] !== "null" && item[key] !== undefined && item[key] !== null) {
                                            total += parseInt(item[key]);
                                            newObj[key] += parseInt(item[key]);
                                        }
                                    }
                                }
                            }
                            tblFeeHead += "<td>" + total + "</td></tr>";
                            finaltotal += total;
                            total = 0;


                        });
                        tblFeeHead += "<tr>";
                        for (var key in newObj) {
                            tblFeeHead += "<th>" + newObj[key] + "</th>";
                        }
                        //console.log(obj[0]);
                        tblFeeHead += "<th>" + finaltotal + "</th></tr>";
                        Header[1] = "<h5 class='page-title'  id='ReceiptBook'><a href='#' onclick='HeaderDisplay(1)'>" + ReceiptBook + "</a></h5>";
                    }
                    else { tblFeeHead += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblFeeHead").innerHTML = tblFeeHead;
                    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("FeeHead").style.display = "Block";
                    statusId = 1;
                }
            });
        }
        function FeeMasterDataBind(FeeHeadId, ReceiptBookId, FeeHead) {
            $.ajax({
                type: "POST",
                url: "PaytypeReceiptCollection.aspx/FeeMasterDataBind",
                data: JSON.stringify({ "FeeHeadId": parseInt(FeeHeadId), "ReceiptBookId": parseInt(ReceiptBookId), "Day": Day, "BatchId": parseInt(BatchId), "OrgGroupId": parseInt(OrgId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var total = 0;
                    var finaltotal = 0;
                    var tblFeeMaster = "";

                    if (obj != "") {
                        var columnsIn = obj[0];
                        var newObj = {};
                        tblFeeMaster += "<tr>";
                        for (var key in columnsIn) {
                            if (key !== "FeeHeadId") {
                                tblFeeMaster += "<th>" + key + "</th>";
                                if (key === "FeeMaster") {

                                    newObj[key] = "Total";
                                }
                                else {
                                    newObj[key] = 0;
                                }
                            }
                        }
                        //console.log(obj[0]);
                        tblFeeMaster += "<th>Total</th></tr>";

                        $.each(obj, function (i, item) {

                            tblFeeMaster += "<tr>";
                            for (var key in item) {
                                if (key !== "FeeHeadId") {

                                    if (key === "FeeMaster") {

                                        if (item[key] !== "null" && item[key] !== undefined && item[key] !== null) {
                                            tblFeeMaster += "<td>" + item[key] + "</td>";
                                            // console.log(item.ReceiptBookId);
                                        }
                                    }
                                    // tblReceipt += "<td>" + item[key] + "</td>";

                                    if (key !== "FeeMaster") {
                                        tblFeeMaster += "<td>" + item[key] + "</td>";
                                        // console.log(item[key]);
                                        if (item[key] !== "null" && item[key] !== undefined && item[key] !== null) {
                                            total += parseInt(item[key]);
                                            newObj[key] += parseInt(item[key]);
                                        }
                                    }
                                }
                            }
                            tblFeeMaster += "<td>" + total + "</td></tr>";
                            finaltotal += total;
                            total = 0;


                        });
                        tblFeeMaster += "<tr>";
                        for (var key in newObj) {
                            tblFeeMaster += "<th>" + newObj[key] + "</th>";
                        }
                        //console.log(obj[0]);
                        tblFeeMaster += "<th>" + finaltotal + "</th></tr>";
                        Header[2] = " <h5 class='page-title' style='display:Block' id='DivisionClass'><a href='#' onclick='HeaderDisplay(2)'>" + FeeHead + "</a></h5>";
                    }
                    else { tblFeeHead += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblFeeMaster").innerHTML = tblFeeMaster;
                    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("FeeHead").style.display = "none";
                    document.getElementById("FeeMaster").style.display = "Block";
                    statusId = 2;
                }
            });
        }
        function BackOrgFunction() {
            if (statusId != 0 || statusId != null) {
                if (statusId == 2) {
                    document.getElementById("ReceiptHead").style.display = "none";
                    document.getElementById("FeeHead").style.display = "Block";
                    document.getElementById("FeeMaster").style.display = "none";
                    $("#ReceiptBook").show();
                    $("#DivisionClass").hide();
                    statusId--;
                }
                else if (statusId == 1) {
                    document.getElementById("ReceiptHead").style.display = "Block";
                    document.getElementById("FeeHead").style.display = "none";
                    document.getElementById("FeeMaster").style.display = "none";
                    $("#ReceiptBook").hide();
                    $("#DivisionClass").hide();
                    document.getElementById("HeaderTitle").innerHTML = ReHeader;
                    Header = [];
                    statusId--;
                }
                else {
                    window.location.href = "../MobileView/FeeDashBoard.aspx?OgrId=" + OrgId;
                }
            }
            else {
                window.location.href = "../MobileView/FeeDashBoard.aspx?OgrId=" + OrgId;
            }
        }
        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>
                        <label class="header-topic justify-content-center" id="HeaderLabel"></label>
                        <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 mb4" id="FeeStatusHead1">
                <div style="width: 100%; overflow: hidden">

                    <div style="float: left">
                        <div class="custom-select width-17" style="width: 100%; margin-left: 32px; margin-top: 32px;">
                            <div class='fLeft pRight5'>

                                <select id='drpFeeCollectionType' onchange="FeeCollectionTypeFunction()">
                                    <option selected="selected" value='11'>Receipt Book Wise</option>
                                    <option value='12'>User Wise</option>
                                    <option value='13'>Organization Wise</option>
                                    <option value='14'>Fee Head Wise</option>
                                    <option value='15'>Fee Master Wise</option>
                                </select>
                              
                            </div>
                        </div>
                    </div>
                       <div style="float: right">
                        <div class="custom-select width-17" style="width: 100%; margin-right: 100px; margin-left: -26px; margin-top: 32px;">
                            <div class='fLeft pRight5'>
                                  <select id='drpFeeCommonOrgGroupBatch' onchange="FeeCommonOrgGroupBatchFunction()">
                                    <option selected="selected" value='0'>Select</option>
                                </select>
                            </div>
                        </div>
                    </div>
                     <div  overflow: hidden" style="width: 100%; margin: 70px; padding-bottom: 3px;">

                                <div style="float: left">From Date</div>
                                <div style="float: left; margin-left: 12px">
                                    <input id="ReceiptStatusFromDatePicker" maxlength="10" onchange="ReceiptStatusFromDateFunction()" onkeyup="return FormatIt(this);" />

                                </div>

                                <div style="float: left; margin-left: 20px">To Date</div>
                                <div style="float: left; margin-left: 12px">
                                    <input id="ReceiptStatusToDatePicker" maxlength="10" onchange="ReceiptStatusToDateFunction()" onkeyup="return FormatIt(this);" />

                                </div>

                                <div style="float: left; margin-left: 106px">
                                    <img id="ReceiptStatusLoader" style="display: none; position: relative; left: 16%; top: 1px;" src="../../Images/Loading1.gif" />
                                </div>
                            </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="CommonFeeCollectionHead" style="display: block">
                            <h3 class="table-topic">Fee Collection PayType</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblCommonFeeCollection' 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="FeeHead" style="display: none">
                            <h3 class="table-topic">Fee Head</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblFeeHead' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="FeeMaster" style="display: none">
                            <h3 class="table-topic">Fee Master</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblFeeMaster' 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>
           <script type="text/javascript">

        $(function () {

          

            $("#ReceiptStatusFromDatePicker").datepicker({
                dateFormat: 'dd/mm/yy', showOn: "button",
                buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
                buttonImageOnly: true
            });

            $("#ReceiptStatusToDatePicker").datepicker({
                dateFormat: 'dd/mm/yy', showOn: "button",
                buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
                buttonImageOnly: true
            });
        })
    </script>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
