diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index e1ed040..c7784ac 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -52,8 +52,8 @@ class DashboardController extends Controller $vehiclesDueSoon = Vehicle::with('user') ->where(function ($query) { - $query->whereBetween('oc_expiry_date', [now()->startOfDay(), now()->addDays(14)->endOfDay()]) - ->orWhereBetween('technical_inspection_date', [now()->startOfDay(), now()->addDays(14)->endOfDay()]); + $query->where('oc_expiry_date', '<=', now()->addDays(14)->endOfDay()) + ->orWhere('technical_inspection_date', '<=', now()->addDays(14)->endOfDay()); }) ->orderBy('oc_expiry_date') ->orderBy('technical_inspection_date') diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 1bfe76d..f159918 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -213,7 +213,7 @@ Samochody do uwagi - do 14 dni + przeterminowane i do 14 dni @@ -221,8 +221,12 @@
@foreach($vehiclesDueSoon as $vehicle) @php - $ocDue = $vehicle->oc_expiry_date && $vehicle->oc_expiry_date->between(now()->startOfDay(), now()->addDays(14)->endOfDay()); - $inspectionDue = $vehicle->technical_inspection_date && $vehicle->technical_inspection_date->between(now()->startOfDay(), now()->addDays(14)->endOfDay()); + $today = now()->startOfDay(); + $limitDate = now()->addDays(14)->endOfDay(); + $ocOverdue = $vehicle->oc_expiry_date && $vehicle->oc_expiry_date->lt($today); + $inspectionOverdue = $vehicle->technical_inspection_date && $vehicle->technical_inspection_date->lt($today); + $ocDue = $vehicle->oc_expiry_date && $vehicle->oc_expiry_date->between($today, $limitDate); + $inspectionDue = $vehicle->technical_inspection_date && $vehicle->technical_inspection_date->between($today, $limitDate); @endphp
@@ -236,15 +240,19 @@
- @if($ocDue) - + @if($ocOverdue || $ocDue) + + @if($ocOverdue) OC: PRZETERMINOWANE ({{ $vehicle->oc_expiry_date->format('d.m.Y') }}) @else OC: {{ $vehicle->oc_expiry_date->format('d.m.Y') }} + @endif @endif - @if($inspectionDue) - + @if($inspectionOverdue || $inspectionDue) + + @if($inspectionOverdue) Przegląd: PRZETERMINOWANY ({{ $vehicle->technical_inspection_date->format('d.m.Y') }}) @else Przegląd: {{ $vehicle->technical_inspection_date->format('d.m.Y') }} + @endif @endif
@@ -253,7 +261,7 @@
@else

- Brak pojazdów z terminem OC lub przeglądu w najbliższych 14 dniach. + Brak pojazdów z przeterminowanym terminem OC lub przeglądem albo terminem w najbliższych 14 dniach.

@endif diff --git a/tests/Feature/VehicleTest.php b/tests/Feature/VehicleTest.php index 4565c2f..27025f2 100644 --- a/tests/Feature/VehicleTest.php +++ b/tests/Feature/VehicleTest.php @@ -170,12 +170,29 @@ test('dashboard shows vehicles with upcoming technical inspection or oc expiry w 'status' => 'aktywny', ]); + $overdueVehicle = Vehicle::create([ + 'brand' => 'Skoda', + 'model' => 'Octavia', + 'registration_number' => 'WI4567B', + 'user_id' => $user->id, + 'year' => 2018, + 'purchase_date' => '2018-02-15', + 'oc_expiry_date' => now()->subDays(3)->toDateString(), + 'oil_change_km' => 10000, + 'insurance_provider' => 'Allianz', + 'technical_inspection_date' => now()->subDays(8)->toDateString(), + 'mileage_km' => 140000, + 'status' => 'używany', + ]); + $response = $this->actingAs($manager)->get(route('dashboard')); $response->assertOk(); $response->assertSee('Samochody do uwagi'); $response->assertSee($urgentVehicle->brand); $response->assertSee('OC'); + $response->assertSee($overdueVehicle->brand); + $response->assertSee('PRZETERMINOWANE'); $response->assertDontSee($safeVehicle->brand); });