@extends('layouts.app')
@section('title','Case Report Summary | ')
@section('content')
<!-- Content Header (Page header) -->
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0">Case Report Summary</h1>
            </div><!-- /.col -->
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Home</a></li>
                    <li class="breadcrumb-item active">Case Report</li>
                </ol>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->

<section class="content">
    <div class="container-fluid">
        <form id="report_form" class="hide_in_print">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-6 col-lg-4">
                            <div class="form-group">
                                <label>Report Type:</label>
                                <select name="report_type" id="report_type"
                                    class="custom-select @if( $errors->has('report_type')) is-invalid border-danger  @endif"
                                    style="width: 100%;">
                                    <option value="">Select Report Type</option>
                                    @php
                                    $report_type = getCaseReportType();
                                    @endphp
                                    @foreach($report_type as $key => $value)
                                    <option value="{{ $key }}" @if(old('report_type')==$key)) {{ __('selected') }}
                                        @endif>{{ $value }}
                                    </option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3 col-lg-4 date-column">
                            <div class="form-group">
                                <label>From Date:</label>
                                <input type="date" class="form-control" value="{{ date('Y-m-d') }}" name="from_date"
                                    id="from_date" max="{{ date('Y-m-d') }}">
                            </div>
                        </div>
                        <div class="col-md-3 col-lg-4 date-column">
                            <div class="form-group">
                                <label>To Date:</label>
                                <input type="date" class="form-control" name="to_date" value="{{ date('Y-m-d') }}"
                                    id="to_date" max="{{ date('Y-m-d') }}">
                            </div>
                        </div>
                        <div class="col-md-3 col-lg-4 month-column">
                            <div class="form-group">
                                <label for="month_from">From Month:</label>
                                <input type="month" class="form-control" name="from_month" value="{{ date('Y-m') }}"
                                    id="month_from" max="{{ date('Y-m') }}">
                            </div>
                        </div>
                        <div class="col-md-3 col-lg-4 month-column">
                            <div class="form-group">
                                <label for="month_to">To Month:</label>
                                <input type="month" class="form-control" name="to_month" value="{{ date('Y-m') }}"
                                    id="month_to" max="{{ date('Y-m') }}">
                            </div>
                        </div>
                        <div class="col-md-12 col-lg-12">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary" id="search_report">
                                    <i class="fa fa-search"></i> Search Case
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        <div class="card mt-4" id="">
            <div class="card-header">
                <div class="card-title font-weight-bolder">
                    <span id="search_type"></span> <span id="search_from_to"></span>
                </div>
                <button type="button" class="float-right btn btn-sm btn-primary print_btn hide_in_print">Print
                    Report</button>
            </div>
            <div class="card-body" id="report_body">
                <table id="claim_summary_report_table" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Sr No.</th>
                            <th>Report Type</th>
                            <th>Pending</th>
                            <th>Processing</th>
                            <th>Done</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody id="claim_summary_report_data">
                        <tr>
                            <td colspan="6" class="text-center">No Record Found</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>
@endsection
@push('js')
<script>
$('#search_report').click(function() {
    let search_type = $('#search_type');
    let search_from_to = $('#search_from_to');
    let type_text = $('#report_type').find('option:selected').text();
    let type = $('#report_type').find('option:selected').val();

    if (type == '') {
        alert('Please Select Record Type');
    } else {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
        });
        let url = "{{ route('get.case.report.summary') }}";
        $.ajax({
            url: url,
            type: 'post',
            data: $('#report_form').serialize(),
            // dataType: 'json',
            success: function(data) {
                //console.log(data);
                $('#claim_summary_report_data').html();
                search_type.text(type_text);
                $('#claim_summary_report_data').html(data);
            }
        });
    }
});
</script>
@endpush
