Ein eigenständig vermarktetes Paket (offers.standalone_bundle) erhält /pakete/{id}
mit seinem tatsächlichen Umfang, Shop-Kachel und Suche. Die Angebotsmaske kennt
Nutzerkreis und Anzahl Trainer. Zwei Bestandstests (CartTest, Vergleich der
Rechte und Erwerbsarten) legen die Vergleichsangebote jetzt als Einzellizenz an,
weil der Nutzerkreis zum identischen Umfang gehört; ihre Aussagen bleiben.
Eine Rechnungs- oder Stripe-Bestellung lässt sich nicht mit der Testzahlung bestätigen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
461 lines
25 KiB
PHP
461 lines
25 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Offers\Pages;
|
||
|
||
use App\Domain\Catalog\BundleService;
|
||
use App\Domain\Catalog\BundleVersion;
|
||
use App\Domain\Catalog\Composition;
|
||
use App\Domain\Catalog\CompositionVersion;
|
||
use App\Domain\Catalog\DomainRuleException;
|
||
use App\Domain\Catalog\LicenceScope;
|
||
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\Domain\Cms\Catalog\PublicCatalogReader;
|
||
use App\Domain\Commerce\Money;
|
||
use App\Domain\Commerce\ProductOptions;
|
||
use App\Filament\Resources\Offers\OfferResource;
|
||
use App\Filament\Support\CatalogLabels;
|
||
use App\Filament\Support\CatalogOptions;
|
||
use App\Filament\Support\PublicationReadiness;
|
||
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;
|
||
use Filament\Schemas\Components\View;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Support\Enums\Width;
|
||
use Illuminate\Contracts\Support\Htmlable;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
/**
|
||
* 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;
|
||
|
||
/** Wert der Auswahl „Produktseite“ für ein Paket mit eigener Seite. */
|
||
private const OWN_BUNDLE_PAGE = '__paket';
|
||
|
||
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 [];
|
||
}
|
||
|
||
/**
|
||
* Der gemeinsame Objektkopf zeigt den Pfad; Filaments eigener Pfad entfällt wie bei Medien und Aufbau.
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public function getBreadcrumbs(): array
|
||
{
|
||
return [];
|
||
}
|
||
|
||
public function infolist(Schema $schema): Schema
|
||
{
|
||
return $schema->components([
|
||
View::make('filament.catalog.objekt')->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
|
||
? 'Option „'.$this->getRecord()->optionName().'“ ändern: Fassung '.$this->nextNumber().' aktivieren'
|
||
: 'Option „'.$this->getRecord()->optionName().'“: erste Fassung aktivieren')
|
||
->modalDescription(fn (): string => ($active = $this->activeVersion()) !== null
|
||
? 'Betroffen ist nur die Option „'.$this->getRecord()->optionName().'“'.$this->productPageSuffix().'. Die Maske ist mit Fassung '.$active->number.' vorbelegt. Erst „Fassung '.$this->nextNumber().' aktivieren“ schaltet die Änderung öffentlich (auch Bezeichnung und Produktseite, sie erzeugen ebenfalls eine neue Fassung und zeigen offenen Warenkörben „Bedingungen aktualisiert“): Fassung '.$active->number.' wird beendet und bleibt gespeichert, neue Käufe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen und Bestellungen ändern sich nicht. Andere Optionen derselben Produktseite bleiben unverändert kaufbar. „Abbrechen“ verwirft die Eingaben.'
|
||
: 'Positionen, Vergabe, Eignung und Preis bilden die erste Fassung dieser Option. Erst das Aktivieren macht sie öffentlich; danach ist sie unveränderlich, Änderungen ergeben eine weitere Fassung.')
|
||
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' aktivieren')
|
||
->modalWidth('4xl')
|
||
->fillForm(fn (): array => $this->formFromActive())
|
||
->schema([
|
||
TextInput::make('option_label')->label('Bezeichnung der Option')
|
||
->helperText('So heißt die Option auf der Produktseite, zum Beispiel „Einzellizenz für Privatpersonen“. Sie ist keine bindende Bedingung, wird aber wie die übrigen Angaben erst mit „Fassung aktivieren“ übernommen.')
|
||
->maxLength(120),
|
||
Select::make('composition_id')->label('Produktseite')
|
||
->options(fn (): array => $this->productPages())
|
||
->searchable()
|
||
->helperText('Optionen derselben Produktseite sind Alternativen; im Warenkorb liegt nur eine davon. Die Beschreibung der Seite wird zentral an der Komposition gepflegt. Die Zuordnung wird mit „Fassung aktivieren“ übernommen.'),
|
||
Select::make('holder_kind')->label('Geeignet für')->options([
|
||
'person' => 'Privatpersonen',
|
||
'organisation' => 'Organisationen und Vereine',
|
||
])->required()
|
||
->helperText('Wähle die Eignung passend zu den Rechten: Organisationslizenzen brauchen institutionelle Rechte. Das System erzwingt diese Kopplung nicht.'),
|
||
Select::make('licence_scope')->label('Nutzerkreis')
|
||
->options(LicenceScope::options())
|
||
->required()
|
||
->live()
|
||
->helperText('Wie viele Trainer die Inhalte einsetzen dürfen. Das ist unabhängig vom Lizenzinhaber (Person oder Verein), vom Nutzungszweck der Rechte und vom Preis; es wird aus keinem davon abgeleitet. Der Download bleibt zum Start beim bestellenden Konto. Der Wert wird mit der Bestellung festgehalten.'),
|
||
TextInput::make('trainer_count')->label('Anzahl Trainer')
|
||
->numeric()->minValue(2)->maxValue(LicenceScope::MAX_TRAINERS)->integer()
|
||
->required(fn (Get $get): bool => $get('licence_scope') === LicenceScope::MULTI)
|
||
->visible(fn (Get $get): bool => $get('licence_scope') === LicenceScope::MULTI)
|
||
->helperText('Höchstzahl der Trainer, die die Inhalte einsetzen dürfen, mindestens 2. Eine Einzellizenz gilt immer für genau einen Trainer.'),
|
||
Select::make('grant_kind')->label('Vergabe')->options([
|
||
'kauf' => 'Kauf',
|
||
'auf_abruf' => 'Auf Abruf',
|
||
'bei_registrierung' => 'Bei Registrierung',
|
||
])->required(),
|
||
TextInput::make('price_euro')->label('Preis in Euro')->suffix('€')
|
||
->helperText('Nur bei einem Kauf, zum Beispiel 49,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 => app(PublicationReadiness::class)->articleOptions())
|
||
->searchable()
|
||
->helperText('Nur Artikel mit veröffentlichtem Stand lassen sich verkaufen. Artikel ohne Stand sind gekennzeichnet.')
|
||
->visible(fn (Get $get): bool => $get('kind') === 'article'),
|
||
Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => app(PublicationReadiness::class)->bundleVersionOptions())
|
||
->searchable()
|
||
->visible(fn (Get $get): bool => $get('kind') === 'bundle'),
|
||
Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(),
|
||
])->minItems(1)->addActionLabel('Position hinzufügen'),
|
||
])
|
||
->action(function (array $data): void {
|
||
$this->report(function () use ($data): string {
|
||
/** @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']),
|
||
];
|
||
}
|
||
|
||
// Voraussetzung: Jeder Artikel der Positionen hat einen veröffentlichten Stand, sonst erhielten Käufer nichts.
|
||
$articleIds = [];
|
||
|
||
foreach ($lines as $line) {
|
||
$target = $line['target'];
|
||
array_push($articleIds, ...($target instanceof BundleVersion ? app(BundleService::class)->articleIds($target) : [$target->id]));
|
||
}
|
||
|
||
$unusable = app(PublicationReadiness::class)->unusableArticles($articleIds);
|
||
|
||
if ($unusable !== []) {
|
||
throw new DomainRuleException(app(PublicationReadiness::class)->unusableMessage($unusable, 'das Angebot aktivierst'));
|
||
}
|
||
|
||
// Bedingungen, die die Maske nicht zeigt, bleiben bei einer Änderung die der aktiven Fassung.
|
||
$active = $this->activeVersion();
|
||
$kept = $active === null ? [] : [
|
||
'term_rule' => $active->term_rule,
|
||
'tax_class' => $active->tax_class,
|
||
'dynamic' => (bool) $active->dynamic,
|
||
];
|
||
$price = Money::parse($data['price_euro'] ?? null);
|
||
|
||
if ($data['grant_kind'] === 'kauf' && ($price === null || $price <= 0)) {
|
||
throw new DomainRuleException('Ein Kauf braucht einen Preis über 0,00 €.');
|
||
}
|
||
|
||
$service = app(OfferService::class);
|
||
$version = DB::transaction(function () use ($service, $offer, $data, $lines, $kept, $price) {
|
||
$service->assignProduct(
|
||
$offer,
|
||
filled($data['composition_id'] ?? null) && $data['composition_id'] !== self::OWN_BUNDLE_PAGE ? (int) $data['composition_id'] : null,
|
||
$data['option_label'] ?? null,
|
||
($data['composition_id'] ?? null) === self::OWN_BUNDLE_PAGE,
|
||
);
|
||
|
||
return $service->activate($offer, $lines, [
|
||
...$kept,
|
||
'holder_kind' => $data['holder_kind'],
|
||
'licence_scope' => $data['licence_scope'] ?? null,
|
||
'trainer_count' => $data['trainer_count'] ?? null,
|
||
'grant_kind' => $data['grant_kind'],
|
||
'price_cents' => $price,
|
||
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
|
||
]);
|
||
});
|
||
|
||
$offer->unsetRelations();
|
||
$readiness = app(PublicationReadiness::class)->forOffer($offer->refresh());
|
||
|
||
return 'Fassung '.$version->number.' ist aktiv.'.($readiness['bereit']
|
||
? ' Die Option ist öffentlich kaufbar und im Shop auffindbar.'
|
||
: ' Noch nicht im Shop kaufbar. Nächster Schritt: '.$readiness['naechster']['titel'].'.');
|
||
}, 'Die Angebotsfassung ist aktiv.');
|
||
$this->getRecord()->unsetRelations();
|
||
$this->getRecord()->refresh();
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Option aus dem Verkauf nehmen: nur die aktive Fassung dieser Option wird beendet.
|
||
*/
|
||
public function endAction(): Action
|
||
{
|
||
return Action::make('end')
|
||
->label('Aus dem Verkauf nehmen')
|
||
->color('danger')
|
||
->requiresConfirmation()
|
||
->modalHeading(fn (): string => 'Option „'.$this->getRecord()->optionName().'“ aus dem Verkauf nehmen?')
|
||
->modalDescription(fn (): string => 'Betroffen ist nur die Option „'.$this->getRecord()->optionName().'“'.$this->productPageSuffix().'. Die aktive Fassung wird beendet und bleibt gespeichert. Die Option ist danach nicht mehr kaufbar; in vorhandenen Warenkörben bleibt sie mit Hinweis sichtbar und blockiert den Abschluss, bis der Käufer sie entfernt. Bestehende Berechtigungen und Bestellungen ändern sich nicht. Andere Optionen derselben Produktseite bleiben kaufbar.')
|
||
->modalSubmitActionLabel('Aus dem Verkauf nehmen')
|
||
->visible(fn (): bool => $this->activeVersion() !== null)
|
||
->action(function (): void {
|
||
$this->report(function (): string {
|
||
$version = app(OfferService::class)->end($this->getRecord());
|
||
|
||
return 'Fassung '.$version->number.' ist beendet. Die Option ist nicht mehr kaufbar.';
|
||
}, 'Die Option ist aus dem Verkauf genommen.');
|
||
$this->getRecord()->unsetRelations();
|
||
$this->getRecord()->refresh();
|
||
});
|
||
}
|
||
|
||
/** „ der Produktseite „Titel““ oder leer, wenn die Option noch keiner Produktseite zugeordnet ist. */
|
||
private function productPageSuffix(): string
|
||
{
|
||
$page = $this->getRecord()->composition;
|
||
|
||
return $page === null ? '' : ' der Produktseite „'.($page->display_title ?: $page->designation).'“';
|
||
}
|
||
|
||
/**
|
||
* Produktseiten, die als Ziel wählbar sind: Kompositionen mit Bezeichnung und Art.
|
||
*
|
||
* @return array<int, string>
|
||
*/
|
||
private function productPages(): array
|
||
{
|
||
$catalog = app(PublicCatalogReader::class);
|
||
|
||
return [self::OWN_BUNDLE_PAGE => 'Eigene Paketseite · zeigt den Umfang des Pakets (nur für ein Angebot aus genau einer Paketfassung)'] + Composition::query()
|
||
->with('editorialContentKind')
|
||
->whereNull('archived_at')
|
||
->orderBy('designation')
|
||
->get()
|
||
->sortBy(fn (Composition $composition): int => $catalog->shownVersion($composition) !== null ? 0 : 1)
|
||
->mapWithKeys(fn (Composition $composition): array => [
|
||
$composition->id => ($composition->display_title ?: $composition->designation)
|
||
.' ('.($composition->editorialContentKind?->label ?? 'Zusammenstellung').')'
|
||
.($catalog->shownVersion($composition) !== null ? ' · im Shop auffindbar' : ' · nicht öffentlich, im Shop nicht auffindbar'),
|
||
])
|
||
->all();
|
||
}
|
||
|
||
/**
|
||
* Vorbelegung aus der aktiven Fassung; ohne aktive Fassung eine leere Position.
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
private function formFromActive(): array
|
||
{
|
||
$active = $this->activeVersion();
|
||
/** @var Offer $offer */
|
||
$offer = $this->getRecord();
|
||
$option = ['option_label' => $offer->option_label, 'composition_id' => $offer->standalone_bundle ? self::OWN_BUNDLE_PAGE : $offer->composition_id];
|
||
|
||
if ($active === null) {
|
||
return [...$option, 'holder_kind' => 'person', 'licence_scope' => LicenceScope::SINGLE, 'grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
|
||
}
|
||
|
||
return [
|
||
...$option,
|
||
'holder_kind' => $active->holder_kind,
|
||
'licence_scope' => $active->licence_scope,
|
||
'trainer_count' => $active->trainer_count,
|
||
'grant_kind' => $active->grant_kind,
|
||
'price_euro' => $active->price_cents === null ? null : number_format($active->price_cents / 100, 2, ',', ''),
|
||
'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;
|
||
}
|
||
|
||
/**
|
||
* Daten der gemeinsamen Katalog-Objektseite.
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
private function angebotDaten(): array
|
||
{
|
||
/** @var Offer $offer */
|
||
$offer = $this->getRecord();
|
||
$active = $this->activeVersion();
|
||
$vergabe = $active !== null ? CatalogLabels::vergabe($active) : null;
|
||
|
||
return [
|
||
'kopf' => [
|
||
'brot' => [['label' => 'Angebote', 'href' => OfferResource::getUrl('index')], $offer->name],
|
||
'titel' => $offer->name,
|
||
'typ' => 'Angebot',
|
||
'status' => $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',
|
||
],
|
||
...($active !== null ? [[
|
||
'label' => 'Aus dem Verkauf nehmen',
|
||
'wire' => "mountAction('end')",
|
||
'art' => 'line',
|
||
]] : []),
|
||
],
|
||
],
|
||
'voraussetzungen' => app(PublicationReadiness::class)->forOffer($offer),
|
||
'haupt' => [
|
||
...($active !== null ? [$this->optionAbschnitt($offer, $active)] : []),
|
||
[
|
||
'titel' => 'Positionen',
|
||
'zusatz' => $active !== null ? 'Fassung '.$active->number : null,
|
||
'hilfe' => $active !== null ? 'Vergabe: '.$vergabe.'. Diese Fassung ist unveränderlich; eine Änderung aktiviert die nächste Fassung.' : null,
|
||
'zeilen' => $active === null ? [] : $active->lines->sortBy('position')->map(fn ($line): array => [
|
||
'text' => $line->article !== null ? 'Lizenzartikel '.$line->article->code : 'Paket '.($line->bundleVersion?->bundle?->name ?? '–').' · Fassung '.($line->bundleVersion?->number ?? '–'),
|
||
'neben' => 'Rechte: '.($line->rights?->profile?->name ?? '–'),
|
||
])->values()->all(),
|
||
'leer' => ['titel' => 'Noch keine Positionen', 'text' => 'Mit „Fassung aktivieren“ legst du fest, welche Lizenzartikel oder Paketfassungen mit welchem Rechteprofil angeboten werden, wie vergeben wird und zu welchem Preis.'],
|
||
],
|
||
...($active !== null ? [[
|
||
'titel' => 'Aufgelöster Leistungsumfang',
|
||
'hilfe' => 'Diese Artikel-Rechte entstehen beim Erwerb dieser Fassung.',
|
||
'zeilen' => $this->leistungsumfang($active),
|
||
'leer' => ['titel' => 'Kein Leistungsumfang', 'text' => 'Diese Fassung hat keinen aufgelösten Leistungsumfang.'],
|
||
]] : []),
|
||
],
|
||
'seite' => [[
|
||
'titel' => 'Fassungen',
|
||
'zeilen' => $offer->versions()->orderByDesc('number')->get()->map(fn (OfferVersion $version): array => [
|
||
'text' => 'Fassung '.$version->number,
|
||
'zustand' => match (StatusValue::of($version->status)) {
|
||
'aktiv' => ['label' => 'Aktiv', 'ton' => 'gut'],
|
||
'beendet' => ['label' => 'Beendet', 'ton' => 'leise'],
|
||
default => ['label' => 'Entwurf', 'ton' => 'offen'],
|
||
},
|
||
'neben' => CatalogLabels::vergabe($version).($version->activated_at ? ' · aktiviert am '.$version->activated_at->format('d.m.Y') : ''),
|
||
])->all(),
|
||
'leer' => 'Noch keine Fassung.',
|
||
'hilfe' => 'Beendete Fassungen bleiben gespeichert; Erwerbe verweisen auf ihre Fassung. Ob ein Angebot künftig auch als Vorlage für ein weiteres dienen soll, ist fachlich noch offen (OFF-04).',
|
||
]],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Die Option auf einen Blick: Preis in Euro, Eignung, Rechte, zugrunde liegender Inhalt, Status und Produktseite.
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
private function optionAbschnitt(Offer $offer, OfferVersion $active): array
|
||
{
|
||
$option = app(ProductOptions::class)->describe($offer, $active);
|
||
$inhalt = collect($option['scope'])->pluck('article')->unique()->implode(', ');
|
||
$rechte = collect($option['scope'])
|
||
->map(fn (array $item): string => $item['purpose'].($item['rights'] === [] ? '' : ': '.implode(', ', $item['rights'])))
|
||
->unique()
|
||
->implode('; ');
|
||
$seite = $offer->composition;
|
||
$eigeneSeite = $offer->standalone_bundle;
|
||
$kaufbar = app(OfferService::class)->purchasableVersion($offer) !== null;
|
||
|
||
return [
|
||
'titel' => 'Die Option auf einen Blick',
|
||
'zusatz' => 'Fassung '.$active->number,
|
||
'hilfe' => 'So erscheint die Option auf der öffentlichen Produktseite und im Warenkorb. Die Angaben dieser Fassung sind unveränderlich.',
|
||
'zeilen' => [
|
||
['text' => 'Preis: '.$option['price'], 'neben' => $active->grant_kind === 'kauf' ? 'Kauf mit Testzahlung' : CatalogLabels::vergabe($active)],
|
||
['text' => 'Geeignet für: '.$option['for'], 'neben' => $option['term']],
|
||
['text' => 'Nutzerkreis: '.$option['licence'], 'neben' => $option['licence_scope'] === null ? 'Mit „Geänderte Fassung aktivieren“ festlegen.' : 'Lizenzinhaber, Nutzerkreis und Downloadkonto sind getrennte Angaben.'],
|
||
['text' => 'Rechte: '.($rechte !== '' ? $rechte : 'keine'), 'neben' => null],
|
||
['text' => 'Zugrunde liegender Inhalt: '.($inhalt !== '' ? $inhalt : '–'), 'neben' => null],
|
||
['text' => 'Status: '.($kaufbar ? 'Öffentlich kaufbar' : 'Nicht als Kauf angeboten'), 'neben' => $kaufbar ? 'Aktive Fassung '.$active->number : null],
|
||
['text' => 'Produktseite: '.($eigeneSeite ? 'eigene Paketseite mit dem Umfang des Pakets' : ($seite !== null ? ($seite->display_title ?: $seite->designation) : 'noch nicht zugeordnet')), 'neben' => $eigeneSeite || $seite !== null ? 'Option „'.$offer->optionName().'“' : 'Mit „Geänderte Fassung aktivieren“ zuordnen.'],
|
||
],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Aufgelöster Leistungsumfang in lesbaren Fähigkeiten (dieselben Bezeichnungen wie beim Rechteprofil).
|
||
*
|
||
* @return list<array{text: string, neben: string}>
|
||
*/
|
||
private function leistungsumfang(OfferVersion $version): array
|
||
{
|
||
$zeilen = [];
|
||
|
||
foreach ($version->resolvedScopes()->with(['article', 'rights.profile'])->get() as $scope) {
|
||
$faehigkeiten = CatalogLabels::faehigkeiten($scope->rights?->capabilities);
|
||
$zeilen[] = [
|
||
'text' => 'Lizenzartikel '.$scope->article?->code,
|
||
'neben' => ($scope->rights?->profile?->name ?? '–').': '.($faehigkeiten === [] ? 'keine Fähigkeiten' : implode(', ', $faehigkeiten)),
|
||
];
|
||
}
|
||
|
||
return $zeilen;
|
||
}
|
||
}
|