<%@ Page Language="C#" AutoEventWireup="true" CodeFile="allaccountreports.aspx.cs" MasterPageFile="~/module/dashboardPage.master" Inherits="module_allaccountreports" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
      var   totalpaid = 0;
      var  remainsamt = 0;
       var  totalremainsamt = 0 ;
        $(document).ready(function () {
            //let today2 = new Date().toISOString().substr(0, 10);

            //document.querySelector("#dp-5").value = today2; 
            //let today3 = new Date().toISOString().substr(0, 10);

            //document.querySelector("#dp-6").value = today3;
            GetData();
            $.ajax({
                url: "allaccountreports.aspx/getpaidamt",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data:"",
                dataType: "json",
                success: function (data) {
                    data = JSON.parse(data.d);
                    $("#lblpaidamt").html(data[0].totalpaidamt);
                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }

            });
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "allaccountreports.aspx/PopulateDropDownList8",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlyears]').empty();
                    //var currentdt = new Date();
                    //var cuurentyr = currentdt.getFullYear();
                    //var prevyr = currentdt.setFullYear(currentdt.getFullYear() - 1);
                    $('select[id$=ddlyears]').append("<option value='0'>Select Year</option>");
                 
                    $.each(result.d, function (key, value) {
                        ddyear1 = value.DeptName;
                        ddyear2 = value.year1;
                        dtyear1 = new Date(ddyear1);
                        dtyear2 = new Date(ddyear2);
                        stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();
                          
                        $('select[id$=ddlyears]').append($("<option data-toggle='tooltip' data-placement='top' title='" + stryr + "'></option>").val(value.DeptId).html(stryr));
                        //console.log(value.DeptName);
                    });
                    // $('select[id$=ddlyears]').val('0').change();
                    //$('select[id$=cat] option:eq(0)').attr("selected", true);
                    //  $('select[id$=ddlclassty]').selectpicker('refresh');
                    //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }

            }); 
            $('select[id$=ddlyears]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "allaccountreports.aspx/PopulateDropDownList9",
                    data: "",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddlclass]').empty();
                        $('select[id$=ddlclass]').append("<option value='0'>Select class</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptId;
                            

                            $('select[id$=ddlclass]').append($("<option data-toggle='tooltip' data-placement='top' title='" + value.DeptId + "'></option>").val(value.DeptId).html(value.DeptName));
                            //console.log(value.DeptName);
                        });
                     
                        $('select[id$=ddlclass]').val(classids).change();
                        //$('select[id$=cat] option:eq(0)').attr("selected", true);
                        //  $('select[id$=ddlclassty]').selectpicker('refresh');
                        //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                    },
                    error: function ajaxError(result) {
                        console.log(result.status + ' : ' + result.statusText);
                    }

                });
            }); 
            $('select[id$=ddlclass]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "allaccountreports.aspx/PopulateDropDownList10",
                    data: "{clids :'" + $('select[id$=ddlclass]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddldivi]').empty();
                        $('select[id$=ddldivi]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=ddldivi]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=ddldivi]').val('0').change();
                        //$('select[id$=cat] option:eq(0)').attr("selected", true);
                        //  $('select[id$=ddlclassty]').selectpicker('refresh');
                        //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                    },
                    error: function ajaxError(result) {
                        console.log(result.status + ' : ' + result.statusText);
                    }

                });
            });
        });
        function GetData() {
            $.ajax({
                url: "allaccountreports.aspx/Getdata",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: "",
                dataType: "json",
                success: function (data) {



                    //$("#dataemp").find("tbody").empty();
                    // $("#dataemp").find("tbody").empty();

                    table = $('#dataemp').DataTable();
                    table.destroy();
                    if (data.d != "") {
                        data = JSON.parse(data.d);
                    }
                    var table = $('#dataemp').DataTable({
                        //"aaSorting": [[0, "desc"]],
                        //"ordering": false,
                        "pageLength": 10,
                        "columns": [
                                 { "width": "5%" },
                                 { "width": "10%" },
                                 { "width": "10%" },
                                 { "width": "10%" },
                                 { "width": "7%" },
                                 { "width": "6%" },
                                 { "width": "10%" },
                                 { "width": "7%" },
                                 { "width": "10%" },
                                 { "width": "10%" },

                        ]
                    });

                    $('#dataemp').DataTable().clear().draw();
                    for (var i = 0,count =1; i < data.length ; i++,count++) {
                       
                            totalpaid = parseFloat(data[i].totalpaidamt); 
                            remainsamt = parseFloat(data[i].pkamt);
                            totalremainsamt = remainsamt - totalpaid;
                     
                        if (totalpaid == "") {
                            totalremainsamt = 0;
                        }
                        fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        var ddyear1 = data[i].fromdate;
                        var ddyear2 = data[i].todate;
                        var dtyear1 = new Date(ddyear1);
                        var dtyear2 = new Date(ddyear2);
                        var stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();

                        //  $("#dataemp").find("tbody").append(markup);

                        table.row.add([
                            count, data[i].studid, fullname, data[i].pkgnm, stryr, data[i].clsname, data[i].divsname, data[i].totalpaidamt, totalremainsamt, "<button  style='height:35px; width: 35px; padding-left:7px;' data-bs-toggle='modal' data-bs-target='#exampleLargeModal6'  type='button' onclick=getdataacctstudent('" + data[i].pkgid + "',\"" + data[i].studids + "\"," + data[i].clsids + "," + data[i].divsid + "," + data[i].admyrs + ") id='btnedit' class='btn btn-success' data-bs-toggle='modal' title='Pay Now' data-bs-target='#exampleLargeModal5' ><i class='bx bx-message-square-edit'></i></button>"
                        ]).draw(false);
                    }
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        }
        function getdataacctstudent(pkgids, studids1, clsids, divisid, years) {
          
            var obj = {};
            obj.packgid = pkgids;
            obj.studids = studids1;
            obj.yrs = years;
            obj.divs = divisid;
            obj.clsids = clsids;
            $.ajax({
                url: "allaccountreports.aspx/Getdata1",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(obj),
                dataType: "json",
                success: function (data) {
                    var chknos = "";
                    var banknm = "";


                    //$("#dataemp").find("tbody").empty();
                     $("#Table1").find("tbody").empty();

                     var tdappend = "";
                   
                    if (data.d != "") {
                        data = JSON.parse(data.d);
                        for (var i = 0 ; i < data.length; i++) {
                            if (data[i].paymode == "cheque") {
                                tdappend = "<tr><td>" + data[i].receiptnos + "</td><td>" + data[i].paymode + "</td><td>" + data[i].chkdate + "</td><td>" + data[i].chequenos + "</<td><td>" + data[i].bankname + "</td><td>" + data[i].paidamt + "</td></tr>";
                            } else if (data[i].paymode == "cash") {
                                if (data[i].chequenos = null) {
                                    chknos = "";
                                }
                                if (data[i].bankname == "") {
                                    banknm = "";
                                }
                                tdappend = "<tr><td>" + data[i].receiptnos + "</td><td>" + data[i].paymode + "</td><td>" + data[i].inspaydt + "</td><td>" + chknos + "</<td><td>" + banknm + "</td><td>" + data[i].paidamt + "</td></tr>";
                            }
                            $("#Table1").find("tbody").append(tdappend);
                        }
                    }
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        } 
        function getstuddata(){
            var obj = {};
            obj.yrs = $('select[id$=ddlyears]').val();
            obj.cls = $('select[id$=ddlclass]').val();
            obj.divs =  $('select[id$=ddldivi]').val();
            obj.fromdt = $("#dp-5").val();
            obj.todt = $("#dp-6").val();
            $.ajax({
                url: "allaccountreports.aspx/GetdataSearch",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(obj),
                dataType: "json",
                success: function (data) {



                    //$("#dataemp").find("tbody").empty();
                    // $("#dataemp").find("tbody").empty();

                    table = $('#dataemp').DataTable();
                    table.destroy();
                    if (data.d != "") {
                        data = JSON.parse(data.d);
                    }
                    var table = $('#dataemp').DataTable({
                        //"aaSorting": [[0, "desc"]],
                        //"ordering": false,
                        "pageLength": 10,
                        "columns": [
                                 { "width": "5%" },
                                 { "width": "10%" },
                                 { "width": "10%" },
                                 { "width": "10%" },
                                 { "width": "7%" },
                                 { "width": "6%" },
                                 { "width": "10%" },
                                 { "width": "7%" },
                                 { "width": "10%" },
                                 { "width": "10%" },

                        ]
                    });

                    $('#dataemp').DataTable().clear().draw();
                    for (var i = 0,count =1; i < data.length ; i++,count++) {
                       
                        totalpaid = parseFloat(data[i].totalpaidamt); 
                        remainsamt = parseFloat(data[i].pkamt);
                        totalremainsamt = remainsamt - totalpaid;
                     
                        if (totalpaid == "") {
                            totalremainsamt = 0;
                        }
                        fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        var ddyear1 = data[i].fromdate;
                        var ddyear2 = data[i].todate;
                        var dtyear1 = new Date(ddyear1);
                        var dtyear2 = new Date(ddyear2);
                        var stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();

                        //  $("#dataemp").find("tbody").append(markup);

                        table.row.add([
                            count, data[i].studid, fullname, data[i].pkgnm, stryr, data[i].clsname, data[i].divsname, data[i].totalpaidamt, totalremainsamt, "<button  style='height:35px; width: 35px; padding-left:7px;' data-bs-toggle='modal' data-bs-target='#exampleLargeModal6'  type='button' onclick=getdataacctstudent('" + data[i].pkgid + "',\"" + data[i].studids + "\"," + data[i].clsids + "," + data[i].divsid + "," + data[i].admyrs + ") id='btnedit' class='btn btn-success' data-bs-toggle='modal' title='Pay Now' data-bs-target='#exampleLargeModal5' ><i class='bx bx-message-square-edit'></i></button>"
                        ]).draw(false);
                    }
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        }
    </script>
<div class="page-wrapper">
			<div class="page-content">
				<div class="row">
					<div class="col-md-12 mx-auto" >
					
				<div class="card">
					<div class="card-body">
						<div class="card-title d-flex align-items-center">

							<h6>Installement Report</h6>&nbsp;&nbsp;&nbsp;
                             <label> Daily Collection  </label>:&nbsp;&nbsp; <label id="lblpaidamt"></label>
						</div>
						<hr />
						
						
						<form class="row g-2">
							
                            <div class="col-md-2">
								<label>Year</label>
							<select id="ddlyears" class="form-select">
								
								</select>
							</div>
                            <div class="col-md-2">
								<label>Class</label>
							<select id="ddlclass" class="form-select">
								
								</select>
							</div>
							<div class="col-md-2">
								<label>Division</label>
									<select id="ddldivi" class="form-select">
								
								</select>
							</div>
                            <div class="col-md-2">
								<label>From </label>
									  <input class="form-control mb-3" id="dp-5" type="date"
                                        aria-label="default input example" />
							</div>
                            <div class="col-md-2">
								<label>To</label>
									  <input class="form-control mb-3" id="dp-6" type="date"
                                        aria-label="default input example" />
							</div>
					<div class="col-md-2" style="margin-top: 4.7vh;">
			        <button type="button" id="btnadd" value="Submit" onclick="getstuddata()" class="btn btn-primary">Search</button>
							
											
						   </div>
						   
                           </form>
                       </div>
                   </div>
				

				   <div class="overlay toggle-icon"></div>
				   <hr/>
				   <div class="col-md-12 mx-auto">
				   <div class="card">
					   <div class="card-body">
						   <div class="table-responsive">
							   <table id="dataemp" class="table table-striped table-bordered">
								   <thead>
									   <tr>
										   <th>Sr.no</th>
                                           <th>Student ID</th>	
                                            <th>Student Name</th>	
                                            
                                             <th>Package Name</th>	
                                      
                                              <th>Year</th>	
                                            <th>Class</th>
										   <th>Division</th>
										   	 <th>Paid Amount</th>  
                                           <th>Balance Amount</th>
										    <th>Action</th>
									   </tr>
								   </thead>
								   <%--<tbody>
									   <tr>
										   <td>1</td>
										   <td>Admission Fee</td>	
										   
										   <td style="background-color: white;">
																			
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
											</button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
											</button>&nbsp;
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-primary"><i class="lni lni-save"></i>
											</button>&nbsp;
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-dark"><i class='bx bx-x'></i></span>
											</button>
											</td>
										</div>	
										</div>		
										</div>								
										   </tr>
									   </tbody>--%>
							   </table>
						   </div>
					   </div>
				   </div>
			   </div>
			   </div>
                    </div>
                </div>
            </div>
     <div class="col">
        	<div class="modal fade" id="exampleLargeModal6" tabindex="-1" data-bs-backdrop="static" aria-hidden="true">
			<div class="modal-dialog modal-xl">
				<div class="modal-content">
					<div class="modal-header">
                      	<h5 class="modal-title">Installment Details</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" id="Button1" aria-label="Close"></button>
                        </div>
                    	<div class="modal-body">
                            <div class="row g-2">
					
							 <div class="col-md-12 mx-auto">
						<div class="card">
							<div class="card-body">
								<table class="table mb-0" id="Table1">
									<thead class="table-dark">
										<tr>
											
												
											<th scope="col">Pref. No.</th>
                                            	<th scope="col">PayMode</th>
											<th scope="col">Payment Date</th>
										
											<th scope="col">Cheque Nos</th>
                                            <th scope="col">Bank Name</th>
                                              <th scope="col">Paid Amount</th>
										</tr>
									</thead>
									<tbody>
										
									
									</tbody>
								</table>
							</div>
						</div>
					
					</div>

                            </div> 
                            </div>
                    </div> 
                </div> 
                </div>
    </div>
    </asp:Content>