172 lines
6.2 KiB
PHP
172 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Imports\ProductionPlanImporter;
|
|
use App\Filament\Resources\ProductionPlanResource\Pages;
|
|
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
|
|
use App\Models\ProductionPlan;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Actions\ImportAction;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class ProductionPlanResource extends Resource
|
|
{
|
|
protected static ?string $model = ProductionPlan::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
// protected static ?string $navigationParentItem = 'Production Line Stops';
|
|
|
|
protected static ?string $navigationGroup = 'Production';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Select::make('plant_id')
|
|
->relationship('plant', 'name')
|
|
->required()
|
|
->nullable()
|
|
->reactive(),
|
|
Forms\Components\Select::make('block_name')
|
|
->required()
|
|
->nullable()
|
|
->reactive()
|
|
->afterStateUpdated(fn ($set) => $set('shift_id', null)),
|
|
Forms\Components\Select::make('shift_id')
|
|
->relationship('shift', 'name')
|
|
->required()
|
|
->nullable()
|
|
// ->options(fn (callable $get) =>
|
|
// \App\Models\Shift::where('plant_id', $get('plant_id'))
|
|
// ->pluck('name', 'id')
|
|
// ->toArray() // Convert collection to array
|
|
// )
|
|
->options(function (callable $get) {
|
|
if (!$get('plant_id')) {
|
|
return [];
|
|
}
|
|
|
|
return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
|
->pluck('name', 'id')
|
|
->toArray();
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(fn ($set) => $set('line_id', null)),
|
|
Forms\Components\Select::make('line_id')
|
|
->relationship('line', 'name')
|
|
->required()
|
|
->nullable()
|
|
// ->options(fn (callable $get) =>
|
|
// \App\Models\Line::where('plant_id', $get('plant_id'))
|
|
// ->pluck('name', 'id')
|
|
// ->toArray() // Convert collection to array
|
|
// )
|
|
->options(function (callable $get) {
|
|
if (!$get('plant_id')) {
|
|
return [];
|
|
}
|
|
|
|
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
|
->pluck('name', 'id')
|
|
->toArray();
|
|
})
|
|
->reactive(),
|
|
Forms\Components\TextInput::make('plan_quantity')
|
|
->required()
|
|
->numeric()
|
|
->minValue(1),
|
|
Forms\Components\TextInput::make('production_quantity')
|
|
->required()
|
|
->numeric()
|
|
->readOnly()
|
|
->default(0),
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('ID')
|
|
->numeric()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('plan_quantity')
|
|
->numeric()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('production_quantity')
|
|
->numeric()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('line.name')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('shift.name')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('plant.name')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
Tables\Filters\TrashedFilter::make(),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
|
Tables\Actions\RestoreBulkAction::make(),
|
|
]),
|
|
])
|
|
->headerActions([
|
|
ImportAction::make()
|
|
->importer(ProductionPlanImporter::class),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListProductionPlans::route('/'),
|
|
'create' => Pages\CreateProductionPlan::route('/create'),
|
|
'view' => Pages\ViewProductionPlan::route('/{record}'),
|
|
'edit' => Pages\EditProductionPlan::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|