Introduced a two-tier media pipeline with dynamic disks, asset tracking, admin controls, and alerting around
upload/archival workflows.
- Added storage metadata + asset tables and models so every photo/variant knows where it lives
(database/migrations/2025_10_20_090000_create_media_storage_targets_table.php, database/ migrations/2025_10_20_090200_create_event_media_assets_table.php, app/Models/MediaStorageTarget.php:1, app/
Models/EventMediaAsset.php:1, app/Models/EventStorageAssignment.php:1, app/Models/Event.php:27).
- Rewired guest and tenant uploads to pick the event’s hot disk, persist EventMediaAsset records, compute
checksums, and clean up on delete (app/Http/Controllers/Api/EventPublicController.php:243, app/Http/
Controllers/Api/Tenant/PhotoController.php:25, app/Models/Photo.php:25).
- Implemented storage services, archival job scaffolding, monitoring config, and queue-failure notifications for upload issues (app/Services/Storage/EventStorageManager.php:16, app/Services/Storage/
StorageHealthService.php:9, app/Jobs/ArchiveEventMediaAssets.php:16, app/Providers/AppServiceProvider.php:39, app/Notifications/UploadPipelineFailed.php:8, config/storage-monitor.php:1).
- Seeded default hot/cold targets and exposed super-admin tooling via a Filament resource and capacity widget (database/seeders/MediaStorageTargetSeeder.php:13, database/seeders/DatabaseSeeder.php:17, app/Filament/Resources/MediaStorageTargetResource.php:1, app/Filament/Widgets/StorageCapacityWidget.php:12, app/Providers/Filament/SuperAdminPanelProvider.php:47).
- Dropped cron skeletons and artisan placeholders to schedule storage monitoring, archival dispatch, and upload queue health checks (cron/storage_monitor.sh, cron/archive_dispatcher.sh, cron/upload_queue_health.sh, routes/console.php:9).
199 lines
7.3 KiB
PHP
199 lines
7.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\PurchaseResource\Pages;
|
|
use App\Models\PackagePurchase;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Columns\BadgeColumn;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Illuminate\Support\Facades\Log;
|
|
use BackedEnum;
|
|
use UnitEnum;
|
|
class PurchaseResource extends Resource
|
|
{
|
|
protected static ?string $model = PackagePurchase::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-shopping-cart';
|
|
|
|
public static function getNavigationGroup(): string
|
|
{
|
|
return 'Billing & Finanzen';
|
|
}
|
|
|
|
protected static ?int $navigationSort = 10;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->schema([
|
|
Select::make('tenant_id')
|
|
->label('Tenant')
|
|
->relationship('tenant', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->nullable(),
|
|
Select::make('event_id')
|
|
->label('Event')
|
|
->relationship('event', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->nullable(),
|
|
Select::make('package_id')
|
|
->label('Package')
|
|
->relationship('package', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->required(),
|
|
TextInput::make('provider_id')
|
|
->label('Provider ID')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('price')
|
|
->label('Price')
|
|
->numeric()
|
|
->step(0.01)
|
|
->prefix('€')
|
|
->required(),
|
|
Select::make('type')
|
|
->label('Type')
|
|
->options([
|
|
'endcustomer_event' => 'Endcustomer Event',
|
|
'reseller_subscription' => 'Reseller Subscription',
|
|
])
|
|
->required(),
|
|
Textarea::make('metadata')
|
|
->label('Metadata')
|
|
->json()
|
|
->columnSpanFull(),
|
|
Toggle::make('refunded')
|
|
->label('Refunded')
|
|
->default(false),
|
|
])
|
|
->columns(2);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
BadgeColumn::make('type')
|
|
->label('Type')
|
|
->color(fn (string $state): string => match($state) {
|
|
'endcustomer_event' => 'info',
|
|
'reseller_subscription' => 'success',
|
|
default => 'gray',
|
|
}),
|
|
TextColumn::make('tenant.name')
|
|
->label('Tenant')
|
|
->searchable()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
TextColumn::make('event.name')
|
|
->label('Event')
|
|
->searchable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
TextColumn::make('package.name')
|
|
->label('Package')
|
|
->badge()
|
|
->color('success'),
|
|
TextColumn::make('price')
|
|
->label('Price')
|
|
->money('EUR')
|
|
->sortable(),
|
|
TextColumn::make('purchased_at')
|
|
->dateTime()
|
|
->sortable(),
|
|
BadgeColumn::make('refunded')
|
|
->label('Status')
|
|
->color(fn (bool $state): string => $state ? 'danger' : 'success'),
|
|
TextColumn::make('provider_id')
|
|
->copyable()
|
|
->toggleable(),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('type')
|
|
->options([
|
|
'endcustomer_event' => 'Endcustomer Event',
|
|
'reseller_subscription' => 'Reseller Subscription',
|
|
]),
|
|
Filter::make('purchased_at')
|
|
->form([
|
|
DateTimePicker::make('started_from'),
|
|
DateTimePicker::make('ended_before'),
|
|
])
|
|
->query(function (Builder $query, array $data): Builder {
|
|
return $query
|
|
->when(
|
|
$data['started_from'],
|
|
fn (Builder $query, $date): Builder => $query->whereDate('purchased_at', '>=', $date),
|
|
)
|
|
->when(
|
|
$data['ended_before'],
|
|
fn (Builder $query, $date): Builder => $query->whereDate('purchased_at', '<=', $date),
|
|
);
|
|
}),
|
|
SelectFilter::make('tenant_id')
|
|
->label('Tenant')
|
|
->relationship('tenant', 'name')
|
|
->searchable(),
|
|
])
|
|
->actions([
|
|
ViewAction::make(),
|
|
EditAction::make(),
|
|
Action::make('refund')
|
|
->label('Refund')
|
|
->color('danger')
|
|
->icon('heroicon-o-arrow-uturn-left')
|
|
->requiresConfirmation()
|
|
->visible(fn (PackagePurchase $record): bool => !$record->refunded)
|
|
->action(function (PackagePurchase $record) {
|
|
$record->update(['refunded' => true]);
|
|
// TODO: Call Stripe/PayPal API for actual refund
|
|
Log::info('Refund processed for purchase ID: ' . $record->id);
|
|
}),
|
|
])
|
|
->bulkActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->emptyStateHeading('No Purchases Found')
|
|
->emptyStateDescription('Create your first purchase.');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListPurchases::route('/'),
|
|
'create' => Pages\CreatePurchase::route('/create'),
|
|
'view' => Pages\ViewPurchase::route('/{record}'),
|
|
'edit' => Pages\EditPurchase::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
// Add RelationManagers if needed
|
|
];
|
|
}
|
|
} |