{{ getAuthCompanyName() }}- Truck#({{$truck->UNIT_ID}})
     
                                        Maintenance Log
                                        
    
                                        
                                        
                                                                                                  
                                                   | 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}} | 
                                                     | 
                                                     | 
                                                     | 
                                                 
                                           
                                            
                                            @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) }} | 
                                                         | 
                                                    
                                                
  
                                           
                                             
                                            
                                            
                                                
                                                     
                                                         | 
                                                        @for ($month = 1; $month <= 12; $month++)
                                                             | 
                                                        @endfor  
                                                    
                                                    @php
                                                        $repairSubtotals = array_fill(1, 12, 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'; 
                                                                $amount = floatval($amount); 
                                                                $repairSubtotals[$month] += $amount;
                                                                $color = $amount > 0 ? 'green' : ($amount < 0 ? 'red' : 'black'); 
                                                            @endphp
                                                            
                                                                @if($amount > 0) ${{ number_format($amount, 2) }} @endif
                                                             | 
                                                        @endfor
                                                        
                                                    @endforeach
                                                    
                                                        | REPAIR SUBTOTAL | 
                                                        @for ($month = 1; $month <= 12; $month++)
                                                            @php
                                                                $amount = $repairSubtotals[$month] ?? 0;
                                                                $color = $amount > 0 ? 'red' : 'black'; 
                                                                $color = $amount > 0 ? 'green' : ($amount < 0 ? 'red' : '#000');
                                                            @endphp
                                                            
                                                                @if($amount > 0)
                                                                    ${{ number_format($amount, 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 = $expenseSubtotals[$month] > 0 ? 'green' : ($expenseSubtotals[$month] < 0 ? 'red' : '#000');
                                                                @endphp
                                                                @if(!empty($amount)) ${{ number_format($amount,2) }} @endif | 
                                                            @endfor
                                                        
                                                    @endforeach
                                                    
                                                                | EXPENSE SUBTOTAL | 
                                                               @for ($month = 1; $month <= 12; $month++)
                                                                @php
                                                                    $amount = $expenseSubtotals[$month] ?? 0;
                                                                    $color = $amount > 0 ? 'green' : ($amount < 0 ? 'red' : '#000');
                                                                @endphp
                                                                
                                                                    @if($amount > 0)
                                                                        ${{ number_format($amount, 2) }}
                                                                    @endif
                                                                 | 
                                                            @endfor
                                                            
                                                    
                                                        | TOTAL COST | 
                                                       
                                                        @for ($month = 1; $month <= 12; $month++)
                                                        @php 
                                                            $color = $monthlyTotals[$month] > 0 ? 'green' : ($monthlyTotals[$month] < 0 ? 'red' : '#000');
                                                        @endphp
                                                            ${{ number_format($monthlyTotals[$month], 2) }} | 
                                                        @endfor
                                                    
                                                
                                             
                                        Vehicle Maintenance Log
                                            
                                            
                                                
                                                    
                                                        
                                                        
                                                        
                                                        
                                                        
                                                        
                                                                                                                
                                                                                                                
                                                        
                                                    
                                                
                                                
                                                @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
                                                    
                                                        
                                                        | {{ strtoupper($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)}} | 
                                                
                                            
                                            Pie  Chart