# ALAMERX Supply Chain Intelligence — Functional V1

PHP + MySQL application designed for OVH shared/VPS hosting and Dynamics NAV 14 OData V4.

## Install
1. Create a MySQL database/user in OVH.
2. Import `sql/schema.sql`.
3. Upload the project. Point the site/subfolder to `public/` (your current `/nav/public/` layout is supported).
4. Set environment variables if available: `DB_HOST`, `DB_NAME`, `DB_USER`, `DB_PASS`, `APP_KEY`.
   If OVH does not expose environment variables, edit `app/config.php` with DB values and replace `CHANGE_ME_TO_A_LONG_RANDOM_SECRET` with a long random secret.
5. Ensure PHP extensions `pdo_mysql`, `curl`, `openssl`, `simplexml` are enabled.
6. Open **NAV Integration** in the sidebar.
7. Enter OData V4 base URL, company, NAV integration username and password/web-service key. Credentials are AES-256-GCM encrypted at rest using APP_KEY.
8. Click **Test Connection**, then **Discover OData Services**.
9. Select entities and sync them. `Purchase_Order` is normalized into purchase-order/supplier tables; every discovered entity can also be cached in `alamerX_nav_raw` and viewed in Data Explorer.

## Security
Use a dedicated read-only NAV integration account first. Do not expose credentials in source control. HTTPS is required. Keep `app/` and `sql/` outside public web access where possible.

## V1 scope
Functional navigation, NAV connection storage/test, OData metadata discovery, entity selection, first-500 manual sync, raw data explorer, Purchase_Order normalization, PO page, supplier page, overview counters.

## Next production work
Pagination (`@odata.nextLink`), incremental sync, scheduled cron, Item/Inventory/Sales/Transfer normalization, replenishment and internal-transfer rules, RBAC/login, CSRF protection, detailed audit trail, background jobs, KPI engine and exports.
