# Dual weighbridge at one site - setup (Phase 1)

## What it does
- One PC reads **two indicators** (two COM ports). The first one listed is the "primary" and also does the shared camera work.
- On **New Transaction** and on the weighing page both weighbridges are shown side by side with their own live reading and
  Online/Offline status. The operator clicks the one they are working on (highlighted "WORKING HERE"). Its reading is the one captured.
- The first and second weighing of a job can be on different weighbridges, or on the same one. Open jobs are shared by both.
- Every weighing records **which weighbridge took it** (audit only: shown in the "Weighings So Far" list, not on the ticket).
- Each camera can be tagged to a weighbridge, or left "Both / shared". A weighing on a weighbridge is photographed by that weighbridge's
  cameras plus the shared ones. Live Cameras groups the cameras by weighbridge.
- A site with ONE weighbridge looks and works exactly as before.

## Install, in this order
1. **Database** - phpMyAdmin -> SQL -> run `sql/migrate_section17_dual_weighbridge.sql` once.
   (If you upload the web files first, weighing keeps working; the new features switch on when the SQL has been run.)
2. **Web files** - upload the files of the patch zip to the same folders under `public_html/webapp/`.
3. **Second weighbridge on the cloud** - ISVAdmin -> Companies & Sites -> the site -> add a weighbridge (name + device ID, for example ISV-02).
   Copy the device key it shows (it is shown once).
4. **Agent** - in Visual Studio replace `Program.cs`, rebuild, copy the new exe to the weighbridge PC.
   Open the agent's `App.config`, ADD the `Weighbridge1.*` and `Weighbridge2.*` keys (see `App.config.dual-example`), and start the agent.
   Check the window: `[ISV-01] [serial] opened COM12 ...` and `[ISV-02] [serial] opened COM13 ...`.
5. **Indicator format** (optional, per weighbridge) - ISVAdmin -> Indicator Settings -> choose weighbridge 2 -> set its COM port / format.
6. **Cameras** - ISVAdmin -> Camera Settings -> Edit each camera -> choose its **Weighbridge** (or leave "Both / shared").

## Checks
- Dashboard shows both weighbridges with live weight. Switch one indicator off: only that one turns Offline.
- New Transaction: click Weighbridge 2 -> it is highlighted and "Weight to be captured" follows its reading.
- Capture a weight, then do the second weighing on the other weighbridge; the weighings list names both.
- Capture photos: only the cameras of that weighbridge (+ shared) appear for that weighing.

## Notes
- Up to four weighbridges per PC are supported by the agent (Weighbridge3.*, Weighbridge4.*).
- Do not give two weighbridges the same COM port.
- A wrong key for one weighbridge only stops that weighbridge (the agent log shows `[ISV-02] [post] REJECTED 401`).
- Sharing jobs between different SITES and per-login report scope are Phase 2.
