Files
accounted/lib/bookkeeping/account-classifier.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

23 lines
939 B
TypeScript

import { getBASReference } from './bas-reference'
import { classifyAccountHeuristic, type ClassifiedAccount } from './account-classifier-heuristic'
/**
* Map a 4-digit BAS account number to its account_type and normal_balance.
*
* Strategy:
* 1. If the number is in BAS_REFERENCE, return that authoritative entry.
* 2. Otherwise fall back to a group-based heuristic aligned with BAS 2026.
*
* Class-8 groups are subtle: 80/81/82/83/87/88 are intäkter (revenue), 84/89 are
* kostnader (expense). The legacy heuristic defaulted everything not in 83/84 to
* expense, which silently misclassified dividends, capital gains, and
* bokslutsdispositioner.
*/
export function classifyAccount(accountNumber: string): ClassifiedAccount {
const ref = getBASReference(accountNumber)
if (ref) {
return { account_type: ref.account_type, normal_balance: ref.normal_balance }
}
return classifyAccountHeuristic(accountNumber)
}