Files
proxmox/scripts/omnl/omnl-gl-accounts-create.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

93 lines
3.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Create the five migration GL accounts (1000, 1050, 2000, 2100, 3000) in OMNL Fineract via API.
# Idempotent: skips if glCode already exists. Run from repo root. Requires: curl, jq.
set -euo pipefail
REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}"
if [ -f "${REPO_ROOT}/omnl-fineract/.env" ]; then
set +u
source "${REPO_ROOT}/omnl-fineract/.env" 2>/dev/null || true
set -u
elif [ -f "${REPO_ROOT}/.env" ]; then
set +u
source "${REPO_ROOT}/.env" 2>/dev/null || true
set -u
fi
BASE_URL="${OMNL_FINERACT_BASE_URL:-}"
TENANT="${OMNL_FINERACT_TENANT:-omnl}"
USER="${OMNL_FINERACT_USER:-app.omnl}"
PASS="${OMNL_FINERACT_PASSWORD:-}"
if [ -z "$BASE_URL" ] || [ -z "$PASS" ]; then
echo "Set OMNL_FINERACT_BASE_URL and OMNL_FINERACT_PASSWORD (e.g. omnl-fineract/.env)" >&2
exit 1
fi
AUTH="${USER}:${PASS}"
CURL_OPTS=(-s -S -w "\n%{http_code}" -H "Fineract-Platform-TenantId: ${TENANT}" -H "Content-Type: application/json" -u "$AUTH")
api_get() {
curl "${CURL_OPTS[@]}" "${BASE_URL}/${1}"
}
api_post() {
local path="$1"
local body="$2"
local out
out=$(curl "${CURL_OPTS[@]}" -X POST -d "$body" "${BASE_URL}/${path}")
HTTP_CODE=$(echo "$out" | tail -n1)
echo "$out" | sed '$d'
}
# type: 1=ASSET, 2=LIABILITY, 3=EQUITY. usage: 1=DETAIL
create_gl() {
local gl_code="$1"
local name="$2"
local type_id="$3"
local description="$4"
local list
list=$(api_get "glaccounts" 2>/dev/null | sed '$d')
if echo "$list" | jq -e --arg c "$gl_code" '.[] | select(.glCode == $c) | .id' >/dev/null 2>&1; then
echo " [skip] $gl_code$name (exists)"
return 0
fi
# Handle both array and object response
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_id" \
--arg desc "$description" \
'{glCode: $code, name: $name, type: $type, usage: 1, manualEntriesAllowed: true, description: $desc}')
api_post "glaccounts" "$body" >/dev/null
if [ "${HTTP_CODE:-0}" = "200" ] || [ "${HTTP_CODE:0:1}" = "2" ]; then
echo " [created] $gl_code$name"
else
echo " [fail] $gl_code HTTP ${HTTP_CODE}" >&2
return 1
fi
}
echo "=== OMNL Fineract — Create migration GL accounts ==="
echo "Base URL: $BASE_URL"
echo ""
create_gl "1000" "USD Settlement Reserves" 1 "USD Settlement & Reserve Assets"
create_gl "1050" "USD Treasury Conversion Reserve (M0)" 1 "Treasury Conversion Reserve (M0); backs M1 capacity at 1:5"
create_gl "2000" "USD Central Deposits" 2 "Central bank customer deposits; M1-denominated claims backed by 1050 where applicable"
create_gl "2100" "USD Restricted Liabilities" 2 "Restricted / held deposits"
create_gl "3000" "Opening Balance Control" 3 "Migration control account"
create_gl "1410" "Due From Head Office (Interoffice Receivable)" 1 "Interoffice receivable at branch"
create_gl "2410" "Due To Offices (Interoffice Payable)" 2 "Interoffice payable at Head Office"
echo ""
echo "Done. Run scripts/omnl/omnl-ledger-post.sh to post T-001T-008."