- AttendanceService: staffCheckin and walkInRegister methods - CheckinController: QR-based check-in (staff & walk-in external) - AttendanceCheckController: semak kehadiran & sijil status - Views: checkin show/success/already/unavailable, semak show/result Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Public;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Certificate;
|
|
use App\Models\Participant;
|
|
use App\Models\ProgramQrCode;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class AttendanceCheckController extends Controller
|
|
{
|
|
public function show(string $qr_token): View
|
|
{
|
|
$qrCode = ProgramQrCode::where('token', $qr_token)->where('is_active', true)->firstOrFail();
|
|
$program = $qrCode->program;
|
|
|
|
abort_if($program->status !== 'published', 404);
|
|
|
|
return view('public.semak.show', compact('program', 'qrCode'));
|
|
}
|
|
|
|
public function check(string $qr_token, Request $request): View
|
|
{
|
|
$qrCode = ProgramQrCode::where('token', $qr_token)->where('is_active', true)->firstOrFail();
|
|
$program = $qrCode->program;
|
|
|
|
$request->validate([
|
|
'no_kp' => ['required', 'digits:12'],
|
|
], [
|
|
'no_kp.required' => 'Sila masukkan No. Kad Pengenalan anda.',
|
|
'no_kp.digits' => 'No. Kad Pengenalan mestilah 12 digit tanpa sempang.',
|
|
]);
|
|
|
|
$noKp = preg_replace('/[^0-9]/', '', $request->no_kp);
|
|
$participant = Participant::where('no_kp', $noKp)->first();
|
|
|
|
if (! $participant) {
|
|
return view('public.semak.result', [
|
|
'program' => $program,
|
|
'qrCode' => $qrCode,
|
|
'found' => false,
|
|
'participant' => null,
|
|
'attendance' => null,
|
|
'certificate' => null,
|
|
]);
|
|
}
|
|
|
|
$attendance = $participant->attendanceForProgram($program->id);
|
|
$certificate = $attendance
|
|
? Certificate::where('program_id', $program->id)
|
|
->where('participant_id', $participant->id)
|
|
->first()
|
|
: null;
|
|
|
|
return view('public.semak.result', compact('program', 'qrCode', 'participant', 'attendance', 'certificate'))
|
|
->with('found', (bool) $attendance);
|
|
}
|
|
}
|