-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathPluginSalesResource.php
More file actions
122 lines (98 loc) · 3.71 KB
/
PluginSalesResource.php
File metadata and controls
122 lines (98 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PluginSalesResource\Pages;
use App\Filament\Resources\PluginSalesResource\Widgets\PluginSalesStats;
use App\Models\PluginLicense;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class PluginSalesResource extends Resource
{
protected static ?string $model = PluginLicense::class;
protected static ?string $navigationIcon = 'heroicon-o-banknotes';
protected static ?string $navigationLabel = 'Sales';
protected static ?string $navigationGroup = 'Products';
protected static ?int $navigationSort = 3;
protected static ?string $modelLabel = 'Sale';
protected static ?string $pluralModelLabel = 'Sales';
protected static ?string $slug = 'plugin-sales';
public static function form(Form $form): Form
{
return $form->schema([]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('purchased_at')
->label('Date')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('user.email')
->label('User')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('plugin.name')
->label('Plugin')
->searchable()
->sortable()
->fontFamily('mono'),
Tables\Columns\TextColumn::make('pluginBundle.name')
->label('Bundle')
->placeholder('-')
->sortable(),
Tables\Columns\TextColumn::make('price_paid')
->label('Amount')
->formatStateUsing(fn (int $state, PluginLicense $record): string => '$'.number_format($state / 100, 2).' '.$record->currency)
->sortable(),
Tables\Columns\IconColumn::make('is_grandfathered')
->label('Grandfathered')
->boolean()
->sortable(),
])
->filters([
Tables\Filters\SelectFilter::make('user_id')
->label('User')
->relationship('user', 'email', fn (Builder $query) => $query->whereNotNull('email'))
->searchable()
->preload(),
Tables\Filters\SelectFilter::make('plugin_id')
->label('Plugin')
->relationship('plugin', 'name', fn (Builder $query) => $query->whereNotNull('name'))
->searchable()
->preload(),
Tables\Filters\SelectFilter::make('plugin_bundle_id')
->label('Bundle')
->relationship('pluginBundle', 'name', fn (Builder $query) => $query->whereNotNull('name'))
->searchable()
->preload(),
Tables\Filters\TernaryFilter::make('is_grandfathered')
->label('Grandfathered'),
])
->actions([])
->bulkActions([])
->defaultSort('purchased_at', 'desc');
}
public static function getRelations(): array
{
return [];
}
public static function getWidgets(): array
{
return [
PluginSalesStats::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPluginSales::route('/'),
];
}
public static function canCreate(): bool
{
return false;
}
}