<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vehicle Profit/Loss Summary</title>
    <style>
        .table,
        .tcell,
        .thead {
            text-align: center;
            border: 1px solid black;
            text-align: center;
        }

        .table {
            width: 100%;
            border-collapse: collapse;
        }

    </style>
</head>

<body>
<div>
    <table style="width: 100%;border-collapse: collapse; margin-bottom: 10px">
        <tr>
            <td style="width:33.33%; text-align: left">{{$business_name->name}}</td>
            <td style="width:33.33%; text-align: center"><b>Vehicle Trip Expense</b></td>
            <td style="width:33.33%; text-align: right"></td>
        </tr>
    </table>

    <table style="width: 100%;border-collapse: collapse; margin-bottom: 10px">
        <tr>
            <td style="width:33.33%; text-align: left">
                <h4>{{ $data['vehicle'] != '' ? $data['vehicle']->vehicle_no: 'All Vehicles' }} Trip Expense
                    Summary</h4>
            </td>
            <td style="width:33.33%; text-align: center">

            </td>
            <td style="width:33.33%; text-align: right">
                <span style="font-weight: bold">From Date:</span> <span
                    style="text-decoration: underline">{{ $data['form_date'] }}</span><br>
                <span style="font-weight: bold">To Date:</span> <span
                    style="text-decoration: underline">{{ $data['to_date'] }}</span>
            </td>
        </tr>
    </table>
</div>

<br>
@forelse($data['trips'] as $trip)
    <table class="table">
        <thead>
        <tr class="bg-info">
            <th class="thead text-center">Trip#: {{ $trip->id }}</th>
            <th class="thead text-center">Vehicle: {{  $data['vehicle'] != '' ? $data['vehicle']->vehicle_no: $trip->vehicle->vehicle_no }}</th>
            <th class="thead text-center"></th>
            <th class="thead text-center"></th>
        </tr>
        <tr class="bg-info">
            <th class="thead text-center">#</th>
            <th class="thead text-center">خرچ - رقم</th>
            <th class="thead text-center">ٹول</th>
            <th class="thead text-center">ٹوٹل</th>
        </tr>
        </thead>
        <tbody>
        @if($trip->trip_expenses !=null)
            @forelse($trip->trip_expenses as $expense)

                <tr>
                    <td class="thead">{{ $loop->iteration }}</td>
                    <td class="thead">
                        <table class="table table-bordered">
                            @php
                                $total = 0;
                            @endphp
                            @forelse ($expense->expense_details as $key => $expense_detail)
                                @php
                                    $total = $total + $expense_detail->amount;
                                @endphp
                                <tr>
                                    <td class="thead">{{ $expense_detail->head->name }}</td>
                                    <td class="thead">{{ number_format($expense_detail->amount, 0) }}</td>
                                </tr>
                            @empty
                            @endforelse
                            <tr>
                                <td class="font-weight-bold text-right">Total</td>
                                <td class="font-weight-bold">{{ number_format($total,0) }}</td>
                            </tr>
                        </table>

                    </td>
                    <td class="thead">{{ $expense->toll_plaza }}</td>
                    <td class="thead">{{ $expense->total_amount }}</td>
                </tr>

            @empty
            @endforelse

        @endif
        </tbody>
    </table>
@empty
@endforelse

</body>

</html>
