{{ getAuthCompanyName() }}      
                                        Maintenance Log
                                        
    
                                        
                                            
                                                                                                  
                                                   | Year: {{$trailer->YEAR}} | 
                                                   Status: {{$trailer->STATUS}} | 
                                                   Trailer Number: {{$trailer->TRAILER_ID}} |  
                                                   Purcahsed Leased: {{$trailer->LEASE_PUR}} | 
                                                
                                                        
                                                    | Copmany / Owner Operator: {{$trailer->OWNER_TYPE}} | 
                                                    Purcahsed From: {{$trailer->LEASE_PUR_FROM}} | 
                                                    Sold To: {{$trailer->SOLD_TO}} |  
                                                    Purcahsed Date: {{ ($trailer->LEASE_PUR_DATE && $trailer->LEASE_PUR_DATE != '0000-00-00 00:00:00') ?  date('m/d/Y',strtotime($trailer->LEASE_PUR_DATE)) : ''}} |                                                    
                                                 
   
                                                   
                                                    | Sold Date: {{ ($trailer->SOLD_DATE && $trailer->SOLD_DATE != '0000-00-00 00:00:00') ? date('m/d/Y',strtotime($trailer->SOLD_DATE)) : ''}} |          
                                                    Purchase Amount: {{$trailer->LEASE_PUR_AMT}} | 
                                                    Sold Amount: {{$trailer->SOLD_AMT}} |   
                                                     |                                                  
                                                  
                                            
                                            
                                            @php
                                                    $totalSum = 0;
                                                    $totalSum2 = 0;
                                                @endphp
                                                
                                                @foreach ($vehicle_maintenances as $item) 
                                                    @php
                                                        $arr = [];
                                                        if (!empty($item->service_provider)) {
                                                            $arr = explode(",", $item->service_provider);
                                                        }
                                                        $total = $item->part + $item->labor;
                                                        $totalSum2 += $total;
                                                    @endphp
                                                @endforeach  
                                           
                                                
                                                    
                                                        |  Total Part Cost: ${{ number_format($sum->total_part, 2) }} | 
                                                        Total Maintenance Cost ${{ number_format($totalSum2, 2) }}  | 
                                                    
                                                    
                                                        | Total Labor Cost: ${{ number_format($sum->total_labour, 2) }} | 
                                                         | 
                                                    
                                                
  
                                           
                                          
                                            
                                            
                                            
                                                     
                                                        | Month | 
                                                        @for ($month = 1; $month <= 12; $month++)
                                                            {{ \Carbon\Carbon::createFromDate($cur_year, $month, 1)->format('M-Y') }} | 
                                                        @endfor  
                                                    
                                                    @php
                                                        $repairSubtotals = array_fill(1, 12, 0);
                                                    @endphp
                                                    @foreach ($repairTypes as $repairType)
                                                        
                                                            | {{ $repairType->NAME }} | 
                                                            @for ($month = 1; $month <= 12; $month++)
                                                                @php
                                                                    $key = sprintf('%02d-%d', $month, $cur_year);
                                                                    $amount = $repairAmounts[$repairType->NAME][$key] ?? '0'; 
                                                                    $amount = floatval($amount); 
                                                                    $repairSubtotals[$month] += $amount;
                                                                @endphp
                                                                
                                                                    @if($amount > 0) ${{ number_format($amount, 2) }} @endif
                                                                 | 
                                                            @endfor
                                                        
                                                    @endforeach
                                                    
                                                        | Repair Subtotal | 
                                                        @for ($month = 1; $month <= 12; $month++)
                                                            
                                                                @if($repairSubtotals[$month] > 0) ${{ number_format($repairSubtotals[$month], 2) }} @endif
                                                             | 
                                                        @endfor
                                                    
                                                      EXPENSE TYPE | 
                                                    
                                                    @php
                                                        $expenseSubtotals = array_fill(1, 12, 0);
                                                    @endphp
                                                    @foreach ($expenseTypes as $expenseType)
                                                        
                                                            | {{ $expenseType->NAME }} | 
                                                            @for ($month = 1; $month <= 12; $month++)
                                                                @php
                                                                    $key = sprintf('%02d-%d', $month, $cur_year); 
                                                                    $amount = $expenseAmounts[$expenseType->NAME][$key] ?? 0;
                                                                    $expenseSubtotals[$month] += $amount;
                                                                @endphp
                                                                @if(!empty($amount)) ${{ number_format($amount,2) }} @endif | 
                                                            @endfor
                                                        
                                                    @endforeach
                                                    
                                                                | Expense Subtotal | 
                                                                @for ($month = 1; $month <= 12; $month++)
                                                                    
                                                                        @if($expenseSubtotals[$month] > 0) ${{ number_format($expenseSubtotals[$month], 2) }} @endif
                                                                     | 
                                                                @endfor
                                                            
                                                    
                                                        | Total Monthly Cost | 
                                                        @for ($month = 1; $month <= 12; $month++)
                                                            ${{ number_format($monthlyTotals[$month], 2) }} | 
                                                        @endfor
                                                    
                                                
                                             
                                            Vehicle Maintenance Log
                                            
                                            
                                                
                                                    
                                                        | Description | 
                                                        Status | 
                                                        Date | 
                                                        Odometer | 
                                                        Type | 
                                                        Vendor | 
                                                        Part |                                                         
                                                        Labor Cost |                                                         
                                                        Total Cost | 
                                                    
                                                
                                                
                                                @php
                                                    $totalSum = 0;
                                                @endphp
                                                
                                                @foreach ($vehicle_maintenances as $item) 
                                                    @php
                                                        $arr = [];
                                                        if (!empty($item->service_provider)) {
                                                            $arr = explode(",", $item->service_provider);
                                                        }
                                                        $total = $item->part + $item->labor;
                                                        $totalSum += $total;
                                                    @endphp
                                                    
                                                        
                                                        | {{$item->description}} | 
                                                        {{$item->status}} | 
                                                        {{date('m/d/Y',strtotime($item->date))}} | 
                                                        {{$item->odometer}} | 
                                                        
                                                           
                                                        {{$item->repair_name}}
                                                         | 
                                                        {{$item->vendorname}} | 
                                                        {{$item->part}} | 
                                                        
                                                        {{$item->labor}} | 
                                                      
                                                        ${{number_format($total, 2)}} | 
                                                    
                                                @endforeach
                                                
                                                
                                                    | Total
                                                     |  | 
                                                     | 
                                                     | 
                                                     | 
                                                     | 
                                                     | 
                                                     |                                                   
                                                    
                                                    ${{number_format($totalSum, 2)}} |