# JEVAPOS Branch Sync pilot

Use a separate head-office installation and one separate shop installation for
the first trial. Install this version of JEVAPOS at both ends and run:

```powershell
& 'E:\xampp\php\php.exe' artisan migrate --path=database/migrations/2026_11_13_000001_create_branch_sync_tables.php
```

Adjust the PHP path for the installation. Run the command from the project directory.
At head office, create the test shop in Branches and use the same branch ID on the
shop installation. Configure `BRANCH_SYNC_MODE=hub` in the head-office `.env`,
clear the config cache, and issue a token for the branch:

```powershell
& 'E:\xampp\php\php.exe' artisan config:clear
& 'E:\xampp\php\php.exe' artisan branch-sync --register=2
```

Use the actual branch ID in place of 2. Registering the branch again replaces its
old token. Keep the token private. The head-office endpoint requires HTTPS with
a certificate the shop computer trusts. Use PHP's normal TLS verification.

In the shop installation's `.env`, set:

```dotenv
BRANCH_SYNC_MODE=branch
BRANCH_SYNC_LOCAL_BRANCH_ID=2
BRANCH_SYNC_URL=https://pos.example.com/api/branch-sync/exchange
BRANCH_SYNC_TOKEN=replace-with-the-shop-token
BRANCH_SYNC_OPERATOR_ID=7
```

Use the complete API URL, including the installation's base path if applicable.
Use the ID of an active local stock operator assigned to this branch. Clear the
shop config cache and run `artisan branch-sync` once from the shop project folder.
After verifying the first sync, open an administrator PowerShell on the shop PC
and run:

```powershell
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\tools\Install-JevaposBranchSync.ps1 -Project 'E:\xampp\htdocs\jevapos.com' -Php 'E:\xampp\php\php.exe'
```

The agent runs each minute. Keep the shop computer and XAMPP running. Only the
shop computer sends sync requests. Tills continue using the shop's local URL.

On head office, use **Inventory → Stock Periods → Branch Sync and Stock Controls**.
Open or close a period for the selected branch and wait for its confirmation.
Use **Save Schedule** to enable planned-date closing and/or monthly rollover.
Monthly rollover closes and opens at the configured time on the first day of
the month, using the branch's timezone. The branch needs to receive the schedule
once before it can run it offline. If the branch PC was off at the deadline,
the capture uses the actual time the agent runs.

Enter physical counts in the branch's existing **Start Stock Taking** workflow.
The head-office report picks them up on the next sync and supports print and CSV.
For a count after trading resumes, use the expected-at-count figure shown alongside
the saved closing stock.

For the outage trial, disconnect the shop's internet while keeping its local
network connected. Sell an item, receive a purchase, and print a receipt. Reconnect
and check the branch's last received time and records at head office. Run sync
again and confirm the records appear once.

This pilot mirrors a branch snapshot for head-office viewing. It does not import
records into the head-office ledger or normal Sales/Purchases tables, distribute
catalogue changes, reconcile cross-branch transactions, or upload via an incremental
outbox. It has an 8 MB snapshot limit and is intended for a test branch with a
small data set. Ensure the pilot host accepts a JSON request larger than that
limit to allow for JSON encoding overhead.
