Deploy / deploy (push) Successful in 16s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
111 lines
3.8 KiB
PHP
111 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\User\Resources;
|
|
|
|
use App\Traits\EnforcesRoles;
|
|
use App\Filament\User\Resources\SpiceResource\Pages;
|
|
use App\Filament\User\Resources\SpiceResource\RelationManagers;
|
|
use App\Models\Spice;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Get;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class SpiceResource extends Resource
|
|
{
|
|
use EnforcesRoles;
|
|
protected static ?string $model = Spice::class;
|
|
protected static ?string $navgationLabel = 'Rohstoffe';
|
|
protected static ?string $modelLabel = 'Rohstoff';
|
|
protected static ?string $slug = 'rohstoffe';
|
|
protected static ?string $navigationGroup = 'Lager';
|
|
|
|
public static function shouldRegisterNavigation(): bool
|
|
{
|
|
return auth()->user()?->hasRole('sms-admin') ?? false;
|
|
}
|
|
protected static ?string $navigationIcon = 'heroicon-o-cube';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\TextInput::make('name')
|
|
->required()
|
|
->maxLength(255),
|
|
Forms\Components\Select::make('unit')
|
|
->label('Mengeneinheit')
|
|
->native(false)
|
|
->searchable()
|
|
->live()
|
|
->options([
|
|
'grams' => '(Kilo-)Gramm',
|
|
'pieces' => 'Stück',
|
|
'liter' => 'Liter',
|
|
])
|
|
->required(),
|
|
Forms\Components\TextInput::make('piece_weight')
|
|
->label('Ø Stückgewicht (g)')
|
|
->numeric()
|
|
->suffix('g')
|
|
->required(fn (Get $get) => $get('unit') === 'pieces')
|
|
->helperText('Wird als Fallback verwendet, wenn bei einer Lieferung kein Gesamtgewicht angegeben wird. Bei Lieferungen mit Gewichtsangabe wird dieser Wert automatisch als gleitender Durchschnitt aktualisiert.')
|
|
->visible(fn (Get $get) => $get('unit') === 'pieces'),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('name')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('unit')
|
|
->label('Einheit')
|
|
->formatStateUsing(fn ($state) => match($state) {
|
|
'grams' => '(Kilo-)Gramm',
|
|
'pieces' => 'Stück',
|
|
'liter' => 'Liter',
|
|
default => ucfirst($state),
|
|
}),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\DeleteAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\StockMovementsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListSpices::route('/'),
|
|
'create' => Pages\CreateSpice::route('/create'),
|
|
'view' => Pages\ViewSpice::route('/{record}'),
|
|
'edit' => Pages\EditSpice::route('/{record}/edit'),
|
|
];
|
|
}
|
|
public static function getPluralLabel(): string
|
|
{
|
|
return 'Rohstoffe'; // Setze hier deinen eigenen Pluralbegriff ein
|
|
}
|
|
}
|