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 €.'), Select::make('composition_version_id')->label('Programmfassung, die abgedeckt sein muss') ->options(function (): array { return CompositionVersion::query() ->where('status', 'bereit') ->with('composition.editorialContentKind') ->orderByDesc('id') ->get() ->mapWithKeys(fn (CompositionVersion $version): array => [$version->id => CatalogOptions::compositionLabel($version)]) ->all(); }) ->searchable() ->helperText('Wenn gewählt, lässt sich die Fassung nur aktivieren, wenn jeder Bestandteil in den Artikeln enthalten ist.'), 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', 'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null, ]); }, 'Die Angebotsfassung ist aktiv.'); $this->getRecord()->unsetRelations(); $this->getRecord()->refresh(); }), ]; } }