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

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

    <script type="text/javascript">

        $(document).ready(function () {
            var total = 0;
            var num = 0;
            var num1 = 0;
            var num2 = 0;
            var num3 = 0;
            var num4 = 0;
            var divids = "";
            $("#btnSubmit").show();
            //$("#btnadd").click(function () {
            //    if ($("#btnadd").val() == "Submit") {
            //        btnadd();
            //    }
            //    else if ($("#btnadd").val() == "Update") {
            //        updatedata();
            //    }
            //});
            $("#txttheory").val("0");
            $("#txtpractical").val("0");
            $("#prjfee").val("0");
            $("#txtprocessing").val("0");
            $("#txtdegree").val("0");
            $("#txtamt").val("0");
           datatable();
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "feemaster.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: "feemaster.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(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: "feemaster.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: "feemaster.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$=ddlclassty]').selectpicker('refresh');
                        //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                    },
                    error: function ajaxError(result) {
                        console.log(result.status + ' : ' + result.statusText);
                    }

                });
            });
            $("#txttheory").bind('blur keyup', function (e) {
                if (e.type === 'blur' || e.keyCode === 13) {

                    total = 0;
                    num = parseFloat($("#txttheory").val());
                    total = total + num; $('#txtamt').val(total);
                }
            });
            $("#txtpractical").bind('blur keyup', function (e) {
                if (e.type === 'blur' || e.keyCode === 13) {

                    total = 0;
                    num1 = parseFloat($("#txtpractical").val()) + num;
                    total = total + num1; $('#txtamt').val(total);
                }
            });
            $("#prjfee").bind('blur keyup', function (e) {
                if (e.type === 'blur' || e.keyCode === 13) {

                    total = 0;
                    num4 = parseFloat($("#prjfee").val()) + num1;
                    total = total + num4; $('#txtamt').val(total);
                }
            });
            $("#txtprocessing").bind('blur keyup', function (e) {
                if (e.type === 'blur' || e.keyCode === 13) {

                    total = 0;
                    num2 = parseFloat($("#txtprocessing").val()) + num4;
                    total = total + num2; $('#txtamt').val(total);
                }
            });
            $("#txtdegree").bind('blur keyup', function (e) {
                if (e.type === 'blur' || e.keyCode === 13) {

                    total = 0;
                    num3 = parseFloat($("#txtdegree").val()) + num2;
                    total = total + num3; $('#txtamt').val(total);
                }
            });
        });

        function btnadd() {
            var obj = {};
            obj.pkgname = $("#txtname").val();
            obj.yrs = $('select[id$=ddlyears]').val();
            obj.clss = $("select[id$=ddlclass]").val();
            obj.divs = $("select[id$=ddldivi]").val();
            obj.semisters = $("select[id$=ddlsemister]").val();
            obj.theoryfee = $("#txttheory").val();
            obj.practical = $("#txtpractical").val();
            obj.projfee = $("#prjfee").val();
            obj.processing = $("#txtprocessing").val();
            obj.degreefee = $("#txtdegree").val();
            obj.amots = $("#txtamt").val();
            obj.taxes = $("#txttax").val();
            obj.remarks = $("#txtremark").val();
            obj.status = $("select[id$=ddlst]").val();
            $.ajax({
                type: "POST",
                url: "feemaster.aspx/SavaData",
                data: JSON.stringify(obj),
                contentType: "application/JSON; charset=utf-8",
                datatype: "JSON",
                success: function (response) {
                   
                    $("#btnSubmit").show();
                    datatable(); clears();
                    noty({ text: 'Saved Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                },
                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 clears() {
           $("#txtname").val("");
            $('select[id$=ddlyears]').val("0").change();
            $("select[id$=ddlclass]").val("0").change();
            $("select[id$=ddldivi]").val("0").change();
           $("select[id$=ddlsemister]").val("").change();
           $("#txttheory").val("0");
           $("#txtpractical").val("0");
           $("#prjfee").val("0");
            $("#txtprocessing").val("0");
            $("#txtdegree").val("0");
          $("#txtamt").val("0");
           $("#txttax").val("");
            $("#txtremark").val("");
            $("select[id$=ddlst]").val("").change(); id1 = "";
        }
        var id1 = "";
        function editdata(id) {
            $("#btnSubmit").hide(); $("#Button1").show();
            $.ajax({

                url: "feemaster.aspx/EditData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: "{examid:'" + id + "'}",
                success: function (data) {
                    data = JSON.parse(data.d);
                    $("#txtname").val(data[0].feepackname);
                    $('select[id$=ddlyears]').val(data[0].yearsid).change();
                    $("select[id$=ddlclass]").val(data[0].classid).change();
                  
                    $("select[id$=ddldivi]").trigger("change");
                    divids = data[0].divsid;
                    $("select[id$=ddlsemister]").val(data[0].semisteryears).change();
                    $("#txttheory").val(data[0].theoryfee);
                    $("#txtpractical").val(data[0].practicalfee);
                    $("#txtprocessing").val(data[0].processingfee);
                    $("#prjfee").val(data[0].projectfee);
                    $("#txtdegree").val(data[0].degreefee);
                    $("#txtamt").val(data[0].totalamount);
                    $("#txttax").val(data[0].taxes);
                    $("#txtremark").val(data[0].remarks);
                    $("select[id$=ddlst]").val(data[0].status).change();
                    id1 = id;

                  //  datatable();
                   // $("#btnadd").val('Update');

                }
            });
        }

        function datatable() {
            $.ajax({
                type: "POST",
                url: "feemaster.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 ddyear1 = data[0].fromdate;
                                               var ddyear2 = data[0].todate;
                                               var dtyear1 = new Date(ddyear1);
                                               var dtyear2 = new Date(ddyear2);
                                               var stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();
                        table.row.add([
                             count, data[i].feepackname, stryr, data[i].class, data[i].division, data[i].semnos, data[i].totalamount, data[i].status,
                             "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=editdata('" + data[i].examid + "') id='btnedit' class='btn btn-success'><i class='bx bx-message-square-edit'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=deletedata('" + data[i].examid + "') id='btndelete' class='btn btn-danger'><i class='fadeIn animated bx bx-trash-alt'></i></button>"

                        ]).draw(true);

                    }
                }
            });
        }

        function updatedata() {
            var obj1 = {};
            obj1.exids = id1;
            obj1.pkgname = $("#txtname").val();
            obj1.yrs = $('select[id$=ddlyears]').val();
            obj1.clss = $("select[id$=ddlclass]").val();
            obj1.divs = $("select[id$=ddldivi]").val();
            obj1.semisters = $("select[id$=ddlsemister]").val();
            obj1.theoryfee = $("#txttheory").val();
            obj1.practical = $("#txtpractical").val();
            obj1.projfee = $("#prjfee").val();
            obj1.processing = $("#txtprocessing").val();
            obj1.degreefee = $("#txtdegree").val();
            obj1.amots = $("#txtamt").val();
            obj1.taxes = $("#txttax").val();
            obj1.remarks = $("#txtremark").val();
            obj1.status = $("select[id$=ddlst]").val();
            $.ajax({
                url: "feemaster.aspx/UpdateData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: JSON.stringify(obj1),
                success: function (data) {
                    clears(); $("#Button1").hide(); datatable();
                    noty({ text: 'Update Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            });
        }

        function deletedata(id1) {
            $.ajax({
                url: "feemaster.aspx/DeleteData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: "{id:'" + id1 + "'}",
                success: function (data) {
                    datatable();
                    $("#dataemp").find("tbody").empty();
                    noty({ text: 'Delete Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            });
        }

    </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>Exam Fees</h6>
						</div>
						<hr />
												
						<form class="row g-2">
							<div class="col-md-12"></div>
                              <div class="col-md-3">
								<label style="font-weight:bold">Fee Package</label>
							<input type="text" class="form-control" id="txtname" />
							</div>
                             <div class="col-md-2">
								<label style="font-weight:bold">Year</label>
								<select id="ddlyears" class="form-select" >
								</select>
							</div>
                            <div class="col-md-2">
								<label style="font-weight:bold">Class</label>
								<select id="ddlclass" class="form-select" >
								</select>
							</div>
							
                              <div class="col-md-2">
								<label style="font-weight:bold">Division</label>
								<select id="ddldivi" class="form-select" >							
								</select>
							</div>
							  <div class="col-md-2">
								<label style="font-weight:bold">Semister</label>
								<select id="ddlsemister" class="form-select">
                                  			
								</select>
							</div>
                             <div class="col-md-12 mx-auto">
					<div class="card">
						<div class="card-body">
							<div class="table-responsive">
								<table id="Table1" class="table table-striped table-bordered">
									<thead>
										<tr>
											<th>Sr.no </th>	
											<th>Fee Category</th>
											<th>Amount</th>  
											
										</tr>
									</thead>
									<tbody>
									 
										<tr>
											<td>1</td>
											<td >Theory Fee</td>	
											<td><input id="txttheory" placeholder="Enter Theory Fee" /></td>
										</tr>
											<tr>
												<td>2</td>
												<td>Practical Fee </td>	
												<td><input id="txtpractical" placeholder="Enter Practical Fee" /></td>
											</tr>
                                        <tr>
												<td>2</td>
												<td>Project Fee </td>	
												<td><input id="prjfee" placeholder="Enter Practical Fee" /></td>
											</tr>
                                        <tr>
												<td>3</td>
												<td>Processing Fee</td>	
												<td><input id="txtprocessing" placeholder=" Enter Processing Fee" /></td>
											</tr>
                                        <tr>
												<td>4</td>
												<td >Degree Fees</td>	
												<td><input id="txtdegree" placeholder="Enter Degree Fees" /></td>
											</tr>
                                      
										</tbody>
								 </table>
								
							</div>
						</div>
					</div>
					<%--<form class="row g-2">--%>
                                 <div class="row">
						<div class="col-md-3">
							<label>Total amount<font color="#FF0000">*</font></label>
							<input class="form-control mb-3" id="txtamt" type="text" placeholder="Total amount"
								aria-label="default input example"/>
						</div>
						<div class="col-md-3">
							<label>Remark<font color="#FF0000">*</font></label>
							<input class="form-control mb-3" id="txtremark" type="text" placeholder="Remark"
								aria-label="default input example"/>
						</div>
						<div class="col-md-3">
							<label>Tax<font color="#FF0000">*</font></label>
							<input class="form-control mb-3" id="txttax" type="text" placeholder="Tax"
								aria-label="default input example"/>
			
						</div>
                                       <div class="col-md-2">
								<label style="font-weight:bold">Status</label>
								<select id="ddlst" class="form-select">
                                    <option value="">Select Status</option>
                                    <option value="Active">Active</option>		
                                      <option value="InActive">InActive</option>						
								</select>
							</div>
					   <div class="col-md-2" style="margin-top: 4vh;">
						<button type="button" id="btnSubmit" onclick="btnadd();"  value="Submit" class="btn btn-primary" style="display:none">Submit</button>
                           	<button type="button" id="Button1" onclick="updatedata();"  value="Submit" class="btn btn-primary" style="display:none">Update</button>
						</div>
					 <%--  </form>--%>
				</div>
						</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>Exam Fee Name</th>
                                             <th>Years</th>		
										   <th>Class</th>
										   <th>Division</th>
                                           <th>Semister</th>
                                           <th>Amount</th>
                                            <th>Status</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>
</asp:Content>

