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

<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "canceladmissionaccount.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: "canceladmissionaccount.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: "canceladmissionaccount.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);
                    }

                });
            });
        
        });
        var totalpaid = 0;
        var remainsamt = 0;
        var totalremainsamt = 0;
        function getdata12() {

            $.ajax({
                url: "canceladmissionaccount.aspx/Getdata",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: "{acdyear :'" + $('select[id$=ddlyears]').val() + "',clasr:'" + $("select[id$=ddlclass]").val() + "', division:'" + $("select[id$=ddldivi]").val() + "'}",
                dataType: "json",
                success: function (data) {



                    //$("#dataemp").find("tbody").empty();
                    // $("#dataemp").find("tbody").empty();

                    table = $('#dataemp').DataTable();
                    table.destroy();
                    if (data.d != "") {
                        data = JSON.parse(data.d);
                    }
                    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%" },
                        { "width": "6%" },
                         { "width": "6%" }, { "width": "6%" }
                        ]
                    });

                    $('#dataemp').DataTable().clear().draw();
                    for (var i = 0; i < data.length ; i++) {
                        if (data[i].packgenme != null) {
                            totalpaid = parseFloat(data[i].totalpaidamt);
                            remainsamt = parseFloat(data[i].amount);
                            totalremainsamt = remainsamt - totalpaid;
                        }
                        if (totalpaid == "") {
                            totalremainsamt = 0;
                        }
                        totalfess = parseFloat(data[i].totaltutionfee) + parseFloat(data[i].totaldevelopfee)
                        if (data[i].firstinstall != "" && data[i].firstinstall != null && data[i].secondinstall != "" && data[i].secondinstall != null) {
                            //  totalfess = parseFloat(data[i].totaltutionfee) +  parseFloat(data[i].totaldevelopfee) + parseFloat(data[i].firstinstall) + parseFloat(data[i].secondinstall);
                            totalschol = parseFloat(data[i].firstinstall) + parseFloat(data[i].secondinstall);
                        }
                        else if (data[i].firstinstall != "" && data[i].firstinstall != null) {
                            //  totalfess = parseFloat(data[i].totaltutionfee) + parseFloat(data[i].totaldevelopfee) + parseFloat(data[i].firstinstall);
                            totalschol = parseFloat(data[i].firstinstall);
                        }

                        else {
                            totalfess = parseFloat(data[i].totaltutionfee) + parseFloat(data[i].totaldevelopfee);
                            totalschol = 0;
                        }
                        if (totalfess != 0 && totalschol == 0) {
                            totalpaid = parseFloat(totalfess);
                        } else if (totalfess == 0 && totalschol != 0) {
                            totalpaid = parseFloat(totalschol);
                        }
                        else if (totalfess != 0 && totalschol != 0) {

                            totalpaid = parseFloat(totalfess) + parseFloat(totalschol);
                        }
                        clgfees = parseFloat(64000);
                        if (totalschol > 0) {
                            if (parseFloat(data[i].scholerhipamount) != 0) {
                                allbalnce = 0;
                            } else {
                                allbalnce = parseFloat(clgfees) - parseFloat(totalpaid);
                            }
                        } else {
                            allbalnce = 0;
                        }

                        fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        var markup = "<tr><td>" + data[i].studid + "</td><td>" + data[i].admdate + "</td><td>" + fullname + "</td><td>" + data[i].packgenme + "</td><td>" + data[i].clsname + "</td><td>" + data[i].divsname + "</td><td>" + data[i].amount + "</td><td>" + data[i].totalpaidamt + "</td><td>" + totalremainsamt + "</td><td>" + data[i].scholerhipstudent + "</td><td>" + data[i].scholershipstatus + "</td><td><button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=getdataacctstudent('" + data[i].pkgid + "',\"" + data[i].studid + "\"," + data[i].clsids + "," + data[i].divsid + "," + data[i].admyrs + ") id='btnedit' class='btn btn-success' data-bs-toggle='modal' data-bs-target='#exampleLargeModal5' ><i class='bx bx-message-square-edit'></i></button></td></tr>";

                        //  $("#dataemp").find("tbody").append(markup);

                        table.row.add([
                            data[i].studid, data[i].admdate, fullname, data[i].packgenme, data[i].clsname, data[i].divsname, data[i].amount, data[i].totalpaidamt, totalremainsamt, totalfess, data[i].firstinstall, data[i].secondinstall, totalschol, totalpaid, clgfees, allbalnce, "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=getdetails(\"" + data[i].studid + "\") id='btnedit' class='btn btn-success' data-bs-toggle='modal' title='Pay Now' data-bs-target='#exampleLargeModal5' ><i class='bx bx-message-square-edit'></i></button>&nbsp;<button  style='height:35px; width: 35px; padding-left:7px;display:none;' type='button' onclick='getstdetails(\"" + data[i].studid + "\"," + data[i].clsids + "," + data[i].divsid + "," + data[i].admyrs + "," + data[i].firstinstall + "," + data[i].secondinstall + "," + allbalnce + ")' id='btnedit' class='btn btn-success' data-bs-toggle='modal' title='Against Scholership' data-bs-target='#exampleLargeModal51' ><i class='bx bx-message-square-edit'></i></button>"
                        ]).draw(false);
                    }
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        }
        var markup1 = "";
        function getdetails(stids) {
            $.ajax({
                url: "canceladmissionaccount.aspx/Getdata12",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: "{studids:'" + stids + "'}",
                dataType: "json",
                success: function (data) {
                    console.log(JSON.stringify(data));
                    data = JSON.parse(data.d);


                    //  $("#Table2").find("tbody").empty();

                    for (var i = 0; i < data.length ; i++) {
                        {
                            if (data[i].chequenos != null) {
                                $("#chk1").show();
                                $("#chk2").show();
                                $("#chk3").show();
                            } else {
                                $("#chk1").hide();
                                $("#chk2").hide();
                                $("#chk3").hide();
                            }
                            if (data[i].chqdt != null) {
                                chksdt = data[i].chqdt;
                            }
                            markup1 = '<tr ><td >' + data[i].receiptnos + '</td><td >' + data[i].paidamt + '</td><td >' + data[i].recptdate + '</td><td>' + data[i].paymode + '</td><td  id="chks1' + i + '"> ' + data[i].chequenos + '</td><td id="chks2' + i + '"> ' + chksdt + '</td><td id="chks3' + i + '"> ' + data[i].bankname + '</td><td><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;" onclick="printdata(\'' + data[i].studid + '\',' + data[i].id + ',' + data[i].receiptnos + ',' + data[i].scholershipids + ')" type="button" class="btn btn-primary"><i class="fadeIn animated bx bx-printer"></i></button> </td></tr>';
                            //  alert(data[i].chequenos);

                            $("#Table2").find("tbody").append(markup1);

                            //if (data[i].chequenos != null) {
                            //    $("#chks1" + i).show(); $("#chks2" + i).show(); $("#chks3" + i).show();
                            //}
                            //else {
                            //    $("#chks1" + i).hide(); $("#chks2" + i).hide(); $("#chks3" + i).hide();
                            //}
                        }
                    }
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            });
        }
        function printdata(stdids, installtid, recptid, scholid) {

            $("#printabel3").remove();
            loadpage1(stdids, installtid, recptid);
        }
        function loadpage1(id, recept, receptsid) {
            setTimeout(function () {
                $("<iframe id='printabel3'>")

            .attr("src", "printreceipt.aspx?student=" + id + "&instids=" + recept + "&receptsids=" + receptsid)

            .appendTo("body");
                $("#printabel3").hide();
            }, 2000);
            // $("#mcloses")[0].click();
        }
    </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>Cancel Admission Student</h6>
						</div>
						<hr />
                        	<form class="row g-2">
							
                            <div class="col-md-2">
								<label>Year</label>
							<select id="ddlyears" class="form-select">
								
								</select>
							</div>
                            <div class="col-md-2">
								<label>Class</label>
							<select id="ddlclass" class="form-select">
								
								</select>
							</div>
							<div class="col-md-2">
								<label>Division</label>
									<select id="ddldivi" class="form-select">
								
								</select>
							</div> 
                               <div class="col-md-3" style="margin-top: 4.7vh;">
							<button type="button" onclick="getdata12()" class="btn btn-primary"><i class='bx bx-search'></i>Search</button>
							<button style="" type="button" title="Print"  class="btn btn-secondary">Print</button>											
						   </div>	
                                </form>
                                </div> 
                     <hr />
						   <div class="table-responsive">
							   <table id="dataemp" class="table table-striped table-bordered">
								   <thead>
									    <tr>
										   <th>Student ID</th>	
                                           <th>Admission Date</th>
                                           <th>Student Name</th>	
									       <th>Package Name</th>  
										   <th>Class Name</th>
										   <th>Divison</th>
										   <th>Total Amount</th>
									       <th>Paid Amount</th>
                                           <th>Balance Amount</th>
                                           <th>All Fees</th>
                                           <th>First Installment</th>
                                           <th>Second Installment</th>
                                           <th>Total Scholership</th>
                                             <th>Total Paid</th>
                                            <th>College Fee</th>
                                               <th>All Balance</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 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">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 mx-auto">
						<div class="card">
							<div class="card-body">
								<table class="table mb-0" id="Table2">
									<thead class="table-dark">
										<tr>
											
												
											<th scope="col">Ref. No</th>
											<th scope="col">Amount</th>
											<th scope="col">Pay Date</th>
                                            <th scope="col">Mode</th>
											<th scope="col"  id="chk1">Cheque/DD No.</th>
                                            <th scope="col"  id="chk2">Date</th>
                                            <th scope="col"  id="chk3">Bank</th>
                                             <th scope="col">Action</th>
										</tr>
									</thead>
									<tbody>
										
									
									</tbody>
								</table>
							</div>
						</div>
					
					</div>
                        </div>
                    </div> 
                </div> 
            </div> 
            </div>

</asp:Content>