- Wired the checkout wizard for Google “comfort login”: added Socialite controller + dependency, new Google env
hooks in config/services.php/.env.example, and updated wizard steps/controllers to store session payloads, attach packages, and surface localized success/error states. - Retooled payment handling for both Stripe and PayPal, adding richer status management in CheckoutController/ PayPalController, fallback flows in the wizard’s PaymentStep.tsx, and fresh feature tests for intent creation, webhooks, and the wizard CTA. - Introduced a consent-aware Matomo analytics stack: new consent context, cookie-banner UI, useAnalytics/ useCtaExperiment hooks, and MatomoTracker component, then instrumented marketing pages (Home, Packages, Checkout) with localized copy and experiment tracking. - Polished package presentation across marketing UIs by centralizing formatting in PresentsPackages, surfacing localized description tables/placeholders, tuning badges/layouts, and syncing guest/marketing translations. - Expanded docs & reference material (docs/prp/*, TODOs, public gallery overview) and added a Playwright smoke test for the hero CTA while reconciling outstanding checklist items.
This commit is contained in:
190
app/Filament/Resources/OAuthClientResource.php
Normal file
190
app/Filament/Resources/OAuthClientResource.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\OAuthClientResource\Pages;
|
||||
use App\Models\OAuthClient;
|
||||
use App\Models\RefreshToken;
|
||||
use BackedEnum;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class OAuthClientResource extends Resource
|
||||
{
|
||||
protected static ?string $model = OAuthClient::class;
|
||||
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-key';
|
||||
|
||||
protected static ?int $navigationSort = 30;
|
||||
|
||||
public static function getNavigationGroup(): string
|
||||
{
|
||||
return __('admin.nav.security');
|
||||
}
|
||||
|
||||
public static function form(Schema $form): Schema
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('admin.oauth.fields.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('client_id')
|
||||
->label(__('admin.oauth.fields.client_id'))
|
||||
->required()
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('client_secret')
|
||||
->label(__('admin.oauth.fields.client_secret'))
|
||||
->password()
|
||||
->revealable()
|
||||
->helperText(__('admin.oauth.hints.client_secret'))
|
||||
->dehydrated(fn (?string $state): bool => filled($state))
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => filled($state) ? Hash::make($state) : null),
|
||||
Forms\Components\Select::make('tenant_id')
|
||||
->label(__('admin.oauth.fields.tenant'))
|
||||
->relationship('tenant', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->nullable(),
|
||||
Forms\Components\Textarea::make('redirect_uris')
|
||||
->label(__('admin.oauth.fields.redirect_uris'))
|
||||
->rows(4)
|
||||
->helperText(__('admin.oauth.hints.redirect_uris'))
|
||||
->formatStateUsing(fn ($state): string => is_array($state) ? implode(PHP_EOL, $state) : (string) $state)
|
||||
->dehydrateStateUsing(function (?string $state): array {
|
||||
$entries = collect(preg_split('/\r\n|\r|\n/', (string) $state))
|
||||
->map(fn ($uri) => trim($uri))
|
||||
->filter();
|
||||
|
||||
return $entries->values()->all();
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TagsInput::make('scopes')
|
||||
->label(__('admin.oauth.fields.scopes'))
|
||||
->placeholder('tenant:read')
|
||||
->suggestions([
|
||||
'tenant:read',
|
||||
'tenant:write',
|
||||
'tenant:admin',
|
||||
])
|
||||
->separator(',')
|
||||
->required(),
|
||||
Forms\Components\Toggle::make('is_active')
|
||||
->label(__('admin.oauth.fields.is_active'))
|
||||
->default(true),
|
||||
Forms\Components\Textarea::make('description')
|
||||
->label(__('admin.oauth.fields.description'))
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
])->columns(2);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('admin.oauth.fields.name'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('client_id')
|
||||
->label(__('admin.oauth.fields.client_id'))
|
||||
->copyable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('tenant.name')
|
||||
->label(__('admin.oauth.fields.tenant'))
|
||||
->toggleable(isToggledHiddenByDefault: true)
|
||||
->sortable(),
|
||||
Tables\Columns\IconColumn::make('is_active')
|
||||
->label(__('admin.oauth.fields.is_active'))
|
||||
->boolean()
|
||||
->color(fn (bool $state): string => $state ? 'success' : 'danger'),
|
||||
Tables\Columns\TextColumn::make('redirect_uris')
|
||||
->label(__('admin.oauth.fields.redirect_uris'))
|
||||
->formatStateUsing(fn ($state) => collect(Arr::wrap($state))->implode("\n"))
|
||||
->limit(50)
|
||||
->toggleable(),
|
||||
Tables\Columns\TagsColumn::make('scopes')
|
||||
->label(__('admin.oauth.fields.scopes'))
|
||||
->separator(', ')
|
||||
->limit(4),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label(__('admin.oauth.fields.updated_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TernaryFilter::make('is_active')
|
||||
->label(__('admin.oauth.filters.is_active'))
|
||||
->placeholder(__('admin.oauth.filters.any'))
|
||||
->trueLabel(__('admin.oauth.filters.active'))
|
||||
->falseLabel(__('admin.oauth.filters.inactive')),
|
||||
Tables\Filters\SelectFilter::make('tenant_id')
|
||||
->label(__('admin.oauth.fields.tenant'))
|
||||
->relationship('tenant', 'name')
|
||||
->searchable(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('regenerate_secret')
|
||||
->label(__('admin.oauth.actions.regenerate_secret'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->action(function (OAuthClient $record): void {
|
||||
$plainSecret = Str::random(48);
|
||||
|
||||
$record->forceFill([
|
||||
'client_secret' => Hash::make($plainSecret),
|
||||
])->save();
|
||||
|
||||
Notification::make()
|
||||
->title(__('admin.oauth.notifications.secret_regenerated_title'))
|
||||
->body(__('admin.oauth.notifications.secret_regenerated_body', [
|
||||
'secret' => $plainSecret,
|
||||
]))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Tables\Actions\DeleteAction::make()
|
||||
->before(function (OAuthClient $record): void {
|
||||
RefreshToken::query()
|
||||
->where('client_id', $record->client_id)
|
||||
->delete();
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make()
|
||||
->before(function (Collection $records): void {
|
||||
$records->each(function (OAuthClient $record) {
|
||||
RefreshToken::query()
|
||||
->where('client_id', $record->client_id)
|
||||
->delete();
|
||||
});
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListOAuthClients::route('/'),
|
||||
'create' => Pages\CreateOAuthClient::route('/create'),
|
||||
'view' => Pages\ViewOAuthClient::route('/{record}'),
|
||||
'edit' => Pages\EditOAuthClient::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\OAuthClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\OAuthClientResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateOAuthClient extends CreateRecord
|
||||
{
|
||||
protected static string $resource = OAuthClientResource::class;
|
||||
|
||||
protected function getCreatedNotificationTitle(): ?string
|
||||
{
|
||||
return __('admin.oauth.notifications.created_title');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\OAuthClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\OAuthClientResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditOAuthClient extends EditRecord
|
||||
{
|
||||
protected static string $resource = OAuthClientResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getSavedNotificationTitle(): ?string
|
||||
{
|
||||
return __('admin.oauth.notifications.updated_title');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\OAuthClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\OAuthClientResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListOAuthClients extends ListRecords
|
||||
{
|
||||
protected static string $resource = OAuthClientResource::class;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\OAuthClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\OAuthClientResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewOAuthClient extends ViewRecord
|
||||
{
|
||||
protected static string $resource = OAuthClientResource::class;
|
||||
}
|
||||
|
||||
189
app/Filament/Resources/PurchaseHistoryResource.php
Normal file
189
app/Filament/Resources/PurchaseHistoryResource.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Exports\PurchaseHistoryExporter;
|
||||
use App\Filament\Resources\PurchaseHistoryResource\Pages;
|
||||
use App\Models\PurchaseHistory;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\ExportBulkAction;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PurchaseHistoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = PurchaseHistory::class;
|
||||
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-receipt-refund';
|
||||
|
||||
protected static ?int $navigationSort = 20;
|
||||
|
||||
public static function getNavigationGroup(): string
|
||||
{
|
||||
return __('admin.nav.billing');
|
||||
}
|
||||
|
||||
public static function form(Schema $form): Schema
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\Select::make('tenant_id')
|
||||
->label(__('admin.purchase_history.fields.tenant'))
|
||||
->relationship('tenant', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('package_id')
|
||||
->label(__('admin.purchase_history.fields.package'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('credits_added')
|
||||
->label(__('admin.purchase_history.fields.credits'))
|
||||
->numeric()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('price')
|
||||
->label(__('admin.purchase_history.fields.price'))
|
||||
->numeric()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('currency')
|
||||
->label(__('admin.purchase_history.fields.currency'))
|
||||
->maxLength(3)
|
||||
->default('EUR'),
|
||||
Forms\Components\TextInput::make('platform')
|
||||
->label(__('admin.purchase_history.fields.platform'))
|
||||
->maxLength(50)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('transaction_id')
|
||||
->label(__('admin.purchase_history.fields.transaction_id'))
|
||||
->maxLength(255),
|
||||
Forms\Components\DateTimePicker::make('purchased_at')
|
||||
->label(__('admin.purchase_history.fields.purchased_at'))
|
||||
->required(),
|
||||
])->columns(2);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('tenant.name')
|
||||
->label(__('admin.purchase_history.fields.tenant'))
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('package_id')
|
||||
->label(__('admin.purchase_history.fields.package'))
|
||||
->badge()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('credits_added')
|
||||
->label(__('admin.purchase_history.fields.credits'))
|
||||
->badge()
|
||||
->color(fn (int $state): string => $state > 0 ? 'success' : ($state < 0 ? 'danger' : 'gray'))
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('price')
|
||||
->label(__('admin.purchase_history.fields.price'))
|
||||
->formatStateUsing(fn ($state, PurchaseHistory $record): string => number_format((float) $state, 2).' '.($record->currency ?? 'EUR'))
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('platform')
|
||||
->label(__('admin.purchase_history.fields.platform'))
|
||||
->badge()
|
||||
->formatStateUsing(function ($state): string {
|
||||
$key = 'admin.purchase_history.platforms.' . (string) $state;
|
||||
$translated = __($key);
|
||||
|
||||
return $translated === $key ? Str::headline((string) $state) : $translated;
|
||||
})
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('transaction_id')
|
||||
->label(__('admin.purchase_history.fields.transaction_id'))
|
||||
->copyable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('purchased_at')
|
||||
->label(__('admin.purchase_history.fields.purchased_at'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('purchased_at')
|
||||
->label(__('admin.purchase_history.filters.purchased_at'))
|
||||
->form([
|
||||
Forms\Components\DatePicker::make('from')->label(__('admin.common.from')),
|
||||
Forms\Components\DatePicker::make('until')->label(__('admin.common.until')),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['from'] ?? null,
|
||||
fn (Builder $builder, $date): Builder => $builder->whereDate('purchased_at', '>=', $date),
|
||||
)
|
||||
->when(
|
||||
$data['until'] ?? null,
|
||||
fn (Builder $builder, $date): Builder => $builder->whereDate('purchased_at', '<=', $date),
|
||||
);
|
||||
}),
|
||||
Tables\Filters\SelectFilter::make('platform')
|
||||
->label(__('admin.purchase_history.filters.platform'))
|
||||
->options([
|
||||
'ios' => __('admin.purchase_history.platforms.ios'),
|
||||
'android' => __('admin.purchase_history.platforms.android'),
|
||||
'web' => __('admin.purchase_history.platforms.web'),
|
||||
'manual' => __('admin.purchase_history.platforms.manual'),
|
||||
]),
|
||||
Tables\Filters\SelectFilter::make('currency')
|
||||
->label(__('admin.purchase_history.filters.currency'))
|
||||
->options([
|
||||
'EUR' => 'EUR',
|
||||
'USD' => 'USD',
|
||||
]),
|
||||
Tables\Filters\SelectFilter::make('tenant_id')
|
||||
->label(__('admin.purchase_history.filters.tenant'))
|
||||
->relationship('tenant', 'name')
|
||||
->searchable(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
ExportBulkAction::make()
|
||||
->label(__('admin.purchase_history.actions.export'))
|
||||
->exporter(PurchaseHistoryExporter::class),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPurchaseHistories::route('/'),
|
||||
'view' => Pages\ViewPurchaseHistory::route('/{record}'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canEdit($record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canDelete($record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canDeleteAny(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PurchaseHistoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PurchaseHistoryResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPurchaseHistories extends ListRecords
|
||||
{
|
||||
protected static string $resource = PurchaseHistoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PurchaseHistoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PurchaseHistoryResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewPurchaseHistory extends ViewRecord
|
||||
{
|
||||
protected static string $resource = PurchaseHistoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use Filament\Tables\Columns\IconColumn;
|
||||
use App\Filament\Resources\TenantResource\RelationManagers\PackagePurchasesRelationManager;
|
||||
use App\Filament\Resources\TenantResource\RelationManagers\TenantPackagesRelationManager;
|
||||
use Filament\Resources\RelationManagers\RelationGroup;
|
||||
use Filament\Notifications\Notification;
|
||||
use UnitEnum;
|
||||
use BackedEnum;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -56,6 +57,10 @@ class TenantResource extends Resource
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('event_credits_balance')
|
||||
->label(__('admin.tenants.fields.event_credits_balance'))
|
||||
->numeric()
|
||||
->readOnly(),
|
||||
TextInput::make('total_revenue')
|
||||
->label(__('admin.tenants.fields.total_revenue'))
|
||||
->prefix('€')
|
||||
@@ -99,6 +104,10 @@ class TenantResource extends Resource
|
||||
->getStateUsing(fn (Tenant $record) => $record->user?->full_name ?? 'Unbekannt'),
|
||||
Tables\Columns\TextColumn::make('slug')->searchable(),
|
||||
Tables\Columns\TextColumn::make('contact_email'),
|
||||
Tables\Columns\TextColumn::make('event_credits_balance')
|
||||
->label(__('admin.tenants.fields.event_credits_balance'))
|
||||
->badge()
|
||||
->color(fn (int $state): string => $state <= 0 ? 'danger' : ($state < 5 ? 'warning' : 'success')),
|
||||
Tables\Columns\TextColumn::make('active_reseller_package_id')
|
||||
->label(__('admin.tenants.fields.active_package'))
|
||||
->badge()
|
||||
@@ -159,10 +168,49 @@ class TenantResource extends Resource
|
||||
'metadata' => ['reason' => $data['reason'] ?? 'manual assignment'],
|
||||
]);
|
||||
}),
|
||||
Actions\Action::make('adjust_credits')
|
||||
->label(__('admin.tenants.actions.adjust_credits'))
|
||||
->icon('heroicon-o-banknotes')
|
||||
->authorize(fn (Tenant $record): bool => auth()->user()?->can('adjustCredits', $record) ?? false)
|
||||
->form([
|
||||
Forms\Components\TextInput::make('delta')
|
||||
->label(__('admin.tenants.actions.adjust_credits_delta'))
|
||||
->numeric()
|
||||
->required()
|
||||
->rule('integer')
|
||||
->helperText(__('admin.tenants.actions.adjust_credits_delta_hint')),
|
||||
Forms\Components\Textarea::make('reason')
|
||||
->label(__('admin.tenants.actions.adjust_credits_reason'))
|
||||
->rows(3)
|
||||
->maxLength(500),
|
||||
])
|
||||
->action(function (Tenant $record, array $data): void {
|
||||
$delta = (int) ($data['delta'] ?? 0);
|
||||
|
||||
if ($delta === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newBalance = max(0, $record->event_credits_balance + $delta);
|
||||
|
||||
$record->forceFill([
|
||||
'event_credits_balance' => $newBalance,
|
||||
])->save();
|
||||
|
||||
Notification::make()
|
||||
->title(__('admin.tenants.actions.adjust_credits_success_title'))
|
||||
->body(__('admin.tenants.actions.adjust_credits_success_body', [
|
||||
'delta' => $delta,
|
||||
'balance' => $newBalance,
|
||||
]))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Actions\Action::make('suspend')
|
||||
->label('Suspendieren')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->authorize(fn (Tenant $record): bool => auth()->user()?->can('suspend', $record) ?? false)
|
||||
->action(fn (Tenant $record) => $record->update(['is_suspended' => true])),
|
||||
Actions\Action::make('export')
|
||||
->label('Daten exportieren')
|
||||
|
||||
61
app/Filament/Widgets/CreditAlertsWidget.php
Normal file
61
app/Filament/Widgets/CreditAlertsWidget.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\PurchaseHistory;
|
||||
use App\Models\Tenant;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class CreditAlertsWidget extends StatsOverviewWidget
|
||||
{
|
||||
protected static ?int $sort = 0;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected function getCards(): array
|
||||
{
|
||||
$lowBalanceCount = Tenant::query()
|
||||
->where('is_active', true)
|
||||
->where('event_credits_balance', '<', 5)
|
||||
->count();
|
||||
|
||||
$monthStart = now()->startOfMonth();
|
||||
$monthlyRevenue = PurchaseHistory::query()
|
||||
->where('purchased_at', '>=', $monthStart)
|
||||
->sum('price');
|
||||
|
||||
$activeSubscriptions = Tenant::query()
|
||||
->whereNotNull('subscription_expires_at')
|
||||
->where('subscription_expires_at', '>', now())
|
||||
->count();
|
||||
|
||||
return [
|
||||
Stat::make(
|
||||
__('admin.widgets.credit_alerts.low_balance_label'),
|
||||
$lowBalanceCount
|
||||
)
|
||||
->description(__('admin.widgets.credit_alerts.low_balance_desc'))
|
||||
->descriptionIcon('heroicon-m-exclamation-triangle')
|
||||
->color('warning')
|
||||
->url(route('filament.superadmin.resources.tenants.index')),
|
||||
Stat::make(
|
||||
__('admin.widgets.credit_alerts.monthly_revenue_label'),
|
||||
number_format((float) $monthlyRevenue, 2).' €'
|
||||
)
|
||||
->description(__('admin.widgets.credit_alerts.monthly_revenue_desc', [
|
||||
'month' => $monthStart->translatedFormat('F'),
|
||||
]))
|
||||
->descriptionIcon('heroicon-m-currency-euro')
|
||||
->color('success'),
|
||||
Stat::make(
|
||||
__('admin.widgets.credit_alerts.active_subscriptions_label'),
|
||||
$activeSubscriptions
|
||||
)
|
||||
->description(__('admin.widgets.credit_alerts.active_subscriptions_desc'))
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up')
|
||||
->color('info'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
55
app/Filament/Widgets/RevenueTrendWidget.php
Normal file
55
app/Filament/Widgets/RevenueTrendWidget.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\PurchaseHistory;
|
||||
use Filament\Widgets\LineChartWidget;
|
||||
|
||||
class RevenueTrendWidget extends LineChartWidget
|
||||
{
|
||||
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
public function getHeading(): ?string
|
||||
{
|
||||
return __('admin.widgets.revenue_trend.heading');
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$start = now()->startOfMonth()->subMonths(11);
|
||||
$months = collect(range(0, 11))->map(fn (int $offset) => $start->copy()->addMonths($offset));
|
||||
|
||||
$records = PurchaseHistory::query()
|
||||
->where('purchased_at', '>=', $start)
|
||||
->get(['purchased_at', 'price']);
|
||||
|
||||
$grouped = $records->groupBy(fn (PurchaseHistory $history) => $history->purchased_at?->format('Y-m'));
|
||||
|
||||
$labels = [];
|
||||
$values = [];
|
||||
|
||||
foreach ($months as $month) {
|
||||
$key = $month->format('Y-m');
|
||||
$labels[] = $month->translatedFormat('M Y');
|
||||
$total = $grouped->get($key, collect())->sum(fn (PurchaseHistory $history) => (float) $history->price);
|
||||
$values[] = round($total, 2);
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => __('admin.widgets.revenue_trend.series'),
|
||||
'data' => $values,
|
||||
'borderColor' => '#ec4899',
|
||||
'backgroundColor' => 'rgba(236, 72, 153, 0.2)',
|
||||
'tension' => 0.4,
|
||||
'fill' => 'origin',
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
}
|
||||
}
|
||||
53
app/Filament/Widgets/TopTenantsByRevenue.php
Normal file
53
app/Filament/Widgets/TopTenantsByRevenue.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Tenant;
|
||||
use Filament\Tables;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
class TopTenantsByRevenue extends BaseWidget
|
||||
{
|
||||
protected static ?string $heading = null;
|
||||
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected ?string $pollingInterval = '120s';
|
||||
|
||||
protected function getHeading(): ?string
|
||||
{
|
||||
return __('admin.widgets.top_tenants_by_revenue.heading');
|
||||
}
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
Tenant::query()
|
||||
->withSum('purchases', 'price')
|
||||
->withCount('purchases')
|
||||
->orderByDesc('purchases_sum_price')
|
||||
->limit(10)
|
||||
)
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('admin.common.tenant'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('purchases_sum_price')
|
||||
->label(__('admin.widgets.top_tenants_by_revenue.total'))
|
||||
->money('EUR')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('purchases_count')
|
||||
->label(__('admin.widgets.top_tenants_by_revenue.count'))
|
||||
->badge()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('event_credits_balance')
|
||||
->label(__('admin.common.credits'))
|
||||
->badge()
|
||||
->sortable(),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user