Added approver_type column on resource file and updated some validations
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Filament\Exports\CharacteristicApproverMasterExporter;
|
||||
use App\Filament\Resources\CharacteristicApproverMasterResource\Pages;
|
||||
use App\Models\CharacteristicApproverMaster;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
@@ -33,26 +34,38 @@ class CharacteristicApproverMasterResource extends Resource
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->columnSpan(2)
|
||||
->reactive()
|
||||
->label('Plant Name')
|
||||
->relationship('plant', 'name')
|
||||
->columnSpan(1)
|
||||
->reactive()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required()
|
||||
->default(function () {
|
||||
return optional(CharacteristicApproverMaster::latest()->first())->plant_id;
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : optional(CharacteristicApproverMaster::latest()->first())->plant_id ?? null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
$set('machine_id', null);
|
||||
$set('machine_name', null);
|
||||
$set('approver_type', null);
|
||||
$set('characteristic_field', null);
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\Select::make('machine_id')
|
||||
->label('Work Center')
|
||||
->columnSpan(2)
|
||||
->columnSpan(1)
|
||||
// ->relationship('machine', 'name')
|
||||
->reactive()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (empty($plantId)) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -60,30 +73,76 @@ class CharacteristicApproverMasterResource extends Resource
|
||||
})
|
||||
->required()
|
||||
->default(function () {
|
||||
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? [];
|
||||
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
$set('machine_name', null);
|
||||
$set('approver_type', null);
|
||||
$set('characteristic_field', null);
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('machine_name')
|
||||
->label('Machine')
|
||||
->columnSpan(2)
|
||||
->columnSpan(1)
|
||||
->reactive()
|
||||
->required()
|
||||
->minLength(5)
|
||||
->default(function () {
|
||||
return optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? '';
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
if (! $state) {
|
||||
$set('approver_type', null);
|
||||
$set('characteristic_field', null);
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\Select::make('approver_type')
|
||||
->label('Request Type')
|
||||
->columnSpan(1)
|
||||
->reactive()
|
||||
->nullable()
|
||||
->searchable()
|
||||
->required()
|
||||
->options(function (callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$machineId = $get('machine_id');
|
||||
$machineName = $get('machine_name');
|
||||
|
||||
if (! $plantId || ! $machineId || ! $machineName) {
|
||||
$set('characteristic_field', null);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'Characteristic' => 'Characteristic',
|
||||
'Quality' => 'Quality',
|
||||
];
|
||||
})
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : 'Characteristic';
|
||||
// return optional(CharacteristicApproverMaster::latest()->first())->approver_type ?? null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
$set('characteristic_field', null);
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('characteristic_field')
|
||||
->label('Master Characteristic Field')
|
||||
->columnSpan(2)
|
||||
->columnSpan(4)
|
||||
->reactive()
|
||||
->required()
|
||||
->minLength(1)
|
||||
->default('NIL')
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : 'NIL';
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
if (strtolower($state) == 'nil' || $state == '' || $state == null) {
|
||||
$set('characteristic_field', 'NIL');
|
||||
@@ -233,6 +292,11 @@ class CharacteristicApproverMasterResource extends Resource
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approver_type')
|
||||
->label('Approver Type')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('characteristic_field')
|
||||
->label('Master Characteristic Field')
|
||||
->alignCenter()
|
||||
|
||||
Reference in New Issue
Block a user