* 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>
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import type { McpResource } from './types'
|
|
|
|
interface AccountSummary {
|
|
account_number: string
|
|
account_name: string
|
|
account_class: number
|
|
account_type: string
|
|
normal_balance: string
|
|
is_active: boolean
|
|
default_vat_code: string | null
|
|
}
|
|
|
|
export const chartOfAccountsResource: McpResource = {
|
|
uri: 'Accounted://chart-of-accounts',
|
|
name: 'Chart of Accounts (BAS)',
|
|
description: 'The active BAS chart of accounts for the current company, grouped by account class (1=assets, 2=liabilities/equity, 3=revenue, 4=COGS, 5-7=expenses, 8=financial). Use to look up account numbers before booking entries.',
|
|
mimeType: 'application/json',
|
|
read: async ({ supabase, companyId }) => {
|
|
const { data, error } = await supabase
|
|
.from('chart_of_accounts')
|
|
.select('account_number, account_name, account_class, account_type, normal_balance, is_active, default_vat_code')
|
|
.eq('company_id', companyId)
|
|
.order('account_number', { ascending: true })
|
|
|
|
if (error) {
|
|
throw new Error(`Failed to read chart of accounts: ${error.message}`)
|
|
}
|
|
|
|
const accounts = (data ?? []) as AccountSummary[]
|
|
|
|
const byClass: Record<number, AccountSummary[]> = {}
|
|
for (const a of accounts) {
|
|
if (!byClass[a.account_class]) byClass[a.account_class] = []
|
|
byClass[a.account_class].push(a)
|
|
}
|
|
|
|
return {
|
|
total: accounts.length,
|
|
classes: {
|
|
'1': { label: 'Tillgångar', accounts: byClass[1] ?? [] },
|
|
'2': { label: 'Eget kapital och skulder', accounts: byClass[2] ?? [] },
|
|
'3': { label: 'Rörelseintäkter', accounts: byClass[3] ?? [] },
|
|
'4': { label: 'Material- och varukostnader', accounts: byClass[4] ?? [] },
|
|
'5': { label: 'Övriga externa rörelseutgifter', accounts: byClass[5] ?? [] },
|
|
'6': { label: 'Övriga externa rörelseutgifter (forts.)', accounts: byClass[6] ?? [] },
|
|
'7': { label: 'Personalkostnader', accounts: byClass[7] ?? [] },
|
|
'8': { label: 'Finansiella poster', accounts: byClass[8] ?? [] },
|
|
},
|
|
}
|
|
},
|
|
}
|