2.7 KiB
2.7 KiB
PLAN: Sync Logs & Overwrite Option
Target Files:
branch-agent/sync.js(Windows agent logging)app/Http/Controllers/BiometricAttendanceController.php(bulk sync overwrite backend)resources/js/pages/hr/biometric-attendance/index.tsx(overwrite option frontend)
Goal
Implement local logging for the Windows sync agent (saving logs in the executable's directory) and add an optional "Overwrite" checkbox to the bulk sync process to allow updating existing records instead of skipping them.
Tasks
Phase 1: Windows Sync Agent Logging
- Implement
writeLoghelper inbranch-agent/sync.js:- Write a function to append messages to
sync.login the executable's directory (path.dirname(process.execPath)). - Format:
[YYYY-MM-DD HH:ii:ss] MESSAGE.
- Write a function to append messages to
- Add log statements for key events:
- Log start of sync, target device, connection success/failure, number of records found, and API response success/failure.
- Verify: Run the sync script and check if
sync.logis created with clear information.
Phase 2: Backend Overwrite Support
- Modify
syncAllinBiometricAttendanceController.php:- Extract
$overwrite = $request->boolean('overwrite', false);. - If
$existsis true and$overwriteis true:- Fetch the existing
AttendanceRecord. - Update its
clock_in,clock_out,biometric_id, and save it. - Call
processAttendance()on it.
- Fetch the existing
- Update return flash message to show how many records were created vs updated.
- Extract
Phase 3: Frontend Overwrite UI Option
- Add Overwrite Checkbox in
resources/js/pages/hr/biometric-attendance/index.tsx:- Add a state variable
overwrite(boolean, defaults tofalseortruebased on preference). - Place a styled checkbox component next to the "Pull Data & Sync" button or wrap it inside a confirm dialog before running bulk sync.
- Pass
{ overwrite }payload inside the Inertia post request toroute('hr.biometric-attendance.sync-all').
- Add a state variable
Phase 4: Build and Release Packaging
- Rebuild the agent executable:
- Run
npx pkg -t node18-win-x64 --output sync-agent.exe sync.js.
- Run
- Update the ZIP distribution archive:
- Package
sync-agent.exeand.env.exampleintosync-agent-1.0.zip.
- Package
Verification Checklist
- Local Logging Verification: Run the Node agent, confirm
sync.logis created in the same folder, and verify it contains timestamps and sync statuses. - Bulk Sync Skips by Default: Trigger bulk sync with
overwrite = falseand ensure existing records are not changed. - Bulk Sync Overwrites when Checked: Trigger bulk sync with
overwrite = trueand verify existing records update to reflect current biometric punches.