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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $('select[id$=Select1] option:eq(1)').attr("selected", true);
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "onlinewisereports.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$=ddlyears]').trigger("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: "onlinewisereports.aspx/PopulateDropDownList5",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlsclass]').empty();
                    $('select[id$=ddlsclass]').append("<option value='0'>Select Class</option>");
                    $.each(result.d, function (key, value) {


                        $('select[id$=ddlsclass]').append($("<option data-toggle='tooltip' data-placement='top' title='" + value.DeptName + "'></option>").val(value.DeptId).html(value.DeptName));
                        //console.log(value.DeptName);
                    });
                    $('select[id$=ddlsclass]').val('0').change();

                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }

            });
            $('select[id$=ddlsclass]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "onlinewisereports.aspx/PopulateDropDownList6",
                    data: "{clsid : '" + $('select[id$=ddlsclass]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddldivision]').empty();
                        $('select[id$=ddldivision]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {


                            $('select[id$=ddldivision]').append($("<option data-toggle='tooltip' data-placement='top' title='" + value.DeptName + "'></option>").val(value.DeptId).html(value.DeptName));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=ddldivision]').val('0').change();

                    },
                    error: function ajaxError(result) {
                        console.log(result.status + ' : ' + result.statusText);
                    }

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

            $.ajax({
                url: "onlinewisereports.aspx/Getdata",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: "{acdyear :'" + $('select[id$=ddlyears]').val() + "',clasr:'" + $("select[id$=ddlsclass]").val() + "', division:'" + $("select[id$=ddldivision]").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": "7%" },
                                    { "width": "7%" },
                                     { "width": "7%" },
                                      { "width": "7%" },

                        ]
                    });

                    $('#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;
                        }
                        fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;

                      
                        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,data[i].paymode,data[i].chequesdt,data[i].chequenos,data[i].bankname,
                        ]).draw(false);
                        total = total + parseFloat(data[i].totalpaidamt);
                    }
                    $("#totalamt").html(total);
                },
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        }
        function ExportData() {

            var obj = {};
            obj.clasr = $("select[id$=ddlsclass]").val();
            obj.division = $("select[id$=ddldivision]").val();
            obj.acdyear = $('select[id$=ddlyears]').val();
            if ($('select[id$=ddlyears]').val() != "0") {
                if ($("select[id$=ddldivision]").val() != "0") {
                    if ($('select[id$=ddlsclass]').val() != "0") {
                        $.ajax({
                            url: 'onlinewisereports.aspx/Export',
                            method: 'post',
                            contentType: 'application/json;charset=utf-8',
                            data: JSON.stringify(obj),
                            dataType: 'json',
                            success: function (_data) {
                                table = $('#dataemp').DataTable();
                                table.destroy();
                                if (_data.d != "") {
                                    _data = JSON.parse(_data.d);
                                }
                                var table = $('#dataemp').DataTable({

                                    "order": [[0, "asc"]],
                                    "ordering": false,
                                    "pageLength": 10,
                                    "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                                    "dom": 'lBfrtip',
                                    buttons: [
                                    {
                                        extend: 'excelHtml5',
                                        text: 'Export to Excel',
                                        title: 'Student List',
                                        download: 'open',
                                        orientation: 'landscape',
                                        exportOptions: {
                                            columns: ':visible'
                                        }
                                    }],
                                    "columns": [
                                   { "width": "5%" },
                                 { "width": "8%" },
                                 { "width": "10%" },
                                 { "width": "10%" },
                                 { "width": "10%" },
                                 { "width": "7%" },
                                 { "width": "6%" },
                                 { "width": "10%" },
                                 { "width": "7%" },
                                   { "width": "7%" },
                                    { "width": "7%" },
                                     { "width": "7%" },
                                      { "width": "7%" },
                                    ]
                                });

                                $('#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;
                                    }
                                    fullname = _data[i].title + "." + _data[i].fname + " " + _data[i].mname + " " + _data[i].lname;
                                    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, _data[i].paymode, _data[i].chequesdt, _data[i].chequenos, _data[i].bankname,



                                    ]).draw(false);
                                }
                            },
                            error: function () {


                                noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                                setTimeout(function () { $.noty.closeAll(); }, 3000);
                            }
                        });
                    } else {
                        noty({ text: 'Please Select Class', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                    }
                }
                else {
                    noty({ text: 'Please Select Division', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            } else {
                noty({ text: 'Please Select Year', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
            }

        }
        </script>
      <div class="page-wrapper">
			<div class="page-content">
                	
                <div class="card">
					<div class="card-body">
						<div class="card-title d-flex align-items-center">

							<h6>Account Online Cash Reports</h6>
                          
						</div>
						<hr/>
						
						
						<form class="row g-2">
							<div class="col-md-2">
								<label>Year</label>
								<select id="ddlyears" class="form-select mb-3" aria-label="Default select example">
													
								</select>
							</div>	
                            <div class="col-md-2">
								<label>College</label>
								<select id="Select1" class="form-select mb-3" aria-label="Default select example">
									<option value="0">Select</option>
									<option value="1">Hi-Tech College of B. Pharmacy</option>
												
								</select>
							</div>															
							<div class="col-md-2">
								<label>Class</label>
								<select id="ddlsclass" class="form-select mb-3" aria-label="Default select example">
						
								</select>
							</div>
							<div class="col-md-2">
								<label>Division</label>
								<select id="ddldivision" class="form-select mb-3" aria-label="Default select example">
																			
								</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>
                   </div>	
                <div class="card">
                     
					<div class="card-body">
                    <div class="card-title d-flex align-items-center">

						
                        </div>
                       <div class="row">
                    <div class="col-md-12">
                            <div class="col-md-3">
                        <label>Total Cash :</label> &nbsp; <label id="totalamt"></label>
                        </div>
                            <div class="col-md-4"></div>
                         <div class="col-md-3" style="float:right;margin-bottom:3px">
                              <button class="btn btn-primary" type="button" style=""  onclick="ExportData();"> Export Data</button>
                             </div>
					
						</div>
						</div>
                               <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>Payment Mode</th>
                                            <th>Payment Date</th>
                                           <th>Cheque Nos.</th>
                                            <th>Bank Name</th>
									   </tr>
								   </thead>
                                
								
							   </table>
                    </div>
                            </div>
					</div>
                    </div>
               
         </div>
    </asp:Content>