{{ getAuthCompanyName() }} - Truck#({{$truck->UNIT_ID}})
                                        Profit and Loss Summary Report
                                        
    
                                        
                                        
                                                
                                                   | Year: {{$truck->year}} | 
                                                   Status: {{$truck->status}} | 
                                                   Operator: {{$truck->driver_name}} | 
                                                   Registration Expiration: {{ ($truck->LIC_1_EXP_DATE && $truck->LIC_1_EXP_DATE != '0000-00-00 00:00:00') ? date('m/d/Y',strtotime($truck->LIC_1_EXP_DATE)) : ''}} | 
                                                
                                                
                                                    | Make: {{$truck->MAKE}} | 
                                                    Tank capacity: {{$truck->TANK_CAPACITY}} | 
                                                    Location: {{$truck->current_address}} | 
                                                    Last Annual PM Service Date: {{  ($truck->LAST_SERVICE && $truck->LAST_SERVICE != '0000-00-00 00:00:00') ? date('m/d/Y', strtotime($truck->LAST_SERVICE)) : ''}} | 
                                                 
                                                    | Model: {{$truck->MODEL}} | 
                                                    VIN: {{$truck->VIN}} | 
                                                    Acquisition Date:{{ ($truck->ACQUISITION_DATE && $truck->ACQUISITION_DATE != '0000-00-00 00:00:00') ? date('m/d/Y', strtotime($truck->ACQUISITION_DATE)) : '' }} | 
                                                     | 
                                                 
                                                 
                                                   | Plate / Reg #: {{$truck->PLATE}} | 
                                                     | 
                                                     | 
                                                     | 
                                                 
                                            
                                               
                                            
                                            
Maintenance Cost Summary
                                            
                                              
                                            
                                            
                                            
                                                            
                                                                | Month | 
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    {{ \Carbon\Carbon::createFromDate($cur_year, $month, 1)->format('M-Y') }}
                                                                @endfor
                                                                 | Total | 
                                                            
                                                            
                                                            @php
                                                                $repairSubtotals = array_fill(1, 12, 0);
                                                                $gtotal = 0;
                                                            @endphp
                                                            @foreach ($repairTypes as $repairType)
                                                               
                                                                    @for ($month = 1; $month <= 12; $month++)
                                                                        @php
                                                                            $key = sprintf('%02d-%d', $month, $cur_year);
                                                                            $amount = $repairAmounts[$repairType->REPID][$key] ?? 0;
                                                                            $repairSubtotals[$month] += $amount;
                                                                            // $color = $amount > 0 ? 'green' : ($amount < 0 ? 'red' : '#000');
                                                                            $color = 'red';
                                                                        @endphp
                                                                     
                                                                    @endfor
                                                                    @php
                                                                        $rowTotal = $amount; 
                                                                        $gtotal += $amount;
                                                                   
                                                                    @endphp
                                                            @endforeach
                                                         
                                                                REPAIR | 
                                                                @php
                                                                $totalRepair = array_sum($repairSubtotals);
                                                            @endphp
                                                            @for ($month = 1; $month <= 12; $month++)
                                                                @php
                                                                    $subtotal = $repairSubtotals[$month] ?? 0;
                                                                    $color = 'red';
                                                                @endphp
                                                                
                                                                    @if($subtotal != 0)
                                                                        ${{ number_format($subtotal, 2) }}
                                                                    @endif
                                                                 | 
                                                            @endfor
                                                            
                                                            
                                                            
                                                                @if($totalRepair != 0)
                                                                    ${{ number_format($totalRepair, 2) }}
                                                                @endif
                                                             | 
                                                                                                                 
                                                            @php
                                                                $expenseSubtotals = array_fill(1, 12, 0);
                                                                $driverpaySubtotals = array_fill(1, 12, 0);
                                                            @endphp
                                                            @foreach ($expenseTypes as $expenseType)
                                                                
                                                                    @if($type->EXPID == $expenseType->EXPID)
                                                                        | {{ strtoupper($expenseType->NAME."+ load driver pay") }} | 
                                                                    @endif
                                                                    @php
                                                                        $totalExpenseForType = 0; // Initialize total for this expense type
                                                                    @endphp
                                                                    @for ($month = 1; $month <= 12; $month++)
                                                                        @php
                                                                            $key = sprintf('%02d-%d', $month, $cur_year);
                                                                            $amount = $expenseAmounts[$expenseType->EXPID][$key] ?? 0;
                                                                            $expenseSubtotals[$month] += $amount;
                                                                            
                                                                            if ($type->EXPID != $expenseType->EXPID) {
                                                                                $driverpaySubtotals[$month] += $amount;
                                                                            }
                                                                            $color = 'red';
                                                                            $totalExpenseForType += $amount; 
                                                                        @endphp
                                                                        @if($type->EXPID == $expenseType->EXPID)
                                                                            
                                                                                @if(!empty($amount)) ${{ number_format($amount, 2) }} @endif
                                                                             | 
                                                                        @endif
                                                                    @endfor
                                                                    
                                                                    @if($type->EXPID == $expenseType->EXPID)
                                                                            
                                                                        
                                                                            @if($totalExpenseForType != 0)
                                                                                ${{ number_format($totalExpenseForType, 2) }}
                                                                            @endif
                                                                         | 
                                                                    @endif
                                                                    
                                                                
                                                            @endforeach
                                                            
                                                        | EXPENSE | 
                                                        @php
                                                                $totalexpense = array_sum($driverpaySubtotals);
                                                            @endphp
                                                        @for ($month = 1; $month <= 12; $month++)
                                                   
                                                            @php
                                                                $subtotal = $driverpaySubtotals[$month] ?? 0;
                                                                $color = $subtotal != 0 ? 'red' : 'black'; // Adjust color logic as needed
                                                            @endphp
                                                            
                                                                @if($subtotal != 0)
                                                                    ${{ number_format($subtotal, 2) }}
                                                                @endif
                                                             | 
                                                        @endfor
                                                        
                                                                            @if($totalexpense != 0)
                                                                                ${{ number_format($totalexpense, 2) }}
                                                                            @endif
                                                             | 
                                                    
                                                            
                                                                | INCOME | 
                                                                @php
                                                                $totalincome = array_sum($loadAmounts['income']);
                                                            
                                                             @endphp
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    @php
                                                                        $key = sprintf('%02d-%d', $month, $cur_year);
                                                                        $income = $loadAmounts['income'][$key] ?? '';
                                                                        $color = $income > 0 ? 'green' : ($income < 0 ? 'red' : '#000');
                                                                    @endphp
                                                                      {{$income ? '$'.number_format($income, 2) : '' }}  | 
                                                                @endfor
                                                                
                                                                            @if($totalexpense != 0)
                                                                                ${{ number_format($totalincome, 2) }}
                                                                            @endif
                                                             | 
                                                            
                                                            
                                                                    | TOTAL MAINTENANCE + EXPENSES | 
                                                                    @php
                                                                        $totalMaintenance = 0;
                                                                    @endphp
                                                                    @for ($month = 1; $month <= 12; $month++)
                                                                        @php
                                                                            $maintenance = ($repairSubtotals[$month] ?? 0) + ($expenseSubtotals[$month] ?? 0);
                                                                            $totalMaintenance += $maintenance;
                                                                            $color = 'red';
                                                                        @endphp
                                                                        {{ $maintenance != 0 ? '$' . number_format($maintenance, 2) : '' }} | 
                                                                    @endfor
                                                                    
                                                                    
                                                                        @if($totalMaintenance != 0)
                                                                            ${{ number_format($totalMaintenance, 2) }}
                                                                        @endif
                                                                     | 
                                                                
                                                                
    | PROFIT | 
    @php
        $totalProfit = 0; // Initialize total profit
    @endphp
    @for ($month = 1; $month <= 12; $month++)
        @php
            $key = sprintf('%02d-%d', $month, $cur_year);
            $income = $loadAmounts['income'][$key] ?? 0;
            $maintenance = ($repairSubtotals[$month] ?? 0) + ($expenseSubtotals[$month] ?? 0);
            $profit = $income - $maintenance;
            $totalProfit += $profit;
        @endphp
        
            {{ $profit != 0 ? '$'.number_format($profit, 2) : '' }}
         | 
    @endfor
    
    
        @if($totalProfit != 0)
            ${{ number_format($totalProfit, 2) }}
        @endif
     | 
                                                                                                                          
                                                                
                                                                    | GRAND TOTAL | 
                                                                    
                                                                        
                                                                                ${{ number_format($totalProfit, 2) }}
                                                                            
                                                                        
                                                                     |