# Upgrading PinnexBridge from v0.3.2 to v0.3.3

Three steps. Your settings are preserved.

## 1. Copy this ZIP to the Windows PC

Email or USB the file `PinnexBridge-0.3.3.zip` to the Windows machine
where Tally Prime runs.

## 2. Extract and run install.ps1

Right-click `install.ps1` -> **Run with PowerShell** (as Administrator).

You will NOT be prompted for the license key, firm code, or company name —
the installer detects your existing `C:\Program Files\Pinnex Bridge\.env`
and leaves it untouched.

What you should see at the end:

```
[*] Existing .env detected at C:\Program Files\Pinnex Bridge\.env - PRESERVING (upgrade mode)
[*] Stopping existing PinnexBridge service
[*] Copying pinnex-bridge.exe and nssm.exe to C:\Program Files\Pinnex Bridge
[+] .env preserved
[*] Starting PinnexBridge
[*] Testing http://127.0.0.1:9888/health
[+] PinnexBridge updated to v0.3.3

  firm_code:        PINNEX
  tally_reachable:  True
  company_loaded:   True
  matched_company:  Being Zero Consulting Private Limited (From Apr 25)
  loaded_companies: Being Zero Consulting Private Limited (From Apr 25), Testing Company
  bridge URL:       http://127.0.0.1:9888

------------------------------------------------------------
  New in v0.3.3
------------------------------------------------------------
  Per-call Tally company override:
    tally_post_voucher and tally_post_voucher_xml now accept
    an optional 'tally_company' parameter. One Bridge can post
    to ANY currently-open Tally company without editing .env
    or restarting the PinnexBridge service.

    Companies you can target right now:
      - Being Zero Consulting Private Limited (From Apr 25)
      - Testing Company

  Raw XML forwarding:
    POST /sync/xml now accepts a raw Tally Import-XML envelope
    (Content-Type: text/xml). Add ?tally_company=<name> on the
    query string to rewrite SVCURRENTCOMPANY in-flight.
```

The line that matters is **`PinnexBridge updated to v0.3.3`**, followed
by `capabilities.per_call_tally_company_override: true` in the JSON
returned by `/health`.

## 3. Verify the new capability from your Mac

Sanity-check that the override works end-to-end. From your Mac:

```bash
# Default .env company (no override)
curl -s -X POST http://100.65.233.69:9888/sync/push \
  -H "Authorization: Bearer $(cat ~/.pinnex/license.jwt)" \
  -H "Content-Type: application/json" \
  -d '{
    "dry_run": true,
    "vouchers": [{
      "type": "Journal", "date": "2026-06-10",
      "entries": [
        { "ledger": "A", "amount": 100, "dr_cr": "Dr" },
        { "ledger": "B", "amount": 100, "dr_cr": "Cr" }
      ]
    }]
  }' | python3 -c 'import json,sys; r=json.load(sys.stdin); print("source:", r["tally_company_source"], " company:", r["tally_company"])'

# Per-call override to the other open company
curl -s -X POST http://100.65.233.69:9888/sync/push \
  -H "Authorization: Bearer $(cat ~/.pinnex/license.jwt)" \
  -H "Content-Type: application/json" \
  -d '{
    "dry_run": true,
    "tally_company": "Testing Company",
    "vouchers": [{
      "type": "Journal", "date": "2026-06-10",
      "entries": [
        { "ledger": "A", "amount": 100, "dr_cr": "Dr" },
        { "ledger": "B", "amount": 100, "dr_cr": "Cr" }
      ]
    }]
  }' | python3 -c 'import json,sys; r=json.load(sys.stdin); print("source:", r["tally_company_source"], " company:", r["tally_company"])'
```

You should see:

```
source: env  company: Being Zero Consulting Private Limited (From Apr 25)
source: per_call_override  company: Testing Company
```

If the second curl reports `source: env`, the upgrade did not land — check
that `/health` returns `version: "0.3.3"` and that nothing is caching the
old binary.

## What if I want to keep using the v0.3.2 wire format?

You can. v0.3.3 is fully backward compatible:

- POST /sync/push without `tally_company` continues to use the .env
  default exactly as before.
- /sync/xml still accepts a JSON body of shape `{"xml": "<ENVELOPE>..."}`
  in addition to raw XML — so older callers don't break.
- The bearer-token auth, the post-OAuth org-membership check, and the
  fail-open license behaviour are unchanged.

## Rollback (if anything breaks)

```powershell
# Stop v0.3.3
Stop-Service PinnexBridge

# Restore the old binary
Copy-Item "<wherever you backed up v0.3.2 exe>" `
          "C:\Program Files\Pinnex Bridge\pinnex-bridge.exe" -Force

# Restart
Start-Service PinnexBridge
```

Your `.env` is untouched in both directions, so rolling back is a pure
binary swap.

## Notes

- Default bridge port is 9888 (unchanged from v0.3.1 / v0.3.2).
- License verify still fails open when `api.pinnex.in` is unreachable.
- The MCP server (`mcp/tally-bridge-mcp.mjs`) has been bumped to v0.3.3
  as well. If you have a long-running Claude Desktop session, restart it
  so the MCP exposes the new `tally_company` tool argument.
