Added id column to load default plant, line, machine with its validation and using motor_testing_master_id instead of item_id remove item_id functionality
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\Configuration;
|
|||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
use App\Models\Machine;
|
use App\Models\Machine;
|
||||||
|
use App\Models\MotorTestingMaster;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\QualityValidation;
|
use App\Models\QualityValidation;
|
||||||
use App\Models\StickerMaster;
|
use App\Models\StickerMaster;
|
||||||
@@ -22,6 +23,7 @@ use Filament\Forms\Components\DateTimePicker;
|
|||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\BulkAction;
|
use Filament\Tables\Actions\BulkAction;
|
||||||
@@ -46,17 +48,40 @@ class TestingPanelReadingResource extends Resource
|
|||||||
return $form
|
return $form
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Select::make('plant_id')
|
Forms\Components\Select::make('plant_id')
|
||||||
|
->label('Plant')
|
||||||
->relationship('plant', 'name')
|
->relationship('plant', 'name')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
// When plant changes, reset the dependent fields
|
// When plant changes, reset the dependent fields
|
||||||
->afterStateUpdated(function (callable $set) {
|
->default(function () {
|
||||||
|
return optional(TestingPanelReading::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (!$plantId) {
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
}),
|
$set('tPrError', 'Please select a plant first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('item_id', null);
|
||||||
|
$set('machine_id', null);
|
||||||
|
$set('tPrError', null);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('tPrError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null)
|
||||||
|
->hintColor('danger'),
|
||||||
Forms\Components\Select::make('line_id')
|
Forms\Components\Select::make('line_id')
|
||||||
->label('Line')
|
->label('Line')
|
||||||
|
->relationship('line', 'name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (!$plantId) {
|
||||||
@@ -66,26 +91,16 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
|
->default(function () {
|
||||||
|
return optional(TestingPanelReading::latest()->first())->line_id;
|
||||||
|
})
|
||||||
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(fn (callable $set) => $set('item_id', null)),
|
->afterStateUpdated(fn (callable $set) => $set('item_id', null)),
|
||||||
Forms\Components\Select::make('item_id')
|
|
||||||
->label('Item')
|
|
||||||
->options(function (callable $get) {
|
|
||||||
$plantId = $get('plant_id');
|
|
||||||
if (!$plantId) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
// Adjust this query as per your item-plant relationship
|
|
||||||
return Item::where('plant_id', $plantId)
|
|
||||||
->pluck('code', 'id')
|
|
||||||
->toArray();
|
|
||||||
})
|
|
||||||
->required()
|
|
||||||
->searchable()
|
|
||||||
->reactive(),
|
|
||||||
Forms\Components\Select::make('machine_id')
|
Forms\Components\Select::make('machine_id')
|
||||||
->label('Machine')
|
->label('Machine')
|
||||||
|
->relationship('machine', 'name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
if (!$lineId) {
|
if (!$lineId) {
|
||||||
@@ -96,8 +111,33 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
|
->default(function () {
|
||||||
|
return optional(TestingPanelReading::latest()->first())->machine_id;
|
||||||
|
})
|
||||||
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
->required()
|
->required()
|
||||||
->reactive(),
|
->reactive(),
|
||||||
|
Forms\Components\Select::make('motor_testing_master_id')
|
||||||
|
->label('Item Code')
|
||||||
|
->relationship('motorTestingMaster', 'item.code')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// return MotorTestingMaster::with('item')
|
||||||
|
// ->whereHas('motorTestingMasters', function ($query) use ($plantId) {
|
||||||
|
// $query->where('plant_id', $plantId);
|
||||||
|
// })->pluck('item.code', 'id')->toArray();
|
||||||
|
// // ->get();
|
||||||
|
|
||||||
|
return Item::where('plant_id', $plantId)->whereHas('motorTestingMasters')->pluck('code', 'id')->toArray();
|
||||||
|
// return Item::whereHas('motorTestingMasters')->pluck('code', 'id')->toArray();
|
||||||
|
})
|
||||||
|
->required()
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
Forms\Components\TextInput::make('output')
|
Forms\Components\TextInput::make('output')
|
||||||
->label('Output')
|
->label('Output')
|
||||||
->required(),
|
->required(),
|
||||||
@@ -190,7 +230,9 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->label('Tested By'),
|
->label('Tested By'),
|
||||||
Forms\Components\TextInput::make('updated_by')
|
Forms\Components\TextInput::make('updated_by')
|
||||||
->label('Updated By'),
|
->label('Updated By'),
|
||||||
|
Forms\Components\TextInput::make('id')
|
||||||
|
->hidden()
|
||||||
|
->readOnly(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,13 +474,15 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
$query = Item::query();
|
return Item::where('plant_id', $plantId)->whereHas('motorTestingMasters')->pluck('code', 'id')->toArray();
|
||||||
|
|
||||||
if ($plantId) {
|
// $query = Item::query();
|
||||||
$query->where('plant_id', $plantId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->pluck('code', 'id')->toArray();
|
// if ($plantId) {
|
||||||
|
// $query->where('plant_id', $plantId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $query->pluck('code', 'id')->toArray();
|
||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
Select::make('machine_name')
|
Select::make('machine_name')
|
||||||
|
|||||||
Reference in New Issue
Block a user