Files
laraundfelix/app/Filament/Resources/Offers/Pages/ViewOffer.php
T
LarsandCursor d6ff881e4e
Deploy Test / test (push) Successful in 18s
Deploy Test / deploy (push) Successful in 22s
Mache die Inhaltsverwaltung fuer die Redaktion bedienbar
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:59:30 +01:00

90 lines
4.4 KiB
PHP

<?php
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\BundleVersion;
use App\Domain\Catalog\CompositionVersion;
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 €.'),
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();
}),
];
}
}