diff --git a/config/offices/office-24-opening-journal.v1.json b/config/offices/office-24-opening-journal.v1.json index b42e95e..9bd7676 100644 --- a/config/offices/office-24-opening-journal.v1.json +++ b/config/offices/office-24-opening-journal.v1.json @@ -1,12 +1,18 @@ { "$schema": "Office 24 opening M1 allocation from Head Office (Fineract journal)", - "version": "1.0.0", + "version": "1.1.0", "officeId": 24, "externalId": "HOSPITALLERS-ZARDASHT-IRAQ-IRAN", "referenceNumber": "HOSPITALLERS-24-OPENING-M1", + "headOfficeReferenceNumber": "HOSPITALLERS-24-OPENING-M1-HO", "comments": "M1 allocation from Head Office — Dr 1410 Due From HO / Cr 2100 M1 Central Liabilities", "debitGlCode": "1410", "creditGlCode": "2100", + "headOfficeDebitGlCode": "2100", + "headOfficeCreditGlCode": "2410", + "materialOpeningUsd": 1000000000, + "journalMatrixDoc": "docs/04-configuration/mifos-omnl-central-bank/omnl-journal-matrix-hospitallers24-opening-1b.json", + "runbookDoc": "docs/04-configuration/mifos-omnl-central-bank/HOSPITALLERS24_OFFICE_OPENING_1B_M1.md", "currency": "USD", "ipsasRef": "IPSAS 28", "amountEnv": "OFFICE24_OPENING_M1_USD", diff --git a/config/omnl-hospitallers-office24-status.v1.json b/config/omnl-hospitallers-office24-status.v1.json new file mode 100644 index 0000000..7be81e2 --- /dev/null +++ b/config/omnl-hospitallers-office24-status.v1.json @@ -0,0 +1,18 @@ +{ + "version": "1.0.0", + "officeId": 24, + "externalId": "HOSPITALLERS-ZARDASHT-IRAQ-IRAN", + "fundingPosted": true, + "openingM1Usd": 1000000000, + "postedAt": "2026-06-29T10:44:05Z", + "references": { + "officeLeg": "HOSPITALLERS-24-OPENING-M1", + "headOfficeLeg": "HOSPITALLERS-24-OPENING-M1-HO" + }, + "evidence": { + "canaryBundle": "reconciliation/canary-office24-hospitallers-1b-20260629-104405/", + "complianceBundle": "reports/compliance/hospitallers-office24-1b-open-20260629/", + "statusReport": "reports/status/hospitallers-office24-1b-open-20260629.json" + }, + "notes": "Do not run seed-office-24-opening-journal.mjs at $1B — office leg already posted in Fineract." +} diff --git a/scripts/deployment/activate-omnl-production.sh b/scripts/deployment/activate-omnl-production.sh index 05c14a1..2005350 100644 --- a/scripts/deployment/activate-omnl-production.sh +++ b/scripts/deployment/activate-omnl-production.sh @@ -34,17 +34,25 @@ else fi log "=== 5/5 Office 24 opening journal (activate live ledgers) ===" +MATERIAL_OPENING_USD="${OMNL_MATERIAL_OPENING_THRESHOLD:-10000000}" +STATUS_FILE="$REPO_DIR/config/omnl-hospitallers-office24-status.v1.json" if [[ "$SEED_JOURNAL" == "1" ]] && [[ -f "$ENV_FILE" ]]; then set -a # shellcheck disable=SC1090 source "$ENV_FILE" set +a - if [[ -n "${OFFICE24_OPENING_M1_USD:-}" ]]; then - node scripts/deployment/seed-office-24-opening-journal.mjs - bash scripts/deployment/deploy-omnl-bank-production.sh + if [[ -f "$STATUS_FILE" ]] && grep -q '"fundingPosted"[[:space:]]*:[[:space:]]*true' "$STATUS_FILE" 2>/dev/null; then + log "Office 24 fundingPosted=true in status SSOT — skip single-leg seed (journal already live)" + elif [[ -n "${OFFICE24_OPENING_M1_USD:-}" ]]; then + opening_amt="${OFFICE24_OPENING_M1_USD//,/}" + if awk -v amt="$opening_amt" -v lim="$MATERIAL_OPENING_USD" 'BEGIN { exit !(amt >= lim) }'; then + log "Material opening amount ($OFFICE24_OPENING_M1_USD) — skip single-leg seed (use 1b canary/execute matrix)" + else + node scripts/deployment/seed-office-24-opening-journal.mjs + bash scripts/deployment/deploy-omnl-bank-production.sh + fi else - log "OFFICE24_OPENING_M1_USD not set — ledger stays connected-but-empty (fineractLive=false)" - log "Set OFFICE24_OPENING_M1_USD in .env and re-run: bash scripts/deployment/activate-omnl-production.sh" + log "OFFICE24_OPENING_M1_USD not set — ledger reads live Fineract only (no seed)" fi else log "Journal seed skipped (SEED_OFFICE24_JOURNAL=$SEED_JOURNAL)" diff --git a/scripts/deployment/seed-office-24-opening-journal.mjs b/scripts/deployment/seed-office-24-opening-journal.mjs index ecbe655..c07b051 100644 --- a/scripts/deployment/seed-office-24-opening-journal.mjs +++ b/scripts/deployment/seed-office-24-opening-journal.mjs @@ -34,6 +34,15 @@ if (!Number.isFinite(amount) || amount <= 0) { process.exit(1); } +const MATERIAL_THRESHOLD = 10_000_000; +if (amount >= MATERIAL_THRESHOLD) { + console.error( + `Amount ${amount} exceeds single-leg seed limit ($${MATERIAL_THRESHOLD}). ` + + 'Material openings use the two-leg HO matrix: scripts/omnl/office24-hospitallers-1b-canary.sh and office24-hospitallers-1b-execute.sh', + ); + process.exit(1); +} + const auth = Buffer.from(`${user}:${pass}`).toString('base64'); const headers = { Authorization: `Basic ${auth}`,