122 lines
3.9 KiB
PHP
122 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\User\Resources;
|
|
|
|
use App\Filament\User\Resources\SpiceSupplierResource\Pages;
|
|
use App\Filament\User\Resources\SpiceSupplierResource\RelationManagers;
|
|
use App\Models\SpiceSupplier;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
|
|
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
class SpiceSupplierResource extends Resource
|
|
{
|
|
protected static ?string $model = SpiceSupplier::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-arrow-down-on-square';
|
|
|
|
protected static ?string $navgationLabel = 'Rohstofflieferungen';
|
|
protected static ?string $modelLabel = 'Rohstofflieferungen';
|
|
protected static ?string $slug = 'rohstofflieferung';
|
|
protected static ?string $navigationGroup = 'Waren Ein/Ausgang';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Select::make('spice_id')
|
|
->label('Rohstoff')
|
|
->relationship('spice', 'name')
|
|
->required()
|
|
->preload()
|
|
->searchable(),
|
|
Select::make('supplier_id')
|
|
->label('Lieferant')
|
|
->relationship('supplier', 'name')
|
|
->required()
|
|
->preload()
|
|
->searchable(),
|
|
|
|
TextInput::make('amount')
|
|
->label('Liefermenge')
|
|
->numeric()
|
|
->required()
|
|
->rules(['min:0.01'])
|
|
->disabled(fn($record) => !is_null($record)),
|
|
|
|
DatePicker::make('supplied_at')
|
|
->label('Lieferdatum')
|
|
->default(now())
|
|
->required(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('spice.name')->label('Rohstoff')->searchable(),
|
|
TextColumn::make('supplier.name')->label('Lieferant')->searchable(),
|
|
TextColumn::make('amount')->label('Liefermenge'),
|
|
TextColumn::make('supplied_at')->label('Lieferdatum')->date('d.m.Y'), // Lieferdatum in der Tabelle anzeigen
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]);
|
|
}
|
|
|
|
protected static function getTableActions(): array
|
|
{
|
|
return [
|
|
DeleteAction::make()
|
|
->before(function ($record, DeleteAction $action) {
|
|
// Custom check logic
|
|
|
|
if (true) {
|
|
// Notify user about the restriction
|
|
Notification::make()
|
|
->title('Deletion Error')
|
|
->body("This record cannot be deleted because it has related records.")
|
|
->status('danger')
|
|
->send();
|
|
|
|
// Cancel the deletion
|
|
$action->cancel();
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListSpiceSuppliers::route('/'),
|
|
'create' => Pages\CreateSpiceSupplier::route('/create'),
|
|
'edit' => Pages\EditSpiceSupplier::route('/{record}/edit'),
|
|
];
|
|
}
|
|
public static function getPluralLabel(): string
|
|
{
|
|
return 'Rohstofflieferungen';
|
|
}
|
|
}
|