* feat(reconciliation): close the bank-feed loop on voucher links and re-tag mis-typed opening balances
Two related fixes to bank reconciliation correctness:
1. Auto-reconcile on voucher link. Linking an invoice or supplier invoice to
an existing voucher previously advanced only the invoice — the bank
transaction that paid it kept sitting in the Transactions inbox with a null
journal_entry_id. linkInvoiceToVoucher / linkSupplierInvoiceToVoucher now
call autoReconcileTransactionForLinkedVoucher (lib/reconciliation), which
links the bank transaction to the same verifikat when exactly one unbooked
line matches it. Best-effort and post-commit: a failure here never fails the
link. The result surfaces reconciledTransactionId; the inbox row leaves the
list and the UI shows link_success_tx_reconciled.
2. Re-tag mis-typed opening balances. getReconciliationStatus and the GL-line
matching RPCs identify a cash account's ingående balans solely by
journal_entries.source_type='opening_balance'. Companies migrated from other
systems often booked the bank IB as an ordinary voucher (source_type
'import' or 'manual'), so it was never excluded and surfaced as a phantom
reconciliation difference equal to the opening balance. Adds:
- migration mark_entry_as_opening_balance: a GUC-gated carve-out in the
immutability trigger plus a SECURITY DEFINER RPC that validates the entry
(balance-sheet lines only, dated on a fiscal-period boundary), flips the
source_type, and writes an audit row — no blanket data sweep.
- POST /api/reconciliation/bank/mark-opening-balance + MarkOpeningBalanceSchema.
- BankReconciliationView action to trigger it from the IB diff.
The gnubok_create_voucher executor now accepts a typed is_opening_balance flag
and derives source_type='opening_balance' only after validating class 1/2 lines
on the period start, so new IBs land correctly typed.
Covered by lib/reconciliation auto-reconcile tests, voucher-executors tests,
and a mark-entry-as-opening-balance pg-real test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore: rebrand gnubok → Accounted and prune swarm agent skills
Product rebrand and skills housekeeping. No runtime behaviour change.
Rebrand: replace user-visible "gnubok" with "Accounted" across docs, READMEs,
in-code comments, doc-site content, MCP skill/resource prose, and the
gnubok-mcp package description. The MCP resource URI scheme is moved gnubok://
→ Accounted:// consistently across resource registrations, the event-type
comment, and the resource/skill tests. Deliberately preserved as stable
identifiers (NOT rebranded): the gnubok-company-id cookie, gnubok_sk_ / gnubok_inv_
token prefixes, the gnubok-mcp npm bridge name, and the AGI <gem:Programnamn>
value (kept 'gnubok' per its source comment — it is the software identifier sent
to Skatteverket and must not churn across visual rebrands).
Skills: remove the 27 swarm-* agent SKILL.md atoms (no longer used; already
absent from the agent_atom_registry in prod), refresh the remaining skill docs,
add the .claude/rules/ path-scoped rule set, and regenerate the
seed_agent_atom_bodies migration + .skill-body-manifest.json via
`npm run skills:generate` so the DB-backed skill bodies match the trimmed set.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
87 lines
4.5 KiB
TypeScript
87 lines
4.5 KiB
TypeScript
import type { Skill } from './types'
|
|
|
|
const body = `# Month-End Close — Accounted
|
|
|
|
Run this at the end of each calendar month to ensure books are clean before locking the period.
|
|
|
|
## When to use
|
|
|
|
Trigger this workflow when the user says any of:
|
|
|
|
- "Close out [month]"
|
|
- "Stäng [månad]"
|
|
- "Month-end close"
|
|
- "Lock [period]"
|
|
|
|
Run it on the **last business day** of the month (or first business day of the next month). Locking too early prevents legitimate late entries; locking too late risks period-skew on VAT filings.
|
|
|
|
## Workflow
|
|
|
|
### Step 1 — Book every business transaction
|
|
|
|
Goal: zero uncategorized business transactions inside the period.
|
|
|
|
1. Call \`gnubok_list_uncategorized_transactions\` to see what's outstanding.
|
|
2. For each, call \`gnubok_suggest_categories\` (batches of up to 20) to get high-confidence proposals.
|
|
3. Stage categorizations via \`gnubok_categorize_transaction\` (or, for income that matches an invoice, \`gnubok_match_transaction_to_invoice\`).
|
|
4. The user approves each in the web app — staging is non-negotiable for legal compliance (BFL 5 kap.).
|
|
|
|
If a transaction is genuinely private, mark it as \`category: 'private'\` — no journal entry will be created.
|
|
|
|
### Step 2 — Reconcile bank
|
|
|
|
Run \`gnubok_get_reconciliation_status\` for the month's date range. The result includes \`bank_balance\`, \`ledger_balance\`, and \`difference\`. Any non-zero difference means unmatched transactions or missing JEs — investigate before locking.
|
|
|
|
### Step 3 — Check voucher gaps
|
|
|
|
Run \`gnubok_list_voucher_gaps\` for the fiscal period. **Every gap must have an explanation** per BFNAR 2013:2. Use \`gnubok_explain_voucher_gap\` to document each one (e.g., "Voucher number reserved but not used because invoice was cancelled before posting").
|
|
|
|
### Step 4 — Run VAT report (monthly filers)
|
|
|
|
If the company files VAT monthly (beskattningsunderlag > 40M SEK, or voluntarily), run \`gnubok_get_vat_report\` with \`period_type: 'monthly'\`. Sanity-check ruta49 ("att betala/återfå"). Use \`gnubok_vat_review_widget\` for a visual review.
|
|
|
|
If quarterly or annual filer: skip — VAT happens on its own cadence (see the quarterly-vat-review skill).
|
|
|
|
### Step 5 — Lock the period
|
|
|
|
Stage the lock via \`gnubok_lock_period(fiscal_period_id)\`. The tool refuses if any business transactions remain unbooked. After user approval, no new entries can be posted into the period — late corrections must use \`gnubok_unlock_period\` (also high-risk, also staged).
|
|
|
|
## Critical rules
|
|
|
|
- **Never delete journal entries.** Use \`gnubok_uncategorize_transaction\` (storno reversal) to undo. DB triggers enforce this — direct deletes will fail.
|
|
- **Posted entries are immutable.** Once a JE is posted, even amounts are locked. Use \`correctEntry\` (web app) for corrections.
|
|
- **Money math:** \`Math.round(x * 100) / 100\`, never \`toFixed()\`. The categorize tool handles this; if you compute manually, follow the same pattern.
|
|
- **Locking ≠ closing.** Locking blocks new entries; closing (after year-end) is irreversible. This skill stops at locking.
|
|
|
|
## Common errors
|
|
|
|
- **"Period must be locked before closing"** — \`gnubok_close_period\` requires \`gnubok_lock_period\` first AND the year-end closing entry. Don't try to close mid-year periods.
|
|
- **"Cannot lock period: N business transactions unbooked"** — Step 1 wasn't complete. Re-run \`gnubok_list_uncategorized_transactions\`.
|
|
|
|
## Tools
|
|
|
|
- \`gnubok_list_uncategorized_transactions\` — find unbooked transactions
|
|
- \`gnubok_suggest_categories\` — get categorization proposals (batch of 20)
|
|
- \`gnubok_categorize_transaction\` — stage a single categorization
|
|
- \`gnubok_match_transaction_to_invoice\` — apply income to a customer invoice
|
|
- \`gnubok_get_reconciliation_status\` — bank vs ledger balance
|
|
- \`gnubok_list_voucher_gaps\` — BFNAR 2013:2 audit check
|
|
- \`gnubok_explain_voucher_gap\` — document a gap
|
|
- \`gnubok_get_vat_report\` — momsdeklaration data
|
|
- \`gnubok_vat_review_widget\` — interactive VAT review
|
|
- \`gnubok_lock_period\` — stage period lock
|
|
- \`gnubok_uncategorize_transaction\` — undo a categorization (storno)
|
|
`
|
|
|
|
export const monthEndCloseSkill: Skill = {
|
|
slug: 'month-end-close',
|
|
name: 'Month-End Close',
|
|
summary: 'End-of-month workflow: book transactions, reconcile bank, verify voucher gaps, file VAT (monthly filers), lock period.',
|
|
tags: ['monthly', 'close', 'reconciliation', 'vat'],
|
|
body,
|
|
tier: 'workflow',
|
|
// Universal — both AB and EF run a monthly close. VAT step is conditional
|
|
// inside the body so non-VAT-registered companies aren't blocked.
|
|
applicability: { entity_type: 'both' },
|
|
}
|