<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="receivedAcTripNo">{{ $trip->id }}</span>
        Veh:
        <span class="badge badge-color2" id="receivedAcVeh">{{ $trip->vehicle->vehicle_no }}</span>
        Dates:
        <span class="badge badge-color3"
              id="receivedAcDates">{{ date('F j,Y', strtotime($trip->starting_date)) }}</span>
    </h4>
</div>
<div class="modal-body">
    <form id="addTripDepositForm">
        <div class="row">
            <div class="col-md-3">
                <label for="">سابقہ پیشگی:</label>
                <input type="text" name="previous_advance" value="{{ $previous_advance }}" readonly
                       class="form-control">
            </div>
            <div class="col-md-3">
                <label for="">ٹرپ پیشگی:</label>
                <input type="text" name="advance" value="{{ $advance }}" readonly class="form-control">
            </div>
            <div class="col-md-3">
                <label for="">ٹرپ اخراجات:</label>
                <input type="text" name="expenses" value="{{ $expenses }}" readonly class="form-control">
            </div>

            <div class="col-md-3">
                <label for="">ٹرپ آئل اخراجات:</label>
                <input type="text" name="oil" value="{{ $oils }}" readonly class="form-control">
            </div>
            <div class="col-md-3">
                <label for="">اصل کرایہ:</label>
                <input type="text" name="actual_freight" value="{{ $freights }}" readonly class="form-control">
            </div>
            <div class="col-md-4">
                <label>تاریخ:</label>
                <input type="date" name="date" id="deposit_date" value="{{ date('Y-m-d') }}" class="form-control">
                <span class="text-danger error" id="date_error"></span>
            </div>
            @php
                $deposit = $freights+$advance+$previous_advance -($expenses + $oils);
            @endphp
            <div class="col-md-3">
                <input type="hidden" name="" value="{{ $deposit }}" id="hidden_actual_deposit">
                <label for="">رقم</label>
                <input type="text" name="deposit_amount" id="trip_deposit_amount" placeholder="{{ $deposit }}"
                       onkeyup="calculate_remaining_deposit_payment()" class="form-control">
                <span class="text-danger error" id="deposit_amount_error"></span>
            </div>
            <div class="col-md-2">
                <label for="">بقایا رقم</label>
                <input type="text" name="remaining_amount" id="trip_deposit_remaining_amount" class="form-control">
                <span class="text-danger error" id="remaining_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 r_error" id="remarks_error"></span>

                </div>
            </div>
        </div>
        @csrf
        <input type="hidden" name="trip_id" value="{{ $trip->id }}">
        <button type="submit" class="btn btn-success btn-sm" name="receivedAcSubmit" id="tripDepositSubmit">
            جمع
        </button>
    </form>

    <div class="row">
        <div class="col-md-12">
            <h3 class="text-center"> کی تفصیلات {{ $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>

                </tr>
                </thead>
                <tbody id="deposit_at_co_modal_table">
                @forelse ($deposits as $key => $detail)
                    <tr class="" style="">
                        <td>{{$loop->iteration}}</td>
                        <td>{{ date('F j, Y', strtotime( $detail->date))  }}</td>
                        <td>{{ number_format($detail->amount) }}</td>
                        <td>{{ $detail->description }}</td>
                    </tr>

                @empty
                    <tr>
                        <td colspan="4" class="text-center">No Data Available</td>
                    </tr>
                @endforelse

                </tbody>

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