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\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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user