@include('header')
@php
$UserId = Session::get('UserId');
@endphp
<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">Average Patient Stay List
         </h4>
    <div class="card mb-4">
        <div class="card-body">
            <div id="alert_message"></div>
            <form id="validation-form" method="post" enctype="multipart/form-data">
                <div class="form-row">
                   
                    <div class="form-group col-md-2">
                        <label class="form-label">From Date </label>
                        <input type="date" name="FromDate" id="FromDate" class="form-control" value="{{date('Y-m-d')}}"
                            autocomplete="off">
                    </div>
                     <div class="form-group col-md-2">
                        <label class="form-label">To Date</label>
                        <input type="date" name="ToDate" id="ToDate" class="form-control" value="{{date('Y-m-d')}}" autocomplete="off">
                    </div> 
                    <input type="hidden" name="Search" value="Search">
                    <div class="form-group col-md-2" style="padding-top:20px;">
                    <button type="button" class="btn btn-primary btn-finish"
                            id="filter">Search</button>
                    </div>

                    <div class="form-group col-md-4" style="padding-top:20px;">
                    <button type="button" class="btn btn-success btn-finish" id="AvgTime">Average Time : 0</button>

</div>
                </div>

            </form>

            <div class="table-responsive" id="custresult">


            </div>
        </div>
    </div>




</div>

@include('footerscript')
@include('excelscript')
<script type="text/javascript">
$(document).ready(function() {
    var FromDate = $('#FromDate').val();
  var ToDate = $('#ToDate').val();
  queueList(FromDate,ToDate);

    $('#filter').click(function(){
  var FromDate = $('#FromDate').val();
  var MrdNo = $('#MrdNo').val();
  var ToDate = $('#ToDate').val();
  if(FromDate != '')
  {
   //$('.yajra-datatable').DataTable().destroy();
   //load_data(FromDate, ToDate);
   queueList(FromDate,ToDate);
  }
  else
  {
   alert('Date is required');
  }
 });

 $('#refresh').click(function(){
  $('#FromDate').val('');
  //$('.yajra-datatable').DataTable().destroy();
  //load_data();
  queueList();
 });

 
});

function avgTime(FromDate = '',ToDate='') {
    $.ajax({
        url: "{{ url('calAvgTime') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            FromDate: FromDate,
            ToDate:ToDate
        },
        success: function(data) {
            //console.log(data);
            $('#AvgTime').html('Average Time : '+data+' Min');
        }
    });

}

function queueList(FromDate = '',ToDate='') {
    //alert(FromDate);alert(MrdNo);
    $.ajax({
        url: "{{ url('viewAvgPatients') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            FromDate: FromDate,
            ToDate:ToDate
        },
        success: function(data) {
            //console.log(data);
            avgTime(FromDate,ToDate);
            $('#custresult').html(data);
        }
    });
}


</script>
</script>
