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
@@ -13,6 +13,8 @@ class Offer extends Model
|
||||
'composition_id',
|
||||
'option_label',
|
||||
'standalone_bundle',
|
||||
'claim_access',
|
||||
'claim_requires_article_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -31,6 +33,12 @@ public function composition(): BelongsTo
|
||||
return $this->belongsTo(Composition::class);
|
||||
}
|
||||
|
||||
/** Freigaben einzelner Konten für den Abruf (nur bei Vergabe „auf Abruf“ mit der Regel „freigeschaltete Konten“). */
|
||||
public function releases(): HasMany
|
||||
{
|
||||
return $this->hasMany(OfferRelease::class);
|
||||
}
|
||||
|
||||
/** Bezeichnung der Option auf der Produktseite. */
|
||||
public function optionName(): string
|
||||
{
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Freigabe eines Kontos für ein Angebot „auf Abruf“ (ADR-56). Gilt je Angebot und Konto, wird nie gelöscht, nur entzogen.
|
||||
*/
|
||||
class OfferRelease extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'offer_id',
|
||||
'user_id',
|
||||
'granted_by',
|
||||
'granted_at',
|
||||
'valid_until',
|
||||
'revoked_by',
|
||||
'revoked_at',
|
||||
'reason',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'granted_at' => 'datetime',
|
||||
'valid_until' => 'datetime',
|
||||
'revoked_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function offer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Offer::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function grantor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'granted_by');
|
||||
}
|
||||
|
||||
public function isActiveAt(CarbonInterface $now): bool
|
||||
{
|
||||
return $this->revoked_at === null
|
||||
&& $this->granted_at->lessThanOrEqualTo($now)
|
||||
&& ($this->valid_until === null || $this->valid_until->greaterThan($now));
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,11 @@ public function claim(User $user, Offer $offer): Acquisition
|
||||
throw new DomainRuleException('Dieses Angebot richtet sich nicht an Personen.');
|
||||
}
|
||||
|
||||
// Wer ein Angebot auf Abruf übernehmen darf, bestimmt seine Regel (ADR-56); „bei Registrierung“ kennt keine.
|
||||
if ($version->grant_kind === 'auf_abruf') {
|
||||
app(OfferAccess::class)->assertMayClaim($user, $offer);
|
||||
}
|
||||
|
||||
return $this->issue($user, $version, AcquisitionType::FreierAbruf, 'offer', $offer->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Entitlement;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Neue Stände zu Artikeln, die das Konto bereits besitzt („Neu für dich“, ADR-56).
|
||||
*
|
||||
* Nach der Updatepolitik (ADR-09, OPEN-01) stehen alle später veröffentlichten Stände desselben Artikels dem Inhaber
|
||||
* ohne Aufpreis zu, solange die Lizenz gilt. Sie erscheinen von selbst in der Bibliothek; diese Liste macht sie nur
|
||||
* sichtbar. Es wird nichts vergeben und nichts übernommen.
|
||||
*/
|
||||
class NewStands
|
||||
{
|
||||
/** So lange (in Tagen) nach der Veröffentlichung erscheint ein neuer Stand in der Liste. */
|
||||
public const DAYS = 90;
|
||||
|
||||
/**
|
||||
* @return Collection<int, array{grant: Grant, title: string, number: int, since: CarbonInterface}>
|
||||
*/
|
||||
public function forUser(User $user): Collection
|
||||
{
|
||||
if ($user->party_id === null) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$limit = now()->subDays(self::DAYS);
|
||||
$titles = app(ProductOptions::class);
|
||||
|
||||
return Grant::query()
|
||||
->with(['article.currentRelease', 'releaseAtGrant'])
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', now()))
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
||||
->whereHas('article', fn ($query) => $query->whereNull('archived_at'))
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->filter(function (Grant $grant) use ($limit): bool {
|
||||
$current = $grant->article?->currentRelease;
|
||||
$had = $grant->releaseAtGrant;
|
||||
|
||||
return $current instanceof ArticleRelease
|
||||
&& $had instanceof ArticleRelease
|
||||
&& (int) $current->number > (int) $had->number
|
||||
&& $current->created_at !== null
|
||||
&& $current->created_at->greaterThanOrEqualTo($limit);
|
||||
})
|
||||
->unique('license_article_id')
|
||||
->map(fn (Grant $grant): array => [
|
||||
'grant' => $grant,
|
||||
'title' => $titles->articleTitle($grant->article),
|
||||
'number' => (int) $grant->article->currentRelease->number,
|
||||
'since' => $grant->article->currentRelease->created_at,
|
||||
])
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Entitlement;
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
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;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Wer ein Angebot „auf Abruf“ in die Bibliothek übernehmen darf (ADR-56). Drei Regeln, serverseitig beim Abruf geprüft:
|
||||
* alle angemeldeten Mitglieder, nur ausdrücklich freigeschaltete Konten (Freigabe je Angebot und Konto, wie bei
|
||||
* Rabattcodes, nie gelöscht, nur entzogen) oder Mitglieder, die einen bestimmten anderen Artikel besitzen.
|
||||
*
|
||||
* Die Regel gilt nur für Vergaben „auf Abruf“. „Bei Registrierung“ geht automatisch an neue Konten; Kauf ist Sache der
|
||||
* Kasse. Die Regel begründet keinen Zugang, sie begrenzt nur den freien Abruf.
|
||||
*/
|
||||
class OfferAccess
|
||||
{
|
||||
public const ALL = 'alle';
|
||||
|
||||
public const RELEASED = 'konten';
|
||||
|
||||
public const OWNERS = 'besitz';
|
||||
|
||||
public const OPTIONS = [
|
||||
self::ALL => 'Alle angemeldeten Mitglieder',
|
||||
self::RELEASED => 'Nur freigeschaltete Konten',
|
||||
self::OWNERS => 'Mitglieder, die einen bestimmten Artikel besitzen',
|
||||
];
|
||||
|
||||
public function __construct(private readonly OfferService $offers) {}
|
||||
|
||||
/**
|
||||
* Die Regel eines Angebots festlegen. Der Artikel ist nur bei „besitzt einen Artikel“ gesetzt.
|
||||
*/
|
||||
public function setRule(Offer $offer, string $access, ?int $articleId = null): void
|
||||
{
|
||||
if (! array_key_exists($access, self::OPTIONS)) {
|
||||
throw new DomainRuleException('Diese Regel für den Abruf gibt es nicht.');
|
||||
}
|
||||
|
||||
if ($access === self::OWNERS) {
|
||||
$article = $articleId === null ? null : LicenseArticle::query()->whereNull('archived_at')->find($articleId);
|
||||
|
||||
if ($article === null) {
|
||||
throw new DomainRuleException('Für diese Regel braucht es einen vorhandenen, nicht archivierten Lizenzartikel.');
|
||||
}
|
||||
} else {
|
||||
$articleId = null;
|
||||
}
|
||||
|
||||
$offer->claim_access = $access;
|
||||
$offer->claim_requires_article_id = $articleId;
|
||||
$offer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Warum das Konto das Angebot nicht abrufen darf; null, wenn es das darf. Regeln gelten nur für Vergaben „auf Abruf“.
|
||||
*/
|
||||
public function refusal(User $user, Offer $offer, ?CarbonInterface $now = null): ?string
|
||||
{
|
||||
$now ??= now();
|
||||
$version = $this->activeVersion($offer);
|
||||
|
||||
if ($version === null || ! in_array($version->grant_kind, ['auf_abruf', 'bei_registrierung'], true) || $version->holder_kind !== 'person') {
|
||||
return 'Dieses Angebot wird nicht frei vergeben.';
|
||||
}
|
||||
|
||||
if ($user->party_id === null) {
|
||||
return 'Nur ein Mitgliedskonto kann ein Angebot abrufen.';
|
||||
}
|
||||
|
||||
// „Bei Registrierung“ geht automatisch an neue Konten und kennt keine Regel.
|
||||
if ($version->grant_kind !== 'auf_abruf') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match ((string) $offer->claim_access) {
|
||||
self::RELEASED => $this->activeRelease($offer, $user, $now) === null ? 'Dieses Angebot ist für dein Konto nicht freigeschaltet.' : null,
|
||||
self::OWNERS => $offer->claim_requires_article_id !== null && $this->owns($user, (int) $offer->claim_requires_article_id, $now) ? null : 'Dieses Angebot steht für dein Konto nicht zur Verfügung.',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function mayClaim(User $user, Offer $offer, ?CarbonInterface $now = null): bool
|
||||
{
|
||||
return $this->refusal($user, $offer, $now) === null;
|
||||
}
|
||||
|
||||
public function assertMayClaim(User $user, Offer $offer): void
|
||||
{
|
||||
$reason = $this->refusal($user, $offer);
|
||||
|
||||
if ($reason !== null) {
|
||||
throw new DomainRuleException($reason);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Angebote auf Abruf, die das Konto jetzt übernehmen darf und noch nicht übernommen hat.
|
||||
*
|
||||
* @return Collection<int, Offer>
|
||||
*/
|
||||
public function claimable(User $user): Collection
|
||||
{
|
||||
if ($user->party_id === null) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$taken = Acquisition::query()
|
||||
->where('party_id', $user->party_id)
|
||||
->where('type', AcquisitionType::FreierAbruf)
|
||||
->where('reference_type', 'offer')
|
||||
->pluck('reference_id')
|
||||
->all();
|
||||
|
||||
return Offer::query()
|
||||
->whereHas('versions', fn ($query) => $query->where('status', OfferStatus::Aktiv)->where('holder_kind', 'person')->whereIn('grant_kind', ['auf_abruf', 'bei_registrierung']))
|
||||
->whereNotIn('id', $taken)
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->filter(fn (Offer $offer): bool => $this->mayClaim($user, $offer))
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Konto für ein Angebot freischalten (Regel „nur freigeschaltete Konten“).
|
||||
*/
|
||||
public function release(Offer $offer, User $member, ?User $actor, ?CarbonInterface $until = null, ?string $reason = null): OfferRelease
|
||||
{
|
||||
if ($offer->claim_access !== self::RELEASED) {
|
||||
throw new DomainRuleException('Freigaben gibt es nur bei der Regel „nur freigeschaltete Konten“.');
|
||||
}
|
||||
|
||||
if ($member->party_id === null) {
|
||||
throw new DomainRuleException('Nur ein Mitgliedskonto kann für ein Angebot freigeschaltet werden.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($offer, $member, $actor, $until, $reason): OfferRelease {
|
||||
Offer::query()->whereKey($offer->id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
if ($this->activeRelease($offer, $member) !== null) {
|
||||
throw new DomainRuleException('Dieses Konto ist für das Angebot bereits freigeschaltet.');
|
||||
}
|
||||
|
||||
if ($until !== null && $until->lessThanOrEqualTo(now())) {
|
||||
throw new DomainRuleException('Das Ende der Freigabe liegt in der Vergangenheit.');
|
||||
}
|
||||
|
||||
return OfferRelease::query()->create([
|
||||
'offer_id' => $offer->id,
|
||||
'user_id' => $member->id,
|
||||
'granted_by' => $actor?->id,
|
||||
'granted_at' => now(),
|
||||
'valid_until' => $until,
|
||||
'reason' => filled($reason) ? trim((string) $reason) : null,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Entzieht die Freigabe. Sie bleibt mit Zeitpunkt, Person und Begründung gespeichert; bereits übernommene Angebote
|
||||
* bleiben in der Bibliothek.
|
||||
*/
|
||||
public function revoke(OfferRelease $release, ?User $actor, ?string $reason = null): OfferRelease
|
||||
{
|
||||
return DB::transaction(function () use ($release, $actor, $reason): OfferRelease {
|
||||
$release = OfferRelease::query()->lockForUpdate()->findOrFail($release->id);
|
||||
|
||||
if ($release->revoked_at !== null) {
|
||||
throw new DomainRuleException('Diese Freigabe ist bereits entzogen.');
|
||||
}
|
||||
|
||||
$release->forceFill([
|
||||
'revoked_at' => now(),
|
||||
'revoked_by' => $actor?->id,
|
||||
'reason' => filled($reason) ? trim((string) $reason) : $release->reason,
|
||||
])->save();
|
||||
|
||||
return $release;
|
||||
});
|
||||
}
|
||||
|
||||
public function activeRelease(Offer $offer, User $member, ?CarbonInterface $now = null): ?OfferRelease
|
||||
{
|
||||
$now ??= now();
|
||||
|
||||
return OfferRelease::query()
|
||||
->where('offer_id', $offer->id)
|
||||
->where('user_id', $member->id)
|
||||
->whereNull('revoked_at')
|
||||
->where('granted_at', '<=', $now)
|
||||
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', $now))
|
||||
->first();
|
||||
}
|
||||
|
||||
/** Das Konto besitzt den Artikel, wenn seine Person eine aktive, gültige Berechtigung darauf hat. */
|
||||
public function owns(User $user, int $articleId, ?CarbonInterface $now = null): bool
|
||||
{
|
||||
$now ??= now();
|
||||
|
||||
if ($user->party_id === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Grant::query()
|
||||
->where('license_article_id', $articleId)
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->where(fn ($query) => $query->whereNull('valid_from')->orWhere('valid_from', '<=', $now))
|
||||
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', $now))
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function activeVersion(Offer $offer): ?OfferVersion
|
||||
{
|
||||
return $offer->versions()->where('status', OfferStatus::Aktiv)->orderByDesc('number')->first();
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Commerce\Cart;
|
||||
use App\Domain\Commerce\Checkout;
|
||||
use App\Domain\Commerce\LedgerEntry;
|
||||
@@ -16,6 +15,8 @@
|
||||
use App\Domain\Commerce\StaleOverview;
|
||||
use App\Domain\Commerce\Stripe\StripeGateway;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Domain\Entitlement\NewStands;
|
||||
use App\Domain\Entitlement\OfferAccess;
|
||||
use App\Domain\Identity\PartyType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -25,21 +26,18 @@
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Angebote für das Konto: was sich ohne Kauf in die Bibliothek übernehmen lässt (Vergabe „auf Abruf“ oder „bei
|
||||
* Registrierung“). Gekauft wird ausschließlich im Shop über Warenkorb oder „Jetzt kaufen“ und die Kasse.
|
||||
* Angebote für das Konto: was sich ohne Kauf in die Bibliothek übernehmen lässt (Regel des Angebots, ADR-56) und
|
||||
* neue Stände zu bereits besessenen Artikeln. Gekauft wird ausschließlich im Shop über Warenkorb oder „Jetzt kaufen“
|
||||
* und die Kasse.
|
||||
*/
|
||||
public function offers(): View
|
||||
public function offers(Request $request, OfferAccess $access, NewStands $stands): View
|
||||
{
|
||||
$offers = Offer::query()
|
||||
->whereHas('versions', fn ($query) => $query->where('status', OfferStatus::Aktiv)->where('holder_kind', 'person')->whereIn('grant_kind', ['auf_abruf', 'bei_registrierung']))
|
||||
->with(['versions' => fn ($query) => $query->where('status', OfferStatus::Aktiv)->orderByDesc('number')])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$user = $request->user();
|
||||
$shop = Shop::visible();
|
||||
|
||||
return view('member.offers', [
|
||||
'offers' => $offers,
|
||||
'offers' => $access->claimable($user),
|
||||
'stands' => $stands->forUser($user),
|
||||
'shop' => $shop,
|
||||
'cards' => $shop ? app(ShopCatalog::class)->cards('', ['sort' => 'neu', 'limit' => 6]) : [],
|
||||
]);
|
||||
|
||||
Reference in new issue
Block a user