Files
laraundfelix/app/Filament/Resources/Offers/Pages/ListOffers.php
T
LarsandClaude Opus 5.5 660b50f418
CI Feature / test (push) Successful in 1m0s
Deploy Test / test (push) Successful in 54s
Deploy Test / deploy (push) Successful in 23s
Stelle die Kataloglisten und das Angebot auf die gemeinsamen Muster um.
- Lizenzartikel, Pakete, Rechteprofile und Angebote nutzen die gemeinsame
  Bestandsliste (ListsCatalog): Suche, Zustandsfilter, lesbare Zustände aus
  vorhandenen Daten statt „Aktueller Stand: 1“ oder „Fassungen: aktiv“
  (Stand veröffentlicht/in Arbeit/gesperrt, in aktivem Angebot, Fassung aktiv
  mit Vergabe und Preis, Bestandteile, Zweck und Fähigkeiten). Lizenzartikel
  zeigen ihr Titelbild.
- Anlegedialoge benennen Zweck und Bestätigung und öffnen danach den neuen
  Eintrag, statt in der Liste stehen zu bleiben.
- Angebot im gemeinsamen Rahmen (Kopf, Positionen, aufgelöster
  Leistungsumfang, Fassungsverlauf). Eine Maske für Anlegen und Ändern
  (FACH-20): „Fassung aktivieren“ bzw. „Geänderte Fassung aktivieren“, bei einer
  Änderung mit der aktiven Fassung vorbelegt (FACH-08). Wirkung unverändert
  OfferService::activate: die bisherige Fassung wird beendet und bleibt
  gespeichert. „Als Vorlage verwenden“ (FACH-09) bleibt offen (OFF-04).
- Entfernt: editorial/catalog-card (ersetzt).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 08:29:28 +01:00

124 lines
4.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
class ListOffers extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = OfferResource::class;
public function getSubheading(): string|Htmlable|null
{
return 'Ein Angebot verbindet Artikel oder eine Paketfassung mit einem Rechteprofil. Die aufgelösten Berechtigungen stehen auf der Angebotsseite.';
}
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Angebot anlegen')
->modalHeading('Neues Angebot')
->modalDescription('Der Name genügt. Positionen, Vergabe und Preis legst du danach am Angebot fest.')
->modalSubmitActionLabel('Angebot anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$offer = null;
$this->report(function () use ($data, &$offer): void {
$offer = app(OfferService::class)->create($data['name']);
}, 'Das Angebot ist angelegt.');
if ($offer instanceof Offer) {
$this->redirect(OfferResource::getUrl('view', ['record' => $offer]));
}
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (Offer::query()->with(['versions.lines.article', 'versions.lines.bundleVersion.bundle', 'versions.lines.rights.profile'])->orderBy('name')->get() as $offer) {
$versions = $offer->versions->sortByDesc('number');
$active = $versions->first(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Aktiv->value);
$ended = $versions->filter(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Beendet->value)->count();
$chips = [];
$zustand = [];
$text = '';
if ($active !== null) {
$chips[] = ['label' => 'Fassung '.$active->number.' aktiv', 'ton' => 'gut'];
$chips[] = ['label' => $this->vergabe($active), 'ton' => 'neutral'];
$zustand[] = 'aktiv';
$text = $active->lines->map(fn ($line): string => ($line->article !== null
? 'Lizenzartikel '.$line->article->code
: 'Paket '.($line->bundleVersion?->bundle?->name ?? '–')).' · '.($line->rights?->profile?->name ?? ''))->implode('; ');
} else {
$chips[] = ['label' => 'Keine aktive Fassung', 'ton' => 'offen'];
$zustand[] = 'ohne';
}
if ($ended > 0) {
$chips[] = ['label' => $ended === 1 ? '1 beendete Fassung' : $ended.' beendete Fassungen', 'ton' => 'leise'];
}
$url = OfferResource::getUrl('view', ['record' => $offer]);
$rows[] = [
'schluessel' => 'o'.$offer->id,
'titel' => $offer->name,
'meta' => 'Angebot',
'text' => $text,
'symbol' => 'etikett',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
private function vergabe(OfferVersion $version): string
{
$kind = match ($version->grant_kind) {
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
default => (string) $version->grant_kind,
};
return $version->price_cents === null ? $kind : $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Mit aktiver Fassung', 'ohne' => 'Ohne aktive Fassung'];
}
protected function einheit(): array
{
return ['Angebot', 'Angebote'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Angebote', 'text' => 'Mit „Angebot anlegen“ oben entsteht das erste Angebot.'];
}
}