Merge pull request 'ranjith-dev' (#733) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s

Reviewed-on: #733
This commit was merged in pull request #733.
This commit is contained in:
2026-06-09 05:54:12 +00:00
5 changed files with 228 additions and 38 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
use App\Models\Plant;
use App\Models\VisitorEntry;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Pages\Page;
use Filament\Forms\Contracts\HasForms;
@@ -37,50 +38,172 @@ class GateOutEntry extends Page implements HasForms
->schema([
Section::make('') // You can give your section a title or leave it blank
->schema([
TextInput::make('scan_out_gate_pass')
Select::make('scan_out_gate_pass')
->label('Scan Gate Pass')
->required()
->reactive()
->options([
'In' => 'In',
'Out' => 'Out',
]),
TextInput::make('scan_out_gate_pass_in')
->label('Scan In Gate Pass')
->required()
->reactive()
->visible(fn ($get) => $get('scan_out_gate_pass') == 'In')
->extraAttributes([
'wire:keydown.enter' => 'processGatePassIn($event.target.value)',
]),
TextInput::make('scan_out_gate_pass_out')
->label('Scan Out Gate Pass')
->required()
->reactive()
->visible(fn ($get) => $get('scan_out_gate_pass') == 'Out')
->extraAttributes([
'wire:keydown.enter' => 'processGatePass($event.target.value)',
'wire:keydown.enter' => 'processGatePassOut($event.target.value)',
]),
])
->columns(5)
]);
}
public function processGatePass($gatePass)
public function processGatePassIn($gatePass)
{
$entry = VisitorEntry::where('register_id', $gatePass)->first();
$entry = VisitorEntry::where('register_id', $gatePass)->latest()->first();
if ($entry) {
if ($entry)
{
if($entry->in_time && !$entry->out_time && (empty($entry->valid_upto) || $entry->valid_upto == '' || $entry->valid_upto == null)){
Notification::make()
->title('Already Entered')
->body('Gate pass In has already been processed for entry.')
->warning()
->send();
$this->filters['scan_out_gate_pass_in'] = '';
return;
}
elseif (
!empty($entry->valid_upto) &&
Carbon::parse($entry->valid_upto)->endOfDay()->gte(now())
){
if (empty($entry->out_time)) {
Notification::make()
->title('Gate In Not Allowed')
->body("Previous gate-out has not been punched. Please complete gate-out first for ID ' . $gatePass . '.")
->warning()
->send();
$this->filters['scan_out_gate_pass_in'] = '';
return;
}
else{
$newEntry = $entry->replicate();
$newEntry->in_time = now();
$newEntry->out_time = null;
$newEntry->save();
Notification::make()
->title('Gate In')
->body('Gate in has been successfully processed. Visitor marked as entered.')
->success()
->send();
$this->filters['scan_out_gate_pass_in'] = '';
}
}
else{
Notification::make()
->title('Visitor Pass Expired')
->body('Your visitor pass validity has expired.')
->danger()
->send();
$this->filters['scan_out_gate_pass_in'] = '';
return;
}
}
else
{
Notification::make()
->title('Invalid Gate Pass')
->body('Scanned gate in pass is not valid.')
->danger()
->send();
return;
}
}
public function processGatePassOut($gatePass)
{
$entry = VisitorEntry::where('register_id', $gatePass)->latest()->first();
if (!$entry) {
Notification::make()
->title('Invalid Gate Pass')
->body('Scanned gate out pass is not valid.')
->danger()
->send();
$this->filters['scan_out_gate_pass_out'] = '';
return;
}
if (empty($entry->valid_upto) || $entry->valid_upto == '' || $entry->valid_upto == null) {
if (!empty($entry->out_time)) {
Notification::make()
->title('Already Exited')
->body('Gate pass has already been processed. Out time was already punched.')
->body('Gate pass has already been processed.')
->warning()
->send();
$this->filters['scan_out_gate_pass'] = '';
$this->filters['scan_out_gate_pass_out'] = '';
return;
}
else
{
$entry->out_time = now();
$entry->save();
Notification::make()
->title('Gate Pass Processed')
->body('Visitor marked as exited.')
->success()
->send();
$this->filters['scan_out_gate_pass_out'] = '';
return;
}
}
elseif ((empty($entry->valid_upto) || $entry->valid_upto != '' || $entry->valid_upto != null))
{
if (Carbon::parse($entry->valid_upto)->endOfDay()->lt(now()))
{
Notification::make()
->title('Visitor Pass Expired')
->body('Your visitor pass validity has expired.')
->danger()
->send();
$this->filters['scan_out_gate_pass_out'] = '';
return;
}
if (!empty($entry->out_time)) {
Notification::make()
->title('Already Exited')
->body('Gate pass has already been processed.')
->warning()
->send();
$this->filters['scan_out_gate_pass_out'] = '';
return;
}
else{
$entry->out_time = now();
$entry->save();
Notification::make()
->title('Gate Pass Processed')
->body('Gate pass has been successfully processed. Visitor marked as exited.')
->title('Gate Out')
->body('Visitor marked as exited.')
->success()
->send();
$this->filters['scan_out_gate_pass'] = '';
$this->filters['scan_out_gate_pass_out'] = '';
}
} else {
Notification::make()
->title('Invalid Gate Pass')
->body('The scanned gate pass is not valid. Please try again.')
->danger()
->send();
}
}

View File

@@ -187,6 +187,15 @@ class VisitorEntryResource extends Resource
->numeric()
->default(1)
->required(),
Forms\Components\Select::make('mode_of_travel')
->label('Mode of Travel')
->options([
'Rental' => 'Rental',
'Car' => 'Car',
'Bike' => 'Bike',
])
->reactive()
->placeholder('Select Mode of Travel'),
Forms\Components\DateTimePicker::make('in_time')
->label('In Time')
->required()
@@ -214,6 +223,7 @@ class VisitorEntryResource extends Resource
public static function table(Table $table): Table
{
return $table
// ->modifyQueryUsing(fn (Builder $query) => $query->whereDate('created_at', today()))
->columns([
Tables\Columns\TextColumn::make('No.')
->label('NO')
@@ -290,6 +300,11 @@ class VisitorEntryResource extends Resource
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('mode_of_travel')
->label('Mode of Travel')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('in_time')
->label('In Time')
->searchable()
@@ -420,9 +435,23 @@ class VisitorEntryResource extends Resource
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['register_id']) && empty($data['type']) && empty($data['name']) && empty($data['company']) && empty($data['employee_master_id']) && empty($data['created_from']) && empty($data['created_to'])) {
$query->where(function ($q) {
});
// if (empty($data['register_id']) && empty($data['type']) && empty($data['name']) && empty($data['company']) && empty($data['employee_master_id']) && empty($data['created_from']) && empty($data['created_to'])) {
// $query->where(function ($q) {
// });
// }
$hasAnyFilter = !empty($data['register_id'])
|| !empty($data['type'])
|| !empty($data['name'])
|| !empty($data['company'])
|| !empty($data['employee_master_id'])
|| !empty($data['employee_department'])
|| !empty($data['created_from'])
|| !empty($data['created_to']);
if (!$hasAnyFilter) {
$query->whereDate('created_at', today());
return;
}
if (! empty($data['register_id'])) {

View File

@@ -21,37 +21,43 @@ class CreateVisitorEntry extends CreateRecord
public function processMobile($mobile)
{
$visitor = VisitorEntry::where('mobile_number', $mobile)->latest()->first();
$registerId = $this->form->getState()['register_id'] ?? '';
$registerId = $this->data['register_id'] ?? null;
$visitor = VisitorEntry::where('mobile_number', $mobile)->latest()->first();
if ($visitor) {
$employee = EmployeeMaster::where('id', $visitor->employee_master_id)->first();
$this->form->fill([
'register_id' => $registerId,
'mobile_number' => $mobile ?? '',
'name' => $visitor->name ?? '',
'company' => $visitor->company ?? '',
'type' => $visitor->type ?? '',
'department' => $employee->department ?? '',
'employee_master_id' => $visitor->employee_master_id->name ?? '',
'code' => $employee->code ?? '',
'register_id' => $registerId ?? '',
'mobile_number' => $visitor->mobile_number,
'name' => $visitor->name ?? '',
'company' => $visitor->company ?? '',
'type' => $visitor->type ?? '',
'department' => $employee?->department ?? '',
'employee_master_id' => $visitor->employee_master_id,
'code' => $employee?->code ?? '',
'purpose_of_visit' => '',
'in_time' => now(),
'out_time' => null,
'valid_upto' => null,
]);
}
else {
$this->form->fill([
'register_id' => $registerId,
'mobile_number' => $mobile,
'name' => '',
'company' => '',
'type' => '',
'department' => '',
'register_id' => $registerId ?? '',
'mobile_number' => $mobile,
'name' => '',
'company' => '',
'type' => '',
'department' => '',
'employee_master_id' => null,
'code' => '',
'code' => '',
'purpose_of_visit' => '',
'in_time' => now(),
'out_time' => null,
'valid_upto' => null,
]);
return;
}
}

View File

@@ -23,6 +23,7 @@ class VisitorEntry extends Model
'employee_master_id',
'number_of_person',
'valid_upto',
'mode_of_travel',
];
public function employeeMaster(): BelongsTo

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$sql1 = <<<'SQL'
ALTER TABLE visitor_entries
ADD COLUMN mode_of_travel TEXT DEFAULT NULL
SQL;
DB::statement($sql1);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// Schema::table('visitor_entries', function (Blueprint $table) {
// //
// });
}
};