Files
HRM-System/docs/PLAN-attendance-validation.md

55 lines
3.4 KiB
Markdown

# PLAN: Fix Attendance Calendar Validation & Display
## Overview
The user reported an issue where updating an attendance record "won't allow" them to save. This occurs when an attendance record has a `present` status in the database but lacks `clock_in` and `clock_out` times (e.g., from imported legacy data).
The root causes are:
1. **Misleading UI Display**: The calendar grid forcibly overrides the display status to `A` (Absent) if `clock_in` and `clock_out` are empty, even if the actual database record has `status = 'present'`. This prompts the user to mistakenly think they need to "fix" it.
2. **Strict Validation Block**: When the user opens the modal and clicks "Save" to ensure it's marked as Present, the frontend and backend both strictly require `clock_in` and `clock_out` times. Because the user leaves them blank (as they only want to confirm the "Present" status), the form silently fails validation in the UI and blocks submission.
## Project Type
WEB
## Success Criteria
1. The calendar accurately displays `P` (Present) if the database status is `present`, even if the time logs are empty (displaying "Present (No Times)").
2. The UI and backend validation allow HR/Admins to save an attendance record as `Present` without forcing them to manually input arbitrary clock-in and clock-out times.
3. The user can successfully update Mark Edward's attendance records without being blocked by the strict time validation.
## Tech Stack
- Laravel (Backend Controller)
- React/Inertia (Frontend Calendar & Modal Components)
## File Structure
- `app/Http/Controllers/AttendanceRecordController.php`
- `app/Http/Requests/...` (if applicable)
- `resources/js/pages/hr/attendance-records/calendar.tsx`
## Task Breakdown
### Task 1: Fix Calendar Status Display Logic
- **Agent**: `backend-specialist`
- **Description**: Update `AttendanceRecordController@calendar` to respect the `present` status even when times are empty.
- **INPUT**: `AttendanceRecordController.php` lines handling status overrides (approx line 1056).
- **OUTPUT**: Modified logic where `else if (!empty($record->clock_in) ...)` is followed by a fallback that checks if `$record->status === 'present'`, and returns `'P'` and `'Present (No Times)'`.
- **VERIFY**: Load calendar, verify Mark Edward's 04/02 record shows as `P`.
### Task 2: Relax Backend Validation for Clock Times
- **Agent**: `backend-specialist`
- **Description**: Remove the strict `required_if:status,present,half_day` validation rules for `clock_in` and `clock_out` in `AttendanceRecordController@store` and `update`.
- **INPUT**: `AttendanceRecordController.php` validation arrays.
- **OUTPUT**: Changed to `nullable|date_format:H:i` or similar, removing the strict requirement.
- **VERIFY**: API accepts PUT requests with empty times for present status.
### Task 3: Relax Frontend Validation for Clock Times
- **Agent**: `frontend-specialist`
- **Description**: Update `calendar.tsx` to remove the strict `required` flag for `clock_in` and `clock_out` fields in the `CrudFormModal` configuration.
- **INPUT**: `resources/js/pages/hr/attendance-records/calendar.tsx`
- **OUTPUT**: `required: false` for both time fields.
- **VERIFY**: User can click "Save" with empty time fields and the modal submits successfully.
## ✅ PHASE X: Verification
- [ ] No purple/violet hex codes
- [ ] No standard template layouts
- [ ] Socratic Gate was respected
- [ ] Run `python .agent/scripts/checklist.py .`