---
title: "Export balanced journals to the accounting · Agent Wranglers"
url: https://agentwranglers.se/playbook/pricing/ledger-and-accounting/general-ledger-export
id: PRC-22
level: Recommended
applies: payments
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1100
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Export balanced journals to the accounting system each period

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Ledger and accounting](https://agentwranglers.se/playbook/pricing/ledger-and-accounting.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: PRC-22
- Level: Recommended
- Chapter: [Ledger and accounting](https://agentwranglers.se/playbook/pricing/ledger-and-accounting.md)
- Rule: At each period end, export the period's journal entries, summed per account and currency, to the general ledger. Each export is balanced, numbered and reconciled against the ledger totals before the period closes.
- Check: A test exports a closed month. The export's debits equal its credits in every currency, and each account total equals the ledger total for that month. A second export of the same month has the same ID and the same lines. A posting dated in a closed month is refused.
- Applies when: The project takes payments.
- How: Accountants post summaries, not every charge. Map each ledger account to an account number in the chart of accounts the accountant uses. Export once per period with a unique export ID, so a rerun replaces the file instead of posting twice. Close the period after export, and book later corrections in the next open period. Reconcile payouts first, as [Reconcile every payout](https://agentwranglers.se/playbook/payments/payment-events-and-reconciliation/payout-reconciliation.md) says, so cash in the export matches the bank. The entries come from [Book every money movement as balanced double-entry postings](https://agentwranglers.se/playbook/pricing/ledger-and-accounting/double-entry-ledger.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### TypeScript example

```ts
export async function exportPeriod(db, period: string) {
  const lines = await db.query(
    `SELECT a.gl_number, p.currency, sum(p.amount_minor) AS amount_minor
     FROM postings p JOIN journal_entries e ON e.id = p.entry_id JOIN gl_accounts a ON a.account = p.account
     WHERE to_char(e.occurred_at, 'YYYY-MM') = $1 GROUP BY a.gl_number, p.currency`, [period])
  const unbalanced = Object.values(Object.groupBy(lines.rows, l => l.currency))
    .some(rows => rows.reduce((sum, l) => sum + BigInt(l.amount_minor), 0n) !== 0n)
  if (unbalanced) throw new Error(`Period ${period} does not balance`)
  return { exportId: `gl-${period}`, lines: lines.rows }
}
```

### Python example

```python
from collections import defaultdict

def export_period(db, period: str) -> dict:
    lines = db.execute(
        """SELECT a.gl_number, p.currency, sum(p.amount_minor)
           FROM postings p JOIN journal_entries e ON e.id = p.entry_id JOIN gl_accounts a ON a.account = p.account
           WHERE to_char(e.occurred_at, 'YYYY-MM') = %s GROUP BY a.gl_number, p.currency""", (period,)).fetchall()
    totals = defaultdict(int)
    for _, currency, amount in lines:
        totals[currency] += amount
    if any(totals.values()):
        raise ValueError(f"Period {period} does not balance")
    return {"export_id": f"gl-{period}", "lines": lines}
```

## Related rules

- PAY-22 [Reconcile every payout](https://agentwranglers.se/playbook/payments/payment-events-and-reconciliation/payout-reconciliation.md) in Payments and billing
- PRC-18 [Book every money movement as balanced double-entry postings](https://agentwranglers.se/playbook/pricing/ledger-and-accounting/double-entry-ledger.md) in Pricing, plans and entitlements

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/pricing/ledger-and-accounting/general-ledger-export">Agent Wranglers pricing, plans and entitlements playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Report unused customer balances under US unclaimed property laws](https://agentwranglers.se/playbook/pricing/ledger-and-accounting/unclaimed-property.md)
- [Ledger and accounting](https://agentwranglers.se/playbook/pricing/ledger-and-accounting.md)
