# ATT2000 database connector

## What was verified

The local source is `C:\Program Files (x86)\Att\att2000.mdb`. The reader opens a
temporary copy using the 32-bit Microsoft Jet provider in read-only mode. No
records, names, enrolments, fingerprint templates or settings in ATT are changed.
The source's USERINFO.SSN field exists but is empty for the supplied punches.
Those punches are imported with blank names and national IDs; the Database Key
column shows the internal USERINFO/CHECKINOUT key only for manual linking.
Attendance is now the default individual-record view, including unmatched punches
with blank names. All Dates is the default so imported history is visible. Filters
include Today, Yesterday, This Month, Last Month, Last 30 Days, This Year, Last Year,
and Custom Date & Time. Custom time boundaries apply to individual punches. Daily
Summary is the separate grouped employee/day report; its filter uses calendar days.

## National ID matching

JEVAPOS uses Employees > National ID (`users.id_number`) as the business identifier.
New employee forms reject duplicate national IDs. Existing ambiguous duplicates
are not guessed. Automatic matching requires one active employee with that ID
assigned to the connector's branch. Preserve leading zeros; do not replace ID
numbers with database primary keys or employee numbers.

When populating ATT, put the actual national ID in USERINFO.SSN. If no national ID
exists there, create/edit the employee's national ID in JEVAPOS, then use Devices
& Mappings > Link Database User to Employee National ID. Select the employee and
enter the Database Key displayed in Attendance. Saving links earlier punches and
rebuilds their daily attendance. Match Earlier Punches also rematches rows with
national IDs after employee profiles have been created. No employees are silently
created from the attendance database.

The existing daily report still uses its original first/last-punch and 08:00/8-hour
calculation. This integration does not establish shift, break or payroll policies.
Configure/review those separately before using attendance to calculate wages.

## Manual sync and diagnosis

Database Connector defaults to the path above and SSN. Configure each connector's
branch correctly. Sync Now reads new punches; `--full` rereads historical records
without duplicating them and can pick up older changes in source ID fields.

```powershell
E:\xampp\php\php.exe E:\xampp\htdocs\jevapos.com\artisan attendance:sync-att --check-only
E:\xampp\php\php.exe E:\xampp\htdocs\jevapos.com\artisan attendance:sync-att --device=3
E:\xampp\php\php.exe E:\xampp\htdocs\jevapos.com\artisan attendance:sync-att --device=3 --full
```

Device 3 is specific to this development installation; use the client's actual ID.
The connector path/ID column are stored in biometric_devices.settings as
database_path/id_column. Change them only if the verified source differs.
The job rereads a two-day overlap and deduplicates punches. Future-dated source
records should be corrected before relying on the sync cursor.

## Automatic background sync

Deploy all updated files and run the migration, then run PowerShell **as
Administrator** on the Windows POS server:

```powershell
powershell -ExecutionPolicy Bypass -File "E:\xampp\htdocs\jevapos.com\public\attendance-agent\Install-AttSync.ps1" -ProjectPath "E:\xampp\htdocs\jevapos.com"
```

The installer registers JEVAPOS Attendance Sync at Windows startup, with a
one-minute restart check and duplicate-process prevention. Its hidden worker runs
the local import every five seconds after the previous run ends. Actual latency
also includes database read time and the time ZKTeco takes to save device punches.
No interactive PowerShell window needs to remain open. MySQL must be running;
failed syncs retry without advancing the cursor. Error logs rotate at 2MB in
storage/logs/att-sync.log. Installation is a separate step, not performed by a
database import or by downloading the installer.

Laravel's scheduler also supports the command every minute if that scheduler is
already installed. Avoid unnecessary duplicate schedulers; per-device locks
prevent concurrent imports.

This implementation reads the database on a local Windows JEVAPOS server. An
online-hosted JEVAPOS cannot read a client's C: drive directly; that deployment
needs a Windows push agent using the existing /api/attendance/punches endpoint.
No hosted Windows push agent was installed by this change.

## Deployment

Back up first, deploy updated files and run `php artisan migrate --force` and
`php artisan view:clear`. Migration 2026_10_12_210000 adds the national ID column.
Do not copy this installation's employee data, source database or imported
historical punches into an unrelated client's installation.
