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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

   
    <script type="text/javascript">
        var count = 0;
        var yrscode = "";
        $(document).ready(function () {
            //$("#dp-5").datepicker({ dateFormat: "dd-mm-yyyy" }).datepicker("setDate", new Date());
            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;
            $("#btnsave").click(function () {
                if ($("#btnsave").val() == "Submit") {
                    SaveData();
                }
                else if ($("#btnsave").val() == "Update") {
              
                    updatedata();
                }
            });
           datatable();
        });

        function SaveData() {

            var obj = {};
            obj.year = $("#txtyear").val();
            obj.fromdate = $("#dp-5").val();
            obj.todate = $("#dp-6").val();

            $.ajax({
                type: "POST",
                url: "academicyearr.aspx/savedata", //It calls our web method.
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(obj),
                dataType: "json",
                success: function (data) {
                    console.log(JSON.stringify(data));

                    noty({ text: 'Saved Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);

                    datatable();
                    Clear();
                },
                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 datatable() {
            $.ajax({
                type: "POST",
                url: "academicyearr.aspx/GetData",
                contentType: "application/JSON; charset=utf-8",

                datatype: "JSON",
                success: function (data) {
                    var table = $('#dataemp').DataTable();
                    data = JSON.parse(data.d);
                    table.clear();
                    for (var i = 0,count = 1; i < data.length; i++,count++) {
                        var date2  = new Date(data[i].fromdate); 
                        var date8 = new Date(data[i].todate);
                        var date2year = date2.getFullYear();
                        var date8year = date8.getFullYear();
                        var dtyearstr = date2year + "-" + date8year;
                        table.row.add([
                             count, data[i].yearcode, dtyearstr, data[i].acdyear,  data[i].acdyear1, data[i].year,
                             "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=editdata('" + data[i].id + "') id='btnedit' 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' onclick=deletedata('" + data[i].id + "') 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;' type='button' class='btn btn-primary'><i class='lni lni-save'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' class='btn btn-dark'><i class='bx bx-x'></i></span></button>"

                        ]).draw(true);

                    }
                }
            });
        } 
        var id1 = "";
        function editdata(id) {
            $.ajax({
                url: "academicyearr.aspx/EditData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: "{id:'" + id + "'}",
                success: function (data) {
                    data = JSON.parse(data.d);
                    console.log(data);
                    $("#txtacdyear").val(data[0].year);
                    yrscode = data[0].yearcode;
                    id1 = id;
               
                  //  var  today4 = new Date(data[0].fromdate).toISOString().substr(0,10);
                    var   today4 = new Date(new Date(data[0].fromdate).setDate(new Date(data[0].fromdate).getDate() + 1)).toISOString().substr(0,10);
                 
                    //today4.setDate(today4.getDate() + parseInt(1));
                    document.querySelector("#ddlfromyear").value = today4;
                   // var  today5 = new Date(data[0].todate).toISOString().substr(0,10);
                    var   today5 = new Date(new Date(data[0].todate).setDate(new Date(data[0].todate).getDate() + 1)).toISOString().substr(0,10);
                    document.querySelector("#ddltoyear").value = today5;
               

                }
            });
        }

        function updatedata() {

            var obj1 = {};
            obj1.acdid = id1;
            obj1.fromdate = $("#ddlfromyear").val();
            obj1.todate = $("#ddltoyear").val();
            obj1.year = $("#txtacdyear").val();
            obj1.yrcode = yrscode;
            $.ajax({
                url: "academicyearr.aspx/UpdateData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: JSON.stringify(obj1),
                success: function (data) {
                    datatable();
                    Clear1();
                    $("#mclose")[0].click();
                    noty({ text: 'Update Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);

                }
            });
        }
        function deletedata(id1) {

            $.ajax({
                url: "academicyearr.aspx/DeleteData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: "{id:'" + id1 + "'}",
                success: function (data) {
                    datatable();
                    noty({ text: 'Delete Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            });
        }
        function Clear() {
            $("#txtyear").val("");
            $("#dp-5").val("");
            $("#dp-6").val("");
        } 
        function Clear1() {
            $("#txtacdyear").val("");
            let today2 = new Date().toISOString().substr(0, 10);
                     
            document.querySelector("#ddlfromyear").value = today2;
            let today3 = new Date().toISOString().substr(0, 10);
                     
            document.querySelector("#ddltoyear").value = today3;
        }
    </script>
    <div class="page-wrapper">
			<div class="page-content">
				<div class="row">
					<div class="col-md-8 mx-auto" >
					
				<div class="card">
					<div class="card-body">
						<div class="card-title d-flex align-items-center">

							<h6>Academic Year</h6>
						</div>
						<hr>
						
						
						<form class="row g-2">
							<div class="col-md-3"></div>
							<div class="col-md-3">
								<label>Academic Year</label>
								<input class="form-control mb-3" type="text" placeholder="Academic Year"
								aria-label="default input example">
							</div>
							
							
							
							
					       <div class="col-md-3" style="margin-top: 4.7vh;">
							<button type="button" class="btn btn-primary"><i class='bx bx-search'></i>Search</button>&nbsp;
							<button style="height:35px; width: 35px; padding-left:7px;" data-bs-toggle="modal" data-bs-target="#exampleLargeModal4" type="button" class="btn btn-secondary"><i class="fadeIn animated bx bx-user-plus"></i>
																	</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>Year ID</th>
										   <th>Year Period</th>  
										   <th>From Date</th>
										   <th>To Date</th>
										   <th>Year</th>
										   <th style="background-color: white;">Action</th>
									   </tr>
								   </thead>
								   <tbody>
								<%--	<tr>
										<td><input class="form-control mb-3" type="text" placeholder=""
											aria-label="default input example"></td>
											<td><input class="form-control mb-3" type="text" placeholder=""
												aria-label="default input example"></td>
												<td><input class="form-control mb-3" type="text" placeholder=""
													aria-label="default input example"></td>
													<td><input class="form-control mb-3" type="text" placeholder=""
														aria-label="default input example"></td>
														<td><input class="form-control mb-3" type="text" placeholder=""
															aria-label="default input example"></td>
															<td><input class="form-control mb-3" type="text" placeholder=""
																aria-label="default input example"></td>
																<td style="background-color: white;">
																	<%--<button style="height:35px; width: 35px; padding-left:7px;" data-bs-toggle="modal" data-bs-target="#exampleLargeModal4" type="button" class="btn btn-secondary"><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="#exampleLargeModal4"><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>
																	</td>
									</tr>--%>
									<%--   <tr>
										   <td>1</td>
										   <td>140</td>	
										   <td>2022-2023</td>
										   <td>12-09-2022</td>
										   <td>14-10-2023</td>
										   <td>2022</td>
										   <td style="background-color: white;">
											<button style="height:35px; width: 35px; padding-left:7px;" data-bs-toggle="modal" data-bs-target="#exampleLargeModal4" type="button" class="btn btn-secondary"><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="#exampleLargeModal4"><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>
											</td>
														
											</tr>--%>
									   </tbody>
							   </table>
						   </div>
					   </div>
				   </div>
			   </div>
			   </div>
		   </div>			
   
				   
		   <div class="col">
		   <!-- Button trigger modal -->
		   <!-- Modal -->
		   <div class="modal fade" id="exampleLargeModal4" tabindex="-1" aria-hidden="true">
			   <div class="modal-dialog modal-lg">
				   <div class="modal-content">
					   <div class="modal-header">
						   <h5 class="modal-title">Academic Year Setup</h5>
						   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
					   </div>
					   <div class="modal-body"><form class="row g-2">
                           								
						<div class="col-md-3">
							<label>From date</label>
							<input class="form-control mb-3" id="dp-5" type="date"
								aria-label="default input example" />

						</div>
                           
						<div class="col-md-3">
							<label>To date</label>
							<input class="form-control mb-3" id="dp-6" type="date"
								aria-label="default input example" />
						</div>
						<div class="col-md-3">
							<label>Academic Year</label>
							<input class="form-control mb-3" id="txtyear" type="text" placeholder="Academic Year"
								aria-label="default input example" />
						</div>
						<div class="col-md-2">
						<button type="button" id="btnsave" value="Submit" class="btn btn-primary" style="margin-top:3vh;">Save</button>
						</div>	

					</form>

                           
					   <!-- <div class="modal-footer"> -->
						
						   
					   </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-lg">
				   <div class="modal-content">
					   <div class="modal-header">
						   <h5 class="modal-title">Academic Year Setup</h5>
						   <button type="button" class="btn-close" id="mclose" data-bs-dismiss="modal" aria-label="Close"></button>
					   </div>
					   <div class="modal-body"><form class="row g-2">
                           								
						<div class="col-md-3">
							<label>From date</label>
							<input class="form-control mb-3" id="ddlfromyear" type="date"
								aria-label="default input example" />

						</div>
                           
						<div class="col-md-3">
							<label>To date</label>
							<input class="form-control mb-3" id="ddltoyear" type="date"
								aria-label="default input example" />
						</div>
						<div class="col-md-3">
							<label>Academic Year</label>
							<input class="form-control mb-3" id="txtacdyear" type="text" placeholder="Academic Year"
								aria-label="default input example" />
						</div>
						<div class="col-md-2">
						<button type="button" id="Button1" value="Submit" class="btn btn-primary" onclick="updatedata()" style="margin-top:3vh;">Update</button>
						</div>	

					</form>

                           
					   <!-- <div class="modal-footer"> -->
						
						   
					   </div>
				   </div>
			   </div>
		   </div>
	   </div>	


				
				<!--end page wrapper -->
				<!--start overlay-->
				
		<!--end page wrapper -->
		<!--start overlay-->
		<div class="overlay toggle-icon"></div>
		<!--end overlay-->
		<!--Start Back To Top Button--> <a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
		<!--End Back To Top Button-->
		
	</div>
            </div>
</asp:Content>

