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

100% Statements 13/13
100% Branches 14/14
100% Functions 3/3
100% Lines 13/13

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                      4x 122x 122x                       146x   14x             10x       10x                   89x             9x         10x         14x         14x             14x                  
// The words of a check, shared by the form 7H page and the year summary PDF.
import {
  formatDate,
  formatList,
  formatMoney,
  formatMonth,
  formatShare,
} from '#/lib/format'
import { m } from '#/paraglide/messages.js'
import type { Check } from './summary'
 
const monthName = (month: string) => {
  const [year, number] = month.split('-').map(Number) as [number, number]
  return formatMonth(year, number)
}
 
/**
 * A check's title and explanation. `own` words a share change as the
 * reader's own; `pdf` writes the change with a dash, because the PDF's
 * standard font has no arrow.
 */
export function checkText(
  check: Check,
  options: { own: boolean; pdf?: boolean },
): { title: string; text: string } {
  switch (check.kind) {
    case 'unpaid':
      return {
        title: m.flat_tax_check_unpaid_title({
          months: formatList(check.months.map(monthName)),
        }),
        text: m.flat_tax_check_unpaid_text(),
      }
    case 'partly_paid':
      return {
        title: m.flat_tax_check_partly_paid_title({
          months: formatList(
            check.months.map((row) =>
              m.flat_tax_check_partly_paid_month({
                month: monthName(row.month),
                amount: formatMoney(row.missing),
              }),
            ),
          ),
        }),
        text: m.flat_tax_check_partly_paid_text(),
      }
    case 'vacant':
      return {
        title: m.flat_tax_check_vacant_title({
          months: formatList(check.months.map(monthName)),
        }),
        text: m.flat_tax_check_vacant_text(),
      }
    case 'details_missing':
      return {
        title: m.flat_tax_check_details_missing_title(),
        text: m.flat_tax_check_details_missing_text(),
      }
    case 'treatment_not_set':
      return {
        title: m.flat_tax_check_treatment_title({ count: check.months.length }),
        text: m.flat_tax_check_treatment_text(),
      }
    case 'share_changed': {
      const values = {
        date: formatDate(check.on),
        from: formatShare(check.from),
        to: formatShare(check.to),
      }
      const title = options.pdf
        ? options.own
          ? m.pdf_check_share_title(values)
          : m.pdf_check_share_person_title(values)
        : options.own
          ? m.flat_tax_check_share_title(values)
          : m.flat_tax_check_share_person_title(values)
      return {
        title,
        text: options.own
          ? m.flat_tax_check_share_text()
          : m.flat_tax_check_share_person_text(),
      }
    }
  }
}