Files
accounted/extensions/general/skatteverket/lib/mappers.ts
T
Jakob WennbergandClaude Sonnet 5 ec27228a8e style: remove em/en dashes repo-wide, add CLAUDE.md rule against them (#890)
Em dashes (—) and en dashes (–) had spread across comments, docs, tests,
and a few UI strings, reading as AI-generated boilerplate rather than
house style. Replaced each with punctuation matching its context: colon
for explanatory clauses, comma for asides, plain hyphen for numeric/legal
ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for
paired-dash asides. messages/en.json and messages/sv.json were fixed by
hand together to keep sv/en in sync.

Left untouched where the dash is the functional subject rather than
decorative punctuation: date-range-parser.ts's separator regex,
charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE
encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the
agent system-prompt files that already instruct against em dashes, and
a golden iXBRL test fixture compared byte-for-byte.

Also fixes two bugs surfaced along the way: an off-by-one in
ApiKeysPanel's scope-label split (a leftover from an earlier partial
pass), and a charset-repair test that had lost the literal en-dash it
exists to verify.

Regenerated the agent atom seed migration (skills:generate) since 27
SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes,
with an explicit carve-out for the functional-dash cases above.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 15:58:06 +02:00

89 lines
3.4 KiB
TypeScript

import type { VatDeclarationRutor } from '@/types'
import type { SkatteverketMomsuppgift } from '../types'
// Re-export shared formatting utilities
export { formatRedovisare, formatRedovisningsperiod } from '@/lib/skatteverket/format'
/**
* Convert Accounted VatDeclarationRutor to Skatteverket's momsuppgift payload.
*
* Fields with value 0 are omitted (Skatteverket treats absent fields as 0).
* This keeps the payload clean and avoids sending unnecessary data.
*
* Rounding: every ruta is rounded to whole kronor (SKV's schema is integers).
* summaMoms is recomputed from the rounded VAT-amount rutor: not from the
* pre-rounding ruta49: so the payload is internally consistent with how
* Skatteverket recomputes the sum on their side. Rounding ruta49 separately
* from the components causes ±1 SEK drift on fractional-öres inputs and
* triggers SKV's FK009 ("summaMoms stämmer inte överens med övriga
* momsuppgifter") even when the underlying ledger arithmetic is correct.
*/
export function rutorToMomsuppgift(rutor: VatDeclarationRutor): SkatteverketMomsuppgift {
const result: SkatteverketMomsuppgift = {}
// Helper: only set non-zero values, rounded to whole kronor (SKV expects integers)
const set = (key: keyof SkatteverketMomsuppgift, value: number) => {
if (value !== 0) result[key] = Math.round(value)
}
// Taxable sales basis
set('momspliktigForsaljning', rutor.ruta05)
set('momspliktigaUttag', rutor.ruta06)
set('vinstmarginal', rutor.ruta07)
set('hyresInkomst', rutor.ruta08)
// Output VAT on sales
set('momsForsaljningUtgaendeHog', rutor.ruta10)
set('momsForsaljningUtgaendeMedel', rutor.ruta11)
set('momsForsaljningUtgaendeLag', rutor.ruta12)
// Reverse charge purchase bases
set('inkopVarorEU', rutor.ruta20)
set('inkopTjansterEU', rutor.ruta21)
set('inkopTjansterUtanforEU', rutor.ruta22)
set('inkopVarorSE', rutor.ruta23)
set('inkopTjansterSE', rutor.ruta24)
// Output VAT on reverse charge purchases
set('momsInkopUtgaendeHog', rutor.ruta30)
set('momsInkopUtgaendeMedel', rutor.ruta31)
set('momsInkopUtgaendeLag', rutor.ruta32)
// EU/export sales
set('forsaljningVarorEU', rutor.ruta35)
set('forsaljningVarorUtanforEU', rutor.ruta36)
set('inkopVaror3pHandel', rutor.ruta37)
set('forsaljningVaror3pHandel', rutor.ruta38)
set('forsaljningTjansterEU', rutor.ruta39)
set('ovrigForsaljningTjansterUtanforSE', rutor.ruta40)
set('forsaljningBskKopareSE', rutor.ruta41)
set('momsfriForsaljning', rutor.ruta42)
// Input VAT
set('ingaendeMomsAvdrag', rutor.ruta48)
// Import
set('import', rutor.ruta50)
set('momsImportUtgaendeHog', rutor.ruta60)
set('momsImportUtgaendeMedel', rutor.ruta61)
set('momsImportUtgaendeLag', rutor.ruta62)
// Net VAT must always be present, whole kronor. Compute from the already-
// rounded VAT-amount rutor so SKV's reconciliation (sum of integer rutor)
// never disagrees with our summaMoms by ±1 SEK.
result.summaMoms =
(result.momsForsaljningUtgaendeHog ?? 0) +
(result.momsForsaljningUtgaendeMedel ?? 0) +
(result.momsForsaljningUtgaendeLag ?? 0) +
(result.momsInkopUtgaendeHog ?? 0) +
(result.momsInkopUtgaendeMedel ?? 0) +
(result.momsInkopUtgaendeLag ?? 0) +
(result.momsImportUtgaendeHog ?? 0) +
(result.momsImportUtgaendeMedel ?? 0) +
(result.momsImportUtgaendeLag ?? 0) -
(result.ingaendeMomsAvdrag ?? 0)
return result
}