Added In and out logic in gate out entry page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Larastan / larastan (pull_request) Failing after 15m44s
Laravel Pint / pint (pull_request) Failing after 15m43s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Larastan / larastan (pull_request) Failing after 15m44s
Laravel Pint / pint (pull_request) Failing after 15m43s
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user