Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
96 lines
4.9 KiB
Bash
Executable File
96 lines
4.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Create OMNL Central Bank Chart of Accounts (GL accounts) in Fineract.
|
|
# Idempotent: GET by glCode before POST. Run from project root.
|
|
# Requires MIFOS_BASE_URL, MIFOS_USER, MIFOS_PASSWORD in .env.
|
|
|
|
set -euo pipefail
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=lib.sh
|
|
source "${SCRIPT_DIR}/lib.sh"
|
|
|
|
fail_if_no_credentials
|
|
|
|
# Fineract: type 1=ASSET, 2=LIABILITY, 3=EQUITY, 4=INCOME, 5=EXPENSE
|
|
# usage: 1=DETAIL, 2=HEADER
|
|
create_gl() {
|
|
local gl_code="$1"
|
|
local name="$2"
|
|
local type="$3"
|
|
local usage="$4"
|
|
local parent_id="${5:-}"
|
|
local desc="${6:-}"
|
|
|
|
# Check if exists (GET glaccounts and filter by glCode)
|
|
local list; list=$(api_get "glaccounts")
|
|
if echo "$list" | grep -q "\"glCode\":\"${gl_code}\""; then
|
|
echo " [skip] $gl_code — $name (exists)"
|
|
return 0
|
|
fi
|
|
|
|
local body
|
|
body=$(jq -n \
|
|
--arg code "$gl_code" \
|
|
--arg name "$name" \
|
|
--argjson type "$type" \
|
|
--argjson usage "$usage" \
|
|
--arg desc "$desc" \
|
|
'{glCode: $code, name: $name, type: $type, usage: $usage, manualEntriesAllowed: true, description: $desc}')
|
|
if [ -n "$parent_id" ]; then
|
|
body=$(echo "$body" | jq --argjson pid "$parent_id" '. + {parentId: $pid}')
|
|
fi
|
|
|
|
api_post "glaccounts" "$body" >/dev/null
|
|
if [ "${MIFOS_HTTP_CODE:-0}" = "200" ]; then
|
|
echo " [created] $gl_code — $name"
|
|
else
|
|
echo " [fail] $gl_code HTTP ${MIFOS_HTTP_CODE}" >&2
|
|
fi
|
|
}
|
|
|
|
echo "=== OMNL Central Bank — Chart of Accounts ==="
|
|
echo "Base URL: $MIFOS_BASE_URL"
|
|
echo ""
|
|
|
|
# Create headers first (no parent), then details with parentId.
|
|
# Fineract returns resource identifier in response; we simplify by creating in order and relying on glCode uniqueness.
|
|
# Parent IDs: we need to resolve by glCode. For idempotency we fetch after each header and pass id for children (optional; some Fineract versions accept parent glCode). Here we create in dependency order and use parentId only when we have it.
|
|
# Simplified: create all accounts; parentId can be omitted for root-level headers, and set for children if API returns IDs. Alternatively create headers first, then GET list, then create children with parentId from list.
|
|
# Creating in order: 10000, 11000, 12000, 13000, then 11010... so children come after parents. We don't pass parentId in this version to avoid extra GETs; hierarchy can be set in UI or in a second pass.
|
|
create_gl "10000" "Assets (header)" 1 2 "" "Total assets"
|
|
create_gl "11000" "Gold and commodity reserves (header)" 1 2 "" "Gold and commodity reserves"
|
|
create_gl "11010" "Gold reserves (XAU)" 1 1 "" "Physical and allocated gold; XAU triangulation asset"
|
|
create_gl "11020" "Silver reserves (XAG)" 1 1 "" "Strategic metal reserves"
|
|
create_gl "11030" "Other commodity reserves" 1 1 "" "Oil, gas, strategic metals as configured"
|
|
create_gl "12000" "Foreign currency reserves (header)" 1 2 "" "FX reserves"
|
|
create_gl "12010" "FX reserves — USD" 1 1 "" "Foreign currency reserves USD"
|
|
create_gl "12020" "FX reserves — EUR" 1 1 "" "Foreign currency reserves EUR"
|
|
create_gl "12090" "FX reserves — other" 1 1 "" "Other ISO and special units"
|
|
create_gl "13000" "FX settlement balances (header)" 1 2 "" "Settlement balances"
|
|
create_gl "13010" "FX settlement — nostro" 1 1 "" "Settlement balances with counterparties"
|
|
|
|
create_gl "20000" "Liabilities (header)" 2 2 "" "Total liabilities"
|
|
create_gl "21000" "M00 — Base reserve (header)" 2 2 "" "Central bank reserve unit; GRU-denominated"
|
|
create_gl "21010" "M00 — Bank reserves (control)" 2 1 "" "Control account for M00"
|
|
create_gl "22000" "M0 — Monetary base (header)" 2 2 "" "Physical currency equivalents; central bank liabilities in circulation"
|
|
create_gl "22010" "M0 — Currency in circulation" 2 1 "" "Vault cash and reserve balances"
|
|
create_gl "23000" "M1 — Narrow money (header)" 2 2 "" "Demand deposits; tokenized/digital representations"
|
|
create_gl "23010" "M1 — Demand deposits (control)" 2 1 "" "Bank-issued liabilities backed by M0/M00"
|
|
|
|
create_gl "30000" "Equity (header)" 3 2 "" "Equity"
|
|
create_gl "31000" "Sovereign capital" 3 1 "" "Capital accounts"
|
|
create_gl "32000" "Revaluation surplus" 3 1 "" "Cumulative revaluation gains"
|
|
create_gl "32010" "Revaluation deficit" 3 1 "" "Cumulative revaluation losses"
|
|
|
|
create_gl "40000" "Income (header)" 4 2 "" "Income"
|
|
create_gl "41000" "Seigniorage" 4 1 "" "Seigniorage income"
|
|
create_gl "42000" "FX gains (realized)" 4 1 "" "Realized foreign exchange gains"
|
|
create_gl "42100" "Unrealized FX gain (P&L)" 4 1 "" "Unrealized FX gain (revaluation)"
|
|
|
|
create_gl "50000" "Expenses (header)" 5 2 "" "Expenses"
|
|
create_gl "51000" "FX losses (realized)" 5 1 "" "Realized foreign exchange losses"
|
|
create_gl "52000" "Monetary operations costs" 5 1 "" "Cost of monetary operations"
|
|
create_gl "52100" "Unrealized FX loss (P&L)" 5 1 "" "Unrealized FX loss (revaluation)"
|
|
|
|
echo ""
|
|
echo "CoA setup complete. See docs/04-configuration/mifos-omnl-central-bank/CHART_OF_ACCOUNTS.md"
|