All files / src/features/year-summary row-text.ts

100% Statements 44/44
100% Branches 2/2
100% Functions 31/31
100% Lines 43/43

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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107                              6x 103x 103x 102x 102x 102x     24x 101x     6x 99x       1x             6x 270x   371x               6x     6x 48x 47x 47x 47x 47x       6x 512x     6x 45x 8x 31x       6x 376x 376x 376x           6x   70x 17x     68x 15x     68x 15x     97x 45x         6x 42x 16x    
// The words of a form 7H row and its parts, shared by the form 7H page and
// the year summary PDF.
import { kindLabel } from '#/features/recurring-amounts/labels'
import { categoryLabel, summaryRowLabel } from '#/features/transactions/labels'
import { chargeKindLabel } from '#/lib/charge-labels'
import { formatMoney } from '#/lib/format'
import { m } from '#/paraglide/messages.js'
import {
  labelWithOriginal,
  withOriginal,
  type WithOriginal,
} from './original-text'
import type { ChargeKind } from '#/server/db/schema'
import type { Part, PartKey, RowNumber } from './summary'
 
export const rowLabel: Record<RowNumber, () => string> = {
  '2.1': () => summaryRowLabel.gross_rent(),
  '2.2': () => summaryRowLabel.maintenance_and_water(),
  '2.3': () => m.flat_tax_row_capital_charges(),
  '2.4': () => summaryRowLabel.annual_repairs(),
  '2.5': () => summaryRowLabel.other_costs(),
}
 
const usagePart = (kind: ChargeKind) => () =>
  m.flat_tax_part_usage({ kind: chargeKindLabel[kind]() })
 
/** Each part's name: usage charges are told apart from entries. */
const partLabel: Record<PartKey, () => string> = {
  rent_payments: () => m.rent_payments_title(),
  ...categoryLabel,
  maintenance_charge: kindLabel.maintenance_charge,
  financing_charge: kindLabel.financing_charge,
  deposit_damage: () => m.flat_tax_part_deposit_damage(),
  water: usagePart('water'),
  parking: usagePart('parking'),
  sauna: usagePart('sauna'),
  other: usagePart('other'),
}
 
export const partsText = (parts: readonly Part[]) =>
  parts
    .map((part) =>
      m.flat_tax_part({
        label: labelWithOriginal(partOriginal(part.key)),
        amount: formatMoney(part.cents),
      }),
    )
    // The app's separator for amounts on one line, as on the charges page.
    .join(' ยท ')
 
const fi = { locale: 'fi' } as const
 
/** The Finnish text of each row's name, for its original. */
const rowFinnish: Record<RowNumber, () => string> = {
  '2.1': () => m.transactions_row_gross_rent({}, fi),
  '2.2': () => m.transactions_row_maintenance_and_water({}, fi),
  '2.3': () => m.flat_tax_row_capital_charges({}, fi),
  '2.4': () => m.transactions_row_annual_repairs({}, fi),
  '2.5': () => m.transactions_row_other_costs({}, fi),
}
 
/** A row's name with its Finnish original (none in Finnish). */
export const rowOriginal = (row: RowNumber): WithOriginal =>
  withOriginal(rowLabel[row](), rowFinnish[row])
 
/** The parts that are tax terms; other parts get no original. */
const partFinnish: Partial<Record<PartKey, () => string>> = {
  maintenance_charge: () => m.amounts_maintenance_charge({}, fi),
  financing_charge: () => m.amounts_financing_charge({}, fi),
  annual_repair: () => m.transactions_category_annual_repair({}, fi),
}
 
/** A part's name with its original, when the part is a tax term. */
export const partOriginal = (key: PartKey): WithOriginal => {
  const finnish = partFinnish[key]
  const text = partLabel[key]()
  return finnish === undefined
    ? { text, original: null }
    : withOriginal(text, finnish)
}
 
/** The titles of the Not on form 7H card and the identity code label. */
export const outsideTitleOriginal = {
  capitalised: () =>
    withOriginal(m.flat_tax_outside_capitalised(), () =>
      m.flat_tax_outside_capitalised({}, fi),
    ),
  deposit_damage: () =>
    withOriginal(m.flat_tax_outside_deposit_damage(), () =>
      m.flat_tax_outside_deposit_damage({}, fi),
    ),
  improvements: () =>
    withOriginal(m.flat_tax_outside_improvements(), () =>
      m.flat_tax_outside_improvements({}, fi),
    ),
  identity_code: () =>
    withOriginal(m.flat_tax_identity_code(), () =>
      m.flat_tax_identity_code({}, fi),
    ),
} satisfies Record<string, () => WithOriginal>
 
/** The estimate's title, a tax term. */
export const estimateTitleOriginal = (): WithOriginal =>
  withOriginal(m.year_summary_estimate_tax_label(), () =>
    m.year_summary_estimate_tax_label({}, fi),
  )