@extends('layout.app')

@section('content')

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title" style="color:#115548;"><i class="fa fa-search"></i> Select Criteria
                            </h3>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                            {{-- <div class="row"> --}}
                            <form action="" id="search">
                                <div class="row">

                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="block text-gray-700 text-sm font-bold mb-2" for="from_date">
                                                From Date
                                            </label>
                                            <div class="input-group date" id="searchFrom" data-target-input="nearest">
                                                <input type="text" name="from_date" value="{{$start->format('m/d/y')}}"
                                                    class="form-control datetimepicker-input input-group-append"
                                                    data-toggle="datetimepicker" data-target="#searchFrom"
                                                    autocomplete="off">

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

                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="block text-gray-700 text-sm font-bold mb-2" for="to_date">
                                                To Date
                                            </label>
                                            <div class="input-group date" id="searchTo" data-target-input="nearest">
                                                <input type="text" name="to_date" value="{{$end->format('m/d/y')}}"
                                                    class="form-control datetimepicker-input input-group-append"
                                                    data-toggle="datetimepicker" data-target="#searchTo" autocomplete="off">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-md-4">

                                            <div class="form-group">
                                                <label class="flex-1 block text-gray-700 text-sm font-bold mb-2" >
                                                    Select Item <span class="text-danger">(require)</span>
                                                </label>
                                                <select name="item_id" id="item_id" class="form-control select2 form-control-sm" required>
                                                    <option value="all" selected>ALL</option>
                                                    @foreach ($items as $item)
                                                        <option value="{{ $item->id }}">{{ $item->name }}</option>

                                                    @endforeach

                                                </select>
                                            </div>

                                    </div>
                                    <span class="text-success text-md badge">NOTE: If you select All, then the Summary Result will come. If item is single, then the full result will come.</span>

                                    <div class="col-md-12">
                                        <div class="form-group float-right mt-2">
                                            {{-- <button @click="search" type="submit" id="searchBtn"
                                                class="btn btn-info byn-block form-control ">
                                                Search
                                            </button> --}}
                                            <button @click="search" class="btn btn-primary" type="submit"
                                                    id="searchBtn"><i class="fa fa-search"></i> Search</button>

                                        </div>
                                    </div>

                                </div>
                            </form>
                            {{-- </div> --}}
                            <br>
                            <div class="col-md-12" id="result">

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

@endsection

@section('js')

@endsection
@push('script')
    <!-- page script -->

@endpush

@section('ajax')
    <script type="text/javascript">
        //console.log('error');
        $(document).ready(function() {
            $('#reset').click(function() {
                $('#result').html('');
            });
            $('#searchBtn').on('click', function(e) {

                e.preventDefault();
                // $('body').prepend('<div id="loading">Loading.....</div>');

                $.ajax({
                    type: 'get',
                    url: '{{ route('crmReturnReportSearch') }}',
                    data: $('#search').serialize(),
                    // alert(result);
                    success: function(result) {
                        console.log(result);
                        $('#result').html(result);
                        $('#loading').remove();

                    }
                });
            });

        });
    </script>

@endsection
