LMIV-SNACKAUTOMAT/resources/views/admin/slots/index.blade.php

218 lines
13 KiB
PHP

@extends('layouts.vending')
@section('title', 'Slot-Verwaltung')
@section('content')
<div class="max-w-7xl mx-auto px-4">
<div class="flex justify-between items-center mb-8">
<div>
<h1 class="text-3xl font-bold text-gray-900">Slot-Verwaltung</h1>
<p class="text-gray-600 mt-2">Verwalten Sie Automaten-Slots und Produktzuordnungen</p>
</div>
<div class="flex space-x-3">
@if(request('machine'))
@php $machine = \App\Models\VendingMachine::find(request('machine')) @endphp
@if($machine)
<a href="{{ route('vending-machines.show', $machine) }}" class="bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700">
Zurück zu {{ $machine->name }}
</a>
@endif
@endif
<a href="{{ route('slots.create') }}" class="bg-purple-600 text-white px-4 py-2 rounded-lg hover:bg-purple-700">
Neuer Slot
</a>
</div>
</div>
<!-- Filter -->
<div class="bg-white shadow rounded-lg p-6 mb-6">
<form method="GET" class="flex flex-wrap gap-4 items-end">
<div class="flex-1 min-w-64">
<label for="machine" class="block text-sm font-medium text-gray-700 mb-2">Automat filtern</label>
<select name="machine" id="machine" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="">Alle Automaten</option>
@foreach(\App\Models\VendingMachine::all() as $machine)
<option value="{{ $machine->id }}" {{ request('machine') == $machine->id ? 'selected' : '' }}>
{{ $machine->name }} ({{ $machine->location }})
</option>
@endforeach
</select>
</div>
<div class="flex-1 min-w-48">
<label for="status" class="block text-sm font-medium text-gray-700 mb-2">Status filtern</label>
<select name="status" id="status" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="">Alle Slots</option>
<option value="occupied" {{ request('status') == 'occupied' ? 'selected' : '' }}>Belegt</option>
<option value="empty" {{ request('status') == 'empty' ? 'selected' : '' }}>Leer</option>
</select>
</div>
<button type="submit" class="px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700">
Filtern
</button>
@if(request()->hasAny(['machine', 'status']))
<a href="{{ route('slots.index') }}" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-md hover:bg-gray-50">
Filter zurücksetzen
</a>
@endif
</form>
</div>
@if(session('success'))
<div class="bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded mb-6">
{{ session('success') }}
</div>
@endif
@if($slots->count() > 0)
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Slot
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Automat
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Produkt
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Bestand
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Preis
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Status
</th>
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
Aktionen
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($slots as $slot)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10">
<div class="h-10 w-10 rounded bg-purple-100 flex items-center justify-center">
<span class="text-purple-600 font-semibold text-sm">{{ $slot->slot_number }}</span>
</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900">{{ $slot->vendingMachine->name }}</div>
<div class="text-sm text-gray-500">{{ $slot->vendingMachine->location }}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($slot->products->count() > 0)
@php $product = $slot->products->first() @endphp
<div class="flex items-center">
@if($product->image)
<img class="h-8 w-8 rounded object-cover mr-3" src="{{ asset('storage/' . $product->image) }}" alt="{{ $product->name }}">
@else
<div class="h-8 w-8 rounded bg-gray-200 flex items-center justify-center mr-3">
<span class="text-gray-400 text-xs">?</span>
</div>
@endif
<div>
<div class="text-sm font-medium text-gray-900">{{ $product->name }}</div>
<div class="text-sm text-gray-500">{{ number_format($product->price, 2) }}</div>
</div>
</div>
@else
<span class="text-gray-400">Kein Produkt zugeordnet</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($slot->products->count() > 0)
<span class="text-sm font-medium text-gray-900">
{{ $slot->products->first()->pivot->stock_quantity ?? 0 }} Stück
</span>
@else
<span class="text-gray-400">-</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($slot->products->count() > 0)
<span class="text-sm font-medium text-gray-900">
{{ number_format($slot->products->first()->pivot->price ?? $slot->products->first()->price, 2) }}
</span>
@else
<span class="text-gray-400">-</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($slot->products->count() > 0)
@php $stock = $slot->products->first()->pivot->stock_quantity ?? 0 @endphp
@if($stock > 5)
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
Verfügbar
</span>
@elseif($stock > 0)
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800">
Niedrig
</span>
@else
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
Leer
</span>
@endif
@else
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
Nicht belegt
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<div class="flex justify-end space-x-2">
<a href="{{ route('slots.show', $slot) }}" class="text-blue-600 hover:text-blue-900">
Details
</a>
<a href="{{ route('slots.edit', $slot) }}" class="text-indigo-600 hover:text-indigo-900">
Bearbeiten
</a>
<form action="{{ route('slots.destroy', $slot) }}" method="POST" class="inline"
onsubmit="return confirm('Sind Sie sicher, dass Sie diesen Slot löschen möchten?')">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:text-red-900">
Löschen
</button>
</form>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="mt-6">
{{ $slots->appends(request()->query())->links() }}
</div>
@else
<div class="text-center py-12">
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2M9 7a2 2 0 012-2h2a2 2 0 012 2m0 10V7m0 10a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2h2a2 2 0 002-2z"/>
</svg>
<h3 class="mt-2 text-sm font-medium text-gray-900">Keine Slots gefunden</h3>
<p class="mt-1 text-sm text-gray-500">
@if(request()->hasAny(['machine', 'status']))
Keine Slots entsprechen den aktuellen Filterkriterien.
@else
Beginnen Sie mit der Erstellung Ihres ersten Slots.
@endif
</p>
<div class="mt-6">
<a href="{{ route('slots.create') }}" class="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700">
Ersten Slot erstellen
</a>
</div>
</div>
@endif
</div>
@endsection