Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m21s
CI/CD Pipeline / Security Scanning (push) Successful in 2m42s
CI/CD Pipeline / Terraform Validation (push) Has been cancelled
CI/CD Pipeline / Kubernetes Validation (push) Has been cancelled
CI/CD Pipeline / Lint and Format (push) Has been cancelled
Deploy ChainID 138 / Deploy ChainID 138 (push) Has been cancelled
Validation / validate-genesis (push) Has been cancelled
Validation / validate-terraform (push) Has been cancelled
Validation / validate-kubernetes (push) Has been cancelled
Validation / validate-smart-contracts (push) Has been cancelled
Validation / validate-security (push) Has been cancelled
Validation / validate-documentation (push) Has been cancelled
Verify Deployment / Verify Deployment (push) Has been cancelled
Add a read-only money-supply endpoint for Office 24 dashboards, pass Fineract env through deploy scripts, and provide a seed script for the opening Dr 1410 / Cr 2100 journal. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.4 KiB
JavaScript
74 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Post Office 24 opening M1 journal to Fineract:
|
|
* Dr 1410 Due From Head Office
|
|
* Cr 2100 M1 Central Liabilities
|
|
*
|
|
* Requires: OMNL_FINERACT_BASE_URL, OMNL_FINERACT_PASSWORD
|
|
* Amount: OFFICE24_OPENING_M1_USD (required unless --dry-run)
|
|
*/
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const repoRoot = path.resolve(__dirname, '../..');
|
|
const configPath = path.join(repoRoot, 'config/offices/office-24-opening-journal.v1.json');
|
|
|
|
const dryRun = process.argv.includes('--dry-run');
|
|
const cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
|
|
const base = (process.env.OMNL_FINERACT_BASE_URL || process.env.FINERACT_BASE_URL || '').replace(/\/$/, '');
|
|
const tenant = process.env.OMNL_FINERACT_TENANT || process.env.FINERACT_TENANT || 'omnl';
|
|
const user =
|
|
process.env.OMNL_FINERACT_USER?.trim() ||
|
|
process.env.OMNL_FINERACT_USERNAME?.trim() ||
|
|
'ali_hospitallers_tenant';
|
|
const pass = process.env.OMNL_FINERACT_PASSWORD || '';
|
|
const amountRaw = process.env[cfg.amountEnv] || process.env.OFFICE24_OPENING_M1_USD || '';
|
|
const amount = parseFloat(amountRaw);
|
|
|
|
if (!base || !pass) {
|
|
console.error('Set OMNL_FINERACT_BASE_URL and OMNL_FINERACT_PASSWORD');
|
|
process.exit(1);
|
|
}
|
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
console.error(`Set ${cfg.amountEnv} to a positive USD amount (e.g. export OFFICE24_OPENING_M1_USD=1000000)`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const entry = {
|
|
officeId: cfg.officeId,
|
|
transactionDate: new Date().toISOString().slice(0, 10),
|
|
referenceNumber: cfg.referenceNumber,
|
|
comments: cfg.comments,
|
|
debits: [{ glAccountId: parseInt(cfg.debitGlCode, 10), amount }],
|
|
credits: [{ glAccountId: parseInt(cfg.creditGlCode, 10), amount }],
|
|
};
|
|
|
|
console.log(JSON.stringify({ dryRun, officeId: cfg.officeId, amount, entry }, null, 2));
|
|
|
|
if (dryRun) {
|
|
console.log('Dry run — no journal posted.');
|
|
process.exit(0);
|
|
}
|
|
|
|
const auth = Buffer.from(`${user}:${pass}`).toString('base64');
|
|
const res = await fetch(`${base}/journalentries`, {
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: `Basic ${auth}`,
|
|
'Fineract-Platform-TenantId': tenant,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(entry),
|
|
});
|
|
|
|
const body = await res.text();
|
|
if (!res.ok) {
|
|
console.error(`Fineract POST failed (${res.status}): ${body}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('Office 24 opening journal posted:', body);
|