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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">	
    <script>
        var studentold = "";
        var packageesidold = "";
        var classold = "";
        var divisionsold = "";
        var yearsold = "";
        $(document).ready(function () {

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "addmissionnextclass.aspx/PopulateDropDownList4",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlyears]').empty();
                    $('select[id$=ddlyears]').append("<option value='0'>Select Year</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$=ddlyears]').trigger("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: "addmissionnextclass.aspx/PopulateDropDownList5",
                    data: "",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddlsclass]').empty();
                        $('select[id$=ddlsclass]').append("<option value='0'>Select class</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=ddlsclass]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=ddlsclass]').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$=ddlsclass]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "addmissionnextclass.aspx/PopulateDropDownList6",
                    data: "{clids :'" + $('select[id$=ddlsclass]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddldivision]').empty();
                        $('select[id$=ddldivision]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=ddldivision]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=ddldivision]').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$=ddlyears1]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "addmissionnextclass.aspx/PopulateDropDownList5",
                    data: "",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=clasrch1]').empty();
                        $('select[id$=clasrch1]').append("<option value='0'>Select class</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=clasrch1]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=clasrch1]').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$=clasrch1]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "addmissionnextclass.aspx/PopulateDropDownList6",
                    data: "{clids :'" + $('select[id$=clasrch1]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=divisrch1]').empty();
                        $('select[id$=divisrch1]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=divisrch1]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=divisrch1]').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 getdata13() {
            var obj = {};
            obj.years = $('select[id$=ddlyears]').val();
            obj.classes = $('select[id$=ddlsclass]').val();
            obj.divisions = $('select[id$=ddldivision]').val();

            $.ajax({
                type: "POST",
                url: "addmissionnextclass.aspx/GetData",
                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.destroy();

                        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%" },

                            ]
                        });

                        $('#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 fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                            table.row.add([
                                 count, data[i].studid, data[i].pkgids, data[i].pkgname, fullname, data[i].clsname, data[i].divsname, stryr, data[i].regdate,
                                 "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' title='Transfer' onclick='transferstudent(\"" + data[i].studid + "\"," + data[i].pkgsids + "," + data[i].yearid + "," + data[i].clsids + "," + data[i].divsids + ")' id='btnedit' class='btn btn-success' data-bs-toggle='modal' data-bs-target='#exampleLargeModal5' ><i class='lni lni-save'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' title='delete' onclick='deletedata('" + data[i].id + "')' id='btndelete' class='btn btn-danger'><i class='fadeIn animated bx bx-trash-alt'></i></button>",

                            ]).draw(true);

                        }
                    }
                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }

            });
        }
        function transferstudent(studids,packagesid,yrsid,classid,divisionid) {
            studentold = studids;
            packageesidold = packagesid; 
           
            classold = classid;
            divisionsold = divisionid;
           yearsold = yrsid;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "addmissionnextclass.aspx/PopulateDropDownList4",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlyears1]').empty();
                    $('select[id$=ddlyears1]').append("<option value='0'>Select Year</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$=ddlyears1]').append($("<option data-toggle='tooltip' data-placement='top' title='" + stryr + "'></option>").val(value.DeptId).html(stryr));
                        //console.log(value.DeptName);
                    });
                    $('select[id$=ddlyears1]').val('0').change();
                    $('select[id$=ddlyears1]').trigger("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: "addmissionnextclass.aspx/PopulateDropDownList7",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlpackages]').empty();
                    $('select[id$=ddlpackages]').append("<option value='0'>Select Year</option>");
                    $.each(result.d, function (key, value) {
                     

                        $('select[id$=ddlpackages]').append($("<option data-toggle='tooltip' data-placement='top' title='" + value.DeptName + "'></option>").val(value.DeptId).html(value.DeptName));
                        //console.log(value.DeptName);
                    });
                    $('select[id$=ddlpackages]').val('0').change();
                    setTimeout(function () { getpaymentdetails(studids, packagesid,yrsid); }, 2000);

                    //$('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);
                }

            });
         
            
        }
        var chequesnos = "";var banknms = "";
        function getpaymentdetails(studids, packagesid,yrsids) {
            $.ajax({
                url: "addmissionnextclass.aspx/Getdata12",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: "{studentids:'" + studids + "', packagesidss:'" + packagesid + "',acdyears : '"+ yrsids +"'}",
                dataType: "json",
                success: function (data) {
                    console.log(JSON.stringify(data));
                    data = JSON.parse(data.d);

                  
                    $("#tblinstall").find("tbody").empty();
                
                    for (var i = 0,count = 1; i < data.length ; i++, count++) {
                        {
                            if (data[i].chequenos != null) {
                                chequesnos = data[i].chequenos;
                                }else{chequesnos = "";
                            }
                            if (data[i].bankname != null) {
                                banknms = data[i].bankname;
                            } else {
                                banknms = "";
                            }
                            var markup = '<tr ><td>' + count + '</td><td >' + data[i].studid + '</td><td>' + data[i].divsname + '</td><td >' + data[i].paymode + '</td><td >' + data[i].receiptnos + '</td><td >' + data[i].instdate + '</td><td>' + chequesnos + '</td><td> ' + banknms + '</td><td> ' + data[i].paidamt + '</td></tr> ';
                            $("#tblinstall").find("tbody").append(markup);
                        }
                    }
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            });
        }
        function updatestudent() {
            if ($('select[id$=ddlyears1]').val() == "0") {
                noty({ text: 'select Year', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            if ($('select[id$=clasrch1]').val() == "0") {
                noty({ text: 'select Class', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            if ($('select[id$=divisrch1]').val() == "0") {
                noty({ text: 'select Division', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            if ($('select[id$=ddlpackages]').val() == "0") {
                noty({ text: 'select Packages', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            var obj = {};
            obj.stids = studentold;
            obj.pksid = packageesidold;
            obj.clsold = classold;
            obj.divsold = divisionsold;
            obj.yrsold = yearsold;
            obj.yearsnews = $('select[id$=ddlyears1]').val();
            obj.classesnew = $('select[id$=clasrch1]').val();
            obj.divisionsnews = $('select[id$=divisrch1]').val();
            obj.packegesnews = $('select[id$=ddlpackages]').val();
            $("#btntransfer").attr("disabled", "disabled");
            $.ajax({
                type: "POST",
                url: "addmissionnextclass.aspx/SavaData",
                data: JSON.stringify(obj),
                contentType: "application/JSON; charset=utf-8",
                datatype: "JSON",
                success: function (response) {
                    //window.location.reload();

                  //  datatable();
                    clearss();
                    noty({ text: 'Admission For Next Year Is confirmed', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                    setTimeout(function () { $("#btntransfer").removeAttr("disabled", "disabled"); }, 3000);
                    $("#exampleLargeModal5")[0].click();
                },
                error: function (error) {
                    console.log(JSON.stringify(error));
                    //alert("Error in insert");
                    noty({ text: 'Error in insert', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);

                }

            });
        }
        function clearss() {
            $('select[id$=ddlyears1]').val("0").change();
         $('select[id$=clasrch1]').val("0").change();
           $('select[id$=divisrch1]').val("0").change();
        $('select[id$=ddlpackages]').val("0").change();
        }
    </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>Admission For Next Class</h6>
						</div>
						<hr/>
						
						
						<form class="row g-2">
							<div class="col-md-2">
								<label>Year</label>
								<select id="ddlyears" class="form-select mb-3" aria-label="Default select example">
													
								</select>
							</div>	
                          															
							<div class="col-md-2">
								<label>Previous Class</label>
								<select id="ddlsclass" class="form-select mb-3" aria-label="Default select example">
						
								</select>
							</div>
							<div class="col-md-2">
								<label> Previous Division</label>
								<select id="ddldivision" class="form-select mb-3" aria-label="Default select example">
																			
								</select>
							</div>														
					       <div class="col-md-3" style="margin-top: 4.7vh;">
							<button type="button" onclick="getdata13();" class="btn btn-primary"><i class='bx bx-search'></i>Search</button>
									
						   </div>						   
                           </form>
                       </div>
                   </div>				   				  						
				<!-- <div class="row row-cols-auto g-2">

				<div class="col">
					<button style="height:35px; width: 35px; padding-left:7px;"  data-bs-toggle="modal" data-bs-target="#exampleLargeModal" type="button" class="btn btn-secondary"6><i class="fadeIn animated bx bx-user-plus"></i>
					</button>
				</div>
				<div class="col">
					<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"><i class='bx bx-message-square-edit'></i>
					</button>
				</div>
				<div class="col">
					<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>
				</div>
				<div class="col">
					<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-warning"><i class="lni lni-share"></i>
					</button>
				</div>
				
				<div class="col">
					<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-dark"><i class="fadeIn animated bx bx-printer"></i>
					</button>
				</div>
				</div>
				</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>Package ID</th>
										   <th>Package Name</th>  
                                           <th>Student Name</th>  
										   <th>Class Name</th>
										   <th>Divison</th>
                                           <th>Academic Year</th>
                                           <th>Registration Date</th>
										   
										   
										<%--   <th>Create Date</th>--%>
										   <th style="background-color:white;">Action</th>
									   </tr>
								   </thead>
                                
								   <%--<tbody>
									<tr>
										<td></td>
										<td><input></td>
										<td><input></td>
										<td><input></td>
										<td><input></td>
										<td><input></td>
										<td><input></td>
										<td><input></td>
										<td style="background-color:white;"></td>
									</tr>
									   <tr>
										   <td>1</td>
										   <td>1321</td>	
										   <td>CAP</td>
										   <td>B.Pharm</td>
										   <td>1st Year</td>
										   <td>12-14-2022</td>
										   <td>749.00</td>
										   <td>14-10-2022</td>
										   <td style="background-color: white;">
											<button style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#exampleLargeModal5"><i class="fadeIn animated bx bx-user-plus"></i>
											</button>							
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  data-bs-toggle="modal" data-bs-target="#exampleLargeModal5" ><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>
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-primary"><i class="lni lni-save"></i>
											</button>
										   </td>										
										   </tr>
										   <tr>
											<td>2</td>
											<td>1321</td>	
											<td>APC</td>
											<td>M.Pharm</td>
											<td>1st Year</td>
											<td>12-14-2022</td>
											<td>749.00</td>
											<td>14-10-2022</td>
											<td style="background-color: white;">
											 <button style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#exampleLargeModal5"><i class="fadeIn animated bx bx-user-plus"></i>
											 </button>								
											 <button style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  data-bs-toggle="modal" data-bs-target="#exampleLargeModal5" ><i class='bx bx-message-square-edit'></i>
											 </button>
											 <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>
											 <button style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-primary"><i class="lni lni-save"></i>
											 </button>
											</td>										
											</tr>
									   </tbody>--%>
							   </table>
						   </div>
					   </div>
				   </div>
			   </div>
			   </div>
		    </div>			
   </div>
            </div> 
     <div class="col">
		<!-- Button trigger modal -->
		
		<!-- Modal -->
		<div class="modal fade" id="exampleLargeModal5" tabindex="-1" aria-hidden="true">
			<div class="modal-dialog modal-xl">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title">Transfer</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
					</div>
					<div class="modal-body"> 
                       <h5> <label>Previous Payment History</label> </h5>
                          <div class="col-md-12 mx-auto">
						<div class="card">
							<div class="card-body">
								<table class="table mb-0" id="tblinstall">
									<thead class="table-dark">
										<tr>
											<th scope="col">Sr.No.</th>
												
											<th scope="col">Stud ID</th>
                                            <th scope="col">Division</th>
											<th scope="col">Paymode</th>
											<th scope="col">Receipt No.</th>
											<th scope="col">Payment Date</th>
                                            <th scope="col">Cheque/DD No.</th>
                                             <th scope="col">Bank Name</th>
                                             <th scope="col">Paid Amount</th>
										</tr>
									</thead>
									<tbody>
										<tr>
										
										</tr>
									
									</tbody>
								</table>
							</div>
						</div>
					
					</div>
                        <hr />
                          <h5> <label>Transfer Form</label> </h5>
                        <form class="row g-2">
						<div class="col-md-2">
						<label>Next Year</label>
							<select class="form-select mb-3" id="ddlyears1" aria-label="Default select example">
						
							</select>
						</div>
						<div class="col-md-2">
						<label>Next Class</label>
							<select class="form-select mb-3" id="clasrch1" aria-label="Default select example">
						
							</select>
						</div>
						
						
						<div class="col-md-2">
						<label>Next Division</label>
								<select class="form-select mb-3" id="divisrch1" aria-label="Default select example">
						
						
							</select>
						</div> 
                        	<div class="col-md-2">
						<label>Package</label>
								<select class="form-select mb-3" id="ddlpackages" aria-label="Default select example">
						
						
							</select>
						</div>
                         <div class="col-md-1" style="margin-top: 1vh;display:none">
						<button type="button" onclick="getdata13();" class="btn btn-primary">Transfer</button>
						
										
					   </div>
						
					  

				

					
					<div class="col-md-1" style="margin-top: 3vh;">
						<button type="button" id="btntransfer" onclick="updatestudent()" class="btn btn-primary">Transfer</button>
						
										
					   </div>

					   
					   </form>

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