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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <style>
        input:focus {
           caret-color : red;
        }
    </style>
<div class="page-wrapper">
    <script>
        var difftotal = 0;
        var totalinstallpay = 0;
        var total = 0;
        var chkval21 = [];
        var firsttotal = 0;
        var secondtotal = 0;
        var yrsidss = "";
        var clsidss = "";
        var dividss = "";
        var studidss = "";
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "scholershipassign.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) {
                        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);
                }

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


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


                            $('select[id$=txtdivi]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=txtdivi]').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: "scholershipassign.aspx/PopulateDropDownList11",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlcategory]').empty();
                    //var currentdt = new Date();
                    //var cuurentyr = currentdt.getFullYear();
                    //var prevyr = currentdt.setFullYear(currentdt.getFullYear() - 1);
                    $('select[id$=ddlcategory]').append("<option value='0'>Select Category</option>");

                    $.each(result.d, function (key, value) {
                      
                        $('select[id$=ddlcategory]').append($("<option data-toggle='tooltip' data-placement='top' title='" + value.DeptName + "'></option>").val(value.DeptId).html(value.DeptName));
                        //console.log(value.DeptName);
                    });
                    $('select[id$=ddlcategory]').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 searchdata() {
            if ($('select[id$=ddlyears]').val() == "0") {
                noty({ text: 'Please Select Year', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            if ($('select[id$=ddlclassty]').val() == "0") {
                noty({ text: 'Please Select Class', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            if ($('select[id$=txtdivi]').val() == "0") {
                noty({ text: 'Please Select Division', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            if ($('select[id$=ddlcategory]').val() == "0") {
                noty({ text: 'Please Select Category', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
                return false;
            }
            var obj = {};
            obj.years = $('select[id$=ddlyears]').val();
            obj.classs = $('select[id$=ddlclassty]').val();
            obj.divisions = $('select[id$=txtdivi]').val();
            obj.cat = $('select[id$=ddlcategory]').val();
            $.ajax({
                type: "POST",
                url: "scholershipassign.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.clear();
                        for (var i = 0; i < data.length; i++) {
                          
                            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();
                            totalinstallpay = parseFloat(data[i].totalpaidamt);
                            total = parseFloat(data[i].totalamtss);
                            difftotal = total - totalinstallpay;
                            if (data[i].installtype == "firstinst" && data[i].firstinstall != "") {
                                firsttotal = parseInt(data[i].firstinstall);
                            }
                            else {
                                firsttotal = 0;
                            }
                            if (data[i].installtype == "secondinst" && data[i].secondinstall != "") {
                                secondtotal = parseInt(data[i].secondinstall);
                            }
                            else {
                                secondtotal = 0;
                            }
                            table.row.add([

                            stryr, data[i].classname, data[i].divname, data[i].pname, data[i].feename, difftotal, totalinstallpay, data[i].status, firsttotal, secondtotal, "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' data-bs-toggle='modal' data-bs-target='#popup5' onclick=editdata(" + data[i].admyears + "," + data[i].classd + "," + data[i].division + ",\"" + data[i].studids + "\") id='btnedit' class='btn btn-success'><i class='bx bx-message-square-edit'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;display:none' type='button' onclick=deletedata() id='btndelete' class='btn btn-danger'><i class='fadeIn animated bx bx-trash-alt'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;display:none' type='button' class='btn btn-primary'><i class='lni lni-save'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;display:none' type='button' class='btn btn-dark'><i class='bx bx-x'></i></span></button>"

                            ]).draw(true);
                            //if (data[i].status == "Scholorship" && data[i].scholershipstatus != "Approved") {
                              
                            //  //  $("#rr" + i).trigger("click");
                            //} else {
                            //    $("#rr" + i).addClass('disabled'); $("#rr" + i).hide();
                            //}
                        }
                    }else{
                        noty({ text: 'No Records Found!!', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                    }
                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }
                });
       
        }
        function editdata(yids, clsid, divid, stsids) {
            yrsidss = yids;
            clsidss = clsid;
            dividss = divid;
            studidss = stsids;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "scholershipassign.aspx/PopulateDropDownList12",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlpackage]').empty();

                    $('select[id$=ddlpackage]').append("<option value='0'>Select Package</option>");

                    $.each(result.d, function (key, value) {

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

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

            }); 
        }
        function assignscholerhip() {
            if ($('select[id$=ddlpackage]').val() != "0") {
                //$("input:checkbox[name=Reception]:checked").each(function () {
                //    ids = $(this).attr('id');

                //    chkval21.push($(this).val());
                //});
           
               
                //if (chkval21 == "") {
                //    noty({ text: 'Please Checked check box after search ', layout: 'topRight', type: 'information' });
                //    setTimeout(function () { $.noty.closeAll(); }, 3000);
                //    return false;
                //}
                $.ajax({
                    url: "scholershipassign.aspx/UpdateData",
                    contentType: "application/JSON; charset=utf-8",
                    method: "post",
                    datatype: "JSON",
                    data: "{studids : '" + studidss + "',scholids:'" + $('select[id$=ddlpackage]').val() + "',yid :'"+ yrsidss +"',cids :'"+ clsidss +"',dids :'"+ dividss +"'}",
                    success: function (data) {

                        if (data.d == "available") {
                            noty({ text: 'Already assign First Installment', layout: 'topRight', type: 'information' });
                            setTimeout(function () { $.noty.closeAll(); }, 3000);

                        }
                        else if (data.d == "insert") {
                            noty({ text: 'Assigned Successfully', layout: 'topRight', type: 'information' });
                            setTimeout(function () { $.noty.closeAll(); }, 3000);
                        }
                        else if (data.d == "update") {
                            noty({ text: 'Second Installment Assign Sucessfully', layout: 'topRight', type: 'information' });
                            setTimeout(function () { $.noty.closeAll(); }, 3000);
                        }
                    }
                });
            } else {
                noty({ text: 'Please Select Package', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);

            }
        }
    </script>
			<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>Scholership Student List</h6>
						</div>
						<hr />
						
						
						<form class="row g-2">
							    <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="ddlclassty" class="form-select">
								
								</select>
							</div>
							<div class="col-md-3">
								<label>Division</label>
								<select id="txtdivi" class="form-select">
								
								</select>
							</div>
                             	<div class="col-md-3">
								<label>Category</label>
								<select id="ddlcategory" class="form-select">
								
								</select>
							</div>
					<div class="col-md-2" style="margin-top: 4.7vh;">
			        <button type="button" id="btnadd" value="Submit" onclick="searchdata();" class="btn btn-primary"><i class='bx bx-plus-circle'></i>Search</button>&nbsp;&nbsp;  
							
											
						   </div>
                              	<div class="col-md-3" style="display:none">
								<label>Scholership Package</label>
								<select id="" class="form-select">
								
								</select>
							</div>
						   <div class="col-md-3" style="margin-top: 4.7vh;display:none">
                                <button type="button" id="Button1" value="Submit" onclick="assignscholerhip();" class="btn btn-primary">Assign Scholership</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>Year</th>
                                           <th>Class</th>
										   <th>Division</th>
                                           <th>Student Name</th>
                                            <th>Category</th>
                                           <th>Balance Amount  </th>
                                           <th>Paid Amount</th>
                                           <th>Status</th>
                                           <th>First Installment</th>
                                            <th>Second Installment</th>
										   <th style="background-color: white;">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="popup5" tabindex="-1" aria-hidden="true">
			<div class="modal-dialog modal-xlg">
				<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="mcloses" aria-label="Close"></button>
					</div>
					<div class="modal-body">
                        	<div class="col-md-12">
                            	<div class="col-md-6">
								<label>Scholership Package</label>
								<select id="ddlpackage" class="form-select">
								
								</select>
							</div>
						   <div class="col-md-3" style="margin-top: 4.7vh;">
                                <button type="button" id="Button2" value="Submit" onclick="assignscholerhip();" class="btn btn-primary">Assign Scholership</button>
						   </div>
                                </div>
                        </div>
				
				</div>
			</div>
		</div>
	</div>
    </asp:Content>