<%@ Page Language="C#" AutoEventWireup="true" CodeFile="examfeereport.aspx.cs" MasterPageFile="~/module/dashboardPage.master" Inherits="module_examfeereport" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script>
        var feepackname = "";
        var semnos = "";
        var totalamount = "";
        var examrecpt = "";
        var paymode = "";
        var utrnos = "";
        var examdates = "";
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "examfeereport.aspx/PopulateDropDownList3",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlyears]').empty();
                    $('select[id$=ddlyears]').append("<option value='0'>Select Years</option>");
                    $.each(result.d, function (key, value) {

                        var ddyear1 = value.DeptName;
                        var ddyear2 = value.year1;
                        var dtyear1 = new Date(ddyear1);
                        var dtyear2 = new Date(ddyear2);
                        var 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);
                }

            });
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "examfeereport.aspx/PopulateDropDownList4",
                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 ddyear1 = value.DeptName;


                        $('select[id$=ddlclass]').append($("<option data-toggle='tooltip' data-placement='top' title='" + ddyear1 + "'></option>").val(value.DeptId).html(ddyear1));
                        //console.log(value.DeptName);
                    });
                    $('select[id$=ddlclass]').val('0').change();
                    // $('select[id$=cat] option:eq(1)').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: "examfeereport.aspx/PopulateDropDownList",
                    data: "{clsid :  '" + $('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 ddyear1 = value.DeptName;


                            $('select[id$=ddldivi]').append($("<option data-toggle='tooltip' data-placement='top' title='" + ddyear1 + "'></option>").val(value.DeptId).html(ddyear1));
                            //console.log(value.DeptName);
                        });

                        $('select[id$=ddldivi]').val('0').change();
                        // $('select[id$=ddldivi]').val(divids).change();




                        //  $('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$=ddldivi]').change(function () {

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "examfeereport.aspx/PopulateDropDownList45",
                    data: "{yrsid :'" + $('select[id$=ddlyears]').val() + "',divsid :'" + $('select[id$=ddldivi]').val() + "',clsid :  '" + $('select[id$=ddlclass]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddlsemister]').empty();
                        $('select[id$=ddlsemister]').append("<option value='0'>Select Semister</option>");
                        $.each(result.d, function (key, value) {
                            var ddyear1 = value.DeptName;


                            $('select[id$=ddlsemister]').append($("<option data-toggle='tooltip' data-placement='top' title='" + ddyear1 + "'></option>").val(value.DeptId).html(ddyear1));
                            //console.log(value.DeptName);
                        });

                        $('select[id$=ddlsemister]').val('0').change();
                        //  $('select[id$=ddlsemister]').val(divids).change();

                        //  $('select[id$=ddlsemister]').trigger("change");


                        //  $('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$=ddlpay]").change(function () {
                if ($("select[id$=ddlpay]").val() == "paid") {
                    $("#divpaymode").show();
                } else if ($("select[id$=ddlpay]").val() == "unpaid") {
                    $("#divpaymode").hide();
                }
            });
        });
        function getstuddata() {
            var obj = {};
            obj.years = $('select[id$=ddlyears]').val();
            obj.classes = $('select[id$=ddlclass]').val();
            obj.divisions = $('select[id$=ddldivi]').val();
            obj.semid = $('select[id$=ddlsemister]').val();
            obj.paymode = $("select[id$=ddlpaymode]").val();
            obj.payst = $("select[id$=ddlpay]").val();
            $.ajax({
                type: "POST",
                url: "examfeereport.aspx/GetData1",
                contentType: "application/JSON; charset=utf-8",
                data: JSON.stringify(obj),
                datatype: "JSON",
                success: function (data) {
                    
                  
                    if (data.d != "") {
                        var table = $('#dataemp').DataTable();
                        data = JSON.parse(data.d);
                        table.clear();
                        table.destroy();
                        var table = $('#dataemp').DataTable({
                            //"aaSorting": [[0, "desc"]],
                            //"ordering": false,
                            "pageLength": 10,
                            "columns": [
                                     { "width": "5%" },
                                     { "width": "8%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                     { "width": "7%" },
                                     { "width": "6%" },
                                     { "width": "10%" },
                                     { "width": "7%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                     { "width": "10%" }, 
                                      { "width": "6%" },
                            { "width": "6%" }
                            
                            ]
                        });
                        $('#dataemp').DataTable().clear().draw();  
                        for (var i = 0, count = 1; i < data.length; i++, count++) {
                            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();
                           
                         
                            var fullnm = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        
                            if ($("select[id$=ddlpay]").val() == "paid") {
                                if (data[i].feepackname != null) {
                                    feepackname = data[i].feepackname;
                                } else {
                                    feepackname = "";
                                }
                                if (data[i].semnos != null) {

                                    semnos = data[i].semnos;
                                }
                                else {
                                    semnos = "";
                                }
                                if (data[i].totalamount != null) {
                                    totalamount = data[i].totalamount;
                                } else {
                                    totalamount = "";
                                }
                                if (data[i].examrecpt != null) {
                                    examrecpt = data[i].examrecpt;
                                }
                                else {
                                    examrecpt = "";
                                }
                                if (data[i].paymode != null) {
                                    paymode = data[i].paymode;
                                }
                                else {
                                    paymode = "";
                                }
                                if (data[i].utrnos != null) {
                                    utrnos = data[i].utrnos;
                                } else {
                                    utrnos = "";
                                }
                                if (data[i].examdate != null) {
                                    examdates = data[i].examdate;
                                } else {
                                    examdates = "";
                                }
                                table.row.add([
                                    count, data[i].studid, fullnm, data[i].pkgname, stryr, data[i].clsname, data[i].divsname, feepackname, semnos, totalamount, examrecpt, paymode, utrnos, examdates


                                ]).draw(true);
                            }
                            else if ($("select[id$=ddlpay]").val() == "unpaid") {
                                feepackname = "";
                                semnos = "";
                                 totalamount = "";
                               examrecpt = "";
                                paymode = "";
                                utrnos = "";
                                examdates = "";
                                table.row.add([
                                   count, data[i].studid, fullnm, data[i].pkgname, stryr, data[i].clsname, data[i].divsname, feepackname, semnos, totalamount, examrecpt, paymode, utrnos, examdates


                                ]).draw(true);
                            }
                            //if(data[i].examfeestatus == "Assigned"){

                            //    $('.btnedit'+i+'').attr('disabled',false);
                            //    $('.prt'+i+'').show();
                            //}
                            //else{

                            //    $('.btnedit'+i+'').removeAttr('disabled');
                            //    $('.prt'+i+'').show('disabled',false);
                            //}
                        }
                    }
                    else {
                      
                        var table = $('#dataemp').DataTable();
                        table.destroy();
                        $('#dataemp').DataTable().clear().draw();
                    }
                }
            });
        }
        function exportdatas() {
            var obj = {};
            obj.years = $('select[id$=ddlyears]').val();
            obj.classes = $('select[id$=ddlclass]').val();
            obj.divisions = $('select[id$=ddldivi]').val();
            obj.semid = $('select[id$=ddlsemister]').val();
            obj.paymode = $("select[id$=ddlpaymode]").val();
            obj.payst = $("select[id$=ddlpay]").val();
            $.ajax({
                type: "POST",
                url: "examfeereport.aspx/GetData1",
                contentType: "application/JSON; charset=utf-8",
                data: JSON.stringify(obj),
                datatype: "JSON",
                success: function (data) {


                    if (data.d != "") {
                        var table = $('#dataemp').DataTable();
                        data = JSON.parse(data.d);
                        table.clear();
                        table.destroy();
                        var table = $('#dataemp').DataTable({
                            "order": [[0, "asc"]],
                            "ordering": false,
                            "pageLength": 10,
                            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                            "dom": 'lBfrtip',
                            buttons: [
                            {
                                extend: 'excelHtml5',
                                text: 'Export to Excel',
                                title: 'Exam Fee Receipt List',
                                download: 'open',
                                orientation: 'landscape',
                                exportOptions: {
                                    columns: ':visible'
                                }
                            }],
                            "columns": [
                                     { "width": "5%" },
                                     { "width": "8%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                     { "width": "7%" },
                                     { "width": "6%" },
                                     { "width": "10%" },
                                     { "width": "7%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                     { "width": "10%" },
                                      { "width": "6%" },
                            { "width": "6%" }

                            ]
                        });
                        $('#dataemp').DataTable().clear().draw(); alert($("select[id$=ddlpay]").val());
                        for (var i = 0, count = 1; i < data.length; i++, count++) {
                            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();


                            var fullnm = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;

                            if ($("select[id$=ddlpay]").val() == "paid") {
                                if (data[i].feepackname != null) {
                                    feepackname = data[i].feepackname;
                                } else {
                                    feepackname = "";
                                }
                                if (data[i].semnos != null) {

                                    semnos = data[i].semnos;
                                }
                                else {
                                    semnos = "";
                                }
                                if (data[i].totalamount != null) {
                                    totalamount = data[i].totalamount;
                                } else {
                                    totalamount = "";
                                }
                                if (data[i].examrecpt != null) {
                                    examrecpt = data[i].examrecpt;
                                }
                                else {
                                    examrecpt = "";
                                }
                                if (data[i].paymode != null) {
                                    paymode = data[i].paymode;
                                }
                                else {
                                    paymode = "";
                                }
                                if (data[i].utrnos != null) {
                                    utrnos = data[i].utrnos;
                                } else {
                                    utrnos = "";
                                }
                                if (data[i].examdate != null) {
                                    examdates = data[i].examdate;
                                } else {
                                    examdates = "";
                                }
                                table.row.add([
                                    count, data[i].studid, fullnm, data[i].pkgname, stryr, data[i].clsname, data[i].divsname, feepackname, semnos, totalamount, examrecpt, paymode, utrnos, examdates


                                ]).draw(true);
                            }
                            else if ($("select[id$=ddlpay]").val() == "unpaid") {
                                feepackname = "";
                                semnos = "";
                                totalamount = "";
                                examrecpt = "";
                                paymode = "";
                                utrnos = "";
                                examdates = "";
                                table.row.add([
                                   count, data[i].studid, fullnm, data[i].pkgname, stryr, data[i].clsname, data[i].divsname, feepackname, semnos, totalamount, examrecpt, paymode, utrnos, examdates


                                ]).draw(true);
                            }
                            //if(data[i].examfeestatus == "Assigned"){

                            //    $('.btnedit'+i+'').attr('disabled',false);
                            //    $('.prt'+i+'').show();
                            //}
                            //else{

                            //    $('.btnedit'+i+'').removeAttr('disabled');
                            //    $('.prt'+i+'').show('disabled',false);
                            //}
                        }
                    }
                    else {

                        var table = $('#dataemp').DataTable();
                        table.destroy();
                        $('#dataemp').DataTable().clear().draw();
                    }
                }
            });
        }
    </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>Exam Fee Report</h6>
						</div>
						<hr />
                        	<form class="row g-2">
							<div class="col-md-2"></div>
                            <div class="col-md-3">
								<label>Year</label>
							<select id="ddlyears" class="form-select">
								
								</select>
							</div>
                            <div class="col-md-3">
								<label>Class</label>
							<select id="ddlclass" class="form-select">
								
								</select>
							</div>
							<div class="col-md-3">
								<label>Division</label>
									<select id="ddldivi" class="form-select">
								
								</select>
							</div> 
                                 <div class="col-md-2">
						<label>Semester</label>
							<select class="form-select mb-3" id="ddlsemister" aria-label="Default select example">
						
							</select>
						</div> 
                                        <div class="col-md-2">
						<label>Status</label>
							<select class="form-select mb-3" id="ddlpay" aria-label="Default select example">
						<option value="">Select Status</option>
                                	<option value="paid">Paid</option>
                                	<option value="unpaid">Unpaid</option>
							</select>
						</div>
                                <div class="col-md-2" style="display:none;" id ="divpaymode">
						<label>Pay Mode</label>
							<select class="form-select mb-3" id="ddlpaymode" aria-label="Default select example">
						<option value="">Select Pay Mode</option>
                                	<option value="cash">Cash</option>
                                	<option value="online">Online</option>
							</select>
						</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> 
                                 <div class="col-md-2" style="margin-top: 4.7vh;">
			        <button type="button" id="Button1" value="Submit" onclick="exportdatas()" class="btn btn-primary">Export Data</button>
							
											
						   </div>
                                </form>
                         <hr />
						   <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>Exam Package</th>  
                                           	 <th>Semister</th>  
                                           <th>Amount</th>
                                             <th>Receipt No.</th>
                                           <th>Pay Mode</th>
                                             <th>Utr Nos.</th>
                                           <th>Exam Receipt Date</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>
</asp:Content>