<script>
    $(document).ready(function (){
        $('#insurer-list').select2();

        /**Anytime someone searches for a vehicle to Remit premium, do as below**/
        $('#filter-certificates').click( function (){
            let insurer = $('#insurer-list').val();
            let regNo = $('#reg-no').val();
            let dateFrom = $('#date-from-filter').val();
            let dateTo = $('#date-to-filter').val();

            $('#my-certificates').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="{{asset('images/loads/loader.gif')}}" border=0></div>');
            if(insurer != ""){
                if(regNo != ""){
                    if(dateFrom != "" && dateTo == ""){
                        alert('Please Choose the End Date');
                        $('#my-certificates').html('');
                        return false;
                    }

                    let my_url_link = '/get-declaration-report-on-vehicle/'+insurer+'/'+regNo+'/'+dateFrom+'/'+dateTo;
                    /**Using AJAX, get the Certificates Issued on this Vehicle**/
                    $.ajax({
                        method: 'GET',
                        url: my_url_link,
                        success: function (res){
                            if(res != "exists"){
                                $('#my-certificates').html(res);
                            }else{
                                alert('There was a System Error. Please Filter the Report again');
                                return false;
                            }
                        }
                    });
                }else{
                    alert('Please Enter Vehicle Registration Number to Proceed');
                    return false;
                }
            }else{
                alert('Please Select an Insurer to Proceed');
                return false;
            }
        });

    });
</script>

<div class="error" style="text-align: center;">On this Window, You can Create a New Requisition</div>
<div class="guestDetails_inputDivider"></div>
<button type="submit" disabled style="display: none" aria-hidden="true"></button>
<div class="guestDetails_inputDivider1"></div>
{{--REMIT PREMIUM REQUISITION--}}
<div id="remit-premium-requisition-div">
    <div class="guestDetails_inputDivider1"></div>
    <div class="inputDivider" style="background-color: lightcyan">
        <div class="fields" >
            <div class="guestDetails_input_right">
                <div class="guestDetails_inputLabel">
                    &nbsp;
                </div>
                <div class="guestDetails_input">
                    <button type="button" name="search" style="cursor: pointer;float: right; height: 22px" id="filter-certificates"><i class="fa fa-search" aria-hidden="true"></i></button>
                </div>
            </div>
            <div class="guestDetails_input_right">
                <div class="guestDetails_inputLabel">
                    Date To:<span class="error">*</span>
                </div>
                <div class="guestDetails_input_right">
                    {!! Form::date('to', $search['to'] ?? "", ['id'=>'date-to-filter','style'=>'cursor:pointer', 'class'=>'input-text-height', 'required'=>true]) !!}
                </div>
            </div>
            <div class="guestDetails_input_right">
                <div class="guestDetails_inputLabel">
                    Date From:<span class="error">*</span>
                </div>
                <div class="guestDetails_input_right">
                    {!! Form::date('from', $search['from'] ?? "", ['id'=>'date-from-filter','style'=>'cursor:pointer', 'class'=>'input-text-height', 'required'=>true]) !!}
                </div>
            </div>
            <div class="guestDetails_input_right">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('reg-number', 'Enter REG Number') !!}<span class="error">*</span>
                </div>
                <div class="guestDetails_input">
                    {!! Form::text('reg-no', $search['regNo'] ?? '', ['size'=>20,'class'=>'input-text-height', 'id'=>'reg-no']) !!}
                </div>
            </div>
            <div class="guestDetails_input_right">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('insurer', 'Select Insurance Company') !!}<span class="error">*</span>
                </div>
                <div class="guestDetails_input">
                    <select name="insurer" id="insurer-list" style="width: 200px">
                        <option value="">--Select Insurer--</option>
                        @foreach(app('Insurers') as $insurer)
                            <option value="{{$insurer['ins_id']}}">{{$insurer['nm']}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="guestDetails_inputDividerNone"></div>
            <div id="my-certificates"></div>
        </div>
    </div>
</div>
