<!-- Update Voucher Modal -->
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">ادائیگی واچر کی تبدیلی</h4>
</div>

<form id="update_voucher_form" method="POST" action="{{ route('payment_update') }}">
    @csrf
    <input type="hidden" name="payment_account_id" id="payment_account_id">
    <input type="hidden" name="update_id" value="{{ $voucher->id }}">
    <input type="hidden" name="party_table" id="u_user_type" value="{{ $voucher->ref_type }}">
    <input type="hidden" name="payment_account_id" id="payment_account_id" value="{{ $voucher->payment_account_id }}">

    <div class="modal-body">
        <div class="row mt-2">
            <div class="col-md-4">
                <label>تاریخ:</label>
                <input type="date" id="u_date" name="date" class="form-control change_focus" data-id="u_amount"
                       value="{{ date('Y-m-d', strtotime($voucher->date)) }}">
                <span class="text-danger error" id="u_date_error"></span>
            </div>
            <div class="col-md-4">
                <label>رقم:</label>
                <input type="text" id="u_amount" name="amount" class="form-control change_focus"
                       data-id="u_party" value="{{ $voucher->amount }}">
                <span class="text-danger error" id="u_amount_error"></span>
            </div>
            <div class="col-md-4">
                <label>پارٹی: <span class="text-danger">*</span></label>
                <select name="party" id="u_party" class="form-control change_focus" data-id="u_cash">
                    <option value="">----Select Party----</option>
                    @foreach ($pumps as $pump)
                        <option value="{{ $pump->id }}" data-table="pump"
                            {{ ($voucher->ref_type == 'pump' && $voucher->ref_id == $pump->id) ? 'selected' : '' }}>
                            {{ $pump->name }}
                        </option>
                    @endforeach
                    @foreach ($brokers as $b)
                        <option value="{{ $b->id }}" data-table="broker"
                            {{ ($voucher->ref_type == 'broker' && $voucher->ref_id == $b->id) ? 'selected' : '' }}>
                            {{ $b->name }}
                        </option>
                    @endforeach
                    @foreach ($vehicles as $v)
                        <option value="{{ $v->id }}" data-table="vehicle"
                            {{ ($voucher->ref_type == 'vehicle' && $voucher->ref_id == $v->id) ? 'selected' : '' }}>
                            {{ $v->vehicle_no }}
                        </option>
                    @endforeach
                    @foreach ($other_accounts as $other)
                        <option value="{{ $other->id }}" data-table="other" {{ ($voucher->ref_type == 'other' && $voucher->ref_id == $other->id) ? 'selected' : '' }}>
                            {{ $other->name }}
                        </option>
                    @endforeach
                    @foreach ($banks as $bank)
                        <option value="{{ $bank->id }}" data-table="bank" {{ ($voucher->ref_type == 'bank' && $voucher->ref_id == $bank->id) ? 'selected' : '' }}>
                            {{ $bank->name }}
                        </option>
                    @endforeach
                </select>
                <span class="text-danger error" id="u_party_error"></span>
            </div>
        </div>

        <div class="row mt-2">
            <div class="col-md-4">
                <label>پیمنٹ قسم:</label><br>
                <label for="u_cash">
                    <input type="radio" id="u_cash" name="payment_type" class="change_focus"
                           data-id="all_bank" value="cash"
                           onchange="payment_type_change('cash', 'yes')"
                           {{ $voucher->payment_type == 'cash' ? 'checked' : '' }}>
                    کیش
                </label>
                &nbsp;&nbsp;
                <label for="u_bank">
                    <input type="radio" id="u_bank" name="payment_type" class="change_focus"
                           data-id="all_bank" value="bank"
                           onchange="payment_type_change('bank', 'yes')"
                           {{ $voucher->payment_type == 'bank' ? 'checked' : '' }}>
                    بینک
                </label>
                <span class="text-danger error" id="payment_type_error"></span>
            </div>
            <div class="col-md-8" id="u_bank_dev">
                @if($voucher->payment_type == 'bank')
                    <div class="col-md-12">
                        <label>بینک:</label>
                        <select name="bank" id="all_bank" class="form-control change_focus" data-id="u_description">
                            <option value="">---Select Bank---</option>
                            @foreach ($banks as $bank)
                                <option value="{{ $bank->id }}" {{ $voucher->bank_id == $bank->id ? 'selected' : '' }}>
                                    {{ $bank->name }}
                                </option>
                            @endforeach
                        </select>
                        <span class="text-danger error" id="bank_error"></span>
                    </div>
                @endif
            </div>
        </div>

        <div class="row mt-2">
            <div class="col-md-12">
                <label>تفصیل:</label>
                <textarea name="description" id="u_description" class="form-control" rows="2">{{ old('description', $voucher->description) }}</textarea>
                <span class="text-danger error" id="u_description_error"></span>
            </div>
        </div>
    </div>

    <div class="modal-footer">
        <button id="update_btn" type="submit" class="btn btn-sm btn-info">اپڈیٹ</button>
    </div>
</form>
