{{ getAuthCompanyName() }} - Truck#({{$truck->UNIT_ID}})
                                        Truck Profit And Loss
                                        
                                        
                                        
                                                
                                                   | 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
                                            Grand Total: ${{   number_format($gtotal, 2) }}
                                              
                                            
                                            
                                            
                                                            
                                                                | Month | 
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    {{ \Carbon\Carbon::createFromDate($cur_year, $month, 1)->format('M-Y') }} | 
                                                                @endfor
                                                            
                                                            
                                                                | REPAIR TYPE | 
                                                            
                                                            @php
                                                                $repairSubtotals = array_fill(1, 12, 0);
                                                                $gtotal = 0;
                                                            @endphp
                                                            @foreach ($repairTypes as $repairType)
                                                                
                                                                    | {{ strtoupper($repairType->NAME) }} | 
                                                                    @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
                                                                        @if(!empty($amount)) ${{ number_format($amount, 2) }} @endif | 
                                                                    @endfor
                                                                
                                                            @endforeach
                                                            
                                                                | REPAIR SUBTOTAL | 
                                                              @for ($month = 1; $month <= 12; $month++)
                                                            
                                                                @if($subtotal != 0)
                                                                    ${{ number_format($subtotal, 2) }}
                                                                @endif
                                                             | 
                                                        @endfor
                                                            
                                                            
                                                                | EXPENSE TYPE | 
                                                            
                                                            @php
                                                                $expenseSubtotals = array_fill(1, 12, 0);
                                                            @endphp
                                                            @foreach ($expenseTypes as $expenseType)
            
                | {{ strtoupper($expenseType->NAME) }} | 
                @for ($month = 1; $month <= 12; $month++)
                    @php
                        $key = sprintf('%02d-%d', $month, $cur_year);
                        $amount = $expenseAmounts[$expenseType->EXPID][$key] ?? 0;
                        $expenseSubtotals[$month] += $amount;
                        // $color = $amount > 0 ? 'green' : ($amount < 0 ? 'red' : '#000');
                        $color = 'red';
                    @endphp
                    @if(!empty($amount)) ${{ number_format($amount, 2) }} @endif | 
                @endfor
            
                                                            @endforeach
                                                            
                                                                | EXPENSE SUBTOTAL | 
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    
                                                                    @if($expenseSubtotal != 0)
                                                                        ${{ number_format($expenseSubtotal, 2) }}
                                                                    @endif
                                                                 | 
                                                                @endfor
                                                            
                                                            
                                                                | Total Income | 
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    @php
                                                                        $key = sprintf('%02d-%d', $month, $cur_year);
                                                                        $income = $loadAmounts['income'][$key] ?? 0;
                                                                        $color = $income > 0 ? 'green' : ($income < 0 ? 'red' : '#000');
                                                                    @endphp
                                                                     ${{ number_format($income, 2) }}  | 
                                                                @endfor
                                                            
                                                            
                                                                | TOTAL MAINTENANCE | 
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    @php
                                                                        $maintenance = $repairSubtotals[$month] + $expenseSubtotals[$month];
                                                                        // $color = $maintenance > 0 ? 'green' : ($maintenance < 0 ? 'red' : '#000');
                                                                        $color = 'red';
                                                                    @endphp
                                                                    
                                                                     ${{ number_format($maintenance, 2) }} | 
                                                                @endfor
                                                            
                                                                
                                                                    | TOTAL PROFIT | 
                                                                    @for ($month = 1; $month <= 12; $month++)
                                                                        @php
                                                                            $key = sprintf('%02d-%d', $month, $cur_year);
                                                                            $income = $loadAmounts['income'][$key] ?? 0;
                                                                            $maintenance = $repairSubtotals[$month] + $expenseSubtotals[$month];
                                                                            $profit = $income - $maintenance;
                                                                            $gtotal += $profit;
                                                                        @endphp
                                                                        
                                                                            ${{ number_format($profit, 2) }}
                                                                         | 
                                                                    @endfor
                                                                
                                                                 
                                                                    | GRAND TOTAL | 
                                                                    
                                                                        
                                                                                ${{ number_format($gtotal, 2) }}
                                                                            
                                                                        
                                                                     |