
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span></button>
    <div class="container-fluid banner">
        <div class="row">
            @php

                // $previous_advance = $trip->previous_advance->sum('amount');
                // $previous_advance = $trip->previous_advance!=null ? $trip->previous_advance->sum('amount'):0;
        //         $trip_advance = $trip->trip_advances!=null ? $trip->trip_advances->sum('amount'):0;
        //    $trip_deposits =$trip->trip_deposits !=null ?$trip->trip_deposits->sum('amount'): 0;
        //    $actual_fregiths = $trip->trip_details !=null ?$trip->trip_details->sum('actual_freight'):0;
        //    $trip_oils = $trip->trip_oils !=null ?  $trip->trip_oils->sum('total_amount'):0;
        //                             $expense = $trip->trip_expenses !=null?$trip->trip_expenses->sum('total_amount'):0;
        // $trip_total_expenses = $expense +$trip_oils;
            @endphp
            <div class="col-md-2 d-flex">
                <div>
                    <i class="fa fa-plus-circle fa-3x text-success"></i>
                </div>
                <div class="ml-3">
                    <h3 class="font-weight-bold mb-0">
                        {{ number_format(0, 0) }}
                    </h3>
                    <small class="text-uppercase">سابقہ پیشگی</small>
                </div>
            </div>
            <div class="col-md-2 d-flex">
                <div class="">
                    <i class="fa fa-minus-circle fa-3x text-danger"></i>
                </div>
                <div class="ml-3">
                    <h3 class="font-weight-bold mb-0">
                        {{ number_format(0, 0) }}
                    </h3>
                    <small class="text-uppercase">پیشگی</small>
                </div>
            </div>
            <div class="col-md-2 d-flex">
                <div>
                    <i class="fa fa-plus-circle fa-3x text-success"></i>
                </div>
                <div class="ml-3">
                    <h3 class="font-weight-bold mb-0">
                        {{ number_format(0, 0) }}
                    </h3>
                    <small class="text-uppercase">ڈپوزٹ</small>
                </div>
            </div>

            <div class="col-md-2 d-flex">
                <div>
                    <i class="fa fa-info-circle fa-3x text-info"></i>
                </div>
                <div class="ml-3">
                    <h3 class="font-weight-bold mb-0">
                        {{ number_format(0, 0) }}
                    </h3>
                    <small class="text-uppercase">کرایہ</small>
                </div>
            </div>
            <div class="col-md-2 d-flex">
                <div class="">
                    <i class="fa fa-minus-circle fa-3x text-danger"></i>
                </div>
                <div class="ml-3">
                    {{-- <h3 class="font-weight-bold mb-0">
                        {{ number_format($trip_total_expenses,0) }}
                    </h3> --}}
                    <small class="text-uppercase">اخراجات</small>
                </div>
            </div>
            <div class="col-md-2 d-flex mt-2">
                <div class="">
                    <i class="fa fa-info-circle fa-3x text-danger"></i>
                </div>
                <div class="ml-3">
                    <h3 class="font-weight-bold mb-0">
                        {{-- @php
                            $oils =$trip->trip_oils->sum('total_amount');
                        @endphp
                        {{ number_format($oils,0) }} --}}
                    </h3>
                    <small class="text-uppercase">آئل/ڈیزل</small>
                </div>
            </div>
            <div class="col-md-3">
                <!--<input id="tableFilter" type="text" placeholder="Search... (Ctrl)"
                                                                                                                                                                                                                           class="form-control">-->
            </div>
        </div>
    </div>
    {{-- <h4 class="modal-title">ٹرپ
        <span class="badge" id="receivedAcTripNo">{{ $trip->id }}</span>
        گاڑی:
        <span class="badge badge-color2" id="receivedAcVeh">{{ $trip->vehicle->vehicle_no }}</span>
        تاریخ:
        <span class="badge badge-color3"
              id="receivedAcDates">{{ date('F j,Y', strtotime($trip->starting_date)) }}</span> میں ادائیگیاں
    </h4> --}}
</div>
<div class="modal-body" id="trip_amount_reach_payable_modal_body">
   @if(auth()->user()->hasPermissionTo('create trip payable'))
        <form method="POST" id="add_reach_TripPayables_Form">

            <div class="row mt-2">

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

                </div>

            </div>

            <div class="row">
                <div class="col-md-4">
                    <label>تاریخ:</label>
                    <input type="date" name="date" id="reach_payable_date" value="{{ date('Y-m-d') }}"
                           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">
                    <label for="">پارٹی نام:</label>
                    <select name="party" id="payable_party" onchange="party_change_for_payable()"
                            class="form-control  change_focus" data-id="remark">
                        <option value="">-----Select Party-----</option>
                        @forelse($pumps as $pump)
                            <option value="{{ $pump->id }}" data-table="pump">{{ $pump->name }}</option>
                        @empty
                        @endforelse
                        @forelse($customers as $item)
                            <option value="{{ $item->id }}" data-table="customer">{{ $item->name }}</option>
                        @empty
                        @endforelse
                        @forelse($workshops as $workshop)
                            <option value="{{ $workshop->id }}" data-table="workshop">{{ $workshop->shop_name }}</option>
                        @empty
                        @endforelse
                    </select>
                    <span class="text-danger p_error" id="p_party_error"></span>
                </div> --}}

                <div class="col-md-4">
                    <div class="form-group">
                        <label for="">  پہنچ بقایا رقم:</label>
                        <select name="payable_pump" id="pump_reach_payalbe_p" onchange="p_pump_reach_payable_change()" class="form-control">
                            <option value="">----Select Pump Payable----</option>

                            @forelse($tripReachAmount as $payable)
                            @php
                                $actual_amount = $payable->tripDetailReach->short_amount != 0
                                    ? $payable->tripDetailReach->short_amount
                                    : $payable->tripDetailReach->remainder_amount;
                            @endphp
                            <option value="{{ $payable->id }}"  data-id="{{ $payable->id }}" data-trip-id = {{ $payable->trip_id }} data-amount="{{ $actual_amount }}" data-broker-id="{{ $payable->broker->id }}">
                                {{ $actual_amount }} ({{ $payable->broker->name }})
                            </option>
                        @empty
                            <option disabled>No unpaid amounts available</option>
                        @endforelse

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


                    </div>
                </div>

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



            <div class="row mt-2">

                <div class="col-md-4">
                    <label for="">رقم</label>
                    <input type="text" name="amount" id="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"></textarea>
                        <span class="text-danger p_error" id="p_remarks_error"></span>

                    </div>
                </div>
            </div>
            @csrf
            <input type="hidden" name="new_trip_id" id="pay_trip_id" value="{{ $trip != null ? $trip->id : '' }}">
            <input type="hidden" name="trip_id" id="pay_trip_id_hidden">
            {{-- <input type="hidden" name="party_type" id="payable_party_type"> --}}
            <input type="hidden" name="party_title" id="adv_party_table">
            <input type="hidden" name="hidden_total_amount" id="reach_payable_hidden_total_amount">
            <input type="hidden" name="party" id="broker_payReach_id_hidden">
            <input type="hidden" name="tripReach_id" id="tripReach_id_hidden">
            <button type="submit" class="btn btn-success btn-sm" id="tripReachPayableSubmit">محفوظ</button>
        </form>
   @endif
    <div class="row">
        <div class="col-md-12">
            <h3 class="text-center"> ٹرپ {{ $trip != null ? $trip->id : '' }} میں ادائیگیاں</h3>
        </div>
        <div class="col-md-12">
            <table class="table table-bordered">
                <thead>

                <tr class="bg-info">
                    <th>#</th>
                    <th>پارٹی</th>
                    <th>تاریخ</th>
                    <th>رقم</th>
                    <th>ادائیگی قسم</th>
                    <th>بینک / ان اکاوؑنٹ</th>
                    <th>ایکشن</th>

                </tr>
                </thead>
                <tbody id="trip_reach_payables_modal_table">
                @forelse($trip_payables as $key => $payable)
                    <tr class="">
                        <td>{{$loop->iteration}}</td>
                        <td>{{ $payable->broker->name}}</td>
                        <td>{{date("F j, Y",strtotime($payable->date))}}</td>
                        <td>{{number_format($payable->amount, 0)}}</td>

                        @if ($payable->payment_type == 'cash')
                        <td>کیش </td>

                      @elseif ($payable->payment_type == 'bank')
                      <td>بینک</td>

                      @elseif ($payable->payment_type == 'in-account')
                      <td>ان اکاوؑنٹ
                      </td>
                      @endif

                      @if (isset($payable->bank->name))
                      <td>{{ $payable->bank->name }}</td>
                   @else
                    <td></td>


                  @endif

                        <td>
                            @if (auth()->user()->hasPermissionTo('edit trip oil'))
                                <button type="button" class="btn-link edit_reach_trip_payable"
                                        data-id="{{ $payable->id }}"><span>
                                            اپڈیٹ</span></button>
                            @endif
                            @if (auth()->user()->hasPermissionTo('delete trip oil'))

                                    <button type="button" class="btn-link delete_reach_trip_payable"
                                            data-id="{{ $payable->id }}"><span class="text-danger">
                                            ڈیلیٹ</span></button>
                                @endif
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="4" class="text-center">NO RECORD AVAILABLE</td>
                    </tr>
                @endforelse
                </tbody>

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