THE LABS GADGET — FINANCE & HR GPS GEOFENCE PATCH V1.4
===================================================
TARGET: crm.thelabsgadget.com/financehub
Compatibility: standard Finance HR V1.1 and PV Layout V1.3 already installed.
Radius: 150 metres (fixed in this patch).
Shop: 53A, Jalan Intan Setia 1, Taman Intan Setia, 08000 Sungai Petani, Kedah.

IMPORTANT: Existing CRM domain files and database are NOT changed by this patch.
This patch modifies only financehub/app/actions.php, financehub/app/views.php,
and adds financehub/app/geofence.php, financehub/assets/geofence.js,
financehub/geo_setup.php. It adds attendance GPS columns and two NEW
fh_geofence_* tables in the existing FINANCE database.

INSTALLATION (OWNER ONLY):
1. Back up Finance DB using phpMyAdmin: thelabsgadget_thelabsgadget_finance.
   Also back up financehub/app folder.
2. cPanel > File Manager > Finance domain document root > financehub.
3. Upload this ZIP and EXTRACT HERE. Do NOT move or replace existing app/ files by hand.
   After extraction, these paths must exist:
     financehub/upgrade_geo_v1_4.php
     financehub/patch_geo_v1_4/app/actions.php
     financehub/patch_geo_v1_4/app/views.php
     financehub/patch_geo_v1_4/app/geofence.php
     financehub/patch_geo_v1_4/geo_setup.php
4. Log in to Finance HR as OWNER/Admin in the same browser.
5. Open https://crm.thelabsgadget.com/financehub/upgrade_geo_v1_4.php
6. Click 'Install GPS Geofence V1.4'. Do not retry blindly if an error appears.
7. Calibration is REQUIRED; user clock-in/out remains blocked until calibration.

CALIBRATE SHOP PIN:
1. While physically at 53A, Jalan Intan Setia 1, near your shop entrance,
   open https://crm.thelabsgadget.com/financehub/geo_setup.php on YOUR phone.
2. Log in as owner, allow Browser Location and Precise Location, and enable GPS.
3. Tap 'Save My Current Location as Shop Centre'. Confirm attendance says enabled.
4. If accuracy is poor (>75m), move closer to an open area and retry.
   Calibration will store your current phone coordinates, not guessed address coordinates.

CLOCK IN/OUT:
Each active employee signs in via the Finance HR page on their own phone.
On Attendance, tap GPS Clock In / GPS Clock Out. App reads GPS once.
Server calculates distance. A reading is accepted only if:
   distance_to_shop + reported_GPS_accuracy <= 150 metres
   and GPS accuracy <= 75 metres, reading fresh <= 60 seconds.
Server time (Malaysia) is used for timekeeping. A failed check saves NO attendance.
Only distance and GPS accuracy are saved per punch; staff raw coordinates are NOT
stored in the attendance record. The shop pin and change history are stored.

NOTES / LIMITATIONS:
- Phone GPS, location permission and HTTPS are required. GPS signal inside buildings
  can be weak; move near an entrance or open area as needed.
- Software/mock GPS may spoof readings. Browser geolocation is not tamper-proof.
- This is a location-at-clock system, not full-day staff tracking.
- Existing attendance records are preserved and will display 'Legacy' GPS distance.
- Existing admin/manager manual clock-out corrections are retained and audited;
  those corrections do not assert GPS validation.
- This patch does not integrate with CRM login or change cash flow.
- No need to create a new database or edit MySQL user privileges.

AFTER TESTING:
Delete only financehub/upgrade_geo_v1_4.php and
financehub/patch_geo_v1_4/ through cPanel. Keep geo_setup.php, app/geofence.php
and assets/geofence.js because they are REQUIRED for the feature.
Never delete financehub/app or touch existing CRM files.

IF THE UPDATER REPORTS AN UNRECOGNIZED HASH OR FILE CHANGE:
STOP. Do NOT manually overwrite the files. Send the message / screenshot for
compatible patch. Previous versions may be customized.
