Added inter unit staff logic in visitor entry page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 1m15s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 2m4s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 1m3s
Laravel Pint / pint (pull_request) Successful in 3m0s
Laravel Larastan / larastan (pull_request) Failing after 4m25s

This commit is contained in:
dhanabalan
2026-07-19 10:05:01 +05:30
parent 107d356745
commit fe5630e7b0

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource\RelationManagers;
use App\Models\VisitorEntry;
use App\Models\EmployeeMaster;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
@@ -63,6 +64,47 @@ class VisitorEntryResource extends Resource
return $prefix . $nextNumber;
})
->readOnly(),
Forms\Components\Select::make('inter_unit')
->label('Inter Unit Staff Code')
->options(
EmployeeMaster::distinct()
->orderBy('code')
->pluck('code', 'code')
)
->searchable()
->reactive()
->afterStateUpdated(function (callable $set, callable $get, $state) {
$code = $get('inter_unit');
if($code){
$employeeExist = EmployeeMaster::where('code', $code)->first();
$plantId = $employeeExist->plant_id;
$plant = Plant::find($plantId);
if ($employeeExist) {
$set('name', $employeeExist->name);
$set('mobile_number', $employeeExist->mobile_number);
$set('company', $plant->name);
$set('type', 'InterUnitStaff');
} else {
$set('name', null);
$set('mobile_number', null);
$set('company', null);
$set('type', null);
}
}
else
{
$set('name', null);
$set('mobile_number', null);
$set('company', null);
$set('type', null);
}
}),
Forms\Components\TextInput::make('mobile_number')
->label('Mobile Number')
->length(10)
@@ -72,6 +114,7 @@ class VisitorEntryResource extends Resource
'maxlength' => 10,
])
->required()
->readOnly(fn (callable $get) => filled($get('inter_unit')))
->extraAttributes([
'id' => 'mobile_number_input',
'x-data' => '{ value: "" }',
@@ -82,9 +125,14 @@ class VisitorEntryResource extends Resource
->label('Name')
->required()
->reactive()
->readOnly(fn (callable $get) => filled($get('inter_unit')))
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^a-zA-Z\s]/g, "")',
]),
Forms\Components\TextInput::make('company')
->label('Company')
->readOnly(fn (callable $get) => filled($get('inter_unit')))
->required(),
Forms\Components\Select::make('type')
->label('Type')
->reactive()
@@ -92,6 +140,7 @@ class VisitorEntryResource extends Resource
'Student' => 'Student',
'Consultant' => 'Consultant',
'Supplier' => 'Supplier',
'InterUnitStaff' => 'Inter Unit Staff',
'InterviewCandidates' => 'Interview Candidates',
'Customers/Dealers' => 'Customers/Dealers',
'Bankers' => 'Bankers',
@@ -104,6 +153,24 @@ class VisitorEntryResource extends Resource
return $state == 'Other'
? $get('other_type')
: $state;
})
->afterStateUpdated(function (callable $set, callable $get, $state) {
$code = $get('inter_unit');
if($code){
$set('inter_unit', null);
$set('name', null);
$set('mobile_number', null);
$set('company', null);
}
else
{
$set('inter_unit', null);
$set('name', null);
$set('mobile_number', null);
$set('company', null);
}
}),
Forms\Components\TextInput::make('other_type')
->label('Specify Type')
@@ -111,9 +178,6 @@ class VisitorEntryResource extends Resource
->visible(fn (callable $get) => $get('type') == 'Other')
->required(fn (callable $get) => $get('type') == 'Other')
->dehydrated(false),
Forms\Components\TextInput::make('company')
->label('Company')
->required(),
Forms\Components\Select::make('department')
->label('Employee Department')
->options(