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>
This commit is contained in:
1 parent
532979aa86
commit
660b50f418
10 files changed
+828
-80
No files matched your search
@@ -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<string, mixed>
|
||||
*/
|
||||
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<string, mixed>
|
||||
*/
|
||||
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, ',', '.').' €';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user