<form method="POST" id="updateTripPayableForm">

    <div class="row mt-2">
        <div class="col-md-4">
            <label for="">ادائیگی قسم:</label><br>
            <label for="adv_cash">
                <input type="radio" name="payment_type" onchange="adv_payment_change('cash')"
                       @checked($tripPayable->payment_type=='cash')
                       id="adv_cash" value="cash">
                کیش</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <label for="adv_bank_payment">
                <input type="radio" name="payment_type"
                       onchange="adv_payment_change('bank')"
                       @checked($tripPayable->payment_type=='bank')
                       id="adv_bank_payment" value="bank">
                بینک</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <label for="adv_broker_payment">
                <input type="radio" name="payment_type"
                       onchange="adv_payment_change('broker')" @checked($tripPayable->payment_type=='on_account')
                       id="adv_broker_payment" value="on_account">
                ان اکاوؑنٹ</label>
            <br>
            <span class="text-danger error" id="payment_type_error"></span>
        </div>
        <div class="col-md-8" id="adv_bank_dev">
            @if($tripPayable->payment_type=='bank')
                <label for="">بینک:</label><br>

                <select name="bank" id="adv_bank" class="from-control">
                    <option value="">----Select Bank----</option>
                    @forelse($banks as $bank)
                        <option
                            value="{{ $bank->id }}" @selected($tripPayable->bank_id == $bank->id)>{{ $bank->name }}</option>
                    @empty
                        <option value="">NO BANK AVAILABLE</option>
                    @endforelse
                </select><br>

                <span class="text-danger error" id="bank_error"></span>

            @endif
            {{-- @if($tripPayable->payment_type=='on_account')
                <label for="">اکاوؑنٹ:</label><br>

                <select name="party" onchange="advance_amount_change()"
                        id="adv_broker" class="from-control">
                    <option value="">----Select Account----</option>
                    @forelse($brokers as $broker)
                        <option value="{{ $broker->id }}"
                                @selected($tripPayable->on_account_id == $broker->id && $tripPayable->on_account_type=='broker') data-table="broker">{{ $broker->name }}</option>
                    @empty
                    @endforelse
                </select><br>

                <span class="text-danger error" id="party_error"></span>

            @endif --}}
        </div>
    </div>

    <div class="row">
        <div class="col-md-4">
            <label>تاریخ:</label>
            <input type="date" name="date" id="payable_date" value="{{ date('Y-m-d',strtotime($tripPayable->date)) }}"
                   class="form-control change_focus" data-id="amount">
            <span class="text-danger p_error" id="p_date_error"></span>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label for="broker_id">پارٹی نام<span class="text-danger">*</span></label>
                <select name="broker_id" class="form-control change_focus" id="payable_party" onchange="party_change_for_payable()"
                        data-id="item_name">
                    <option value="">SELECT</option>
                    @forelse ($brokers as $broker)
                        <option value="{{ $broker->id }}"  {{ $broker->id == $tripPayable->broker_id ? 'selected' : '' }} >{{ $broker->name }}</option>
                    @empty
                    @endforelse
                </select>
                <span class="text-danger error" id="broker_id_error"></span>

            </div>
        </div>

        <div class="col-md-4" id="pump_payable_dev"></div>


    </div>



    <div class="row mt-2">
        <div class="col-md-4">
            <label for="">رقم</label>
            <input type="text" name="amount" id="amount" value="{{ $tripPayable->amount }}" class="form-control change_focus" data-id="payable_party">
            <span class="text-danger p_error" id="p_amount_error"></span>
        </div>
    </div>
    <div class="row mt-2">
        <div class="col-md-12">
            <div class="form-group">
                <label for="remark">ریمارکس:</label>
                <textarea rows="2" cols="10" id="remark" name="remarks"  class="form-control">{{ $tripPayable->description }}</textarea>
                <span class="text-danger p_error" id="p_remarks_error"></span>

            </div>
        </div>
    </div>
    @csrf
    <input type="hidden" name="user_type" id="u_user_type" value="{{ $tripPayable->ref_type }}">

    <input type="hidden" name="update_id" value="{{ $tripPayable->id }}">
    <input type="hidden" name="vehicle_id" value="{{ $tripPayable->vehicle_id }}">
    <input type="hidden" name="trip_id" value="{{ $tripPayable->trip_id }}">
    <input type="hidden" name="brokerReach_id" value="{{ $tripPayable->trip_oil_id }}">
    <input type="hidden" name="old_amount" value="{{ $tripPayable->amount }}">
    <input type="hidden" name="total_amount" value="{{ $tripAdvance->advance_amount }}">
    @php
    $short_amount = $tripAdvance->adv_short_amount ?? 0;
    $advance_amount = $tripAdvance->advance_amount ?? 0;

    $actual_amount = ($short_amount != 0) ? $short_amount : $advance_amount;
@endphp
<input type="hidden" name="hidden_total_amount_reach" value="{{ $actual_amount }}">
    <button type="submit" class="btn btn-success btn-sm" id="advancePayableUpdate">محفوظ</button>
</form>
