4.0 KiB
4.0 KiB
Biometric Attendance Synchronization Assessment & Manual Pairing Plan
This plan documents the current integration state between the biometric devices, the Windows Sync Agent, and the core HRMS attendance records, and proposes a design for enhanced manual pairing when multiple daily pings occur.
🔍 Codebase Assessment Findings
1. The Sync Pipeline Architecture
The system uses a pull-then-push architecture split into three main parts:
- Branch Sync Agent (
branch-agent/sync.js):- A packaged Node.js script (
sync-agent.exe) running locally on a branch PC. - It queries the local ZKTeco biometric device via TCP (port 4370) using the
zklib-jslibrary. - It filters pings to the last 15 days and sends an HTTP POST request with an API key to the cloud API endpoint:
/api/zkteco/sync.
- A packaged Node.js script (
- Receiving API (
AttendanceSyncController@sync):- Authenticates the agent using the
ZKTECO_SYNC_KEY(configured in.env). - Receives the JSON payload and registers punches in the
biometric_attendancestable with a state ofpending. It avoids duplicates by checkingbiometric_emp_idandpunch_time.
- Authenticates the agent using the
- Attendance Mapping & Conversion (
BiometricAttendanceController):- Is it synced automatically? No. It is currently designed to be manually triggered by an HR administrator from the
/hr/biometric-attendancedashboard. - How it works:
- Bulk Trigger (
Pull Data & Syncbutton): Loops through allpendingbiometric records, groups them by employee + date, takes the first entry asclock_in, the last entry asclock_out(requires at least 2 pings), creates anAttendanceRecord, and processes payroll hours. - Row Trigger (
Syncaction): Syncs a single employee-day grouping using the first/last punch logic.
- Bulk Trigger (
- Is it synced automatically? No. It is currently designed to be manually triggered by an HR administrator from the
🛠️ Proposed Improvements: Manual Triggering & Multiple Punch Pairing
Currently, if an employee has multiple entries (e.g., Clock In, break pings, Clock Out), the system automatically picks the first and last. If the user wants to manually pair custom punch times (e.g. ignoring a false scan or choosing a specific middle scan):
Phase 1: Database Schema Support
No schema changes are required as BiometricAttendance records already store the individual raw punch timestamps and can be marked as synced individually.
Phase 2: Backend Controller Updates (BiometricAttendanceController)
- [New Endpoint] Custom Sync Pairing (
/hr/biometric-attendance/sync-custom):- Accept a custom POST request containing
employee_code,date,clock_in_biometric_id, andclock_out_biometric_id. - Fetch the specific biometric records by ID to extract the custom clock-in and clock-out times.
- Insert/update the
AttendanceRecordwith these custom values. - Mark all biometric entries for that employee/date as
synced.
- Accept a custom POST request containing
Phase 3: Frontend UI Enhancements (resources/js/pages/hr/biometric-attendance/index.tsx)
- Enhance the Details Modal (
Viewcomponent) to display checkbox selectors or action buttons next to the list of pings for a specific day. - Allow HR to check one ping as the desired "Clock In" and another ping as the "Clock Out".
- Provide a "Confirm Custom Sync" button in the modal that triggers the new custom pairing endpoint.
📋 Verification Plan
Automated Verification
- Run
npm run buildto verify React components bundle correctly with Shadcn UI additions. - Execute unit/integration tests for the new
sync-customendpoint.
Manual Walkthrough
- Agent Simulation: Push mock data containing 4 punches for an employee on a single day to
/api/zkteco/sync. - Dashboard Review: View the record on the
/hr/biometric-attendancepage (it will show 4 total entries). - Details Pairing: Click "Details" (Eye icon), select Punch #1 as Clock In and Punch #4 as Clock Out, and click "Confirm Custom Sync".
- Attendance Parity: Verify that the generated
AttendanceRecordmatches the chosen times, and all 4 logs are marked assynced.