# Fixes applied — 2026-09-17

Follow-up to a full link/QR audit of https://ciba.res.in/laksyashrimp/. Three real bugs were found and fixed in this package. Nothing else was touched.

## 1. Two QR codes / block links led to a 404 ("No block found for index N")

**Root cause:** `static/json/block_mapping.json` (used by the `/lineage_block/<species>/<n>` route) is built by keying each block's exported JSON file on its `Unique Blockchain ID` / `Unique ID`. Two source records in `blockchain_logic.py` accidentally shared the same ID as a *different* record, so when the export step wrote files by ID, the second record silently overwrote the first on disk — the first one's block-mapping entry vanished entirely, leaving a gap.

- **Monodon block #8 ("Marketing-1")** — `Unique Blockchain ID: 251021020882849623` was identical to Monodon "Marketing-3"'s ID. Both are real, distinct records (Pattinapakkam Fish Market vs. Marina Fish Market) that got merged into one file under the same key.
- **Vannamei 2025 block #6 ("Hatchery-Nursery")** — `Unique ID: TNII15981720010126` was identical to the "Grow-out System" (RGCA) record's ID. `app.py` already had special-case code (`VANNAMEI_2025_SUB_LABELS["TNII15981720010126_grow"]`) working around this exact collision for the sub-label display, but the export/mapping step was never patched, so the Hatchery-Nursery record still vanished.

**Fix:**
- `blockchain_logic.py`: gave Monodon's "Marketing-1" a new, non-colliding `Unique Blockchain ID` (`...849624`, was `...849623`) and `Unique Secondary ID` (`...877904`, was `...877903`).
- `blockchain_logic.py`: gave Vannamei 2025's "Hatchery-Nursery" a new `Unique ID` (`TNII15981720010127`, was `TNII15981720010126`).
- `app.py`: updated `VANNAMEI_2025_SUB_LABELS` to key the Hatchery-Nursery sub-label ("2e") off the new ID.
- Added the two missing per-block export files with their real, existing content (nothing invented) and the corrected IDs:
  - `static/json/monodon/251021020882849624.json`
  - `static/json/vannamei_2025/TNII15981720010127.json`
- Added the corresponding entries to `static/json/block_mapping.json` (index 8 and index 6). Verified: both species now have a complete, gap-free 1..N index range.

No QR image files needed to change — the QR codes on the dashboard already encoded the correct URL; they just pointed at a mapping entry that didn't exist yet.

## 2. "Dashboard →" link on every species page went to an "Unknown Product" page

**Root cause:** `templates/index.html` called `url_for('product_trace', batch_id=selected_product_id)`, passing the species key (e.g. `"vannamei"`) as if it were a real batch ID. `product_trace()` looks for `static/data/<species>/<batch_id>.json`, and no such file (`vannamei.json`, `monodon.json`, etc.) exists, so it always rendered `traceability_view_full.html` with `batch=None` → "Unknown Product". This returns HTTP 200, so a plain status check won't catch it.

**Fix:**
- `app.py` (`index()`): now looks up the first real batch export that exists for the selected species under `static/data/<species>/` (e.g. `VAN-CIBA-001`, `MON-CIBA-001`, `IND-CIBA-001`) and passes it as `dashboard_batch_id`.
- `templates/index.html`: the "Dashboard →" link now points at that real batch id. **Vannamei 2025 has no `static/data/vannamei_2025/` export yet**, so rather than link to something guaranteed to still say "Unknown Product," the link is hidden for that species until a real batch export exists for it. If you'd rather it point somewhere specific for Vannamei 2025, let us know and we'll wire that up instead of hiding it.

## 3. Not changed

Everything else audited (all 211 QR codes across the 4 species dashboards, all block/feedback links, the lineage-trace pages, CSS/font assets) was already working and is unaffected by this patch.

## To deploy

This only changes application code and static JSON — no server config or dependency changes. Standard redeploy (copy these files over, restart the WSGI/Flask process) is all that's needed. The two SQLite `.db` files are untouched.
