118 lines
7.6 KiB
PHP

<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('Flota') }}
</h2>
</x-slot>
@php
$showActions = !auth()->user()->hasRole('pracownik');
@endphp
<div class="py-12">
<div class="max-w-[1800px] mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg p-6 text-gray-900 dark:text-gray-100">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<h3 class="text-lg font-semibold">Lista pojazdów</h3>
@if(!auth()->user()->hasRole('pracownik'))
<a href="{{ route('flota.create') }}" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-md">
+ Dodaj pojazd
</a>
@endif
</div>
<div class="mt-5 mb-6 flex items-center justify-between gap-4">
<form method="GET" action="{{ route('flota') }}" class="flex items-center gap-2 w-full max-w-xl">
<div class="w-full">
<input type="text" name="search" value="{{ request('search') }}" placeholder="Szukaj po marce, modelu, numerze rejestracyjnym..." class="block w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-700 rounded-md shadow-sm bg-white dark:bg-gray-900 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<button type="submit" class="inline-flex items-center px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-sm font-medium rounded-md shadow-sm transition duration-150">
Szukaj
</button>
@if(request('search'))
<a href="{{ route('flota') }}" class="inline-flex items-center px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-md font-semibold text-xs text-gray-700 dark:text-gray-300 uppercase tracking-widest shadow-sm hover:bg-gray-50 dark:hover:bg-gray-700 transition ease-in-out duration-150 whitespace-nowrap">
Wyczyść
</a>
@endif
</form>
</div>
</div>
@if(session('status'))
<div class="rounded-md bg-green-100 border border-green-300 text-green-800 px-4 py-3">
{{ session('status') }}
</div>
@endif
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg text-gray-900 dark:text-gray-100">
<div class="overflow-x-auto">
<table class="min-w-[1400px] w-full table-fixed divide-y divide-gray-200 dark:divide-gray-700">
<thead class="bg-gray-50 dark:bg-gray-900">
<tr>
<th class="px-4 py-3 text-left text-xs uppercase">Marka</th>
<th class="px-4 py-3 text-left text-xs uppercase">Model</th>
<th class="px-4 py-3 text-left text-xs uppercase">Nr rejestracyjny</th>
<th class="px-4 py-3 text-left text-xs uppercase">Właściciel</th>
<th class="px-4 py-3 text-left text-xs uppercase">Rok</th>
<th class="px-4 py-3 text-left text-xs uppercase">Zakup</th>
<th class="px-4 py-3 text-left text-xs uppercase">OC do</th>
<th class="px-4 py-3 text-left text-xs uppercase">Ubezpieczyciel</th>
<th class="px-4 py-3 text-left text-xs uppercase">Przegląd</th>
<th class="px-4 py-3 text-left text-xs uppercase">Olej</th>
<th class="px-4 py-3 text-left text-xs uppercase">Przebieg</th>
<th class="px-4 py-3 text-left text-xs uppercase">Status</th>
@if($showActions)
<th class="px-4 py-3 text-left text-xs uppercase">Akcje</th>
@endif
</tr>
</thead>
<tbody class="divide-y divide-gray-200 dark:divide-gray-700">
@forelse($vehicles as $vehicle)
<tr>
<td class="px-4 py-3">{{ $vehicle->brand }}</td>
<td class="px-4 py-3">{{ $vehicle->model ?? '-' }}</td>
<td class="px-4 py-3">{{ $vehicle->registration_number }}</td>
<td class="px-4 py-3">{{ $vehicle->user ? $vehicle->user->name.' '.$vehicle->user->surname : '-' }}</td>
<td class="px-4 py-3">{{ $vehicle->year }}</td>
<td class="px-4 py-3">{{ $vehicle->purchase_date?->format('d.m.Y') ?? '-' }}</td>
<td class="px-4 py-3">{{ $vehicle->oc_expiry_date?->format('d.m.Y') ?? '-' }}</td>
<td class="px-4 py-3">{{ $vehicle->insurance_provider ?? '-' }}</td>
<td class="px-4 py-3">{{ $vehicle->technical_inspection_date?->format('d.m.Y') ?? '-' }}</td>
<td class="px-4 py-3">{{ number_format($vehicle->oil_change_km, 0, ',', ' ') }} km</td>
<td class="px-4 py-3">{{ number_format($vehicle->mileage_km, 0, ',', ' ') }} km</td>
<td class="px-4 py-3">
<span class="inline-flex rounded-full px-2 py-1 text-xs font-semibold bg-gray-200 text-gray-800">
{{ $vehicle->status }}
</span>
</td>
@if($showActions)
<td class="px-4 py-3 space-x-2">
<a href="{{ route('flota.edit', $vehicle) }}" class="text-blue-600 hover:underline">Edytuj</a>
<form method="POST" action="{{ route('flota.destroy', $vehicle) }}" class="inline-block" onsubmit="return confirm('Usunąć pojazd?');">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:underline">Usuń</button>
</form>
</td>
@endif
</tr>
@empty
<tr>
<td colspan="{{ $showActions ? 13 : 12 }}" class="px-4 py-6 text-center text-gray-500">Brak pojazdów do wyświetlenia.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<div class="p-4">
{{ $vehicles->links() }}
</div>
</div>
</div>
</div>
</x-app-layout>