<script>
    $(document).ready(function (){
        $('#requisition-list').select2();
        $('#debit-list').select2();
        $('#currency-option').select2();
        $('#bills-list').select2();

        /**Anytime we Chose a Requisition Type, Display affected ledgers**/
        $('#requisition-list').change(function (){
            let type = $(this).val();
            $('#insurer-list-div').hide();
            $("#debit-list option[value !='']").remove();
            if(type != ""){
                /**Load Accounts to be Debited(Mostly these are always CR Accounts)**/
                $.ajax({
                    method: 'GET',
                    url: '/requisition-debit-accounts/'+type,
                    data: type,
                    success: function (res){
                        if(res != ""){
                            $('#debit-list').append(res);
                        }
                    }
                });
            }
        });
        {{--CHANGING CURRENCY SECTION--}}
        $('#currency-option').on('change',function (){
            var currencySelected = $(this).val();
            $('#conversion-rate-div').hide();

            $.ajax({
                method: 'GET',
                url: '/currency-conversion-rate/'+currencySelected,
                data: currencySelected,
                success: function (res){
                    if(res != ""){
                        $('#conversion-rate-div').show();
                        $('#conversion-rate-field').html(res);

                    }else{
                        $('#conversion-rate-div').hide();
                    }
                }
            });
        });
    });
</script>
{!! Form::open(['action'=>['Payments\RequisitionController@storeCreateNewAdvanceSalaryRequisition', 'id'=>$id], 'id'=>'create-advance-salary-requisition', 'method'=>'POST']) !!}
<div class="error" style="text-align: center;">On this Window, You can Create a New Requisition to Pay a Advance Salary</div>
<div class="guestDetails_inputDivider"></div>
<button type="submit" disabled style="display: none" aria-hidden="true"></button>
<div class="guestDetails_inputDivider1"></div>

<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Select a Requisition Type <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <select name="requisition-type" style="width: 240px" id="requisition-list">
            <option value="">--Select an Item--</option>
            <option value="advance-salary">ADVANCE SALARY</option>
        </select>
    </div>
</div>

<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Credited Account (CR) <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <select name="debit-type" style="width: 240px" id="debit-list">
            <option value="">--Select Account to Pay To--</option>
        </select>
    </div>
</div>
<div class="guestDetails_inputDivider1"></div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Payee <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        {!! Form::text('payee', $advance->employee ? $advance->employee->firstName." ".$advance->employee->lastName : 0, ['id'=>'payee-details','class'=>'input-text-height', 'size'=>90]) !!}
    </div>
</div>
<div class="guestDetails_inputDivider1"></div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Current Balance <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        {!! Form::text('current-bill-balance', $advance->amount ?? 0, ['id'=>'current-bill-balance','class'=>'input-text-height', 'size'=>15, 'readonly'=>true]) !!}
    </div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        <span class="error">Requisition Amount *</span>
    </div>
    <div class="guestDetails_input">
        {!! Form::number('req-amount', $advance->amount ?? 0, ['id'=>'requisition-amount','class'=>'input-text-height', 'style'=>'width: 110px']) !!}
    </div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Currency <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <select name="currency" style="width: 120px" id="currency-option">
            <option value="{{app('BaseCurrency')->id}}">{!! app('BaseCurrency')->abbr !!}</option>
            @foreach(app('OtherCurrency') as $other)
                <option value="{!! $other->id !!}">{!! $other->abbr !!}</option>
            @endforeach
        </select>
    </div>
</div>
<div class="guestDetails_input" id="conversion-rate-div" style="display: none">
    <div class="guestDetails_inputLabel">
        <i class="" id="conversion-rate-label">Conversion Rate:</i> <span class="error">*</span>
    </div>
    <div class="guestDetails_input" id="conversion-rate-field"></div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Requisition Date <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        {!! Form::date('req-date', '', ['class'=>'input-text-height', 'style'=>'width:90px']) !!}
    </div>
</div>
<div class="guestDetails_inputDivider1"></div>

<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        {!! Form::label('narration', 'Narration') !!} <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        {!! Form::textarea('narration', '',['style'=>'width:500px; height:60px']) !!}
    </div>
</div>

{!! Form::close() !!}
