From 660b50f418e526774a1b9a278e0c869221bcd992 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 20 Nov 2026 08:29:28 +0100 Subject: [PATCH] Stelle die Kataloglisten und das Angebot auf die gemeinsamen Muster um. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../Resources/Bundles/Pages/ListBundles.php | 89 +++++++++- .../Pages/ListLicenseArticles.php | 116 ++++++++++++- .../Resources/Offers/Pages/ListOffers.php | 101 +++++++++++- .../Resources/Offers/Pages/ViewOffer.php | 154 +++++++++++++++++- .../Pages/ListRightsProfiles.php | 126 ++++++++++---- app/Filament/Support/ListsCatalog.php | 90 ++++++++++ .../views/filament/catalog/angebot.blade.php | 67 ++++++++ .../filament/editorial/catalog-card.blade.php | 29 ---- .../views/filament/verwaltung/icon.blade.php | 2 + tests/Feature/BestandslisteTest.php | 134 +++++++++++++++ 10 files changed, 828 insertions(+), 80 deletions(-) create mode 100644 app/Filament/Support/ListsCatalog.php create mode 100644 resources/views/filament/catalog/angebot.blade.php delete mode 100644 resources/views/filament/editorial/catalog-card.blade.php diff --git a/app/Filament/Resources/Bundles/Pages/ListBundles.php b/app/Filament/Resources/Bundles/Pages/ListBundles.php index 513b39d..9f1667f 100644 --- a/app/Filament/Resources/Bundles/Pages/ListBundles.php +++ b/app/Filament/Resources/Bundles/Pages/ListBundles.php @@ -2,8 +2,12 @@ namespace App\Filament\Resources\Bundles\Pages; +use App\Domain\Catalog\Bundle; use App\Domain\Catalog\BundleService; +use App\Domain\Catalog\BundleStatus; +use App\Domain\Catalog\StatusValue; use App\Filament\Resources\Bundles\BundleResource; +use App\Filament\Support\ListsCatalog; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; use Filament\Forms\Components\TextInput; @@ -12,6 +16,7 @@ class ListBundles extends ListRecords { + use ListsCatalog; use ReportsDomainRules; protected static string $resource = BundleResource::class; @@ -24,13 +29,83 @@ public function getSubheading(): string|Htmlable|null protected function getHeaderActions(): array { return [ - Action::make('create')->label('Paket anlegen')->schema([ - TextInput::make('name')->label('Name')->required(), - ])->action(function (array $data): void { - $this->report(function () use ($data): void { - app(BundleService::class)->create($data['name']); - }, 'Das Paket ist angelegt.'); - }), + Action::make('create')->label('Paket anlegen') + ->modalHeading('Neues Paket') + ->modalDescription('Der Name genügt. Bestandteile stellst du danach am Paket zusammen.') + ->modalSubmitActionLabel('Paket anlegen') + ->schema([ + TextInput::make('name')->label('Name')->required(), + ])->action(function (array $data): void { + $bundle = null; + $this->report(function () use ($data, &$bundle): void { + $bundle = app(BundleService::class)->create($data['name']); + }, 'Das Paket ist angelegt.'); + + if ($bundle instanceof Bundle) { + $this->redirect(BundleResource::getUrl('view', ['record' => $bundle])); + } + }), ]; } + + protected function catalogRows(): array + { + $rows = []; + + foreach (Bundle::query()->with(['versions.items'])->orderBy('name')->get() as $bundle) { + $versions = $bundle->versions->sortByDesc('number'); + $published = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value); + $draft = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Entwurf->value); + $chips = []; + $zustand = []; + + if ($published !== null) { + $chips[] = ['label' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut']; + $chips[] = ['label' => $published->items->count() === 1 ? '1 Bestandteil' : $published->items->count().' Bestandteile', 'ton' => 'leise']; + $zustand[] = 'veroeffentlicht'; + } else { + $chips[] = ['label' => $versions->isEmpty() ? 'Noch keine Fassung' : 'Noch nicht veröffentlicht', 'ton' => 'offen']; + $zustand[] = 'ohne'; + } + + if ($draft !== null) { + $chips[] = ['label' => 'Fassung '.$draft->number.' in Arbeit', 'ton' => 'offen']; + $zustand[] = 'entwurf'; + } + + if ($bundle->archived_at !== null) { + $chips[] = ['label' => 'Archiviert', 'ton' => 'leise']; + $zustand[] = 'archiviert'; + } + + $url = BundleResource::getUrl('view', ['record' => $bundle]); + $rows[] = [ + 'schluessel' => 'p'.$bundle->id, + 'titel' => $bundle->name, + 'meta' => 'Paket', + 'symbol' => 'modul', + 'url' => $url, + 'chips' => $chips, + 'zustand' => $zustand, + 'aktionen' => [['label' => 'Öffnen', 'href' => $url]], + ]; + } + + return $rows; + } + + protected function zustandOptionen(): array + { + return ['alle' => 'Jeder Zustand', 'veroeffentlicht' => 'Veröffentlicht', 'ohne' => 'Noch nicht veröffentlicht', 'entwurf' => 'Fassung in Arbeit', 'archiviert' => 'Archiviert']; + } + + protected function einheit(): array + { + return ['Paket', 'Pakete']; + } + + protected function leer(): array + { + return ['titel' => 'Noch keine Pakete', 'text' => 'Mit „Paket anlegen“ oben entsteht das erste Paket.']; + } } diff --git a/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php b/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php index 111bd20..a8af291 100644 --- a/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php +++ b/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php @@ -3,15 +3,24 @@ namespace App\Filament\Resources\LicenseArticles\Pages; use App\Domain\Catalog\ArticleService; +use App\Domain\Catalog\ContentElement; +use App\Domain\Catalog\LicenseArticle; +use App\Domain\Catalog\PresentationMedia; +use App\Domain\Catalog\ReleaseStatus; +use App\Domain\Catalog\StatusValue; +use App\Domain\Media\ThumbnailRef; use App\Filament\Resources\LicenseArticles\LicenseArticleResource; +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; +use Illuminate\Support\Facades\DB; class ListLicenseArticles extends ListRecords { + use ListsCatalog; use ReportsDomainRules; protected static string $resource = LicenseArticleResource::class; @@ -26,15 +35,118 @@ protected function getHeaderActions(): array return [ Action::make('create') ->label('Artikel anlegen') + ->modalHeading('Neuer Lizenzartikel') + ->modalDescription('Kennung und Produktlinie genügen. Titel, Texte und Stand pflegst du danach am Artikel.') + ->modalSubmitActionLabel('Artikel anlegen') ->schema([ TextInput::make('code')->label('Kennung')->required(), TextInput::make('product_line')->label('Produktlinie'), ]) ->action(function (array $data): void { - $this->report(function () use ($data): void { - app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null); + $article = null; + $this->report(function () use ($data, &$article): void { + $article = app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null); }, 'Der Lizenzartikel ist angelegt.'); + + if ($article instanceof LicenseArticle) { + $this->redirect(LicenseArticleResource::getUrl('view', ['record' => $article])); + } }), ]; } + + protected function catalogRows(): array + { + $offered = DB::table('resolved_scopes') + ->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id') + ->where('offer_versions.status', 'aktiv') + ->distinct() + ->pluck('resolved_scopes.license_article_id') + ->map(fn (mixed $id): int => (int) $id) + ->all(); + $presentation = app(PresentationMedia::class); + $rows = []; + + foreach (LicenseArticle::query()->with(['currentRelease', 'releases'])->orderBy('code')->get() as $article) { + $current = $article->currentRelease; + $currentStatus = $current !== null ? StatusValue::of($current->status) : null; + $draft = $article->releases->first(fn ($release): bool => StatusValue::of($release->status) === ReleaseStatus::Entwurf->value); + $chips = []; + $zustand = []; + + if ($current === null) { + $chips[] = ['label' => 'Noch kein Stand', 'ton' => 'offen']; + $zustand[] = 'ohne'; + } elseif ($currentStatus === ReleaseStatus::Gesperrt->value) { + $chips[] = ['label' => 'Stand '.$current->number.' gesperrt', 'ton' => 'achtung']; + $zustand[] = 'gesperrt'; + } else { + $chips[] = ['label' => 'Stand '.$current->number.' veröffentlicht', 'ton' => 'gut']; + $zustand[] = 'stand'; + } + + if ($draft !== null) { + $chips[] = ['label' => 'Stand '.$draft->number.' in Arbeit', 'ton' => 'offen']; + $zustand[] = 'entwurf'; + } + + $inOffer = in_array($article->id, $offered, true); + $chips[] = $inOffer ? ['label' => 'In einem aktiven Angebot', 'ton' => 'gut'] : ['label' => 'In keinem aktiven Angebot', 'ton' => 'leise']; + $zustand[] = $inOffer ? 'angebot' : 'ohne-angebot'; + + if ($article->archived_at !== null) { + $chips[] = ['label' => 'Archiviert', 'ton' => 'leise']; + $zustand[] = 'archiviert'; + } + + $coverId = $presentation->coverElementId($article); + $cover = $coverId !== null ? ContentElement::query()->find($coverId) : null; + $title = trim((string) ($article->display_title ?: $article->working_title)) ?: $article->code; + $url = LicenseArticleResource::getUrl('view', ['record' => $article]); + $rows[] = [ + 'schluessel' => 'a'.$article->id, + 'titel' => $title, + 'meta' => 'Lizenzartikel · '.$article->code.(filled($article->product_line) ? ' · '.$article->product_line : ''), + 'text' => trim((string) ($article->teaser ?: $article->summary)), + 'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null, + 'symbol' => 'dokument', + 'url' => $url, + 'chips' => $chips, + 'zustand' => $zustand, + 'suchtext' => implode(' ', array_filter([$article->code, $article->working_title, $article->display_title, $article->summary, $article->product_line, $article->search_terms])), + 'aktionen' => [['label' => 'Öffnen', 'href' => $url]], + ]; + } + + return $rows; + } + + protected function zustandOptionen(): array + { + return [ + 'alle' => 'Jeder Zustand', + 'stand' => 'Mit veröffentlichtem Stand', + 'ohne' => 'Noch ohne Stand', + 'entwurf' => 'Stand in Arbeit', + 'gesperrt' => 'Gesperrter Stand', + 'angebot' => 'In einem aktiven Angebot', + 'ohne-angebot' => 'In keinem aktiven Angebot', + 'archiviert' => 'Archiviert', + ]; + } + + protected function einheit(): array + { + return ['Lizenzartikel', 'Lizenzartikel']; + } + + protected function leer(): array + { + return ['titel' => 'Noch keine Lizenzartikel', 'text' => 'Mit „Artikel anlegen“ oben entsteht der erste Artikel.']; + } + + protected function suchPlatzhalter(): string + { + return 'Kennung, Titel oder Produktlinie'; + } } diff --git a/app/Filament/Resources/Offers/Pages/ListOffers.php b/app/Filament/Resources/Offers/Pages/ListOffers.php index bddef5e..bb6ff11 100644 --- a/app/Filament/Resources/Offers/Pages/ListOffers.php +++ b/app/Filament/Resources/Offers/Pages/ListOffers.php @@ -2,8 +2,13 @@ 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; @@ -12,6 +17,7 @@ class ListOffers extends ListRecords { + use ListsCatalog; use ReportsDomainRules; protected static string $resource = OfferResource::class; @@ -24,13 +30,94 @@ public function getSubheading(): string|Htmlable|null protected function getHeaderActions(): array { return [ - Action::make('create')->label('Angebot anlegen')->schema([ - TextInput::make('name')->label('Name')->required(), - ])->action(function (array $data): void { - $this->report(function () use ($data): void { - app(OfferService::class)->create($data['name']); - }, 'Das Angebot ist angelegt.'); - }), + 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.']; + } } diff --git a/app/Filament/Resources/Offers/Pages/ViewOffer.php b/app/Filament/Resources/Offers/Pages/ViewOffer.php index 5a9a6af..e30f0eb 100644 --- a/app/Filament/Resources/Offers/Pages/ViewOffer.php +++ b/app/Filament/Resources/Offers/Pages/ViewOffer.php @@ -7,9 +7,13 @@ use App\Domain\Catalog\LicenseArticle; use App\Domain\Catalog\Offer; use App\Domain\Catalog\OfferService; +use App\Domain\Catalog\OfferStatus; +use App\Domain\Catalog\OfferVersion; use App\Domain\Catalog\RightsProfileVersion; +use App\Domain\Catalog\StatusValue; use App\Filament\Resources\Offers\OfferResource; use App\Filament\Support\CatalogOptions; +use App\Filament\Support\CatalogReading; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; use Filament\Forms\Components\Repeater; @@ -17,17 +21,75 @@ use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ViewRecord; use Filament\Schemas\Components\Utilities\Get; +use Filament\Schemas\Components\View; +use Filament\Schemas\Schema; +use Filament\Support\Enums\Width; +use Illuminate\Contracts\Support\Htmlable; +/** + * Angebot im gemeinsamen Rahmen. Anlegen und Ändern nutzen dieselbe Maske (FACH-20): „Fassung aktivieren“ legt die + * nächste, danach unveränderliche Angebotsfassung an; bei einer Änderung ist die Maske mit der aktiven Fassung + * vorbelegt (FACH-08). Die Wirkung bleibt die bestehende von OfferService::activate. + */ class ViewOffer extends ViewRecord { use ReportsDomainRules; protected static string $resource = OfferResource::class; + public function getTitle(): string|Htmlable + { + return (string) $this->getRecord()->name; + } + + public function getHeading(): string|Htmlable + { + return ''; + } + + public function getMaxContentWidth(): Width|string|null + { + return Width::Full; + } + protected function getHeaderActions(): array { - return [ - Action::make('activate')->label('Fassung aktivieren')->schema([ + return []; + } + + public function infolist(Schema $schema): Schema + { + return $schema->components([ + View::make('filament.catalog.angebot')->viewData(fn (): array => $this->angebotDaten())->columnSpanFull(), + ])->columns(1); + } + + public function activeVersion(): ?OfferVersion + { + /** @var Offer $offer */ + $offer = $this->getRecord(); + + return $offer->versions() + ->where('status', OfferStatus::Aktiv) + ->orderByDesc('number') + ->with(['lines.article', 'lines.bundleVersion.bundle', 'lines.rights.profile']) + ->first(); + } + + public function activateAction(): Action + { + return Action::make('activate') + ->label(fn (): string => $this->activeVersion() !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren') + ->modalHeading(fn (): string => $this->activeVersion() !== null + ? 'Angebot ändern: Fassung '.$this->nextNumber().' aktivieren' + : 'Erste Fassung aktivieren') + ->modalDescription(fn (): string => ($active = $this->activeVersion()) !== null + ? 'Die Maske ist mit Fassung '.$active->number.' vorbelegt. Beim Aktivieren wird Fassung '.$active->number.' beendet und bleibt unverändert gespeichert; neue Erwerbe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen ändern sich dadurch nicht.' + : 'Positionen, Vergabe und Preis bilden die erste Fassung. Nach dem Aktivieren ist sie unveränderlich; Änderungen ergeben eine weitere Fassung.') + ->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' aktivieren') + ->modalWidth('4xl') + ->fillForm(fn (): array => $this->formFromActive()) + ->schema([ Select::make('grant_kind')->label('Vergabe')->options([ 'kauf' => 'Kauf', 'auf_abruf' => 'Auf Abruf', @@ -57,9 +119,10 @@ protected function getHeaderActions(): array Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => CatalogOptions::bundleVersions()) ->visible(fn (Get $get): bool => $get('kind') === 'bundle'), Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(), - ])->minItems(1), - ])->action(function (array $data): void { - $this->report(function () use ($data): void { + ])->minItems(1)->addActionLabel('Position hinzufügen'), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): string { /** @var Offer $offer */ $offer = $this->getRecord(); $lines = []; @@ -74,16 +137,93 @@ protected function getHeaderActions(): array ]; } - app(OfferService::class)->activate($offer, $lines, [ + $version = app(OfferService::class)->activate($offer, $lines, [ 'grant_kind' => $data['grant_kind'], 'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'], 'holder_kind' => 'person', 'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null, ]); + + return 'Fassung '.$version->number.' ist aktiv.'; }, 'Die Angebotsfassung ist aktiv.'); $this->getRecord()->unsetRelations(); $this->getRecord()->refresh(); - }), + }); + } + + /** + * Vorbelegung aus der aktiven Fassung; ohne aktive Fassung eine leere Position. + * + * @return array + */ + private function formFromActive(): array + { + $active = $this->activeVersion(); + + if ($active === null) { + return ['grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]]; + } + + return [ + 'grant_kind' => $active->grant_kind, + 'price_cents' => $active->price_cents, + 'lines' => $active->lines->sortBy('position')->map(fn ($line): array => [ + 'kind' => $line->license_article_id !== null ? 'article' : 'bundle', + 'article_id' => $line->license_article_id, + 'bundle_version_id' => $line->bundle_version_id, + 'rights_id' => $line->rights_profile_version_id, + ])->values()->all(), ]; } + + private function nextNumber(): int + { + return ((int) $this->getRecord()->versions()->max('number')) + 1; + } + + /** + * @return array + */ + private function angebotDaten(): array + { + /** @var Offer $offer */ + $offer = $this->getRecord(); + $active = $this->activeVersion(); + $reading = app(CatalogReading::class); + $versions = $offer->versions()->orderByDesc('number')->get(); + + return [ + 'offer' => $offer, + 'active' => $active, + 'grants' => $active !== null ? $reading->offerGrants($offer) : [], + 'versions' => $versions->map(fn (OfferVersion $version): array => [ + 'number' => $version->number, + 'status' => match (StatusValue::of($version->status)) { + 'aktiv' => 'Aktiv', + 'beendet' => 'Beendet', + default => 'Entwurf', + }, + 'ton' => match (StatusValue::of($version->status)) { + 'aktiv' => 'gut', + 'beendet' => 'leise', + default => 'offen', + }, + 'vergabe' => $this->vergabe($version), + 'wann' => $version->activated_at?->format('d.m.Y'), + ])->all(), + 'vergabe' => $active !== null ? $this->vergabe($active) : null, + ]; + } + + 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, ',', '.').' €'; + } } diff --git a/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php b/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php index c3c6311..9db81ed 100644 --- a/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php +++ b/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php @@ -3,7 +3,9 @@ namespace App\Filament\Resources\RightsProfiles\Pages; use App\Domain\Catalog\OfferService; +use App\Domain\Catalog\RightsProfile; use App\Filament\Resources\RightsProfiles\RightsProfileResource; +use App\Filament\Support\ListsCatalog; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; use Filament\Forms\Components\CheckboxList; @@ -14,8 +16,22 @@ class ListRightsProfiles extends ListRecords { + use ListsCatalog; use ReportsDomainRules; + /** Lesbare Fähigkeiten; dieselben Werte wie im Anlegedialog. */ + public const FAEHIGKEITEN = [ + 'film:streamen' => 'Film ansehen', + 'film:laden' => 'Film herunterladen', + 'audio:streamen' => 'Hörstück ansehen', + 'document:ansehen' => 'Dokument ansehen', + 'document:laden' => 'Dokument herunterladen', + 'pdf:ansehen' => 'PDF ansehen', + 'pdf:laden' => 'PDF herunterladen', + 'text:ansehen' => 'Text ansehen', + 'bild:ansehen' => 'Bild ansehen', + ]; + protected static string $resource = RightsProfileResource::class; public function getSubheading(): string|Htmlable|null @@ -26,36 +42,90 @@ public function getSubheading(): string|Htmlable|null protected function getHeaderActions(): array { return [ - Action::make('create')->label('Rechteprofil anlegen')->schema([ - TextInput::make('name')->label('Name')->required(), - Select::make('purpose')->label('Zweck')->options([ - 'ehrenamtlich' => 'Ehrenamtlich', - 'kommerziell' => 'Kommerziell', - 'institutionell' => 'Institutionell', - ])->required(), - CheckboxList::make('capabilities')->label('Fähigkeiten')->options([ - 'film:streamen' => 'Film ansehen', - 'film:laden' => 'Film herunterladen', - 'audio:streamen' => 'Hörstück ansehen', - 'document:ansehen' => 'Dokument ansehen', - 'document:laden' => 'Dokument herunterladen', - 'pdf:ansehen' => 'PDF ansehen', - 'pdf:laden' => 'PDF herunterladen', - 'text:ansehen' => 'Text ansehen', - 'bild:ansehen' => 'Bild ansehen', - ])->required(), - ])->action(function (array $data): void { - $this->report(function () use ($data): void { - $capabilities = []; + Action::make('create')->label('Rechteprofil anlegen') + ->modalHeading('Neues Rechteprofil') + ->modalDescription('Zweck und erlaubte Handlungen. Ein Angebot verbindet das Profil später mit Artikeln.') + ->modalSubmitActionLabel('Rechteprofil anlegen') + ->schema([ + TextInput::make('name')->label('Name')->required(), + Select::make('purpose')->label('Zweck')->options([ + 'ehrenamtlich' => 'Ehrenamtlich', + 'kommerziell' => 'Kommerziell', + 'institutionell' => 'Institutionell', + ])->required(), + CheckboxList::make('capabilities')->label('Fähigkeiten')->options(self::FAEHIGKEITEN)->required(), + ])->action(function (array $data): void { + $this->report(function () use ($data): void { + $capabilities = []; - foreach ($data['capabilities'] as $entry) { - [$class, $action] = explode(':', $entry, 2); - $capabilities[$class][] = $action; - } + foreach ($data['capabilities'] as $entry) { + [$class, $action] = explode(':', $entry, 2); + $capabilities[$class][] = $action; + } - app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities); - }, 'Das Rechteprofil ist angelegt.'); - }), + app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities); + }, 'Das Rechteprofil ist angelegt.'); + }), ]; } + + protected function catalogRows(): array + { + $rows = []; + + foreach (RightsProfile::query()->with('versions')->orderBy('name')->get() as $profile) { + $version = $profile->versions->sortByDesc('number')->first(); + $faehigkeiten = []; + + foreach ($version?->capabilities ?? [] as $class => $actions) { + foreach ((array) $actions as $action) { + $faehigkeiten[] = self::FAEHIGKEITEN[$class.':'.$action] ?? $class.': '.$action; + } + } + + $purpose = match ((string) $version?->purpose) { + 'ehrenamtlich' => 'Ehrenamtlich', + 'kommerziell' => 'Kommerziell', + 'institutionell' => 'Institutionell', + default => (string) $version?->purpose, + }; + $chips = $version === null + ? [['label' => 'Noch keine Fassung', 'ton' => 'offen']] + : [['label' => 'Fassung '.$version->number, 'ton' => 'neutral'], ['label' => $purpose, 'ton' => 'leise']]; + + if ($version?->locked_at !== null) { + $chips[] = ['label' => 'Festgeschrieben', 'ton' => 'leise']; + } + + $url = RightsProfileResource::getUrl('view', ['record' => $profile]); + $rows[] = [ + 'schluessel' => 'r'.$profile->id, + 'titel' => $profile->name, + 'meta' => 'Rechteprofil', + 'text' => $faehigkeiten === [] ? 'Keine Fähigkeiten' : implode(', ', $faehigkeiten), + 'symbol' => 'schluessel', + 'url' => $url, + 'chips' => $chips, + 'zustand' => [(string) $version?->purpose], + 'aktionen' => [['label' => 'Öffnen', 'href' => $url]], + ]; + } + + return $rows; + } + + protected function zustandOptionen(): array + { + return ['alle' => 'Jeder Zweck', 'ehrenamtlich' => 'Ehrenamtlich', 'kommerziell' => 'Kommerziell', 'institutionell' => 'Institutionell']; + } + + protected function einheit(): array + { + return ['Rechteprofil', 'Rechteprofile']; + } + + protected function leer(): array + { + return ['titel' => 'Noch keine Rechteprofile', 'text' => 'Mit „Rechteprofil anlegen“ oben entsteht das erste Profil.']; + } } diff --git a/app/Filament/Support/ListsCatalog.php b/app/Filament/Support/ListsCatalog.php new file mode 100644 index 0000000..52f5fd8 --- /dev/null +++ b/app/Filament/Support/ListsCatalog.php @@ -0,0 +1,90 @@ +> + */ + abstract protected function catalogRows(): array; + + /** + * @return array Zustandsschlüssel => Bezeichnung, beginnend mit 'alle' + */ + abstract protected function zustandOptionen(): array; + + /** + * @return array{0: string, 1: string} + */ + abstract protected function einheit(): array; + + /** + * @return array{titel: string, text: string} + */ + abstract protected function leer(): array; + + protected function suchPlatzhalter(): string + { + return 'Name oder Beschreibung'; + } + + public function getMaxContentWidth(): Width|string|null + { + return Width::Full; + } + + public function content(Schema $schema): Schema + { + return $schema->components([View::make('filament.verwaltung.bestand')]); + } + + public function resetFilters(): void + { + $this->suche = ''; + $this->zustand = 'alle'; + $this->bestandGrenze = Bestand::SCHRITT; + } + + /** + * @return array + */ + public function bestand(): array + { + $needle = mb_strtolower(trim($this->suche)); + $rows = array_values(array_filter($this->catalogRows(), function (array $row) use ($needle): bool { + if ($this->zustand !== 'alle' && ! in_array($this->zustand, $row['zustand'] ?? [], true)) { + return false; + } + + return $needle === '' || str_contains(mb_strtolower(implode(' ', array_filter([ + $row['titel'], $row['meta'] ?? '', $row['text'] ?? '', $row['suchtext'] ?? '', + ]))), $needle); + })); + + return [ + 'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => $this->suchPlatzhalter()], + 'filter' => [['eigenschaft' => 'zustand', 'label' => 'Zustand', 'vorgabe' => 'alle', 'optionen' => $this->zustandOptionen()]], + 'zeilen' => $rows, + 'einheit' => $this->einheit(), + 'leer' => $this->leer(), + ]; + } +} diff --git a/resources/views/filament/catalog/angebot.blade.php b/resources/views/filament/catalog/angebot.blade.php new file mode 100644 index 0000000..2234c20 --- /dev/null +++ b/resources/views/filament/catalog/angebot.blade.php @@ -0,0 +1,67 @@ +{{-- Angebot im gemeinsamen Rahmen: Kopf, aktive Fassung (Positionen, Leistungsumfang), Fassungsverlauf. --}} +@php + $kopfStatus = $active !== null + ? ['text' => 'Fassung '.$active->number.' aktiv · '.$vergabe, 'ton' => 'gut'] + : ['text' => 'Noch keine aktive Fassung. Ein Angebot ohne aktive Fassung kann niemand erwerben.', 'ton' => 'offen']; + $aktionen = [[ + 'label' => $active !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren', + 'wire' => "mountAction('activate')", + 'art' => 'primary', + ]]; +@endphp +
+ @include('filament.verwaltung.kopf', [ + 'brot' => [['label' => 'Angebote', 'href' => \App\Filament\Resources\Offers\OfferResource::getUrl('index')], $offer->name], + 'titel' => $offer->name, + 'typ' => 'Angebot', + 'status' => $kopfStatus, + 'aktionen' => $aktionen, + ]) + +
+
+

Positionen @if ($active)· Fassung {{ $active->number }}@endif

+ @if ($active === null) +
+ Noch keine Positionen +

Mit „Fassung aktivieren“ legst du fest, welche Lizenzartikel oder Paketfassungen mit welchem Rechteprofil angeboten werden, wie vergeben wird und zu welchem Preis.

+
+ @else +

Vergabe: {{ $vergabe }}. Diese Fassung ist unveränderlich; eine Änderung aktiviert die nächste Fassung.

+
    + @foreach ($active->lines->sortBy('position') as $line) +
  • + {{ $line->article !== null ? 'Lizenzartikel '.$line->article->code : 'Paket '.($line->bundleVersion?->bundle?->name ?? '–').' · Fassung '.($line->bundleVersion?->number ?? '–') }} + Rechte: {{ $line->rights?->profile?->name ?? '–' }} +
  • + @endforeach +
+

Aufgelöster Leistungsumfang

+

Diese Artikel-Rechte entstehen beim Erwerb dieser Fassung.

+
    + @foreach ($grants as $grant) +
  • {{ $grant }}
  • + @endforeach +
+ @endif +
+ + +
+
diff --git a/resources/views/filament/editorial/catalog-card.blade.php b/resources/views/filament/editorial/catalog-card.blade.php deleted file mode 100644 index 8884097..0000000 --- a/resources/views/filament/editorial/catalog-card.blade.php +++ /dev/null @@ -1,29 +0,0 @@ -@php - $summary = \Illuminate\Support\Str::limit(trim((string) ($card['summary'] ?? '')), 160); -@endphp - - - @if (! empty($card['image'])) - - @else - - Kein Titelbild - @endif - @if (! empty($card['image_note'])) - {{ $card['image_note'] }} - @endif - - - {{ $card['kind'] }} - {{ $card['title'] }} - {{ $summary !== '' ? $summary : 'Noch keine Kurzbeschreibung' }} - - @foreach ($card['chips'] as $chip) - {{ $chip['label'] }} - @endforeach - - - diff --git a/resources/views/filament/verwaltung/icon.blade.php b/resources/views/filament/verwaltung/icon.blade.php index 263753c..4cc72a8 100644 --- a/resources/views/filament/verwaltung/icon.blade.php +++ b/resources/views/filament/verwaltung/icon.blade.php @@ -20,6 +20,8 @@ 'audio' => '', 'extern' => '', 'modul' => '', + 'schluessel' => '', + 'etikett' => '', 'filter' => '', 'zuruecksetzen' => '', ]; diff --git a/tests/Feature/BestandslisteTest.php b/tests/Feature/BestandslisteTest.php index faf144c..08e2c45 100644 --- a/tests/Feature/BestandslisteTest.php +++ b/tests/Feature/BestandslisteTest.php @@ -2,14 +2,25 @@ namespace Tests\Feature; +use App\Domain\Catalog\ArticleService; +use App\Domain\Catalog\BundleService; use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\ContentService; +use App\Domain\Catalog\LicenseArticle; +use App\Domain\Catalog\OfferService; use App\Filament\Pages\EditorialDesk; +use App\Filament\Resources\Bundles\Pages\ListBundles; use App\Filament\Resources\ContentElements\Pages\ListContentElements; use App\Filament\Resources\Courses\Pages\ListCourses; use App\Filament\Resources\Exercises\ExerciseResource; use App\Filament\Resources\Exercises\Pages\ListExercises; +use App\Filament\Resources\LicenseArticles\LicenseArticleResource; +use App\Filament\Resources\LicenseArticles\Pages\ListLicenseArticles; +use App\Filament\Resources\Offers\OfferResource; +use App\Filament\Resources\Offers\Pages\ListOffers; +use App\Filament\Resources\Offers\Pages\ViewOffer; +use App\Filament\Resources\RightsProfiles\Pages\ListRightsProfiles; use App\Filament\Support\Bestand; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -140,6 +151,129 @@ public function test_only_editors_reach_the_composition_lists(): void $this->actingAs($keeper, 'staff')->get(EditorialDesk::getUrl())->assertForbidden(); } + public function test_catalog_lists_show_readable_states_and_filter_them(): void + { + $content = app(ContentService::class); + $articles = app(ArticleService::class); + $offers = app(OfferService::class); + $sheet = $content->publishElementVersion($content->createElement('pdf', 'pdf', 'Merkblatt Alltag'), 'Hinweis'); + $released = $articles->create('demo-merkblatt', 'Erprobung'); + $articles->publishRelease($released, $sheet, 'Eigenständiges Merkblatt.'); + $articles->create('demo-leer', 'Erprobung'); + $bundle = app(BundleService::class)->create('Demo Basis'); + app(BundleService::class)->publish($bundle, [$released->fresh()]); + $rights = $offers->createRightsProfile('Erprobung lesen', 'ehrenamtlich', ['pdf' => ['ansehen', 'laden']]); + $offer = $offers->create('Kostenloses Merkblatt'); + $offers->activate($offer, [['target' => $released->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']); + $offers->create('Noch leer'); + $keeper = $this->keeper(); + + Livewire::actingAs($keeper, 'staff') + ->test(ListLicenseArticles::class) + ->assertSee('demo-merkblatt') + ->assertSee('Stand 1 veröffentlicht') + ->assertSee('In einem aktiven Angebot') + ->assertSee('Noch kein Stand') + ->assertSeeHtml('wire:partial="action-modals"') + ->set('zustand', 'ohne') + ->assertSee('Zustand: Noch ohne Stand') + ->assertSee('demo-leer') + ->assertDontSee('demo-merkblatt') + ->set('suche', 'merkblatt') + ->assertSee('Nichts gefunden'); + + Livewire::actingAs($keeper, 'staff') + ->test(ListOffers::class) + ->assertSee('Fassung 1 aktiv') + ->assertSee('Auf Abruf') + ->assertSee('Lizenzartikel demo-merkblatt · Erprobung lesen') + ->assertSee('Keine aktive Fassung') + ->assertDontSee('>aktiv<', false); + + Livewire::actingAs($keeper, 'staff') + ->test(ListBundles::class) + ->assertSee('Demo Basis') + ->assertSee('Fassung 1 veröffentlicht') + ->assertSee('1 Bestandteil'); + + Livewire::actingAs($keeper, 'staff') + ->test(ListRightsProfiles::class) + ->assertSee('Erprobung lesen') + ->assertSee('PDF ansehen, PDF herunterladen') + ->assertSee('Ehrenamtlich'); + } + + public function test_creating_a_catalog_object_opens_it_and_editors_without_the_keeper_role_stay_out(): void + { + $keeper = $this->keeper(); + + Livewire::actingAs($keeper, 'staff') + ->test(ListLicenseArticles::class) + ->callAction('create', ['code' => 'neuer-artikel', 'product_line' => 'Erprobung']) + ->assertRedirect(LicenseArticleResource::getUrl('view', ['record' => LicenseArticle::query()->where('code', 'neuer-artikel')->firstOrFail()])); + + Livewire::actingAs($keeper, 'staff') + ->test(ListOffers::class) + ->callAction('create', ['name' => 'Neues Angebot']) + ->assertRedirectContains('/verwaltung/offers/'); + + $this->actingAs($this->editor(), 'staff')->get(OfferResource::getUrl('index'))->assertForbidden(); + $this->actingAs($this->editor(), 'staff')->get(LicenseArticleResource::getUrl('index'))->assertForbidden(); + } + + public function test_one_offer_mask_activates_the_first_version_and_is_prefilled_for_a_change(): void + { + $content = app(ContentService::class); + $articles = app(ArticleService::class); + $offers = app(OfferService::class); + $sheet = $content->publishElementVersion($content->createElement('pdf', 'pdf', 'Merkblatt'), 'Hinweis'); + $article = $articles->create('demo-merkblatt', 'Erprobung'); + $articles->publishRelease($article, $sheet, 'Eigenständig.'); + $rights = $offers->createRightsProfile('Lesen', 'ehrenamtlich', ['pdf' => ['ansehen']]); + $offer = $offers->create('Merkblatt kostenlos'); + $keeper = $this->keeper(); + + $component = Livewire::actingAs($keeper, 'staff') + ->test(ViewOffer::class, ['record' => $offer->getKey()]) + ->assertSee('Noch keine aktive Fassung') + ->assertSee('Fassung aktivieren') + ->mountAction('activate'); + $this->assertSame('Erste Fassung aktivieren', $component->instance()->getMountedAction()->getModalHeading()); + $component + ->fillForm(['grant_kind' => 'auf_abruf', 'lines' => [['kind' => 'article', 'article_id' => $article->id, 'rights_id' => $rights->id]]]) + ->callMountedAction() + ->assertHasNoFormErrors() + ->assertSee('Fassung 1 aktiv · Auf Abruf') + ->assertSee('Lizenzartikel demo-merkblatt'); + + $component = Livewire::actingAs($keeper, 'staff') + ->test(ViewOffer::class, ['record' => $offer->getKey()]) + ->assertSee('Geänderte Fassung aktivieren') + ->mountAction('activate'); + $this->assertSame('Angebot ändern: Fassung 2 aktivieren', $component->instance()->getMountedAction()->getModalHeading()); + $data = $component->get('mountedActions.0.data'); + $this->assertSame('auf_abruf', $data['grant_kind']); + $this->assertSame((string) $article->id, (string) array_values($data['lines'])[0]['article_id']); + $this->assertSame((string) $rights->id, (string) array_values($data['lines'])[0]['rights_id']); + + $component->fillForm(['grant_kind' => 'kauf', 'price_cents' => 500]) + ->callMountedAction() + ->assertHasNoFormErrors() + ->assertSee('Fassung 2 aktiv · Kauf · 5,00 €') + ->assertSee('Beendet'); + + $statuses = $offer->versions()->orderBy('number')->pluck('status')->map(fn ($status) => $status instanceof \BackedEnum ? $status->value : $status)->all(); + $this->assertSame(['beendet', 'aktiv'], $statuses); + } + + private function keeper(): User + { + $keeper = User::factory()->katalogverwalter()->create(); + $keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + return $keeper; + } + private function editor(): User { $editor = User::factory()->redakteur()->create();