Files
HRM-System/docs/PLAN-sync-logs-overwrite.md

52 lines
2.7 KiB
Markdown

# 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 `writeLog` helper in `branch-agent/sync.js`**:
* Write a function to append messages to `sync.log` in the executable's directory (`path.dirname(process.execPath)`).
* Format: `[YYYY-MM-DD HH:ii:ss] MESSAGE`.
- [ ] **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.log` is created with clear information.
### Phase 2: Backend Overwrite Support
- [ ] **Modify `syncAll` in `BiometricAttendanceController.php`**:
* Extract `$overwrite = $request->boolean('overwrite', false);`.
* If `$exists` is true and `$overwrite` is true:
* Fetch the existing `AttendanceRecord`.
* Update its `clock_in`, `clock_out`, `biometric_id`, and save it.
* Call `processAttendance()` on it.
* Update return flash message to show how many records were created vs updated.
### 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 to `false` or `true` based 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 to `route('hr.biometric-attendance.sync-all')`.
### Phase 4: Build and Release Packaging
- [ ] **Rebuild the agent executable**:
* Run `npx pkg -t node18-win-x64 --output sync-agent.exe sync.js`.
- [ ] **Update the ZIP distribution archive**:
* Package `sync-agent.exe` and `.env.example` into `sync-agent-1.0.zip`.
---
## Verification Checklist
- [ ] **Local Logging Verification**: Run the Node agent, confirm `sync.log` is created in the same folder, and verify it contains timestamps and sync statuses.
- [ ] **Bulk Sync Skips by Default**: Trigger bulk sync with `overwrite = false` and ensure existing records are not changed.
- [ ] **Bulk Sync Overwrites when Checked**: Trigger bulk sync with `overwrite = true` and verify existing records update to reflect current biometric punches.