schema([ Forms\Components\Select::make('product_id') ->label('Produkt') ->native(false) ->searchable() ->options(Product::all()->pluck('title', 'id')) ->reactive() ->afterStateUpdated(fn(callable $set) => $set('size_id', null)) ->disabled(fn($record) => !is_null($record)) ->required(), Forms\Components\Select::make('size_id') ->label('Größe') ->native(false) ->options(function (callable $get) { $productId = $get('product_id'); if (!$productId) { return []; } return ProductSize::where('product_id', $productId) ->get() ->mapWithKeys(function ($product) { return [$product->id => "{$product->description} ({$product->price}€)"]; }); }) ->required() ->disabled(fn($record) => !is_null($record)) ->reactive(), TextInput::make('amount') ->label('Verkaufsmenge') ->numeric() ->step(1) ->required() ->disabled(fn($record) => !is_null($record)) ->rules(['min:1']), DatePicker::make('sold_at') ->label('Verkaufsdatum') ->default(now()) ->disabled(fn($record) => !is_null($record)) ->required(), TextInput::make('comment') ->label('Kommentar') ->helperText('Verkaufsquelle (Bsp. Shopify, etc.)'), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('product.title')->label('Produkt'), Tables\Columns\TextColumn::make('size')->label('Größe') ->formatStateUsing(fn(ProductSale $record) => "{$record->size->description} ({$record->size->price}€)"), TextColumn::make('amount')->label('Verkaufsmenge'), TextColumn::make('sold_at')->label('Verkaufsdatum')->date('d.m.Y'), TextColumn::make('comment')->label('Kommentar'), ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), ]) ->emptyStateHeading('Keine Warenausgänge') ->recordUrl(null); } public static function getRelations(): array { return []; } public static function getPages(): array { return [ 'index' => Pages\ListProductSales::route('/'), 'create' => Pages\CreateProductSale::route('/create'), 'edit' => Pages\EditProductSale::route('/{record}/edit'), ]; } public static function getPluralLabel(): string { return 'Warenausgang'; } }