geschenkgutscheine implementiert ("Paket verschenken"). Neuer Upload-Provider: Sparkbooth.
This commit is contained in:
109
app/Filament/Resources/GiftVoucherResource.php
Normal file
109
app/Filament/Resources/GiftVoucherResource.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\GiftVoucherResource\Pages;
|
||||
use App\Models\GiftVoucher;
|
||||
use App\Services\GiftVouchers\GiftVoucherService;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class GiftVoucherResource extends Resource
|
||||
{
|
||||
protected static ?string $model = GiftVoucher::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-gift';
|
||||
|
||||
protected static ?int $navigationSort = 12;
|
||||
|
||||
public static function getNavigationGroup(): UnitEnum|string|null
|
||||
{
|
||||
return __('admin.nav.billing');
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('code')
|
||||
->label('Code')
|
||||
->searchable()
|
||||
->copyable(),
|
||||
TextColumn::make('amount')
|
||||
->label('Betrag')
|
||||
->money(fn (GiftVoucher $record) => $record->currency ?? 'EUR'),
|
||||
BadgeColumn::make('status')
|
||||
->label('Status')
|
||||
->colors([
|
||||
'success' => GiftVoucher::STATUS_REDEEMED,
|
||||
'warning' => GiftVoucher::STATUS_ISSUED,
|
||||
'danger' => [GiftVoucher::STATUS_REFUNDED, GiftVoucher::STATUS_EXPIRED],
|
||||
]),
|
||||
TextColumn::make('purchaser_email')
|
||||
->label('Käufer')
|
||||
->toggleable()
|
||||
->searchable(),
|
||||
TextColumn::make('recipient_email')
|
||||
->label('Empfänger')
|
||||
->toggleable()
|
||||
->searchable(),
|
||||
TextColumn::make('paddle_transaction_id')
|
||||
->label('Paddle Tx')
|
||||
->toggleable()
|
||||
->copyable()
|
||||
->wrap(),
|
||||
TextColumn::make('expires_at')
|
||||
->label('Gültig bis')
|
||||
->dateTime(),
|
||||
TextColumn::make('redeemed_at')
|
||||
->label('Eingelöst am')
|
||||
->dateTime(),
|
||||
TextColumn::make('refunded_at')
|
||||
->label('Erstattet am')
|
||||
->dateTime(),
|
||||
TextColumn::make('created_at')
|
||||
->label('Erstellt')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->options([
|
||||
GiftVoucher::STATUS_ISSUED => 'Ausgestellt',
|
||||
GiftVoucher::STATUS_REDEEMED => 'Eingelöst',
|
||||
GiftVoucher::STATUS_REFUNDED => 'Erstattet',
|
||||
GiftVoucher::STATUS_EXPIRED => 'Abgelaufen',
|
||||
]),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('refund')
|
||||
->label('Refund')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (GiftVoucher $record): bool => $record->canBeRefunded())
|
||||
->action(function (GiftVoucher $record, GiftVoucherService $service): void {
|
||||
$service->refund($record, 'customer_request');
|
||||
})
|
||||
->successNotificationTitle('Gutschein erstattet'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->schema([]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListGiftVouchers::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user