Zeige im Katalog, wie Inhalte, Pakete und Rechte zusammenhängen.
Deploy Test / test (push) Successful in 13s
Deploy Test / deploy (push) Successful in 23s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-15 10:03:19 +01:00
1 parent fa706e5080
commit cd79fb99d7
22 files changed
+1066 -200

No files matched your search

@@ -5,10 +5,16 @@
use App\Domain\Catalog\Offer;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Resources\Offers\Pages\ListOffers;
use App\Filament\Resources\Offers\Pages\ViewOffer;
use App\Filament\Support\CatalogReading;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Auth\Access\Response;
use Illuminate\Database\Eloquent\Model;
class OfferResource extends Resource
{
@@ -24,11 +30,32 @@ class OfferResource extends Resource
protected static ?string $recordTitleAttribute = 'name';
protected static ?int $navigationSort = 4;
public static function canViewAny(): bool
{
return LicenseArticleResource::keeper();
}
public static function getViewAuthorizationResponse(Model $record): Response
{
return LicenseArticleResource::keeper() ? Response::allow() : Response::deny();
}
public static function infolist(Schema $schema): Schema
{
return $schema->components([
Section::make('Positionen')->description('Was angeboten wird, mit welchem Rechteprofil.')->schema([
TextEntry::make('positions')->hiddenLabel()->listWithLineBreaks()
->state(fn (Offer $record): array => app(CatalogReading::class)->offerPositions($record)),
]),
Section::make('Aufgelöste Berechtigungen')->description('Diese Artikel-Rechte entstehen beim Erwerb.')->schema([
TextEntry::make('grants')->hiddenLabel()->listWithLineBreaks()
->state(fn (Offer $record): array => app(CatalogReading::class)->offerGrants($record)),
]),
]);
}
public static function form(Schema $schema): Schema
{
return $schema;
@@ -39,13 +66,14 @@ public static function table(Table $table): Table
return $table->columns([
TextColumn::make('name')->label('Name')->searchable(),
TextColumn::make('versions.status')->label('Fassungen')->badge(),
])->recordUrl(null);
]);
}
public static function getPages(): array
{
return [
'index' => ListOffers::route('/'),
'view' => ViewOffer::route('/{record}'),
];
}
}
@@ -2,20 +2,13 @@
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\BundleVersion;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\RightsProfileVersion;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Filament\Schemas\Components\Utilities\Get;
use Illuminate\Contracts\Support\Htmlable;
class ListOffers extends ListRecords
{
@@ -23,6 +16,11 @@ class ListOffers extends ListRecords
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 [
@@ -33,46 +31,6 @@ protected function getHeaderActions(): array
app(OfferService::class)->create($data['name']);
}, 'Das Angebot ist angelegt.');
}),
Action::make('activate')->label('Fassung aktivieren')->schema([
Select::make('offer_id')->label('Angebot')->options(fn (): array => CatalogOptions::offers())->required(),
Select::make('grant_kind')->label('Vergabe')->options([
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
])->required(),
TextInput::make('price_cents')->label('Preis in Cent')->numeric(),
Repeater::make('lines')->label('Positionen')->schema([
Select::make('kind')->label('Ziel')->options([
'article' => 'Lizenzartikel',
'bundle' => 'Paketfassung',
])->required()->live(),
Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles())
->visible(fn (Get $get): bool => $get('kind') === 'article'),
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 {
$lines = [];
foreach ($data['lines'] as $line) {
$target = $line['kind'] === 'bundle'
? BundleVersion::query()->findOrFail($line['bundle_version_id'])
: LicenseArticle::query()->findOrFail($line['article_id']);
$lines[] = [
'target' => $target,
'rights' => RightsProfileVersion::query()->findOrFail($line['rights_id']),
];
}
app(OfferService::class)->activate(Offer::query()->findOrFail($data['offer_id']), $lines, [
'grant_kind' => $data['grant_kind'],
'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'],
'holder_kind' => 'person',
]);
}, 'Die Angebotsfassung ist aktiv.');
}),
];
}
}
@@ -0,0 +1,75 @@
<?php
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\BundleVersion;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\RightsProfileVersion;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\Utilities\Get;
class ViewOffer extends ViewRecord
{
use ReportsDomainRules;
protected static string $resource = OfferResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('activate')->label('Fassung aktivieren')->schema([
Select::make('grant_kind')->label('Vergabe')->options([
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
])->required(),
TextInput::make('price_cents')->label('Preis in Cent')->numeric()
->helperText('Nur bei einem Kauf. 500 bedeutet 5,00 €.'),
Repeater::make('lines')->label('Positionen')->schema([
Select::make('kind')->label('Ziel')->options([
'article' => 'Lizenzartikel',
'bundle' => 'Paketfassung',
])->required()->live(),
Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles())
->visible(fn (Get $get): bool => $get('kind') === 'article'),
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 {
/** @var Offer $offer */
$offer = $this->getRecord();
$lines = [];
foreach ($data['lines'] as $line) {
$target = $line['kind'] === 'bundle'
? BundleVersion::query()->findOrFail($line['bundle_version_id'])
: LicenseArticle::query()->findOrFail($line['article_id']);
$lines[] = [
'target' => $target,
'rights' => RightsProfileVersion::query()->findOrFail($line['rights_id']),
];
}
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',
]);
}, 'Die Angebotsfassung ist aktiv.');
$this->getRecord()->unsetRelations();
$this->getRecord()->refresh();
}),
];
}
}