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
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:
@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
|
|||||||
|
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\VisitorEntry;
|
use App\Models\VisitorEntry;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Pages\Page;
|
use Filament\Pages\Page;
|
||||||
use Filament\Forms\Contracts\HasForms;
|
use Filament\Forms\Contracts\HasForms;
|
||||||
@@ -37,50 +38,172 @@ class GateOutEntry extends Page implements HasForms
|
|||||||
->schema([
|
->schema([
|
||||||
Section::make('') // You can give your section a title or leave it blank
|
Section::make('') // You can give your section a title or leave it blank
|
||||||
->schema([
|
->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')
|
->label('Scan Out Gate Pass')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->visible(fn ($get) => $get('scan_out_gate_pass') == 'Out')
|
||||||
->extraAttributes([
|
->extraAttributes([
|
||||||
'wire:keydown.enter' => 'processGatePass($event.target.value)',
|
'wire:keydown.enter' => 'processGatePassOut($event.target.value)',
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
->columns(5)
|
->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)) {
|
if (!empty($entry->out_time)) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Already Exited')
|
->title('Already Exited')
|
||||||
->body('Gate pass has already been processed. Out time was already punched.')
|
->body('Gate pass has already been processed.')
|
||||||
->warning()
|
->warning()
|
||||||
->send();
|
->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;
|
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{
|
else{
|
||||||
$entry->out_time = now();
|
$entry->out_time = now();
|
||||||
$entry->save();
|
$entry->save();
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Gate Pass Processed')
|
->title('Gate Out')
|
||||||
->body('Gate pass has been successfully processed. Visitor marked as exited.')
|
->body('Visitor marked as exited.')
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,15 @@ class VisitorEntryResource extends Resource
|
|||||||
->numeric()
|
->numeric()
|
||||||
->default(1)
|
->default(1)
|
||||||
->required(),
|
->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')
|
Forms\Components\DateTimePicker::make('in_time')
|
||||||
->label('In Time')
|
->label('In Time')
|
||||||
->required()
|
->required()
|
||||||
@@ -214,6 +223,7 @@ class VisitorEntryResource extends Resource
|
|||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
|
// ->modifyQueryUsing(fn (Builder $query) => $query->whereDate('created_at', today()))
|
||||||
->columns([
|
->columns([
|
||||||
Tables\Columns\TextColumn::make('No.')
|
Tables\Columns\TextColumn::make('No.')
|
||||||
->label('NO')
|
->label('NO')
|
||||||
@@ -290,6 +300,11 @@ class VisitorEntryResource extends Resource
|
|||||||
->searchable()
|
->searchable()
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('mode_of_travel')
|
||||||
|
->label('Mode of Travel')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('in_time')
|
Tables\Columns\TextColumn::make('in_time')
|
||||||
->label('In Time')
|
->label('In Time')
|
||||||
->searchable()
|
->searchable()
|
||||||
@@ -420,9 +435,23 @@ class VisitorEntryResource extends Resource
|
|||||||
])
|
])
|
||||||
->query(function ($query, array $data) {
|
->query(function ($query, array $data) {
|
||||||
// Hide all records initially if no filters are applied
|
// 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'])) {
|
// 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) {
|
// $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'])) {
|
if (! empty($data['register_id'])) {
|
||||||
|
|||||||
@@ -21,37 +21,43 @@ class CreateVisitorEntry extends CreateRecord
|
|||||||
|
|
||||||
public function processMobile($mobile)
|
public function processMobile($mobile)
|
||||||
{
|
{
|
||||||
$visitor = VisitorEntry::where('mobile_number', $mobile)->latest()->first();
|
$registerId = $this->data['register_id'] ?? null;
|
||||||
$registerId = $this->form->getState()['register_id'] ?? '';
|
|
||||||
|
|
||||||
|
$visitor = VisitorEntry::where('mobile_number', $mobile)->latest()->first();
|
||||||
if ($visitor) {
|
if ($visitor) {
|
||||||
|
|
||||||
$employee = EmployeeMaster::where('id', $visitor->employee_master_id)->first();
|
$employee = EmployeeMaster::where('id', $visitor->employee_master_id)->first();
|
||||||
|
|
||||||
$this->form->fill([
|
$this->form->fill([
|
||||||
'register_id' => $registerId,
|
'register_id' => $registerId ?? '',
|
||||||
'mobile_number' => $mobile ?? '',
|
'mobile_number' => $visitor->mobile_number,
|
||||||
'name' => $visitor->name ?? '',
|
'name' => $visitor->name ?? '',
|
||||||
'company' => $visitor->company ?? '',
|
'company' => $visitor->company ?? '',
|
||||||
'type' => $visitor->type ?? '',
|
'type' => $visitor->type ?? '',
|
||||||
'department' => $employee->department ?? '',
|
'department' => $employee?->department ?? '',
|
||||||
'employee_master_id' => $visitor->employee_master_id->name ?? '',
|
'employee_master_id' => $visitor->employee_master_id,
|
||||||
'code' => $employee->code ?? '',
|
'code' => $employee?->code ?? '',
|
||||||
|
'purpose_of_visit' => '',
|
||||||
|
'in_time' => now(),
|
||||||
|
'out_time' => null,
|
||||||
|
'valid_upto' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->form->fill([
|
$this->form->fill([
|
||||||
'register_id' => $registerId,
|
'register_id' => $registerId ?? '',
|
||||||
'mobile_number' => $mobile,
|
'mobile_number' => $mobile,
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'company' => '',
|
'company' => '',
|
||||||
'type' => '',
|
'type' => '',
|
||||||
'department' => '',
|
'department' => '',
|
||||||
'employee_master_id' => null,
|
'employee_master_id' => null,
|
||||||
'code' => '',
|
'code' => '',
|
||||||
|
'purpose_of_visit' => '',
|
||||||
|
'in_time' => now(),
|
||||||
|
'out_time' => null,
|
||||||
|
'valid_upto' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class VisitorEntry extends Model
|
|||||||
'employee_master_id',
|
'employee_master_id',
|
||||||
'number_of_person',
|
'number_of_person',
|
||||||
'valid_upto',
|
'valid_upto',
|
||||||
|
'mode_of_travel',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function employeeMaster(): BelongsTo
|
public function employeeMaster(): BelongsTo
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
// //
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user