Fuehre Regeln fuer freie Artikel und Fuer dich im Mitgliederbereich ein
- Regel je Angebot auf Abruf: alle Mitglieder, nur freigeschaltete Konten, wer einen Artikel besitzt - Freigaben je Angebot und Konto (offer_releases), nie geloescht, nur entzogen; Pflege im Angebot - Pruefung serverseitig in GrantIssuer::claim; Angebote bei Registrierung bleiben regelfrei - Mitgliederseite Angebote: Neu fuer dich (neue Staende besessener Artikel), Zum Uebernehmen, Shop - Migration 2026_12_01_110000, ADR-56, DEPLOYMENT.md Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
61c65595e1
commit
95a888d1ca
14 files changed
+1045
-33
No files matched your search
@@ -10,6 +10,7 @@
|
||||
use App\Domain\Catalog\LicenceScope;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferRelease;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
@@ -17,6 +18,7 @@
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Domain\Commerce\Money;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Domain\Entitlement\OfferAccess;
|
||||
use App\Filament\Pages\Zahlungsjournal;
|
||||
use App\Filament\Resources\Offers\OfferResource;
|
||||
use App\Filament\Support\CatalogLabels;
|
||||
@@ -24,9 +26,12 @@
|
||||
use App\Filament\Support\PublicationReadiness;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Filament\Support\ShopAccess;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
@@ -34,6 +39,7 @@
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
@@ -243,6 +249,175 @@ public function endAction(): Action
|
||||
});
|
||||
}
|
||||
|
||||
/** Ein Angebot auf Abruf: nur dafür gibt es Regeln, wer es übernehmen darf (ADR-56). */
|
||||
private function isOnDemand(): bool
|
||||
{
|
||||
return $this->activeVersion()?->grant_kind === 'auf_abruf';
|
||||
}
|
||||
|
||||
/**
|
||||
* Wer das Angebot übernehmen darf: alle Mitglieder, nur freigeschaltete Konten oder wer einen Artikel besitzt.
|
||||
*/
|
||||
public function claimRuleAction(): Action
|
||||
{
|
||||
return Action::make('claimRule')
|
||||
->label('Regel für den Abruf')
|
||||
->modalHeading(fn (): string => 'Wer darf „'.$this->getRecord()->name.'“ abrufen?')
|
||||
->modalDescription('Die Regel gilt für den kostenlosen Abruf in die Bibliothek und wird beim Abruf geprüft. Sie begrenzt nur den Abruf; sie vergibt nichts. Bereits übernommene Angebote bleiben in der Bibliothek.')
|
||||
->modalSubmitActionLabel('Regel speichern')
|
||||
->visible(fn (): bool => $this->isOnDemand())
|
||||
->fillForm(fn (): array => [
|
||||
'claim_access' => (string) ($this->getRecord()->claim_access ?: OfferAccess::ALL),
|
||||
'claim_requires_article_id' => $this->getRecord()->claim_requires_article_id,
|
||||
])
|
||||
->schema([
|
||||
Select::make('claim_access')->label('Wer darf abrufen')
|
||||
->options(OfferAccess::OPTIONS)
|
||||
->required()->live()->native(false)
|
||||
->helperText('„Nur freigeschaltete Konten“: Du schaltest einzelne Konten auf dieser Seite frei und entziehst die Freigabe wieder. Sie gilt nur für dieses Angebot.'),
|
||||
Select::make('claim_requires_article_id')->label('Artikel, den das Konto besitzen muss')
|
||||
->options(fn (): array => LicenseArticle::query()->whereNull('archived_at')->orderBy('code')->get()
|
||||
->mapWithKeys(fn (LicenseArticle $article): array => [$article->id => app(ProductOptions::class)->articleTitle($article)])->all())
|
||||
->searchable()
|
||||
->required(fn (Get $get): bool => $get('claim_access') === OfferAccess::OWNERS)
|
||||
->visible(fn (Get $get): bool => $get('claim_access') === OfferAccess::OWNERS)
|
||||
->helperText('Das Konto muss eine gültige Berechtigung auf diesen Artikel haben, zum Beispiel durch einen Kauf.'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): string {
|
||||
app(OfferAccess::class)->setRule($this->getRecord(), (string) $data['claim_access'], filled($data['claim_requires_article_id'] ?? null) ? (int) $data['claim_requires_article_id'] : null);
|
||||
|
||||
return 'Die Regel für den Abruf ist gespeichert.';
|
||||
}, 'Die Regel ist gespeichert.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
public function releaseAction(): Action
|
||||
{
|
||||
return Action::make('release')
|
||||
->label('Konto freischalten')
|
||||
->modalHeading(fn (): string => 'Konto für „'.$this->getRecord()->name.'“ freischalten')
|
||||
->modalDescription('Das Konto darf genau dieses Angebot abrufen, solange Freigabe und Angebot gelten. Die Freigabe gilt nicht für andere Angebote und bleibt mit dem Entzug im Verlauf stehen.')
|
||||
->modalSubmitActionLabel('Konto freischalten')
|
||||
->visible(fn (): bool => $this->isOnDemand() && $this->getRecord()->claim_access === OfferAccess::RELEASED)
|
||||
->schema([
|
||||
Select::make('user_id')->label('Mitgliedskonto')->required()->searchable()
|
||||
->getSearchResultsUsing(fn (string $search): array => $this->searchMembers($search))
|
||||
->getOptionLabelUsing(fn ($value): ?string => ($user = User::query()->find($value)) === null ? null : $user->name.' ('.$user->email.')')
|
||||
->helperText('Suche nach Name oder E-Mail-Adresse. Nur Konten mit Mitgliedsprofil.'),
|
||||
DatePicker::make('valid_until')->label('Freigabe gültig bis einschließlich')->native(false)->displayFormat('d.m.Y')
|
||||
->helperText('Leer: ohne Ende.'),
|
||||
Textarea::make('reason')->label('Grundlage der Freigabe')->rows(2)->maxLength(500)
|
||||
->helperText('Zum Beispiel „Teilnahme am Seminar am 12.11.2026“. Bleibt im Verlauf stehen.'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): string {
|
||||
$member = User::query()->findOrFail($data['user_id']);
|
||||
$until = filled($data['valid_until'] ?? null) ? Carbon::parse((string) $data['valid_until'], config('app.timezone'))->endOfDay() : null;
|
||||
app(OfferAccess::class)->release($this->getRecord(), $member, auth('staff')->user() ?? auth()->user(), $until, $data['reason'] ?? null);
|
||||
|
||||
return 'Das Konto von '.$member->name.' ist für das Angebot freigeschaltet.';
|
||||
}, 'Das Konto ist freigeschaltet.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
public function revokeAction(): Action
|
||||
{
|
||||
return Action::make('revoke')
|
||||
->label('Freigabe entziehen')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Freigabe entziehen?')
|
||||
->modalDescription('Das Konto kann das Angebot danach nicht mehr abrufen. Bereits übernommene Angebote bleiben in der Bibliothek. Die Freigabe bleibt mit dem Entzug im Verlauf stehen.')
|
||||
->modalSubmitActionLabel('Freigabe entziehen')
|
||||
->schema([
|
||||
Textarea::make('reason')->label('Grund')->rows(2)->maxLength(500),
|
||||
])
|
||||
->action(function (array $data, array $arguments): void {
|
||||
$this->report(function () use ($data, $arguments): string {
|
||||
$release = OfferRelease::query()->where('offer_id', $this->getRecord()->id)->findOrFail((int) ($arguments['release'] ?? 0));
|
||||
app(OfferAccess::class)->revoke($release, auth('staff')->user() ?? auth()->user(), $data['reason'] ?? null);
|
||||
|
||||
return 'Die Freigabe ist entzogen.';
|
||||
}, 'Die Freigabe ist entzogen.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function searchMembers(string $search): array
|
||||
{
|
||||
$like = '%'.mb_strtolower(trim($search)).'%';
|
||||
|
||||
return User::query()
|
||||
->whereNotNull('party_id')
|
||||
->where(fn ($query) => $query->whereRaw('LOWER(name) LIKE ?', [$like])->orWhereRaw('LOWER(email) LIKE ?', [$like]))
|
||||
->orderBy('name')
|
||||
->limit(20)
|
||||
->get()
|
||||
->mapWithKeys(fn (User $user): array => [$user->id => $user->name.' ('.$user->email.')'])
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abschnitte „Wer darf abrufen“ und „Freigeschaltete Konten“ für ein Angebot auf Abruf.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function abrufAbschnitte(Offer $offer): array
|
||||
{
|
||||
$date = fn ($value): string => $value?->format('d.m.Y') ?? '';
|
||||
$access = (string) ($offer->claim_access ?: OfferAccess::ALL);
|
||||
$article = $offer->claim_requires_article_id !== null ? LicenseArticle::query()->find($offer->claim_requires_article_id) : null;
|
||||
$releases = $offer->releases()->with(['user', 'grantor'])->orderByDesc('id')->get();
|
||||
$active = $releases->filter(fn (OfferRelease $release): bool => $release->revoked_at === null);
|
||||
$past = $releases->filter(fn (OfferRelease $release): bool => $release->revoked_at !== null);
|
||||
$sections = [[
|
||||
'titel' => 'Wer darf abrufen',
|
||||
'hilfe' => 'Diese Regel gilt für den kostenlosen Abruf in die Bibliothek (Mitgliederbereich → Angebote). Sie wird beim Abruf geprüft, nicht nur in der Anzeige.',
|
||||
'zeilen' => [[
|
||||
'text' => OfferAccess::OPTIONS[$access] ?? $access,
|
||||
'neben' => $access === OfferAccess::OWNERS
|
||||
? 'Erforderlich: '.($article !== null ? app(ProductOptions::class)->articleTitle($article) : 'ein Artikel fehlt (Regel prüfen)')
|
||||
: ($access === OfferAccess::RELEASED ? 'Mit „Konto freischalten“ gibst du einzelne Konten frei.' : 'Jedes angemeldete Mitgliedskonto sieht das Angebot und kann es übernehmen.'),
|
||||
]],
|
||||
]];
|
||||
|
||||
if ($access === OfferAccess::RELEASED) {
|
||||
$sections[] = [
|
||||
'titel' => 'Freigeschaltete Konten',
|
||||
'zusatz' => $active->count().' aktiv',
|
||||
'hilfe' => 'Nur diese Konten sehen das Angebot im Mitgliederbereich und können es übernehmen.',
|
||||
'zeilen' => $active->map(fn (OfferRelease $release): array => [
|
||||
'text' => ($release->user?->name ?? 'Konto').' ('.($release->user?->email ?? '').')',
|
||||
'neben' => 'freigeschaltet am '.$date($release->granted_at).($release->grantor ? ' von '.$release->grantor->name : '').($release->valid_until ? ', gültig bis einschließlich '.$date($release->valid_until) : '').(filled($release->reason) ? ' · '.$release->reason : ''),
|
||||
'aktion' => ['label' => 'Entziehen', 'wire' => "mountAction('revoke', { release: ".$release->id.' })'],
|
||||
])->values()->all(),
|
||||
'leer' => ['titel' => 'Noch kein Konto freigeschaltet', 'text' => 'Mit „Konto freischalten“ gibst du ein Konto für dieses Angebot frei.'],
|
||||
];
|
||||
|
||||
if ($past->isNotEmpty()) {
|
||||
$sections[] = [
|
||||
'titel' => 'Entzogene Freigaben',
|
||||
'hilfe' => 'Der Verlauf bleibt erhalten.',
|
||||
'zeilen' => $past->map(fn (OfferRelease $release): array => [
|
||||
'text' => $release->user?->name ?? 'Konto',
|
||||
'neben' => 'entzogen am '.$date($release->revoked_at).(filled($release->reason) ? ' · '.$release->reason : ''),
|
||||
])->values()->all(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/** „ der Produktseite „Titel““ oder leer, wenn die Option (noch) keine Produktseite hat. */
|
||||
private function productPageSuffix(): string
|
||||
{
|
||||
@@ -330,6 +505,16 @@ private function angebotDaten(): array
|
||||
'wire' => "mountAction('end')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
...($this->isOnDemand() ? [[
|
||||
'label' => 'Regel für den Abruf',
|
||||
'wire' => "mountAction('claimRule')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
...($this->isOnDemand() && $offer->claim_access === OfferAccess::RELEASED ? [[
|
||||
'label' => 'Konto freischalten',
|
||||
'wire' => "mountAction('release')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
...(ShopAccess::allowed() ? [[
|
||||
'label' => 'Zahlungen zu diesem Angebot',
|
||||
'href' => Zahlungsjournal::getUrl(['angebot' => $offer->id, 'zeitraum' => 'jahr', 'betrieb' => 'alle']),
|
||||
@@ -340,6 +525,7 @@ private function angebotDaten(): array
|
||||
'voraussetzungen' => app(PublicationReadiness::class)->forOffer($offer),
|
||||
'haupt' => [
|
||||
...($active !== null ? [$this->optionAbschnitt($offer, $active)] : []),
|
||||
...($this->isOnDemand() ? $this->abrufAbschnitte($offer) : []),
|
||||
[
|
||||
'titel' => 'Positionen',
|
||||
'zusatz' => $active !== null ? 'Fassung '.$active->number : null,
|
||||
|
||||
Reference in new issue
Block a user