<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');
                $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($previous_advance, 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_advance, 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($trip_deposits, 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($actual_fregiths, 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="addAdvanceInTripNo">{{ $trip->id }}</span>
        گاڑی :
        <span class="badge badge-color2" id="addAdvanceInTripVeh">{{ $trip->vehicle->vehicle_no }}</span>
        تاریخ:
        <span class="badge badge-color3" id="addAdvanceInTripDates">{{ date('F j, Y') }}</span>
        میں ایڈوانس
    </h4>
</div>
<div class="modal-body" id="trip_advance_modal_body">
    @if(auth()->user()->hasPermissionTo('create trip advance'))
        <form id="addAdvanceInTripForm">
            <div class="row">

                <div class="col-md-4">
                    <div class="form-group">
                        <label for="adv_date">تاریخ<span class="text-danger">*</span></label>
                        <input type="date" id="adv_date" name="adv_date" class="form-control change_focus"
                               data-id="adv_cash"
                               value="{{ date('Y-m-d') }}">
                        <span class="text-danger advance_error" id="adv_date_error"></span>

                    </div>
                </div>
                <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="payment_type_error"></span>
                </div>
                <div class="col-md-4" id="adv_bank_dev">

                </div>

            </div>


            <div class="row mt-2">

                <div class="col-md-6">
                    <div class="form-group">
                        <label for="adv_amount">رقم<span class="text-danger">*</span></label>
                        <input type="number" min="1" id="adv_amount" name="adv_amount" class="form-control change_focus"
                               data-id="adv_note">
                        <span class="text-danger advance_error" id="adv_amount_error"></span>
                    </div>
                </div>
            </div>
            <div class="row mt-2">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="adv_note">نوٹ</label>
                        <textarea id="adv_note" name="adv_note" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            @csrf
            <input type="hidden" name="trip_id" id="advance_trip_id" value="{{ $trip->id }}">
            <input type="hidden" name="party_title" id="adv_party_table">
            <button type="submit" class="btn btn-success" name="addAdvanceInTripSubmit" id="addAdvanceInTripSubmit">
                محفوظ
            </button>
        </form>
    @endif
    <hr>
    <table class="table table-bordered" id="advance-payment-details-table">
        <thead>
        <tr class="bg-primary">
            <th>رقم</th>
            <th>تاریخ</th>
            <th>نوٹ</th>
            <th>ایکشن</th>
        </tr>
        </thead>
        <tbody id="trip_advance_table_body">
        @forelse ($advances as $advance)
            <tr>
                <td>{{ number_format($advance->amount, 0) }}</td>
                <td>{{ date('F j, Y', strtotime($advance->date)) }}</td>
                <td>{{ $advance->note }}</td>
                <td>
                    @if (auth()->user()->hasPermissionTo('edit trip advance'))
                        <button type="button" class="btn-link edit_advance" data-id="{{ $advance->id }}">
                            <span> اپڈیٹ</span>
                        </button>
                    @endif
                    @if (auth()->user()->hasPermissionTo('edit trip advance'))
                        <button type="button" class="btn-link delete_advance" data-id="{{ $advance->id }}"><span
                                class="text-danger">
                            ڈیلیٹ</span>
                        </button>
                    @endif
                </td>
            </tr>
        @empty
            <tr>
                <td colspan="3"> No Data Available</td>
            </tr>
        @endforelse
        </tbody>
    </table>

</div>
