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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script  type="text/javascript">
        var chkval = [];
        $(document).ready(function () {
            getdata();
        });
        function getdata() {
            $.ajax({
                type: "POST",
                url: "leavingcertilist.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, '<input class="form-check-input" type="checkbox" style="display:none" name="Reception" value="' + data[i].id + '" id="' + "rr" + i + '">',
                                 "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=printdata(" + data[i].id + ") 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, '<input class="form-check-input" type="checkbox" style="display:none" name="Reception" value="' + data[i].id + '" id="' + "rr" + i + '">',
                                " <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);
                            if (data[i].status == "Pending For Approval") {
                                $("#rr" + i).show();

                            }
                            else {
                                $("#rr" + i).hide();
                            }
                        }
                    }
                }
            });
        }
        function printdata(cerid) {
            $("#printabel3").remove();
            loadotherpage(cerid);
        }
        function loadotherpage(cerid) {
            setTimeout(function () {
                $("<iframe id='printabel3'>")

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

            .appendTo("body");
                $("#printabel3").hide();
            }, 2000);
        }
        function btnapprove() {
          
                $("input:checkbox[name=Reception]:checked").each(function () {
                    chkval.push($(this).val());
                });
                if (chkval != "") {
                $.ajax({
                    url: 'leavingcertilist.aspx/PopulateDropDownListselectmemb',
                    method: 'post',
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    data: "{ certiids :'" + chkval + "'}",
                    success: function (data) {
                        console.log(data.d);
                        if (data.d == "approved") {


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

                    },
                    error: function () {
                        noty({ text: 'Error in insert', layout: 'topRight', type: 'warning' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);

                    }

                });
            } else {
                noty({ text: 'Please Select checkbox', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
            }
        }
    </script>
     <div class="page-wrapper">
			<div class="page-content">
                	<h6>Leaving Certificate Approve List</h6>
                <div class="card">
                     
					<div class="card-body">
                    <div class="card-title d-flex align-items-center">

						  <button type="button" id="Button1"  class="btn btn-primary" onclick="btnapprove();" style="float:right">Approve</button>
                  
						</div>
                        
                         
                               <div class="table-responsive">
                        <table id="Table1" class="addrow1" style="margin-top:20px" 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" id="tdapprove">Approve</th>
                            <th style="text-align:center">Action</th>
                        </tr>
                    </thead>
                    <tbody>

                    </tbody>

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