All files / src/features/transactions categories.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                        12x                       94x 658x                 7x    
// Entry categories and the form 7H row each one fills (openspec:
// transactions; design.md, "Categories map to form 7H rows"). Rows from the
// Tax Administration's 7H instructions, updated 4.2.2026. Pure data: the year
// summary (#34) imports it too.
import type { TransactionCategory, TransactionType } from '#/server/db/schema'
 
/**
 * Form 7H rows that entries fill. `capital_charges` (2.3) comes only from
 * the financing charge periods, so no category maps to it.
 */
export type SummaryRow =
  | 'gross_rent' // 2.1 Oma osuutesi bruttovuokratuloista
  | 'maintenance_and_water' // 2.2 Hoitovastikkeet ja vesimaksut
  | 'annual_repairs' // 2.4 Vuosikorjauskulut
  | 'other_costs' // 2.5 Muut kulut
 
export interface Category {
  type: TransactionType
  /**
   * The row the entry's amount fills in the year it is paid, or null for an
   * improvement, which is not deducted all at once: for a flat in a housing
   * company a tenth a year in row 2.5 for 10 years from the year paid, or on
   * sale (a building is depreciated from its acquisition cost instead). The
   * year summary (#34) calculates it.
   */
  row: SummaryRow | null
}
 
export const CATEGORIES: Record<TransactionCategory, Category> = {
  tenant_water_charge: { type: 'income', row: 'gross_rent' },
  other_income: { type: 'income', row: 'gross_rent' },
  annual_repair: { type: 'expense', row: 'annual_repairs' },
  improvement: { type: 'expense', row: null },
  water_charge: { type: 'expense', row: 'maintenance_and_water' },
  insurance: { type: 'expense', row: 'other_costs' },
  other_expense: { type: 'expense', row: 'other_costs' },
}
 
/** A type's categories, in the order the form shows them. */
export function categoriesOf(type: TransactionType): TransactionCategory[] {
  return (Object.keys(CATEGORIES) as TransactionCategory[]).filter(
    (category) => CATEGORIES[category].type === type,
  )
}
 
/** Whether the category belongs to the type. */
export function categoryFits(
  type: TransactionType,
  category: TransactionCategory,
): boolean {
  return CATEGORIES[category].type === type
}