Merge pull request 'ranjith-dev' (#658) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #658
This commit was merged in pull request #658.
This commit is contained in:
2026-05-27 06:12:59 +00:00
13 changed files with 1228 additions and 0 deletions

View File

@@ -0,0 +1,351 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource\RelationManagers;
use App\Models\VisitorEntry;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Infolists\Infolist;
use Filament\Infolists\Components\ImageEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Components\Section;
class VisitorEntryResource extends Resource
{
protected static ?string $model = VisitorEntry::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('mobile_number')
->label('Mobile Number')
->length(10)
->reactive()
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^0-9]/g, "").slice(0, 10)', // blocks non-numbers + limits to 10 chars
'maxlength' => 10,
])
->required()
->extraAttributes([
'id' => 'mobile_number_input',
'x-data' => '{ value: "" }',
'x-model' => 'value',
'wire:keydown.enter.prevent' => 'processMobile(value)',
]),
Forms\Components\TextInput::make('name')
->label('Name')
->required()
->reactive()
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^a-zA-Z\s]/g, "")',
]),
Forms\Components\Select::make('type')
->label('Type')
->reactive()
->options([
'Student' => 'Student',
'Consultant' => 'Consultant',
'Vendor' => 'Vendor',
'Other' => 'Other',
])
->required()
->dehydrateStateUsing(function ($state, callable $get) {
return $state == 'Other'
? $get('other_type')
: $state;
}),
Forms\Components\TextInput::make('other_type')
->label('Specify Type')
->reactive()
->visible(fn (callable $get) => $get('type') == 'Other')
->required(fn (callable $get) => $get('type') == 'Other')
->dehydrated(false),
Forms\Components\TextInput::make('company')
->label('Company')
->required(),
Forms\Components\Select::make('department')
->label('Employee Department')
->options(
\App\Models\EmployeeMaster::distinct()
->pluck('department', 'department')
)
->required()
->reactive()
->afterStateUpdated(function (callable $set) {
$set('employee_master_id', null);
$set('code', null);
}),
// Forms\Components\Select::make('employee_master_id')
// ->label('Recipient Employee')
// ->required()
// ->options(function (callable $get) {
// $department = $get('department');
// if (!$department) {
// return [];
// }
// return \App\Models\EmployeeMaster::where('department', $department)
// ->pluck('name', 'id');
// })
// ->reactive()
// ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
// $department = $get('department');
// $employee = \App\Models\EmployeeMaster::where('id', $state)
// ->where('department', $department)
// ->first();
// $set('code', $employee ? $employee->code : '');
// }),
Forms\Components\Select::make('employee_master_id')
->label('Recipient Employee')
->required()
->options(function (callable $get) {
$department = $get('department');
// Always load ALL employees, filter by department if set
if ($department) {
return \App\Models\EmployeeMaster::where('department', $department)
->pluck('name', 'id');
}
// Fallback: load all so fill() can always match the ID
return \App\Models\EmployeeMaster::pluck('name', 'id');
})
->reactive()
->afterStateUpdated(function (callable $set, ?string $state) {
$employee = \App\Models\EmployeeMaster::find($state);
$set('code', $employee?->code ?? '');
}),
Forms\Components\TextInput::make('code')
->label('Employee Code')
->readOnly(),
Forms\Components\Textarea::make('purpose_of_visit')
->label('Purpose of Visit')
->required(),
Forms\Components\TextInput::make('number_of_person')
->numeric()
->default(1)
->required(),
Forms\Components\DateTimePicker::make('in_time')
->label('In Time'),
Forms\Components\DateTimePicker::make('out_time')
->label('Out Time'),
Forms\Components\View::make('components.webcam-field')
->columnSpanFull(),
Forms\Components\Hidden::make('photo'),
Forms\Components\Hidden::make('created_by')
->label('created_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->label('updated_by')
->default(Filament::auth()->user()?->name),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
->label('NO')
->alignCenter()
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\ImageColumn::make('photo')
->label('Photo')
->disk('public')
->height(50)
->width(50)
// ->defaultImageUrl('https://ui-avatars.com/api/?name=Visitor&background=555&color=fff')
->defaultImageUrl(asset('images/profile.png'))
->alignCenter()
->extraImgAttributes(['style' => 'border-radius: 6px; object-fit: cover;']),
Tables\Columns\TextColumn::make('type')
->label('Visitor Type')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('name')
->label('Visitor Name')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('mobile_number')
->label('Visitor Mobile Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('employeeMaster.name')
->label('Recipient Name')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('employeeMaster.code')
->label('Receipient ID')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('employeeMaster.department')
->label('Receipient Department')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('number_of_person')
->label('Number of Person')
->numeric()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('in_time')
->label('In Time')
->dateTime()
->sortable()
->alignCenter(),
Tables\Columns\TextColumn::make('out_time')
->label('Out Time')
->dateTime()
->sortable()
->alignCenter(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->alignCenter(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->alignCenter(),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->alignCenter(),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
// ── Visitor Photo (full width at the top) ──
Section::make('Visitor Photo')
->schema([
ImageEntry::make('photo')
->label('')
->disk('public')
->height(220)
->defaultImageUrl(asset('images/profile.png'))
->extraImgAttributes([
'style' => 'border-radius: 10px; object-fit: cover;'
]),
])
->columnSpanFull(),
// ── Visitor Details ──
Section::make('Visitor Details')
->schema([
TextEntry::make('name')
->label('Visitor Name'),
TextEntry::make('mobile_number')
->label('Mobile Number'),
TextEntry::make('type')
->label('Visitor Type')
->badge()
->color(fn (string $state): string => match ($state) {
'internal' => 'success',
'external' => 'warning',
default => 'gray',
}),
TextEntry::make('company')
->label('Company'),
TextEntry::make('purpose_of_visit')
->label('Purpose of Visit')
->columnSpanFull(),
])
->columns(2),
// ── Employee Details ──
Section::make('Recipient Details')
->schema([
TextEntry::make('employeeMaster.name')
->label('Recipient Employee'),
TextEntry::make('code')
->label('Employee Code'),
TextEntry::make('employeeMaster.department')
->label('Department'),
TextEntry::make('number_of_person')
->label('Number of Persons'),
])
->columns(2),
// ── Visit Timing ──
Section::make('Visit Timing')
->schema([
TextEntry::make('in_time')
->label('In Time')
->dateTime(),
TextEntry::make('out_time')
->label('Out Time')
->dateTime(),
])
->columns(2),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListVisitorEntries::route('/'),
'create' => Pages\CreateVisitorEntry::route('/create'),
'view' => Pages\ViewVisitorEntry::route('/{record}'),
'edit' => Pages\EditVisitorEntry::route('/{record}/edit'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,121 @@
<?php
namespace App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource;
use App\Models\EmployeeMaster;
use App\Models\VisitorEntry;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\On;
class CreateVisitorEntry extends CreateRecord
{
protected static string $resource = VisitorEntryResource::class;
public $capturedPhoto;
public function processMobile($mobile)
{
$visitor = VisitorEntry::where('mobile_number', $mobile)->latest()->first();
if ($visitor) {
$employee = EmployeeMaster::where('id', $visitor->employee_master_id)->first();
$this->form->fill([
'mobile_number' => $mobile ?? '',
'name' => $visitor->name ?? '',
'company' => $visitor->company ?? '',
'type' => $visitor->type ?? '',
'department' => $employee->department ?? '',
'employee_master_id' => $visitor->employee_master_id->name ?? '',
'code' => $employee->code ?? '',
]);
}
else {
$this->form->fill([
'mobile_number' => $mobile ?? '',
'name' => $visitor->name ?? '',
'company' => $visitor->company ?? '',
'type' => $visitor->type ?? '',
'department' => $employee->department ?? '',
'employee_master_id' => $visitor->employee_master_id->name ?? '',
'code' => $employee->code ?? '',
]);
}
}
#[On('photo-captured')]
public function handlePhotoCapture(string $photo): void
{
$this->data['photo'] = $photo;
\Log::info('WEBCAM: photo-captured event received, length: ' . strlen($photo));
}
protected function mutateFormDataBeforeCreate(array $data): array
{
if (
!empty($data['photo']) &&
str_starts_with($data['photo'], 'data:image')
) {
try {
$imageData = explode(',', $data['photo'])[1];
$filename = 'visitor_' . time() . '_' . uniqid() . '.jpg';
$path = 'visitor-photos/' . $filename;
$decoded = base64_decode($imageData);
$saved = Storage::disk('public')->put($path, $decoded);
$data['photo'] = $path;
} catch (\Exception $e) {
\Log::error('PHOTO UPLOAD ERROR: ' . $e->getMessage());
}
}
return $data;
}
public function setPhoto(string $photo): void
{
$this->capturedPhoto = $photo;
$this->dispatch('photo-captured', photo: $photo)->to(\App\Filament\Resources\VisitorEntryResource\Pages\CreateVisitorEntry::class);
}
// ── Custom form action buttons ──
protected function getFormActions(): array
{
return [
$this->getCreateFormAction(),
$this->getCreateAnotherFormAction(),
Action::make('createAndPrint')
->label('Create & Print')
->color('success')
->icon('heroicon-o-printer')
->action(function () {
// Save the record using existing logic (calls mutateFormDataBeforeCreate internally)
$this->create();
// Open the badge print page in a new tab
$this->js("window.open('" . route('visitor.badge', $this->record->id) . "', '_blank')");
}),
$this->getCancelFormAction(),
];
}
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('view', ['record' => $this->record]);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\On;
class EditVisitorEntry extends EditRecord
{
protected static string $resource = VisitorEntryResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
// Receives the photo from the webcam component
#[On('photo-captured')]
public function handlePhotoCapture(string $photo): void
{
$this->data['photo'] = $photo;
}
// Runs automatically before the record is updated in the database
protected function mutateFormDataBeforeSave(array $data): array
{
if (
!empty($data['photo']) &&
str_starts_with($data['photo'], 'data:image')
) {
// Delete the old photo file if one exists
$oldPhoto = $this->record->photo;
if ($oldPhoto && Storage::disk('public')->exists($oldPhoto)) {
Storage::disk('public')->delete($oldPhoto);
}
// Save the new photo
$imageData = explode(',', $data['photo'])[1];
$filename = 'visitor_' . time() . '_' . uniqid() . '.jpg';
$path = 'visitor-photos/' . $filename;
Storage::disk('public')->put($path, base64_decode($imageData));
$data['photo'] = $path;
}
return $data;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListVisitorEntries extends ListRecords
{
protected static string $resource = VisitorEntryResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewVisitorEntry extends ViewRecord
{
protected static string $resource = VisitorEntryResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
Actions\Action::make('print')
->label('Print Badge')
->icon('heroicon-o-printer')
->color('success')
->url(fn () => route('visitor.badge', $this->record->id))
->openUrlInNewTab(),
];
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers;
use App\Models\VisitorEntry;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class VisitorBadgeController extends Controller
{
public function show($id)
{
$visitor = VisitorEntry::with('employeeMaster')->findOrFail($id);
$photoUrl = $visitor->photo
? Storage::disk('public')->url($visitor->photo)
: null;
return view('visitor.badge', compact('visitor', 'photoUrl'));
}
}

33
app/Livewire/Webcam.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Livewire;
use Livewire\Component;
class Webcam extends Component
{
public string $capturedPhoto = '';
// Called from JavaScript when a photo is taken
public function setPhoto(string $photo): void
{
$this->capturedPhoto = $photo;
// Fires a browser event that the Filament form will listen to
$this->dispatch('photo-captured', photo: $photo);
}
// Called from JavaScript when user clicks "Retake"
public function clearPhoto(): void
{
$this->capturedPhoto = '';
$this->dispatch('photo-captured', photo: '');
}
public function render()
{
return view('livewire.webcam');
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class VisitorEntry extends Model
{
use SoftDeletes;
protected $fillable = [
'mobile_number',
'name',
'company',
'purpose_of_visit',
'type',
'in_time',
'out_time',
'photo',
'employee_master_id',
'number_of_person'
];
public function employeeMaster(): BelongsTo
{
return $this->belongsTo(EmployeeMaster::class);
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Policies;
use Illuminate\Auth\Access\Response;
use App\Models\VisitorEntry;
use App\Models\User;
class VisitorEntryPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any VisitorEntry');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, VisitorEntry $visitorentry): bool
{
return $user->checkPermissionTo('view VisitorEntry');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create VisitorEntry');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, VisitorEntry $visitorentry): bool
{
return $user->checkPermissionTo('update VisitorEntry');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, VisitorEntry $visitorentry): bool
{
return $user->checkPermissionTo('delete VisitorEntry');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any VisitorEntry');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, VisitorEntry $visitorentry): bool
{
return $user->checkPermissionTo('restore VisitorEntry');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any VisitorEntry');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, VisitorEntry $visitorentry): bool
{
return $user->checkPermissionTo('replicate VisitorEntry');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder VisitorEntry');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, VisitorEntry $visitorentry): bool
{
return $user->checkPermissionTo('force-delete VisitorEntry');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any VisitorEntry');
}
}

View File

@@ -0,0 +1,47 @@
<?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
{
$sql = <<<'SQL'
CREATE TABLE visitor_entries (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
employee_master_id BIGINT NOT NULL,
mobile_number BIGINT NOT NULL,
name TEXT DEFAULT NULL,
company TEXT DEFAULT NULL,
purpose_of_visit TEXT DEFAULT NULL,
type TEXT DEFAULT NULL,
photo TEXT DEFAULT NULL,
number_of_person INTEGER DEFAULT NULL,
in_time TIMESTAMP DEFAULT NULL,
out_time TIMESTAMP DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
created_by TEXT DEFAULT NULL,
updated_by TEXT DEFAULT NULL,
deleted_at TIMESTAMP,
FOREIGN KEY (employee_master_id) REFERENCES employee_masters (id)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('visitor_entries');
}
};

View File

@@ -0,0 +1,193 @@
<div
x-data="{
cameraActive: false,
captured: false,
errorMessage: '',
photoData: '',
async startCamera() {
this.errorMessage = '';
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { width: 640, height: 480, facingMode: 'user' }
});
this.$refs.video.srcObject = stream;
await this.$refs.video.play();
this.cameraActive = true;
} catch (err) {
if (err.name === 'NotAllowedError') {
this.errorMessage = 'Camera permission denied. Please allow camera access in your browser and try again.';
} else if (err.name === 'NotFoundError') {
this.errorMessage = 'No camera found. Please connect a webcam and try again.';
} else {
this.errorMessage = 'Could not access camera: ' + err.message;
}
}
},
capture() {
const canvas = this.$refs.canvas;
const video = this.$refs.video;
canvas.width = video.videoWidth || 640;
canvas.height = video.videoHeight || 480;
canvas.getContext('2d').drawImage(video, 0, 0);
const photoData = canvas.toDataURL('image/jpeg', 0.85);
// Stop the camera stream after capture
if (video.srcObject) {
video.srcObject.getTracks().forEach(track => track.stop());
}
this.cameraActive = false;
this.captured = true;
this.photoData = photoData;
// Send photo data to PHP via Livewire
$wire.setPhoto(photoData);
},
retake() {
this.captured = false;
this.photoData = '';
$wire.clearPhoto();
this.$nextTick(() => this.startCamera());
}
}"
style="font-family: inherit;"
>
{{-- ── Error message ── --}}
<template x-if="errorMessage">
<div style="
background: #3b1a1a;
border: 1px solid #7f2020;
color: #f87171;
padding: 10px 14px;
border-radius: 8px;
margin-bottom: 12px;
font-size: 13px;
" x-text="errorMessage"></div>
</template>
{{-- ── Live video feed (shown while camera is active) ── --}}
<div x-show="cameraActive && !captured" style="position: relative;">
<video
x-ref="video"
autoplay
playsinline
muted
style="
width: 100%;
max-width: 480px;
border-radius: 10px;
display: block;
background: #111;
"
></video>
</div>
{{-- ── Captured photo preview (shown after capture) ── --}}
<div x-show="captured" style="position: relative;">
<img
{{-- x-bind:src="$refs.canvas ? $refs.canvas.toDataURL('image/jpeg') : ''" --}}
x-bind:src="photoData"
style="
width: 100%;
max-width: 480px;
border-radius: 10px;
display: block;
border: 2px solid #16a34a;
"
alt="Captured visitor photo"
/>
<div style="
position: absolute;
top: 10px; left: 10px;
background: #16a34a;
color: white;
padding: 3px 10px;
border-radius: 20px;
font-size: 12px;
">✓ Photo captured</div>
</div>
{{-- ── Placeholder (before camera starts) ── --}}
<div
x-show="!cameraActive && !captured"
style="
width: 100%;
max-width: 480px;
height: 200px;
background: #1a1a1a;
border: 2px dashed #444;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
color: #666;
font-size: 14px;
"
>
📷 Camera not started yet
</div>
{{-- ── Hidden canvas used for capturing the frame ── --}}
<canvas x-ref="canvas" style="display: none;"></canvas>
{{-- ── Buttons ── --}}
<div style="display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap;">
{{-- Start Camera button --}}
<button
type="button"
x-show="!cameraActive && !captured"
x-on:click="startCamera()"
style="
background: #2563eb;
color: white;
border: none;
padding: 9px 20px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
"
>
📷 Start Camera
</button>
{{-- Capture button --}}
<button
type="button"
x-show="cameraActive && !captured"
x-on:click="capture()"
style="
background: #16a34a;
color: white;
border: none;
padding: 9px 20px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
"
>
📸 Capture Photo
</button>
{{-- Retake button --}}
<button
type="button"
x-show="captured"
x-on:click="retake()"
style="
background: #b45309;
color: white;
border: none;
padding: 9px 20px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
"
>
🔄 Retake Photo
</button>
</div>
</div>

View File

@@ -0,0 +1,222 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Visitor Badge</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
@page {
size: 80mm 50mm;
margin: 0;
}
body {
width: 80mm;
height: 50mm;
font-family: Arial, sans-serif;
font-size: 7pt;
background: #fff;
color: #000;
}
.badge {
width: 80mm;
height: 50mm;
border: 1px solid #333;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ── Header bar ── */
.badge-header {
background: #1a1a2e;
color: #fff;
text-align: center;
padding: 2mm 2mm 1.5mm;
font-size: 8pt;
font-weight: bold;
letter-spacing: 1px;
display: flex;
justify-content: space-between;
align-items: center;
}
.badge-header .type {
font-size: 9pt;
letter-spacing: 2px;
}
.badge-header .badge-id {
font-size: 7pt;
opacity: 0.85;
}
/* ── Body ── */
.badge-body {
display: flex;
flex: 1;
padding: 2mm;
gap: 2mm;
}
/* ── Fields (left) ── */
.badge-fields {
flex: 1;
display: flex;
flex-direction: column;
gap: 1.2mm;
}
.field-row {
display: flex;
gap: 1mm;
line-height: 1.3;
}
.field-label {
color: #555;
min-width: 14mm;
font-size: 6.5pt;
}
.field-value {
font-weight: 600;
font-size: 6.5pt;
color: #111;
flex: 1;
}
/* ── Photo (right) ── */
.badge-photo {
display: flex;
flex-direction: column;
align-items: center;
gap: 1mm;
width: 18mm;
}
.badge-photo img {
width: 16mm;
height: 18mm;
object-fit: cover;
border: 1px solid #ccc;
}
.badge-photo .no-photo {
width: 16mm;
height: 18mm;
border: 1px dashed #aaa;
display: flex;
align-items: center;
justify-content: center;
font-size: 5.5pt;
color: #aaa;
text-align: center;
}
.host-sign {
font-size: 5.5pt;
color: #555;
text-align: center;
border-top: 0.5px solid #aaa;
padding-top: 0.5mm;
width: 100%;
}
/* ── Footer ── */
.badge-footer {
border-top: 0.5px solid #ddd;
padding: 1mm 2mm;
text-align: right;
font-size: 5.5pt;
color: #888;
}
@media print {
body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.no-print { display: none !important; }
}
</style>
</head>
<body onload="window.print()">
{{-- ── Print button (visible on screen only, hidden when printing) ── --}}
<div class="no-print" style="padding: 8px; text-align:center; background:#f3f4f6;">
<button onclick="window.print()" style="padding:6px 18px; background:#1a1a2e; color:#fff; border:none; border-radius:6px; cursor:pointer; font-size:13px;">
🖨️ Print Badge
</button>
<button onclick="window.close()" style="padding:6px 18px; background:#e5e7eb; color:#333; border:none; border-radius:6px; cursor:pointer; font-size:13px; margin-left:8px;">
Close
</button>
</div>
<div class="badge">
{{-- 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>
</div>
{{-- Body --}}
<div class="badge-body">
{{-- Left: fields --}}
<div class="badge-fields">
<div class="field-row">
<span class="field-label">Name:</span>
<span class="field-value">{{ strtoupper($visitor->name) }}</span>
</div>
<div class="field-row">
<span class="field-label">Company:</span>
<span class="field-value">{{ $visitor->company }}</span>
</div>
<div class="field-row">
<span class="field-label">To Meet:</span>
<span class="field-value">{{ strtoupper($visitor->employeeMaster?->name ?? '—') }}</span>
</div>
<div class="field-row">
<span class="field-label">Dept:</span>
<span class="field-value">
{{ strtoupper($visitor->employeeMaster?->department ?? $visitor->department ?? '—') }}
</span>
</div>
<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') : '—' }}
</span>
</div>
<div class="field-row">
<span class="field-label">Date&Time:</span>
<span class="field-value">
{{ $visitor->in_time ? \Carbon\Carbon::parse($visitor->in_time)->format('d/m/Y H:i') : '—' }}
</span>
</div>
<div class="field-row">
<span class="field-label">No of Visitor:</span>
<span class="field-value">{{ $visitor->number_of_person ?? 1 }}</span>
</div>
</div>
{{-- Right: photo + host sign --}}
<div class="badge-photo">
@if($photoUrl)
<img src="{{ $photoUrl }}" alt="Visitor Photo" />
@else
<div class="no-photo">No Photo</div>
@endif
<div class="host-sign">Host Sign</div>
</div>
</div>
{{-- Footer --}}
<div class="badge-footer">Mobile: {{ $visitor->mobile_number }}</div>
</div>
</body>
</html>

View File

@@ -3,6 +3,7 @@
use App\Http\Controllers\CharacteristicApprovalController;
use App\Http\Controllers\ProductionOrderController;
// use App\Http\Controllers\FileUploadController;
use App\Http\Controllers\VisitorBadgeController;
use App\Models\EquipmentMaster;
use App\Models\User;
use Filament\Facades\Filament;
@@ -65,6 +66,8 @@ Route::get('production-orders/{production_order}/{plant_code}/printItemSerial',
[ProductionOrderController::class, 'printItemSerial']
)->name('production-orders.printItemSerial');
Route::get('/visitor-badge/{id}', [VisitorBadgeController::class, 'show'])
->name('visitor.badge');
// Route::get('/characteristic/approve', [CharacteristicApprovalController::class, 'approve'])
// ->name('characteristic.approve')
// ->middleware('signed');