@extends('layout')
@section('title', 'پہنچ بقایا  ')
@section('page_title', 'پہنچ بقایا  ')
@section('content')
    <div class="row">
        @if(auth()->user()->hasPermissionTo('create payment voucher'))
            <div class="col-md-4">
                <div class="panel panel-card margin-b-30">
                    <div class="panel-body">

                        <form id="add_broker_reach_form">

                            <div class="row mt-2">
                                <div class="col-md-6">
                                    <label for="">تاریخ:</label>
                                    <input type="date" id="date" class="form-control change_focus" data-id="amount"
                                           name="date" value="{{ date('Y-m-d') }}" autofocus>
                                    <span class="text-danger error" id="date_error"></span>
                                </div>



                            </div>
                            <div class="row mt-2">
                                <div class="col-md-12">

                                    <label for="">پیمنٹ قسم:</label>
                                </div>
                            </div>
                            <div class="row mt-2">
                                <div class="col-md-12">
                                    <label for="cash"><input type="radio" id="cash" name="payment_type"
                                                             class=" change_focus" data-id="bank"
                                                             onchange="payment_type_change('cash')" value="cash">
                                        کیش</label>
                                    &nbsp; &nbsp;
                                    <label for="bank"><input type="radio" id="bank" name="payment_type"
                                                             class="change_focus"
                                                             data-id="party"
                                                             onchange="payment_type_change('bank')" value="bank">
                                        بینک</label>
                                        <label for="in-account"><input type="radio" id="in-account" name="payment_type" class="change_focus"
                                                             data-id="in-account"
                                                             onchange="payment_type_change('in-account')" value="in-account">
                                                             ان اکاؤنٹ</label>
                                        <br>
                                    <span class="text-danger error" id="payment_type_error"></span>
                                </div>
                            </div>
                            <div class="row mt-2" id="bank_dev">

                            </div>
                            <div class="row mt-2" id="workshop_div">

                            </div>

                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="party">پارٹی: <span class="text-danger">*</span></label>
                                        <select name="party" id="party" class="form-control change_focus">
                                            <option value="">----Select Payment Party----</option>
                                            @forelse ($brokers as $b)
                                                <option value="{{ $b->id }}" data-table="broker">{{ $b->name }}</option>
                                            @empty
                                                <option value="">No brokers available</option>
                                            @endforelse
                                        </select>
                                        <span class="text-danger error" id="party_error"></span>
                                    </div>
                                </div>
                            </div>

                            <div class="row mt-2 ">
                                <div class="col-md-12" id="broker_advance_dev"></div>
                            </div>

                            <div class="row mt-2" >
                                <div class="col-md-12">
                                    <label for="">رقم:</label>
                                    <input type="text" class="form-control  change_focus" data-id="cash" id="amount"
                                           name="amount">
                                    <span class="text-danger error" id="amount_error"></span>
                                </div>
                            </div>



                            <div class="row mt-2">
                                <div class="col-md-12">
                                    <label for="">تفصیل:</label>
                                    <textarea name="description" id="description" cols="10" rows="2"
                                              class="form-control"></textarea>
                                    <span class="text-danger error" id="description_error"></span>
                                </div>

                            </div>

                            <div class="row mt-2">
                                <div class="col-md-12">
                                    <div class="">
                                        @csrf
                                        <input type="hidden" name="hidden_total_amount" id="payable_hidden_total_amount">
                                        <input type="hidden" name="vehicle_id" id="vehicle_id_hidden">
                                        <input type="hidden" name="trip_id" id="trip_id_hidden">
                                        <input type="hidden" name="brokerReach_id" id="brokerReach_id_hidden">

                                        <button name="createCitySubmit" id="submit_btn" class="btn btn-sm btn-primary"
                                                type="submit">
                                            محفوظ
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        @endif

        <div class="{{ auth()->user()->hasPermissionTo('create payment voucher')?'col-md-8':'col-md-12' }}">
            <div class="panel panel-card ">
                <div class="panel-body">
                    <table id="driver_table_" class="table table-bordered" cellspacing="0" width="100%">
                        <thead class="bg-gold text-white">
                            <tr style="white-space: nowrap">
                                <th>#</th>
                                <th>تاریخ</th>
                                <th>گاڑی</th>
                                <th>پارٹی</th>
                                <th>رقم	</th>
                                <th>ایکشن</th>
                            </tr>
                            </thead>
                            <tbody>
                                        <?php

                                            $i=1;
                                            foreach($brokerReach as $d){

                                                if($d['type']=='Received'){
                                                    $style= 'green';
                                                }
                                                else {
                                                    $style='red';
                                                }
                                                ?>
                                                    <tr>
                                                        <td>{{ $i }}</td>
                                                        <td>{{ $d->date }}</td>
                                                        <td >{{ $d->vehicle->vehicle_no }}</td>
                                                        <td>{{ $d->broker->name}}</td>
                                                        <td>{{ $d->amount}}</td>
                                                        <td>
                                                            @if (auth()->user()->hasPermissionTo('edit trip oil'))
                                                                <button type="button" class="btn-link broker_reach_edit"
                                                                        data-id="{{ $d->id }}"><span>
                                                                            اپڈیٹ</span></button>
                                                            @endif
                                                            @if (auth()->user()->hasPermissionTo('delete trip oil'))

                                                                    <button type="button" class="btn-link delete_broker_reach"
                                                                            data-id="{{ $d->id }}"><span class="text-danger">
                                                                            ڈیلیٹ</span></button>
                                                                @endif
                                                        </td>
                                                    </tr>
                                                <?php
                                                 $i++;
                                            }

                                        ?>

                            </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    {{-- Edit Voucher Modal--}}
    <div class="modal fade" id="editBrokerReachModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content panel-card" id="editBrokerReachData">

            </div>
        </div>
    </div>
@endsection
@section('javascript')
    @include('broker_reach.js')
@endsection
