ranjith-dev #664
@@ -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),
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class VisitorEntry extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'mobile_number',
|
||||
'register_id',
|
||||
'name',
|
||||
'company',
|
||||
'purpose_of_visit',
|
||||
@@ -20,7 +21,8 @@ class VisitorEntry extends Model
|
||||
'out_time',
|
||||
'photo',
|
||||
'employee_master_id',
|
||||
'number_of_person'
|
||||
'number_of_person',
|
||||
'valid_upto',
|
||||
];
|
||||
|
||||
public function employeeMaster(): BelongsTo
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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 register_id TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
|
||||
$sql2 = <<<'SQL'
|
||||
ALTER TABLE visitor_entries
|
||||
ADD COLUMN valid_upto TIMESTAMP DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('visitor_entries', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -157,7 +157,7 @@
|
||||
{{-- Header --}}
|
||||
<div class="badge-header">
|
||||
<span class="type">{{ strtoupper($visitor->type ?? 'VISITOR') }}</span>
|
||||
<span class="badge-id">#{{ str_pad($visitor->id, 5, '0', STR_PAD_LEFT) }}</span>
|
||||
<span class="badge-id">#{{ strtoupper($visitor->register_id) }}</span>
|
||||
</div>
|
||||
|
||||
{{-- Body --}}
|
||||
@@ -186,7 +186,7 @@
|
||||
<div class="field-row">
|
||||
<span class="field-label">Valid upto:</span>
|
||||
<span class="field-value">
|
||||
{{ $visitor->out_time ? \Carbon\Carbon::parse($visitor->out_time)->format('d/m/Y H:i') : '—' }}
|
||||
{{ $visitor->valid_upto ? \Carbon\Carbon::parse($visitor->valid_upto)->format('d/m/Y H:i') : '—' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="field-row">
|
||||
@@ -212,7 +212,7 @@
|
||||
<div class="visitor-qr" style="margin-top:2mm;">
|
||||
{!! QrCode::size(25)
|
||||
->margin(0)
|
||||
->generate($visitor->id) !!}
|
||||
->generate($visitor->register_id) !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user