Files
accounted/lib/vat/moms-box-mapping.ts
T
Jakob WennbergandClaude Opus 4.6 6ccd4f429c fix: Swedish VAT compliance — representation, domestic RC, full 26xx mapping, SIE (#206)
* feat: add INK2 declaration improvements, invoice delivery date, and Swedish compliance skills

Expand INK2 engine with full INK2S/INK2R support and improved SRU generation.
Add delivery_date field to invoices and corresponding PDF/migration support.
Add Claude skills for Swedish asset accounting, invoice compliance, SIE import/export, SRU filing, and tax planning.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address PR review — map BAS 4500–4899, strip CRLF in SRU, document P3

- Map BAS accounts 4500–4599 (legoarbeten), 4700–4899 (diverse
  varuinköpskostnader) to SRU 7512 so they are not silently dropped
  from INK2R declarations
- Strip \r\n in sanitizeString to prevent CRLF injection in SRU fields
- Document P3 period suffix limitation for brutet räkenskapsår

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: correct BAS 4500-4599, 4700-4899 mapping from 7512 to 7511

Per the official BAS-to-SRU mapping, these account ranges are cost of
goods (legoarbeten, inkurans, svinn) and belong under 7511 (Råvaror
och förnödenheter), not 7512 (Handelsvaror). 7512 remains 4600-4699.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: Swedish VAT compliance — representation VAT, domestic RC, full BAS 26xx mapping, SIE encoding

- Representation expenses now default to reduced_12 VAT (ML 13 kap 24-25 §§);
  income tax deduction was abolished 2017 but VAT deduction at 12% remains
- Domestic reverse charge (byggtjänster etc.) uses 2647 instead of 2645,
  with distinct line descriptions for Swedish vs EU/non-EU RC
- VAT declaration maps all BAS 26xx variant accounts (egna uttag 2612/2622/2632,
  uthyrning 2613/2623/2633, VMB 2616/2626/2636, import 2615/2625/2635,
  domestic RC 2647, frivillig skattskyldighet 2642) and revenue variants
  (3108/3105/3004/3100) to correct momsdeklaration rutor
- SIE parser: remove unreliable #FORMAT PC8 encoding detection (most software
  exports UTF-8 with PC8 header), parse #FLAGGA for import-already-done warning,
  default SIE type to 1 when absent, fix RTRANS/BTRANS documentation
- SIE export: add #RAR -1 (previous fiscal year), fix UB = IB + movements
- Error messages: add pattern matching for locked period trigger errors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address Greptile review — update ruta49 JSDoc, use null sentinel in error map

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 14:13:15 +02:00

162 lines
5.8 KiB
TypeScript

/**
* Momsdeklaration box mapping for Swedish VAT returns.
*
* Maps BAS revenue accounts to the correct box (ruta) in the
* momsdeklaration filed with Skatteverket. Used by:
* - Export VAT Monitor (full box overview)
* - EU Sales List (cross-validation against box 35/39)
*
* Reference: Skatteverket momsdeklaration (SKV 4700)
* https://www.skatteverket.se/foretag/moms/deklareramoms/fyllaimomsdeklarationen
*/
/** Momsdeklaration box number */
export type MomsBox =
| '05' // Momspliktig försäljning (taxable sales)
| '06' // Momspliktiga uttag (taxable withdrawals)
| '07' // Vinstmarginalbeskattning (margin scheme)
| '08' // Hyresinkomster frivillig beskattning (rental)
| '10' // Utgående moms 25%
| '11' // Utgående moms 12%
| '12' // Utgående moms 6%
| '20' // Inköp varor från EU
| '21' // Inköp tjänster från EU
| '22' // Inköp tjänster utanför EU
| '23' // Inköp varor Sverige omvänd skattskyldighet
| '24' // Inköp tjänster Sverige omvänd skattskyldighet
| '30' // Utgående moms inköp 25%
| '31' // Utgående moms inköp 12%
| '32' // Utgående moms inköp 6%
| '35' // Varuförsäljning till annat EU-land
| '36' // Varuförsäljning utanför EU (export)
| '37' // Mellanmans inköp trepartshandel
| '38' // Mellanmans försäljning trepartshandel
| '39' // Tjänsteförsäljning EU (huvudregeln)
| '40' // Övrig försäljning av tjänster utomlands
| '41' // Försäljning omvänd skattskyldighet Sverige
| '42' // Övrig försäljning m.m.
| '48' // Ingående moms att dra av
| '49' // Moms att betala eller få tillbaka
| '50' // Importbeskattningsunderlag
| '60' // Importmoms 25%
| '61' // Importmoms 12%
| '62' // Importmoms 6%
/** Map BAS account to momsdeklaration box */
export const ACCOUNT_TO_BOX: Record<string, MomsBox> = {
// Domestic revenue (taxable) → Box 05
'3001': '05', // Försäljning varor/tjänster 25%
'3002': '05', // Försäljning varor/tjänster 12%
'3003': '05', // Försäljning varor/tjänster 6%
// EU goods (reverse charge, VAT-free) → Box 35
'3108': '35', // Försäljning varor till annat EU-land
'3521': '35', // Fakturerade frakter EU (follows goods treatment)
// Non-EU goods export (zero-rated) → Box 36
'3105': '36', // Försäljning varor export utanför EU
'3522': '36', // Fakturerade frakter export
// Triangular trade → Box 38
'3109': '38', // Mellanmans försäljning trepartshandel
// EU services (reverse charge, main rule) → Box 39
'3308': '39', // Försäljning tjänster EU
// Non-EU services → Box 40
'3305': '40', // Försäljning tjänster export utanför EU
// VAT-exempt sales → Box 42
'3004': '42', // Momsfri försäljning (AB)
'3100': '42', // Momsfria intäkter (EF)
// Output VAT 25% → Box 10
'2611': '10', // Försäljning inom Sverige
'2612': '10', // Egna uttag
'2613': '10', // Uthyrning (frivillig skattskyldighet)
'2616': '10', // Vinstmarginalbeskattning
// Output VAT 12% → Box 11
'2621': '11',
'2622': '11', // Egna uttag
'2623': '11', // Uthyrning
'2626': '11', // VMB
// Output VAT 6% → Box 12
'2631': '12',
'2632': '12', // Egna uttag
'2633': '12', // Uthyrning
'2636': '12', // VMB
// Reverse charge output VAT → Boxes 30, 31, 32
'2614': '30',
'2624': '31',
'2634': '32',
// Import VAT (since 2015, via momsdeklaration) → Boxes 60, 61, 62
'2615': '60', // Import 25%
'2625': '61', // Import 12%
'2635': '62', // Import 6%
// Input VAT → Box 48
'2641': '48', // Debiterad ingående moms
'2642': '48', // Frivillig skattskyldighet
'2645': '48', // Beräknad ingående moms (EU/non-EU förvärv)
'2646': '48', // Uthyrning
'2647': '48', // Omvänd skattskyldighet i Sverige
'2649': '48', // Blandad verksamhet
}
/** Swedish labels for each momsdeklaration box */
export const BOX_LABELS: Record<MomsBox, string> = {
'05': 'Momspliktig försäljning',
'06': 'Momspliktiga uttag',
'07': 'Vinstmarginalbeskattning',
'08': 'Hyresinkomster (frivillig beskattning)',
'10': 'Utgående moms 25%',
'11': 'Utgående moms 12%',
'12': 'Utgående moms 6%',
'20': 'Inköp varor från EU',
'21': 'Inköp tjänster från EU',
'22': 'Inköp tjänster utanför EU',
'23': 'Inköp varor Sverige (omvänd skattskyldighet)',
'24': 'Inköp tjänster Sverige (omvänd skattskyldighet)',
'30': 'Utgående moms på inköp 25%',
'31': 'Utgående moms på inköp 12%',
'32': 'Utgående moms på inköp 6%',
'35': 'Varuförsäljning till annat EU-land',
'36': 'Varuförsäljning utanför EU (export)',
'37': 'Mellanmans inköp vid trepartshandel',
'38': 'Mellanmans försäljning vid trepartshandel',
'39': 'Tjänsteförsäljning till EU (huvudregeln)',
'40': 'Övrig försäljning av tjänster utomlands',
'41': 'Försäljning med omvänd skattskyldighet (Sverige)',
'42': 'Övrig försäljning m.m.',
'48': 'Ingående moms att dra av',
'49': 'Moms att betala eller få tillbaka',
'50': 'Beskattningsunderlag vid import',
'60': 'Importmoms 25%',
'61': 'Importmoms 12%',
'62': 'Importmoms 6%',
}
/** Get the momsdeklaration box for a BAS account number */
export function getBoxForAccount(accountNumber: string): MomsBox | undefined {
return ACCOUNT_TO_BOX[accountNumber]
}
/** Get the Swedish label for a momsdeklaration box */
export function getBoxLabel(box: MomsBox): string {
return BOX_LABELS[box]
}
/** Boxes that represent VAT-exempt export/EU sales (no output VAT) */
export const EXPORT_BOXES: MomsBox[] = ['35', '36', '38', '39', '40']
/** Boxes that represent taxable domestic sales (have output VAT) */
export const DOMESTIC_BOXES: MomsBox[] = ['05', '06', '07', '08']
/** Boxes that represent output VAT */
export const OUTPUT_VAT_BOXES: MomsBox[] = ['10', '11', '12']
/** Boxes that represent input VAT */
export const INPUT_VAT_BOXES: MomsBox[] = ['48']