Added two columns in visitor entry resource page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -17,6 +17,7 @@ use Filament\Infolists\Infolist;
|
||||
use Filament\Infolists\Components\ImageEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Components\Section;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class VisitorEntryResource extends Resource
|
||||
{
|
||||
@@ -24,10 +25,35 @@ class VisitorEntryResource extends Resource
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Gate Entry';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('register_id')
|
||||
->label('Register ID')
|
||||
->default(function () {
|
||||
|
||||
$datePart = Carbon::now()->format('ymd'); // 260527
|
||||
|
||||
$prefix = 'CRI' . $datePart . 'V';
|
||||
|
||||
// Get latest record for today
|
||||
$lastRecord = VisitorEntry::where('register_id', 'like', $prefix . '%')
|
||||
->latest('id')
|
||||
->first();
|
||||
|
||||
if ($lastRecord) {
|
||||
$lastNumber = (int) substr($lastRecord->register_id, -3);
|
||||
$nextNumber = str_pad($lastNumber + 1, 3, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
$nextNumber = '001';
|
||||
}
|
||||
|
||||
return $prefix . $nextNumber;
|
||||
})
|
||||
->readOnly(),
|
||||
Forms\Components\TextInput::make('mobile_number')
|
||||
->label('Mobile Number')
|
||||
->length(10)
|
||||
@@ -140,9 +166,17 @@ class VisitorEntryResource extends Resource
|
||||
->default(1)
|
||||
->required(),
|
||||
Forms\Components\DateTimePicker::make('in_time')
|
||||
->label('In Time'),
|
||||
->label('In Time')
|
||||
->required()
|
||||
->default(now()),
|
||||
Forms\Components\DateTimePicker::make('out_time')
|
||||
->label('Out Time'),
|
||||
Forms\Components\DateTimePicker::make('valid_upto')
|
||||
->label('Valid Upto')
|
||||
->after('in_time')
|
||||
->validationMessages([
|
||||
'after' => 'Valid Upto must be after the In Time.',
|
||||
]),
|
||||
Forms\Components\View::make('components.webcam-field')
|
||||
->columnSpanFull(),
|
||||
Forms\Components\Hidden::make('photo'),
|
||||
@@ -178,6 +212,10 @@ class VisitorEntryResource extends Resource
|
||||
->defaultImageUrl(asset('images/profile.png'))
|
||||
->alignCenter()
|
||||
->extraImgAttributes(['style' => 'border-radius: 6px; object-fit: cover;']),
|
||||
Tables\Columns\TextColumn::make('register_id')
|
||||
->label('Register ID')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label('Visitor Type')
|
||||
->alignCenter()
|
||||
@@ -218,6 +256,15 @@ class VisitorEntryResource extends Resource
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('valid_upto')
|
||||
->label('Valid Upto')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->alignCenter()
|
||||
->color(fn ($record) => $record->valid_upto && \Carbon\Carbon::parse($record->valid_upto)->isPast()
|
||||
? 'danger'
|
||||
: 'success'
|
||||
),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
@@ -318,6 +365,14 @@ class VisitorEntryResource extends Resource
|
||||
TextEntry::make('out_time')
|
||||
->label('Out Time')
|
||||
->dateTime(),
|
||||
TextEntry::make('valid_upto')
|
||||
->label('Valid Upto')
|
||||
->dateTime()
|
||||
->badge()
|
||||
->color(fn ($record) => $record->valid_upto && \Carbon\Carbon::parse($record->valid_upto)->isPast()
|
||||
? 'danger'
|
||||
: 'success'
|
||||
),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user