ranjith-dev #325

Merged
jothi merged 8 commits from ranjith-dev into master 2026-02-10 08:49:35 +00:00
Showing only changes of commit 0b231390e3 - Show all commits

View File

@@ -6,6 +6,7 @@ use App\Filament\Exports\CharacteristicApproverMasterExporter;
use App\Filament\Resources\CharacteristicApproverMasterResource\Pages; use App\Filament\Resources\CharacteristicApproverMasterResource\Pages;
use App\Models\CharacteristicApproverMaster; use App\Models\CharacteristicApproverMaster;
use App\Models\Machine; use App\Models\Machine;
use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
@@ -33,26 +34,38 @@ class CharacteristicApproverMasterResource extends Resource
Section::make('') Section::make('')
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant Name')
->columnSpan(2)
->reactive()
->relationship('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() ->required()
->default(function () { ->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) { ->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); $set('updated_by', Filament::auth()->user()?->name);
}), }),
Forms\Components\Select::make('machine_id') Forms\Components\Select::make('machine_id')
->label('Work Center') ->label('Work Center')
->columnSpan(2) ->columnSpan(1)
// ->relationship('machine', 'name') // ->relationship('machine', 'name')
->reactive() ->reactive()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (empty($plantId)) { if (! $plantId) {
return []; return [];
} }
@@ -60,30 +73,76 @@ class CharacteristicApproverMasterResource extends Resource
}) })
->required() ->required()
->default(function () { ->default(function () {
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? []; return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? null;
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('machine_name', null);
$set('approver_type', null);
$set('characteristic_field', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}), }),
Forms\Components\TextInput::make('machine_name') Forms\Components\TextInput::make('machine_name')
->label('Machine') ->label('Machine')
->columnSpan(2) ->columnSpan(1)
->reactive() ->reactive()
->required() ->required()
->minLength(5) ->minLength(5)
->default(function () { ->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) { ->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); $set('updated_by', Filament::auth()->user()?->name);
}), }),
Forms\Components\TextInput::make('characteristic_field') Forms\Components\TextInput::make('characteristic_field')
->label('Master Characteristic Field') ->label('Master Characteristic Field')
->columnSpan(2) ->columnSpan(4)
->reactive() ->reactive()
->required() ->required()
->minLength(1) ->minLength(1)
->default('NIL') ->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : 'NIL';
})
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
if (strtolower($state) == 'nil' || $state == '' || $state == null) { if (strtolower($state) == 'nil' || $state == '' || $state == null) {
$set('characteristic_field', 'NIL'); $set('characteristic_field', 'NIL');
@@ -233,6 +292,11 @@ class CharacteristicApproverMasterResource extends Resource
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approver_type')
->label('Approver Type')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('characteristic_field') Tables\Columns\TextColumn::make('characteristic_field')
->label('Master Characteristic Field') ->label('Master Characteristic Field')
->alignCenter() ->alignCenter()