* chore: repo-wide bloat sweep, remove dead code and fold duplicate helpers Remove 33 dead files, ~270 unreferenced exports/types, 13 dead i18n namespaces and 4 unused dependencies; fold byte-identical helper copies into one canonical home each (lib/utils chunk/sleep/utcDateStamp, lib/dates/iso, lib/invariants/uuid, lib/xml/escape, lib/reports/sru/format, lib/pdf/number-text, lib/browser/panel-request, lib/api/v1/body + v1ValidationError rolled out to ~55 v1 routes, booking-template schemas). No behaviour change: v1 bodies and status codes, MCP tool schemas, DB writes and money math are untouched. Naive ore rounding was deliberately not swapped for roundOre; see DECISIONS.md 2026-09-02 for the full list of things left alone on purpose. tsc, lint, 19588 unit tests and check:guards green; antipattern baseline ratcheted (naive-ore-round 622 -> 620, hand-rolled-invariant 115 -> 113). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * test(transactions): import RawTransaction from @/types after the ingest re-export removal CI's type ratchet (check:types, full tsconfig) caught the one test file that still imported the type through lib/transactions/ingest. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
/**
|
|
* Group-based account classification aligned with BAS 2026. Pure, no data
|
|
* import: the server classifier (account-classifier.ts) consults the BAS
|
|
* chart first and falls back to this; the client classifier
|
|
* (account-classifier-client.ts) uses the lazily loaded chart the same way.
|
|
*/
|
|
|
|
import type { AccountType, NormalBalance } from '@/types'
|
|
|
|
export type { AccountType, NormalBalance }
|
|
|
|
export interface ClassifiedAccount {
|
|
account_type: AccountType
|
|
normal_balance: NormalBalance
|
|
}
|
|
|
|
/**
|
|
* 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 classifyAccountHeuristic(accountNumber: string): ClassifiedAccount {
|
|
const cls = parseInt(accountNumber[0], 10)
|
|
const group = parseInt(accountNumber.substring(0, 2), 10)
|
|
|
|
switch (cls) {
|
|
case 1:
|
|
return { account_type: 'asset', normal_balance: 'debit' }
|
|
case 2:
|
|
if (group === 20) return { account_type: 'equity', normal_balance: 'credit' }
|
|
if (group === 21) return { account_type: 'untaxed_reserves', normal_balance: 'credit' }
|
|
return { account_type: 'liability', normal_balance: 'credit' }
|
|
case 3:
|
|
return { account_type: 'revenue', normal_balance: 'credit' }
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
return { account_type: 'expense', normal_balance: 'debit' }
|
|
case 8:
|
|
if (group >= 80 && group <= 83) return { account_type: 'revenue', normal_balance: 'credit' }
|
|
if (group === 84) return { account_type: 'expense', normal_balance: 'debit' }
|
|
if (group === 85) return { account_type: 'revenue', normal_balance: 'credit' }
|
|
if (group === 86) return { account_type: 'expense', normal_balance: 'debit' }
|
|
if (group === 87 || group === 88) return { account_type: 'revenue', normal_balance: 'credit' }
|
|
if (group === 89) return { account_type: 'expense', normal_balance: 'debit' }
|
|
return { account_type: 'expense', normal_balance: 'debit' }
|
|
default:
|
|
return { account_type: 'expense', normal_balance: 'debit' }
|
|
}
|
|
}
|