20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:57:50 +01:00
parent 854ce02bf6
commit 4d6b4930b2
128 changed files with 18247 additions and 2093 deletions

View file

@ -0,0 +1,563 @@
<?php
use App\Enums\ProductStatus;
use App\Enums\ProductType;
use App\Models\Category;
use App\Models\Product;
use Flux\Flux;
use Illuminate\Support\Facades\Storage;
use Livewire\Volt\Component;
use Livewire\WithPagination;
use function Livewire\Volt\{layout, title};
layout('components.layouts.app');
title('Produkt-Verwaltung');
new class extends Component {
use WithPagination;
public string $search = '';
public string $statusFilter = '';
public string $productTypeFilter = '';
public string $categoryFilter = '';
public string $partnerFilter = '';
public string $curationNotes = '';
public string $rejectionReason = '';
public ?int $correctingProductId = null;
public ?int $rejectingProductId = null;
public function updatedSearch(): void
{
$this->resetPage();
}
public function updatedStatusFilter(): void
{
$this->resetPage();
}
public function updatedProductTypeFilter(): void
{
$this->resetPage();
}
public function updatedCategoryFilter(): void
{
$this->resetPage();
}
public function updatedPartnerFilter(): void
{
$this->resetPage();
}
public function approve(int $productId): void
{
$this->authorize('curate', Product::class);
$product = Product::findOrFail($productId);
$product->update([
'status' => ProductStatus::Active,
'is_curated' => true,
'curated_at' => now(),
'curated_by' => auth()->id(),
'curation_notes' => null,
]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'approved',
'note' => null,
]);
Flux::toast(variant: 'success', text: __('Produkt ":name" wurde freigegeben.', ['name' => $product->name]), duration: 5000);
}
public function openCorrection(int $productId): void
{
$this->correctingProductId = $productId;
$this->curationNotes = '';
$this->rejectingProductId = null;
$this->rejectionReason = '';
}
public function cancelCorrection(): void
{
$this->correctingProductId = null;
$this->curationNotes = '';
}
public function sendCorrection(int $productId): void
{
$this->authorize('curate', Product::class);
$this->validate([
'curationNotes' => 'required|string|max:5000',
], [
'curationNotes.required' => __('Bitte geben Sie eine Korrekturanweisung ein.'),
]);
$product = Product::findOrFail($productId);
$product->update([
'status' => ProductStatus::Correction,
'is_curated' => false,
'curation_notes' => $this->curationNotes,
]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'correction',
'note' => $this->curationNotes,
]);
$this->correctingProductId = null;
$this->curationNotes = '';
Flux::toast(variant: 'success', text: __('Korrekturanweisung für ":name" wurde gesendet.', ['name' => $product->name]), duration: 5000);
}
public function openRejection(int $productId): void
{
$this->rejectingProductId = $productId;
$this->rejectionReason = '';
$this->correctingProductId = null;
$this->curationNotes = '';
}
public function cancelRejection(): void
{
$this->rejectingProductId = null;
$this->rejectionReason = '';
}
public function reject(int $productId): void
{
$this->authorize('curate', Product::class);
$this->validate([
'rejectionReason' => 'required|string|max:5000',
], [
'rejectionReason.required' => __('Bitte geben Sie einen Ablehnungsgrund ein.'),
]);
$product = Product::findOrFail($productId);
$product->update([
'status' => ProductStatus::Archived,
'is_curated' => false,
'curation_notes' => $this->rejectionReason,
]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'rejected',
'note' => $this->rejectionReason,
]);
$this->rejectingProductId = null;
$this->rejectionReason = '';
Flux::toast(variant: 'success', text: __('Produkt ":name" wurde abgelehnt.', ['name' => $product->name]), duration: 5000);
}
public function archiveProduct(int $productId): void
{
$this->authorize('curate', Product::class);
$product = Product::findOrFail($productId);
$product->update(['status' => ProductStatus::Archived]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'archived',
'note' => null,
]);
Flux::toast(variant: 'success', text: __('Produkt ":name" wurde archiviert.', ['name' => $product->name]), duration: 5000);
}
public function markAsSold(int $productId): void
{
$this->authorize('curate', Product::class);
$product = Product::findOrFail($productId);
$product->update(['status' => ProductStatus::Sold]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'sold',
'note' => null,
]);
Flux::toast(variant: 'success', text: __('Produkt ":name" als verkauft markiert.', ['name' => $product->name]), duration: 5000);
}
public function with(): array
{
$this->authorize('curate', Product::class);
$query = Product::query()
->with(['partner', 'categories', 'media'])
->when($this->search, fn($q) => $q->where(function ($q) {
$q->where('name', 'like', "%{$this->search}%")
->orWhere('b2in_article_number', 'like', "%{$this->search}%")
->orWhere('partner_product_number', 'like', "%{$this->search}%");
}))
->when($this->statusFilter, fn($q) => $q->where('status', $this->statusFilter))
->when($this->productTypeFilter, fn($q) => $q->where('product_type', $this->productTypeFilter))
->when($this->categoryFilter, fn($q) => $q->whereHas('categories', fn($q) => $q->where('categories.id', $this->categoryFilter)))
->when($this->partnerFilter, fn($q) => $q->where('partner_id', $this->partnerFilter));
$products = $query->latest()->paginate(25);
$categories = Category::orderBy('name')->get();
$partners = \App\Models\Partner::orderBy('company_name')->get(['id', 'company_name']);
$statusCounts = Product::query()
->selectRaw("status, count(*) as count")
->groupBy('status')
->pluck('count', 'status');
return [
'products' => $products,
'categories' => $categories,
'partners' => $partners,
'totalCount' => Product::count(),
'pendingCount' => $statusCounts[ProductStatus::Pending->value] ?? 0,
'correctionCount' => $statusCounts[ProductStatus::Correction->value] ?? 0,
'activeCount' => $statusCounts[ProductStatus::Active->value] ?? 0,
];
}
}; ?>
<div class="space-y-6 p-6">
{{-- Header --}}
<div class="flex items-center justify-between">
<div>
<flux:heading size="xl" class="mb-2">{{ __('Produkt-Verwaltung') }}</flux:heading>
<flux:subheading>{{ __('Alle Produkte verwalten, freigeben und bearbeiten') }}</flux:subheading>
</div>
<div class="flex items-center gap-2">
<flux:button variant="primary" icon="plus" href="{{ route('products.create.teaser') }}">
{{ __('Neues Teaser-Produkt') }}
</flux:button>
<flux:button variant="primary" icon="plus" href="{{ route('products.create.standard') }}">
{{ __('Neues Standard-Produkt') }}
</flux:button>
</div>
</div>
{{-- Statistiken --}}
<div class="grid grid-cols-1 gap-4 md:grid-cols-4">
<flux:card class="shadow-elegant">
<div class="flex items-center justify-between">
<div>
<flux:subheading>{{ __('Gesamt') }}</flux:subheading>
<flux:heading size="2xl" class="mt-2">{{ $totalCount }}</flux:heading>
</div>
<div class="flex h-12 w-12 items-center justify-center rounded-lg bg-blue-100 dark:bg-blue-900/20">
<flux:icon.shopping-bag class="h-6 w-6 text-blue-600 dark:text-blue-400" />
</div>
</div>
</flux:card>
<flux:card class="shadow-elegant cursor-pointer" wire:click="$set('statusFilter', 'pending')">
<div class="flex items-center justify-between">
<div>
<flux:subheading>{{ __('Zur Freigabe') }}</flux:subheading>
<flux:heading size="2xl" class="mt-2">{{ $pendingCount }}</flux:heading>
</div>
<div class="flex h-12 w-12 items-center justify-center rounded-lg bg-amber-100 dark:bg-amber-900/20">
<flux:icon.clock class="h-6 w-6 text-amber-600 dark:text-amber-400" />
</div>
</div>
</flux:card>
<flux:card class="shadow-elegant cursor-pointer" wire:click="$set('statusFilter', 'correction')">
<div class="flex items-center justify-between">
<div>
<flux:subheading>{{ __('In Korrektur') }}</flux:subheading>
<flux:heading size="2xl" class="mt-2">{{ $correctionCount }}</flux:heading>
</div>
<div class="flex h-12 w-12 items-center justify-center rounded-lg bg-orange-100 dark:bg-orange-900/20">
<flux:icon.arrow-uturn-left class="h-6 w-6 text-orange-600 dark:text-orange-400" />
</div>
</div>
</flux:card>
<flux:card class="shadow-elegant cursor-pointer" wire:click="$set('statusFilter', 'active')">
<div class="flex items-center justify-between">
<div>
<flux:subheading>{{ __('Freigegeben') }}</flux:subheading>
<flux:heading size="2xl" class="mt-2">{{ $activeCount }}</flux:heading>
</div>
<div class="flex h-12 w-12 items-center justify-center rounded-lg bg-green-100 dark:bg-green-900/20">
<flux:icon.check-circle class="h-6 w-6 text-green-600 dark:text-green-400" />
</div>
</div>
</flux:card>
</div>
{{-- Filter --}}
<flux:card class="shadow-elegant">
<div class="flex flex-wrap items-end gap-4">
<flux:field class="flex-1">
<flux:label>{{ __('Suche') }}</flux:label>
<flux:input wire:model.live.debounce.300ms="search"
placeholder="{{ __('Name, Artikelnummer...') }}" icon="magnifying-glass" />
</flux:field>
<flux:field>
<flux:label>{{ __('Status') }}</flux:label>
<flux:select wire:model.live="statusFilter">
<flux:select.option value="">{{ __('Alle Status') }}</flux:select.option>
@foreach (ProductStatus::cases() as $status)
<flux:select.option value="{{ $status->value }}">{{ $status->label() }}</flux:select.option>
@endforeach
</flux:select>
</flux:field>
<flux:field>
<flux:label>{{ __('Produkttyp') }}</flux:label>
<flux:select wire:model.live="productTypeFilter">
<flux:select.option value="">{{ __('Alle Typen') }}</flux:select.option>
<flux:select.option value="local_stock">{{ __('Teaser (Local Express)') }}</flux:select.option>
<flux:select.option value="smart_order">{{ __('Standard (Smart Club)') }}</flux:select.option>
</flux:select>
</flux:field>
<flux:field>
<flux:label>{{ __('Händler') }}</flux:label>
<flux:select wire:model.live="partnerFilter">
<flux:select.option value="">{{ __('Alle Händler') }}</flux:select.option>
@foreach ($partners as $partner)
<flux:select.option :value="$partner->id">{{ $partner->company_name }}</flux:select.option>
@endforeach
</flux:select>
</flux:field>
<flux:field>
<flux:label>{{ __('Kategorie') }}</flux:label>
<flux:select wire:model.live="categoryFilter">
<flux:select.option value="">{{ __('Alle Kategorien') }}</flux:select.option>
@foreach ($categories as $category)
<flux:select.option :value="$category->id">{{ $category->name }}</flux:select.option>
@endforeach
</flux:select>
</flux:field>
</div>
</flux:card>
{{-- Produkttabelle --}}
<flux:card class="shadow-elegant">
<flux:table>
<flux:table.columns>
<flux:table.column>{{ __('Produkt') }}</flux:table.column>
<flux:table.column>{{ __('Händler') }}</flux:table.column>
<flux:table.column>{{ __('Kategorie') }}</flux:table.column>
<flux:table.column>{{ __('Status') }}</flux:table.column>
<flux:table.column>{{ __('Kuration') }}</flux:table.column>
<flux:table.column>{{ __('Erstellt') }}</flux:table.column>
<flux:table.column></flux:table.column>
</flux:table.columns>
<flux:table.rows>
@forelse($products as $product)
<flux:table.row wire:key="product-{{ $product->id }}">
{{-- Produkt --}}
<flux:table.cell>
<div class="flex items-center gap-3">
@php
$thumbnail = $product->media->sortBy('order_column')->first();
@endphp
@if ($thumbnail)
<img src="{{ Storage::url($thumbnail->file_path) }}"
alt="{{ $thumbnail->alt_text ?? $product->name }}"
class="h-12 w-12 shrink-0 rounded-lg border border-zinc-200 object-cover dark:border-zinc-700" />
@else
<div
class="flex h-12 w-12 shrink-0 items-center justify-center rounded-lg border border-zinc-200 bg-zinc-100 dark:border-zinc-700 dark:bg-zinc-800">
<flux:icon.photo class="h-5 w-5 text-zinc-400" />
</div>
@endif
<div>
<div class="font-medium text-zinc-900 dark:text-white">
{{ $product->name }}
</div>
<div class="flex items-center gap-2 mt-1">
<flux:badge size="sm"
color="{{ $product->product_type?->value === 'local_stock' ? 'amber' : 'blue' }}">
{{ $product->product_type?->label() ?? '' }}
</flux:badge>
@if ($product->b2in_article_number)
<span class="text-xs text-zinc-400">{{ $product->b2in_article_number }}</span>
@endif
</div>
</div>
</div>
</flux:table.cell>
{{-- Händler --}}
<flux:table.cell>
<span class="text-sm text-zinc-600 dark:text-zinc-400">
{{ $product->partner?->company_name ?? '' }}
</span>
</flux:table.cell>
{{-- Kategorie --}}
<flux:table.cell>
<span class="text-sm text-zinc-600 dark:text-zinc-400">
{{ $product->categories->first()?->name ?? '' }}
</span>
</flux:table.cell>
{{-- Status --}}
<flux:table.cell>
<flux:badge size="sm" color="{{ $product->status?->color() ?? 'zinc' }}">
{{ $product->status?->label() ?? '' }}
</flux:badge>
</flux:table.cell>
{{-- Kuration --}}
<flux:table.cell>
@if ($product->status === ProductStatus::Pending)
<div class="flex items-center gap-1">
<flux:button wire:click="approve({{ $product->id }})"
wire:loading.attr="disabled"
size="xs" variant="primary" icon="check"
title="{{ __('Freigeben') }}" />
<flux:button wire:click="openCorrection({{ $product->id }})"
wire:loading.attr="disabled"
size="xs" variant="filled" icon="arrow-uturn-left"
title="{{ __('Korrektur') }}" />
<flux:button wire:click="openRejection({{ $product->id }})"
wire:loading.attr="disabled"
size="xs" variant="danger" icon="x-mark"
title="{{ __('Ablehnen') }}" />
</div>
@elseif ($product->status === ProductStatus::Correction)
<flux:badge size="sm" color="orange" icon="arrow-uturn-left">
{{ __('Warte auf Korrektur') }}
</flux:badge>
@elseif ($product->is_curated)
<flux:badge size="sm" color="green" icon="check-circle">
{{ __('Freigegeben') }}
</flux:badge>
@else
<span class="text-xs text-zinc-400"></span>
@endif
</flux:table.cell>
{{-- Erstellt --}}
<flux:table.cell>
<span class="text-sm text-zinc-500">
{{ $product->created_at?->format('d.m.Y') }}
</span>
</flux:table.cell>
{{-- Aktionen --}}
<flux:table.cell>
<div class="flex items-center gap-1">
<flux:button
href="{{ $product->product_type === ProductType::LocalStock ? route('products.edit.teaser', $product) : route('products.edit.standard', $product) }}"
size="sm" variant="ghost" icon="pencil"
title="{{ __('Bearbeiten') }}" />
@if (!in_array($product->status, [ProductStatus::Archived, ProductStatus::Sold]))
<flux:dropdown>
<flux:button size="sm" variant="ghost" icon="ellipsis-vertical" />
<flux:menu>
<flux:menu.item wire:click="markAsSold({{ $product->id }})"
wire:confirm="{{ __('Produkt wirklich als verkauft markieren?') }}"
icon="check-badge">
{{ __('Als verkauft') }}
</flux:menu.item>
<flux:menu.item wire:click="archiveProduct({{ $product->id }})"
wire:confirm="{{ __('Produkt wirklich archivieren?') }}"
icon="archive-box" variant="danger">
{{ __('Archivieren') }}
</flux:menu.item>
</flux:menu>
</flux:dropdown>
@endif
</div>
</flux:table.cell>
</flux:table.row>
{{-- Inline Korrektur-Formular --}}
@if ($correctingProductId === $product->id)
<flux:table.row wire:key="correction-{{ $product->id }}">
<flux:table.cell colspan="7">
<div class="rounded-lg border border-orange-200 bg-orange-50 p-4 dark:border-orange-800 dark:bg-orange-950/30">
<flux:field>
<flux:label>{{ __('Korrekturanweisung für ":name"', ['name' => $product->name]) }}</flux:label>
<flux:textarea wire:model="curationNotes" rows="3"
placeholder="{{ __('Bitte beschreiben Sie, was der Partner korrigieren soll...') }}" />
<flux:error name="curationNotes" />
</flux:field>
<div class="mt-3 flex gap-2">
<flux:button wire:click="sendCorrection({{ $product->id }})"
wire:loading.attr="disabled" variant="primary" size="sm"
icon="paper-airplane">
{{ __('Korrektur senden') }}
</flux:button>
<flux:button wire:click="cancelCorrection" variant="ghost" size="sm">
{{ __('Abbrechen') }}
</flux:button>
</div>
</div>
</flux:table.cell>
</flux:table.row>
@endif
{{-- Inline Ablehnungs-Formular --}}
@if ($rejectingProductId === $product->id)
<flux:table.row wire:key="rejection-{{ $product->id }}">
<flux:table.cell colspan="7">
<div class="rounded-lg border border-red-200 bg-red-50 p-4 dark:border-red-800 dark:bg-red-950/30">
<flux:field>
<flux:label>{{ __('Ablehnungsgrund für ":name"', ['name' => $product->name]) }}</flux:label>
<flux:textarea wire:model="rejectionReason" rows="3"
placeholder="{{ __('Bitte geben Sie den Grund für die Ablehnung an...') }}" />
<flux:error name="rejectionReason" />
</flux:field>
<div class="mt-3 flex gap-2">
<flux:button wire:click="reject({{ $product->id }})"
wire:loading.attr="disabled" variant="danger" size="sm"
icon="x-mark">
{{ __('Ablehnen') }}
</flux:button>
<flux:button wire:click="cancelRejection" variant="ghost" size="sm">
{{ __('Abbrechen') }}
</flux:button>
</div>
</div>
</flux:table.cell>
</flux:table.row>
@endif
{{-- Korrekturhinweis anzeigen --}}
@if ($product->status === ProductStatus::Correction && $product->curation_notes)
<flux:table.row wire:key="correction-notes-{{ $product->id }}">
<flux:table.cell colspan="7">
<flux:callout variant="warning" icon="exclamation-triangle">
<flux:callout.heading>{{ __('Korrekturanweisung') }}</flux:callout.heading>
<flux:callout.text>{{ $product->curation_notes }}</flux:callout.text>
</flux:callout>
</flux:table.cell>
</flux:table.row>
@endif
@empty
<flux:table.row>
<flux:table.cell colspan="7" class="py-12 text-center text-zinc-500">
<flux:icon.shopping-bag class="mx-auto mb-2 h-12 w-12 text-zinc-400" />
<div>{{ __('Keine Produkte gefunden') }}</div>
</flux:table.cell>
</flux:table.row>
@endforelse
</flux:table.rows>
</flux:table>
@if ($products->hasPages())
<div class="mt-4">
{{ $products->links() }}
</div>
@endif
</flux:card>
</div>