<div class="panel panel-card">
    <div class="panel-body">
        <table class="table table-bordered">
            <tr class="bg-primary text-black">
                <td class="font-weight-bold text-center" colspan="4">سالانہ بچت رپورٹ</td>

            </tr>
            <tr class="bg-info text-black">
                <td class="font-weight-bold">گاڑی</td>
                <td class="font-weight-bold" colspan=""> {{$vehicle!=null ?$vehicle->vehicle_no: 'تمام گاڑیاں'}}</td>
                <td class="font-weight-bold">سال</td>
                <td class="font-weight-bold" colspan=""> {{date('Y',strtotime($from_date))}}</td>
            </tr>
            <tr class="bg-info text-black">
            </tr>
            <tr class="bg-info text-black">
                <td class="font-weight-bold"> کل دن</td>
                <td class="font-weight-bold"> فی دن بچت</td>
                <td class="font-weight-bold" colspan="2"> کل بچت</td>
            </tr>
            <tr class="text-black">

                <td>{{ $total_days }}</td>
                <td>{{ number_format($profit,0) }}</td>
                <td colspan="2">{{ number_format($profit*$total_days,0) }}</td>
            </tr>
            <tr>
                <td colspan="2"></td>
            </tr>

        </table>
        @if($vehicle==null)
            <table class="table table-bordered" style="margin-top: 10px;">
                <tr class="bg-primary text-black">
                    <td class="font-weight-bold text-center" colspan="5">درجہ بندی</td>
                </tr>
                <tr class="bg-info text-black">
                    <td class="font-weight-bold">#</td>
                    <td class="font-weight-bold">گاڑی</td>
                    <td class="font-weight-bold">دن</td>
                    <td class="font-weight-bold">فی دن بچت</td>
                    <td class="font-weight-bold">بچت</td>
                </tr>
                @php
                    $rankings =$trips->groupBy('vehicle_no')->map(function ($value,$index){
                                  $days=$value->sum('days');
                                   $profit=$value->sum('profit');
                                     return ['profit'=>$profit,'days'=>$days,'per_day_profit'=>$profit/$days];
                                });
                @endphp
                @foreach($rankings->sortByDesc('per_day_profit')->take(3) as $key=> $ranking)
                    <tr class="text-black">
                        <td class="thead" colspan="">{{$loop->iteration}}</td>
                        <td class="thead" colspan="">{{ $key}}</td>
                        <td class="thead" colspan="">{{ $ranking['days'] }}</td>
                        <td class="thead" colspan="">{{ number_format($ranking['per_day_profit'],2) }}</td>
                        <td class="thead" colspan="">{{ number_format($ranking['profit'],2) }}</t
                    </tr>
                @endforeach
            </table>
        @endif
    </div>
</div>
