@extends('Admin.layout') @section('content') @php $selectedMonth = $selectedMonth ?? request('month', now()->format('Y-m')); $selectedStaffId = $selectedStaffId ?? request('staff_id'); $leaveCount = (int) ($leaveCount ?? 0); $wfhCount = (int) ($wfhCount ?? 0); $permissionCount = (int) ($permissionCount ?? 0); $lateLoginCount = (int) ($lateLoginCount ?? 0); $onTimeLoginCount = (int) ($onTimeLoginCount ?? 0); $completedTaskCount = (int) ($completedTaskCount ?? 0); $incompleteTaskCount = (int) ($incompleteTaskCount ?? 0); $reopenTaskCount = (int) ($reopenTaskCount ?? 0); $positiveFeedbackCount = (int) ($positiveFeedbackCount ?? 0); $negativeFeedbackCount = (int) ($negativeFeedbackCount ?? 0); $emailCount = (int) ($emailCount ?? 0); $workingDays = (int) ($workingDays ?? 22); try { $displayMonth = \Carbon\Carbon::createFromFormat( 'Y-m', $selectedMonth )->format('F Y'); } catch (\Throwable $exception) { $selectedMonth = now()->format('Y-m'); $displayMonth = now()->format('F Y'); } if (!isset($selectedStaff)) { $selectedStaff = null; if (!empty($selectedStaffId)) { $selectedStaff = collect( $staffList ?? [] )->firstWhere( 'id', (int) $selectedStaffId ); } } /* |-------------------------------------------------------------------------- | Performance calculation (unchanged) |-------------------------------------------------------------------------- */ $totalTasks = $completedTaskCount + $incompleteTaskCount + $reopenTaskCount; $taskCompletionScore = $totalTasks > 0 ? ($completedTaskCount / $totalTasks) * 100 : 0; $reopenPenalty = $totalTasks > 0 ? ($reopenTaskCount / $totalTasks) * 20 : 0; $taskScore = (int) round( max( 0, min( 100, $taskCompletionScore - $reopenPenalty ) ) ); $totalFeedback = $positiveFeedbackCount + $negativeFeedbackCount; $feedbackScore = $totalFeedback > 0 ? (int) round( ($positiveFeedbackCount / $totalFeedback) * 100 ) : null; $attendanceImpact = ($leaveCount * 1) + ($permissionCount * 0.5) + ($lateLoginCount * 0.25); $attendanceScore = $workingDays > 0 ? (int) round( max( 0, min( 100, 100 - ( ($attendanceImpact / $workingDays) * 100 ) ) ) ) : 0; if ($feedbackScore === null) { $overallPerformance = (int) round( ($taskScore * 0.80) + ($attendanceScore * 0.20) ); } else { $overallPerformance = (int) round( ($taskScore * 0.60) + ($feedbackScore * 0.25) + ($attendanceScore * 0.15) ); } $overallPerformance = max( 0, min(100, $overallPerformance) ); $performanceGrade = match (true) { $overallPerformance >= 90 => 'Excellent', $overallPerformance >= 80 => 'Very Good', $overallPerformance >= 70 => 'Good', $overallPerformance >= 60 => 'Average', default => 'Needs Improvement', }; $performanceClass = match (true) { $overallPerformance >= 90 => 'performance-excellent', $overallPerformance >= 80 => 'performance-very-good', $overallPerformance >= 70 => 'performance-good', $overallPerformance >= 60 => 'performance-average', default => 'performance-poor', }; $performanceIcon = match (true) { $overallPerformance >= 90 => 'tabler-trophy', $overallPerformance >= 80 => 'tabler-award', $overallPerformance >= 70 => 'tabler-thumb-up', $overallPerformance >= 60 => 'tabler-chart-bar', default => 'tabler-alert-triangle', }; // Certificate reference number — deterministic per staff + month so re-prints match. $certRef = 'PR-' . ($selectedStaffId ?: 'ALL') . '-' . str_replace('-', '', $selectedMonth); @endphp
{{-- Filters (screen only) --}} {{-- ================= CERTIFICATE ================= --}}
{{-- Letterhead --}}
Logo
Certified Performance Record

Monthly Staff Performance Report

Reference {{ $certRef }}
Issued {{ now()->format('d M Y') }}
{{-- Subject line --}}
{{ $selectedStaff?->name ?? 'All Staff — Combined Overview' }}
@if (!empty($selectedStaffId)) Employee ID {{ $selectedStaff?->user_id }} · {{ $selectedStaff?->designation ?? 'Unknown Position' }} @else Aggregated across every active staff member @endif
Reporting period {{ $displayMonth }}
{{-- Attendance --}}
Attendance
Leave Days
{{ $leaveCount }}
WFH
{{ $wfhCount }}
Permissions
{{ $permissionCount }}
Total Logins
0
On-Time Logins
{{ $onTimeLoginCount }}
Late Logins
{{ $lateLoginCount }}
{{-- Tasks --}}
Tasks
Assigned Task
0
Completed
{{ $completedTaskCount }}
Incomplete
{{ $incompleteTaskCount }}
Reopened
{{ $reopenTaskCount }}
{{-- Review & communication --}}
Review & Communication
Positive Feedback
{{ $positiveFeedbackCount }}
Negative Feedback
{{ $negativeFeedbackCount }}
Emails Sent
{{ $emailCount }}
{{-- Performance --}}
Performance Analysis
{{ $overallPerformance }}%
{{ $performanceGrade }}
Overall Performance
Task Performance {{ $taskScore }}%
{{ $completedTaskCount }} completed out of {{ $totalTasks }} tasks. @if ($reopenTaskCount > 0) Includes {{ $reopenTaskCount }} reopened task(s). @endif
Attendance Discipline {{ $attendanceScore }}%
Based on {{ $workingDays }} working days, {{ $leaveCount }} leave day(s), {{ $permissionCount }} permission(s), {{ $onTimeLoginCount }} on-time login(s) and {{ $lateLoginCount }} late login(s). Approved WFH is not treated as a penalty.
Feedback Performance {{ $feedbackScore !== null ? $feedbackScore . '%' : 'N/A' }}
@if ($totalFeedback > 0) {{ $positiveFeedbackCount }} positive feedback out of {{ $totalFeedback }} feedback record(s). @else No feedback was recorded for this month. @endif
Task Score Weight {{ $feedbackScore === null ? '80%' : '60%' }}
Attendance Score Weight {{ $feedbackScore === null ? '20%' : '15%' }}
Feedback Score Weight {{ $feedbackScore === null ? 'N/A' : '25%' }}
Email Activity {{ $emailCount }} email(s)
{{-- Attestation — one row, two columns side by side --}}
Employee Signature
Manager / Authorized Signature
Report generated on {{ now()->format('d M Y, h:i A') }} · Reference {{ $certRef }} · This is a system-generated record.
@endsection