feat(packages): implement package-based business model
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TenantResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\BulkActionGroup;
|
||||
use Filament\Tables\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class PackagePurchasesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'packagePurchases';
|
||||
|
||||
protected static ?string $title = 'Package-Käufe';
|
||||
|
||||
public function form(Schema $form): Schema
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Select::make('package_id')
|
||||
->label('Paket')
|
||||
->relationship('package', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Select::make('type')
|
||||
->label('Typ')
|
||||
->options([
|
||||
'endcustomer_event' => 'Endkunden-Event',
|
||||
'reseller_subscription' => 'Reseller-Abo',
|
||||
])
|
||||
->required(),
|
||||
TextInput::make('purchased_price')
|
||||
->label('Gekaufter Preis')
|
||||
->numeric()
|
||||
->step(0.01)
|
||||
->prefix('€')
|
||||
->required(),
|
||||
Select::make('provider_id')
|
||||
->label('Anbieter')
|
||||
->options([
|
||||
'stripe' => 'Stripe',
|
||||
'paypal' => 'PayPal',
|
||||
'manual' => 'Manuell',
|
||||
'free' => 'Kostenlos',
|
||||
])
|
||||
->required(),
|
||||
TextInput::make('transaction_id')
|
||||
->label('Transaktions-ID')
|
||||
->maxLength(255),
|
||||
Toggle::make('refunded')
|
||||
->label('Rückerstattet'),
|
||||
Textarea::make('metadata')
|
||||
->label('Metadaten')
|
||||
->json()
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('package.name')
|
||||
->columns([
|
||||
TextColumn::make('package.name')
|
||||
->label('Paket')
|
||||
->badge()
|
||||
->color('success'),
|
||||
TextColumn::make('type')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match($state) {
|
||||
'endcustomer_event' => 'info',
|
||||
'reseller_subscription' => 'success',
|
||||
default => 'gray',
|
||||
}),
|
||||
TextColumn::make('purchased_price')
|
||||
->money('EUR')
|
||||
->sortable(),
|
||||
TextColumn::make('provider_id')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match($state) {
|
||||
'stripe' => 'info',
|
||||
'paypal' => 'warning',
|
||||
'manual' => 'gray',
|
||||
'free' => 'success',
|
||||
}),
|
||||
TextColumn::make('transaction_id')
|
||||
->copyable()
|
||||
->toggleable(),
|
||||
TextColumn::make('metadata')
|
||||
->label('Metadaten')
|
||||
->toggleable(),
|
||||
IconColumn::make('refunded')
|
||||
->boolean()
|
||||
->color(fn (bool $state): string => $state ? 'danger' : 'success'),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('type')
|
||||
->options([
|
||||
'endcustomer_event' => 'Endkunden-Event',
|
||||
'reseller_subscription' => 'Reseller-Abo',
|
||||
]),
|
||||
SelectFilter::make('provider_id')
|
||||
->options([
|
||||
'stripe' => 'Stripe',
|
||||
'paypal' => 'PayPal',
|
||||
'manual' => 'Manuell',
|
||||
'free' => 'Kostenlos',
|
||||
]),
|
||||
SelectFilter::make('refunded')
|
||||
->options([
|
||||
'1' => 'Rückerstattet',
|
||||
'0' => 'Nicht rückerstattet',
|
||||
]),
|
||||
])
|
||||
->headerActions([])
|
||||
->actions([
|
||||
ViewAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user