feat(finance): ledger API + auto-posting (#97 increment 2)#97
Merged
Conversation
Increment 2 of the general ledger — wires the domain from #96 into the app. - /ledger admin API (routes/ledger.ts): POST /init seeds the default chart of accounts (idempotent, lib/coa.ts); GET /accounts; POST /journal-entries for manual/adjusting entries with the balanced-entry guard enforced at the boundary; GET /journal-entries; GET /accounts/:id/ledger drill-down with a running balance in the account's normal direction. - Posting service (lib/ledger-posting.ts): resolves accounts by code, inserts balanced entries idempotently (unique index), and auto-posts §6.1 bill-issued and §6.2 payment-received. Best-effort + swallowed so a ledger issue never blocks the finance write; no-op until the CoA is initialized. - Wired into bills (create + generate), the monthly cron, and payments. - account_id on bill_line_items + bill_config template lines so charges post to the right income/fund head (default Maintenance Income). Migration 0020. - Tests: splitReceivableAdvance unit tests + /ledger route tests (auth + unbalanced-entry rejection). Full suite 311 green. Migrations 0019/0020 are committed for the deploy step; not applied to any DB here. Backfill/opening-balances and the trial balance surface come with #98.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M3.5 · Task #97 (increment 2 of 2) — completes the GL
Wires the pure posting domain from #96 into the running app. Builds on the merged foundation.
API (
apps/api/src/routes/ledger.ts, ADMIN-only)POST /ledger/init— idempotently seed the default chart of accounts (lib/coa.ts). Run once to switch accounting on.GET /ledger/accounts— chart of accounts.POST /ledger/journal-entries— manual/adjusting entries; the balanced-entry invariant is enforced at the boundary (unbalanced → 400).GET /ledger/journal-entries— filter by?period/?sourceType.GET /ledger/accounts/:id/ledger— account drill-down with a running balance in the account's normal direction.Auto-posting (
apps/api/src/lib/ledger-posting.ts)POST /ledger/initruns.Schema
account_idonbill_line_items+bill_configtemplate lines → charges post to the right income/fund head (default Maintenance Income). Migration 0020 (additive column + FK).Tests
splitReceivableAdvanceunit tests +/ledgerroute tests (auth + unbalanced-entry rejection). Full suite 311 green; API lint clean; web typechecks.Deploy note
Migrations 0019 + 0020 are committed but not applied to any DB here — apply on deploy, then
POST /ledger/init. Historical backfill / opening balances and the trial-balance surface land with #98 (statements).