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

<asp:Content ID="content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
          //  Getcode();
            datatable();
            let today2 = new Date().toISOString().substr(0, 10);
                     
            document.querySelector("#issuedt").value = today2;
            $("select[id$=Select1]").change(function () {
                if($("select[id$=Select1]").val() ==  "bonafidecertificate"){
                    $("#bonadiv").show();  $("#leavediv").hide();
                    $("#divnat").hide();
                    $("#divbirth").hide();
                    $("#lastcol").hide();$("#lastprog").hide();$("#divcon").hide();$("#divleaves").hide();
                    $("#divclass").hide();$("#curyear").hide();$("#divreasons").hide();$("#divremarks").hide();

                }
                else  if($("select[id$=Select1]").val() ==  "leavingcertificate"){
                    $("#leavediv").show();  $("#bonadiv").show();
                    $("#divnat").show();
                    $("#divbirth").show();
                    $("#lastcol").show();$("#lastprog").show();$("#divcon").show();$("#divleaves").show();
                    $("#divclass").show();$("#curyear").show();$("#divreasons").show();$("#divremarks").show();
                }
            });
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "certificates.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$=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: "certificates.aspx/PopulateDropDownList15",
                    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 dd = value.DeptName;


                            $('select[id$=ddlclass]').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$=ddlclass]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "certificates.aspx/PopulateDropDownList6",
                    data: "{clids :'" + $('select[id$=ddlclass]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddldivisions]').empty();
                        $('select[id$=ddldivisions]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=ddldivisions]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        //$('select[id$=ddldivisions]').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$=ddldivisions]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "certificates.aspx/PopulateDropDownList7",
                    data: "{yrsids : '"+$('select[id$=ddlyears]').val() +"',clids :'" + $('select[id$=ddlclass]').val() + "',divsid :'"+  $('select[id$=ddldivisions]').val()  +"'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddlstudents]').empty();
                        $('select[id$=ddlstudents]').append("<option value='0'>Select Student</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;
                            var fullname = value.fname + " "+ value.mname + " " + value.lastname;

                            $('select[id$=ddlstudents]').append($("<option data-toggle='tooltip' data-placement='top' title='" + fullname + "'></option>").val(dd).html(fullname));
                            //console.log(value.DeptName);
                        });
                        //$('select[id$=ddldivisions]').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);
                    }

                });
            });
        });
        var fill = 0;
        function Getcode() {

            $.ajax({
                url: 'certificates.aspx/GetEmpData',
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                data: "{}",
                success: function (data) {

                    data = JSON.parse(data.d);
                
                    var nn = parseFloat( data[0].recptno);
                  
                    if(nn == 0){
                        fill = 1;
                    }
                    else{
                        fill = nn + 1;
                    }
                  //  var name = "REC";

                  //  fill = nn;
                    $("#lblrecptnos").html(fill);
                    //  $('#pre').html(fill);
                },



                error: function (error) {
                    console.log(JSON.stringify(error));
                }
            });
        } 
        function Savedata(){
            var obj = {};
            obj.recptnos = $("#lblrecptnos").html();
            obj.issudt = $("#issuedt").val();
            obj.yrs = $("select[id$=ddlyears]").val();
            obj.fathersnm = $("#txtfathernm").val();
            obj.clses = $("select[id$=ddlclass]").val();
            obj.divisions = $("select[id$=ddldivisions]").val();
        
            obj.studnm = $("select[id$=ddlstudents]").val();
            obj.certype = $("select[id$=Select1]").val();
            obj.certimes = $("select[id$=ddlcerttimes]").val();
            obj.nationality = $("#txtnational").val();
            obj.birplace = $("#txtbirth").val();
            obj.attends = $("#txtcolattend").val();

            obj.progresss = $("#txtprogress").val();
            obj.conducts = $("#txtconducts").val();
            obj.leaves = $("#txtleaving").val();
            obj.curclass = $("#txtclass").val();
            obj.curyear = $("#txtyear").val();
            obj.reasons = $("#txtreasons").val();
            obj.remarks = $("#txtremarks").val();
            $.ajax({
                url: 'certificates.aspx/SaveData',
                method: 'post',
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                data: JSON.stringify(obj),
                success: function (data) {
                    // var lstid = data.d;
                  
                  
                    noty({ text: 'Saved Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                    datatable(); 
                },
                error: function () {
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        } 
        function datatable() {
            $.ajax({
                type: "POST",
                url: "certificates.aspx/GetData",
                contentType: "application/JSON; charset=utf-8",

                datatype: "JSON",
                success: function (data) {
                    var table = $('#Table1').DataTable();
                    data = JSON.parse(data.d);
                    table.clear();
               
                    for (var i = 0,count = 1; i < data.length; i++,count++) {
                        if(data[i].status  == "Approved"){
                            table.row.add([
                                 count, data[i].receptnos, data[i].paymentdt, data[i].certtype,data[i].status,
                                 "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=printdata('" + data[i].id + "',\""+ data[i].certtype +"\") id='btnedit' class='btn btn-success'><i class='fadeIn animated bx bx-printer'></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>"

                            ]).draw(true);
                        }else{
                            table.row.add([
                                count, data[i].receptnos, data[i].paymentdt, data[i].certtype,data[i].status,
                                " <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>"

                            ]).draw(true);
                        }
                    }
                }
            });
        } 
        function printdata(cerid,certype) {
            $("#printabel3").remove();
            loadotherpage(cerid,certype);
        }
        function loadotherpage(cerid,certtype) {
            if(certtype == "bonafidecertificate"){
                setTimeout(function () {
                    $("<iframe id='printabel3'>")

                .attr("src", "bonafidecertificates.aspx?ID=" + cerid)

                .appendTo("body");
                    $("#printabel3").hide();
                }, 2000);
            }
            else if(certtype == "leavingcertificate"){
                 setTimeout(function () {
                    $("<iframe id='printabel3'>")

                .attr("src", "leavingcertificates.aspx?ID=" + cerid)

                .appendTo("body");
                    $("#printabel3").hide();
            }, 2000);
            }
        } 
        function clear(){
        } 
        function deletedata(installids) {
            $.ajax({
                type: "POST",
                url: "certificates.aspx/Deletedata",
                data: "{ids :'"+ installids +"'}",
                contentType: "application/JSON; charset=utf-8",
                datatype: "JSON",
                success: function (response) {
                    //window.location.reload();
                  
                  
                        noty({ text: 'Deleted Successfully', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                        datatable();
                  
                    $("#Table1").find("tbody").empty();
                    // $("#Table2 TBODY tr:gt(0)").remove();
                
                    Clear();

                },
                error: function (error) {
                    console.log(JSON.stringify(error));
                    //alert("Error in insert");
                    noty({ text: 'Error in delete', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);

                }

            });
        }
    </script>
    <div class="row">
					<div class="col-md-12 mx-auto" >
    <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>Certificates</h6>
						</div>
                        <div class="col-md-12">
                             <div class="col-md-2" style="display:none">
								<label style="font-weight:bold">Receipt No.</label> <label id="lblrecptnos" style= "color:#0033CC;"></label>
								</div>
							</div>
                    <form class="row g-2">
                        
                    
                      
                        
                          <div class="col-md-2">
								<label style="font-weight:bold">Academic Year<font color="#FF0000">*</font></label>
								<select id="ddlyears" class="form-select mb-3" aria-label="Default select example">
								
                                    </select>
							</div>
							<div class="col-md-2">
								<label style="font-weight:bold">Class<font color="#FF0000">*</font></label>
									<select id="ddlclass" class="form-select mb-3" aria-label="Default select example">
								
                                    </select>
							</div>

								<div class="col-md-2">
								<label style="font-weight:bold">Division<font color="#FF0000">*</font></label>
									<select id="ddldivisions" class="form-select mb-3" aria-label="Default select example">
								
                                    </select>
							</div>
								<div class="col-md-2">
								<label style="font-weight:bold">Student List<font color="#FF0000">*</font></label>
								<select id="ddlstudents" class="form-select mb-3" aria-label="Default select example">
								
                                    </select>
							</div>
                        	
                            	<div class="col-md-2">
								<label style="font-weight:bold">Issue Date<font color="#FF0000">*</font></label>
								<input type="date" id="issuedt" class="form-control" />
							</div>
                          <div class="col-md-2">
								<label style="font-weight:bold">Certificate<font color="#FF0000">*</font></label>
								<select id="Select1" class="form-select mb-3" aria-label="Default select example">
									<option value ="">Select</option>
									<option value="bonafidecertificate">Bonafide Certificate</option>
									<option value="leavingcertificate">Leaving Certificate</option>
                                   
                                    </select>
							</div>
                       <div class="row">
                         <div class="col-md-2">
								<label style="font-weight:bold">Certificate Type<font color="#FF0000">*</font></label>
								<select id="ddlcerttimes" class="form-select mb-3" aria-label="Default select example">
									<option value ="">Select</option>
									<option value="Original">Original</option>
									<option value="Duplicate">Duplicate</option>
                                   <option value="Triplicate">Triplicate</option>
                                    </select>
							</div>
                     
                          
                            <div class="col-md-2" id="bonadiv" style="display:none">
								<label style="font-weight:bold">Father Name<font color="#FF0000">*</font></label>
								<input type="text" id="txtfathernm" class="form-control" />
							</div>
                      
                            
                            	<div class="col-md-2" id="divnat" style="display:none">
								<label style="font-weight:bold">Nationality<font color="#FF0000">*</font></label>
								<input type="text" id="txtnational" class="form-control" />
							</div>
                            <div class="col-md-2" id="divbirth" style="display:none">
								<label style="font-weight:bold">Birth Place<font color="#FF0000">*</font></label>
								<input type="text" id="txtbirth" class="form-control" />
							</div>
                             <div class="col-md-2" id="lastcol" style="display:none">
								<label style="font-weight:bold">Last College Attended<font color="#FF0000">*</font></label>
								<input type="text" id="txtcolattend" class="form-control" />
							</div>
                             <div class="col-md-2" id="lastprog" style="display:none">
								<label style="font-weight:bold">Progress<font color="#FF0000">*</font></label>
								<input type="text" id="txtprogress" class="form-control" />
							</div>
                             <div class="col-md-2" id="divcon" style="display:none">
								<label style="font-weight:bold">Conduct<font color="#FF0000">*</font></label>
								<input type="text" id="txtconducts" class="form-control" />
							</div>
                             <div class="col-md-2" id="divleaves" style="display:none">
								<label style="font-weight:bold">Leaving Date<font color="#FF0000">*</font></label>
								<input type="date" id="txtleaving" class="form-control" />
							</div>
                              <div class="col-md-2" id="divclass" style="display:none">
								<label style="font-weight:bold">Currently Studying Class<font color="#FF0000">*</font></label>
								<input type="text" id="txtclass" class="form-control" />
							</div>
                            <div class="col-md-2" id="curyear" style="display:none">
								<label style="font-weight:bold">Currently Studying Year<font color="#FF0000">*</font></label>
								<input type="text" id="txtyear" class="form-control" />
							</div>
                             <div class="col-md-2" id="divreasons" style="display:none">
								<label style="font-weight:bold">Reason Of Leaving<font color="#FF0000">*</font></label>
								<textarea id="txtreasons" class="form-control"></textarea>
							</div>
                              <div class="col-md-2" id="divremarks" style="display:none">
								<label style="font-weight:bold">Remark<font color="#FF0000">*</font></label>
								<textarea id="txtremarks" class="form-control"></textarea>
							</div>
                       
                                 
                      
                        
                      </div>
                          
							   <div class="col-md-12">
                        <button type="button" id="Button2" value="Submit" onclick="Savedata();" class="btn btn-primary" style="float:right">Add</button>
                                                        </div>
                       </form>
                    </div>
                </div>
                      </div>
                        	<div class="card">
					<div class="card-body">
                          <table id="Table1" class="addrow1" width="100%" border="0">
                    <thead>
                        <!--  <H6>Vendor List</H6> -->
                        <tr style="background-color:#f0f0f0; font-size:12px; height:30px;">

                            <th width="8%" style="text-align:center;"> Sr.No.</th>
                             <th width="14%" style="text-align:center"> ReceiptNos </th>
                           
                            
                             <th style="text-align:center">Issue Date</th>
                            <th style="text-align:center">Certificate </th>
                              <th style="text-align:center">Status </th>
                            <th style="text-align:center">Action</th>
                        </tr>
                    </thead>
                    <tbody>

                    </tbody>

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