Files
accounted/extensions/general/skatteverket/lib/mappers.ts
T
Jakob WennbergandClaude Opus 4.6 d8e0a22495 feat: counterparty templates, Skatteverket extension, complete VAT form (#117)
* feat: separate AR/AP/accounting into distinct nav groups (#92)

Split the flat "Finans" sidebar group into three visually distinct
sections — Försäljning (AR), Inköp (AP), and Redovisning — so users
coming from Fortnox immediately find customer invoicing and supplier
invoices as top-level concepts.

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

* feat: journal entry detail view, correction chain, and account name display

- Add journal entry detail page at /bookkeeping/[id] with full entry view
- Add correction chain API and component showing storno relationships
- Add JournalEntryStatusBadge component for entry status display
- Show debit/credit account names in template picker and review dialogs
- Expand client-side BAS account name mapping with additional accounts
- Show account codes on transaction inbox suggestion buttons

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

* fix: address review feedback — N+1 query, duplicate name, nav dedup

- Batch reverse-lookup into single query per BFS iteration (was N+1)
- Differentiate account 2393 from 2893 in display names
- Extract shared loop for desktop/mobile nav group rendering

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

* feat: counterparty templates, Skatteverket extension, VAT form completeness, and UI cleanup

- Add counterparty-based categorization templates (learned from user approvals
  and auto-ingestion) with fuzzy matching in the mapping engine
- Add Skatteverket extension for direct VAT declaration submission via API
- Complete VAT declaration form with all 30 SKV 4700 boxes (ruta 08, 35-42, 50, 60-62)
- Fix ruta 49 formula to include import VAT (ruta 60+61+62)
- Simplify dashboard UI: remove redundant icons from stat cards, customer cards,
  invoice list, supplier invoices; use Badge variants consistently
- Add SkatteverketPanel component to reports page
- Add categorization_templates and skatteverket_tokens migrations
- Update tests and helpers for new types

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

* fix: address PR review feedback — VAT detection, migration timestamps, dedup

- Fix detectVatTreatment to derive actual rate (12%/6%) from VAT line
  description instead of hardcoding standard_25
- Rename skatteverket_tokens migration to 20260324120001 to avoid
  duplicate timestamp with categorization_templates (fixes Supabase
  deployment failure)
- Make refreshAccessToken accept previousRefreshCount param to enforce
  refresh limit contract at the type level
- Fix rate limiter TOCTOU by claiming slot before await
- Extract formatRedovisare/formatRedovisningsperiod to shared
  lib/skatteverket/format.ts — eliminates duplication between
  mappers.ts and SkatteverketPanel.tsx

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-03-24 13:41:12 +01:00

69 lines
2.3 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 gnubok 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.
*/
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)
// Net VAT (must always be present, whole kronor)
result.summaMoms = Math.round(rutor.ruta49)
// Import
set('import', rutor.ruta50)
set('momsImportUtgaendeHog', rutor.ruta60)
set('momsImportUtgaendeMedel', rutor.ruta61)
set('momsImportUtgaendeLag', rutor.ruta62)
return result
}