<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">
    <div class="modal-body">
        <div class="row mt-2">
            <div class="col-md-4">
                <label for="">تاریخ:</label>
                <input type="date" id="u_date" class="form-control change_focus" data-id="u_amount"
                       name="date" 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 for="">رقم:</label>
                <input type="text" class="form-control change_focus" data-id="u_broker" name="amount"
                       value="{{ $voucher->amount }}"
                       id="u_amount">
                <span class="text-danger error" id="u_amount_error"></span>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label for="name">پاڑٹی: <span class="text-danger">*</span></label>
                    <select name="broker" id="u_broker" class="form-control change_focus"
                            data-id="u_cash">
                        <option value="">----Select Party----</option>
                        @forelse ($brokers as $broker) 
                            <option value="{{ $broker->id }}"
                                    data-table="broker"
                                    @selected($voucher->ref_type=='broker'
                                    && $voucher->ref_id == $broker->id)>{{ $broker->name }}</option>
                        @empty
                        @endforelse
                        @forelse ($customers as $customer)
                            <option value="{{ $customer->id }}"
                                    data-table="customer" @selected($voucher->ref_type=='customer' && $voucher->ref_id == $customer->id)>{{ $customer->name }}</option>
                        @empty
                        @endforelse
                        @forelse ($other_accounts as $other)
                            <option value="{{ $other->id }}"
                                    data-table="other" @selected($voucher->ref_type=='other' && $voucher->ref_id == $other->id)>{{ $other->name }}</option>
                        @empty
                        @endforelse


                        @forelse ($brokers as $b)
                            <option value="{{ $b->id }}"
                                    data-table="broker" @selected($voucher->ref_type=='broker' && $voucher->ref_id == $b->id)>{{ $b->name }}</option>
                        @empty
                        @endforelse

                        @forelse ($vehicles as $v)
                            <option value="{{ $v->id }}"
                                    data-table="vehicle" @selected($voucher->ref_type=='vehicle' && $voucher->ref_id == $v->id)>{{ $v->vehicle_no }}</option>
                        @empty
                        @endforelse
                        @forelse ($drivers as $d)
                            <option value="{{ $d->id }}"
                                    data-table="driver" @selected($voucher->ref_type=='driver' && $voucher->ref_id == $d->id)>{{ $d->name }}</option>
                        @empty
                        @endforelse

                        @forelse ($workshops as $s)
                            <option value="{{ $s->id }}"
                                    data-table="workshop" @selected($voucher->ref_type=='workshop' && $voucher->ref_id == $s->id)>{{ $s->shop_name }}</option>
                        @empty
                        @endforelse
                        @forelse ($banks as $b)
                            <option value="{{ $b->id }}"
                                    data-table="bank" @selected($voucher->ref_type=='bank' && $voucher->ref_id == $b->id)>{{ $b->name }}</option>
                        @empty
                        @endforelse
                    </select>
                    <span class="text-danger error" id="u_broker_error"></span>
                </div>
            </div>

        </div>
        <div class="row">
            <div class="col-md-4">
                <label for="">ادائیگی کی قسم:</label><br>
                <label for="u_cash">
                    <input type="radio" id="u_cash" name="payment_type" class="change_focus" data-id="u_bank"
                           onchange="payment_type_change('cash', 'yes')"
                           value="cash" @checked($voucher->payment_type== 'cash')>
                    کیش</label>
                &nbsp; &nbsp;
                <label for="u_bank">
                    <input type="radio" id="u_bank" name="payment_type" class="change_focus" data-id="all_bank"
                           onchange="payment_type_change('bank', 'yes')"
                           value="bank" @checked($voucher->payment_type=='bank')>
                    بینک</label><br>
                <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 for="">بینکس</label>
                        <select name="bank" id="all_bank" class="form-control change_focus" data-id="broker">
                            <option value="">---Select Bank---</option>
                            @forelse ($banks as $bank)
                                <option
                                    value="{{ $bank->id }}" @selected($bank->id == $voucher->bank_id)>{{ $bank->name }}</option>
                            @empty
                            @endforelse
                        </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 for="">تفصیل:</label>
                <textarea name="description" id="u_description" cols="10" rows="2"
                          class="form-control"></textarea>
                <span class="text-danger error" id="u_description_error"></span>
            </div>

        </div>
    </div>
    <div class="modal-footer">
        @csrf
        <button id="update_btn" class="btn btn-sm btn-info" type="submit">
            اپ ڈیٹ
        </button>
        <input type="hidden" name="user_type" id="u_user_type" value="{{ $voucher->ref_type }}">

        <input type="hidden" name="update_id" value="{{ $voucher->id }}">
    </div>
</form>
