brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
trygdeavgiftExpert knowledge of trygdeavgift (social insurance charge) domain in melosys-api. Use when: (1) Understanding avgift calculation for different member types, (2) Debugging årsavregning (annual reconciliation) processing, (3) Understanding fakturering flow to OEBS/faktureringskomponenten, (4) Investigating avgiftssatser and calculation rules per year, (5) Und…
Independent GitHub snapshot · Automated classification · Original documentation governs
Trygdeavgift (social insurance charge) is the domain handling calculation, collection, and reconciliation of social security contributions for members of Norwegian folketrygden. This includes advance invoicing (forskuddsfakturering), annual reconciliation (årsavregning), and integration with OEBS.
Behandlingsresultat
├── trygdeavgiftType: Trygdeavgift_typer
├── trygdeavgiftFritekst: String?
├── medlemskapsperioder: List<Medlemskapsperiode>
│ └── trygdeavgiftsperioder: Set<Trygdeavgiftsperiode>
├── lovvalgsperioder: List<Lovvalgsperiode>
│ └── trygdeavgiftsperioder: Set<Trygdeavgiftsperiode>
├── helseutgiftDekkesPeriode: HelseutgiftDekkesPeriode?
│ └── trygdeavgiftsperioder: Set<Trygdeavgiftsperiode>
├── årsavregning: Årsavregning?
└── fakturaserieReferanse: String?
Trygdeavgiftsperiode
├── id: Long
├── periodeFra: LocalDate
├── periodeTil: LocalDate?
├── trygdeavgiftsbeløpMd: Penger
├── trygdesats: BigDecimal
├── grunnlagMedlemskapsperiode: Medlemskapsperiode?
├── grunnlagLovvalgsPeriode: Lovvalgsperiode?
├── grunnlagHelseutgiftDekkesPeriode: HelseutgiftDekkesPeriode?
├── grunnlagInntekstperiode: Inntektsperiode
└── grunnlagSkatteforholdTilNorge: SkatteforholdTilNorge
Årsavregning
├── id: Long
├── år: Int
├── beregnetAvgiftBeløp: BigDecimal?
├── harTrygdeavgiftFraAvgiftssystemet: Boolean?
├── trygdeavgiftFraAvgiftssystemet: BigDecimal?
├── manueltAvgiftBeløp: BigDecimal?
├── endeligAvgiftValg: EndeligAvgiftValg?
├── tidligereBehandlingsresultatId: Long?
└── behandlingsresultat: Behandlingsresultat
| Enum | Values | Description |
|---|---|---|
| Trygdeavgift_typer | ORDINÆR, FORENKLET_SKATT, EØS_PENSJONIST, etc. | Type of avgift calculation |
| Avgiftsdekning | HELSEDEL_UTEN_SYKEPENGER, HELSEDEL_MED_SYKEPENGER, PENSJONSDEL_UTEN_YRKESSKADETRYGD, PENSJONSDEL_MED_YRKESSKADETRYGD | Coverage affecting calculation |
| Skatteplikttyyper | BEGRENSET, FULL | Tax liability type |
| EndeligAvgiftValg | BEREGNET, MANUELT, FRA_AVGIFTSSYSTEMET | Source of final avgift |
| Betalingstype | FAKTURA, KONTONUMMER | Payment method choice |
┌─────────────────────┐
│ Vedtaksfatting │
│ (fattVedtak) │
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ TrygdeavgiftsService│
│ beregnOgLagre() │
└─────────┬───────────┘
│
▼
┌─────────────────────┐ ┌─────────────────────┐
│ melosys-trygdeavgift│────►│ Trygdeavgiftsperiode│
│ -beregning │ │ created & stored │
└─────────────────────┘ └─────────┬───────────┘
│
▼
┌─────────────────────┐
│ OPPRETT_FAKTURASERIE│
│ (saksflyt steg) │
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ Fakturerings- │
│ komponenten/OEBS │
└─────────────────────┘
Location: service/src/main/kotlin/.../avgift/TrygdeavgiftsberegningService.kt
Key operations:
beregnOgLagreTrygdeavgift() - Calculate and persist avgift periodslagNyeTrygeavgiftsperioder() - Create new avgift periodsberegnTrygdeavgift() - Call external beregning modulesjekkTrygdeavgiftSkalBetalesTilNav() - Determine if NAV collects avgiftLocation: service/src/main/kotlin/.../avgift/TrygdeavgiftService.kt
Key operations:
harFagsakBehandlingerMedTrygdeavgift() - Check for avgift on caseharFakturerbarTrygdeavgift() - Check if avgift should be invoicedharTrygdeavgift() - Check if behandling has avgiftLocation: service/src/main/kotlin/.../avgift/aarsavregning/ÅrsavregningService.kt
Key operations:
opprettÅrsavregning() - Create annual reconciliationhentTidligereTrygdeavgiftsgrunnlag() - Get previous year's basishentNyttTrygdeavgiftsgrunnlag() - Get new basishentGjeldendeBehandlingsresultaterForÅrsavregning() - Get results for yearLocation: service/src/main/kotlin/.../avgift/TrygdeavgiftMottakerService.kt
Key operations:
skalBetalesTilNav() - Determine if avgift is collected by NAVfinnFakturamottaker() - Find invoice recipient| ProsessSteg | Description |
|---|---|
OPPRETT_FAKTURASERIE | Create invoice series in faktureringskomponenten |
KANSELLER_FAKTURASERIE | Cancel existing invoice series |
OPPDATER_FAKTURAMOTTAKER | Update invoice recipient |
SEND_FAKTURA_AARSAVREGNING | Send annual reconciliation invoice |
BEREGN_OG_SEND_FAKTURA | Calculate and send invoice (satsendring) |
IVERKSETT_VEDTAK_FTRL:
LAGRE_MEDLEMSKAPSPERIODE_MEDL →
OPPRETT_FAKTURASERIE → # Creates invoice in OEBS
AVSLUTT_SAK_OG_BEHANDLING →
SEND_MELDING_OM_VEDTAK →
RESET_ÅPNE_ÅRSAVREGNINGER
IVERKSETT_VEDTAK_AARSAVREGNING:
SEND_FAKTURA_AARSAVREGNING → # Annual reconciliation invoice
VARSLE_PENSJONSOPPTJENING →
AVSLUTT_SAK_OG_BEHANDLING →
SEND_MELDING_OM_VEDTAK
Location: integrasjon/src/main/kotlin/.../faktureringskomponenten/
SELECT t.*, mp.id as medlemskap_id, lp.id as lovvalg_id
FROM trygdeavgiftsperiode t
LEFT JOIN medlemskapsperiode mp ON t.grunnlag_medlemskapsperiode_id = mp.id
LEFT JOIN lovvalgsperiode lp ON t.grunnlag_lovvalgsperiode_id = lp.id
WHERE mp.behandlingsresultat_id = :behandlingsresultatId
OR lp.behandlingsresultat_id = :behandlingsresultatId;
SELECT br.id, br.fakturaserie_referanse, b.status, f.saksnummer
FROM behandlingsresultat br
JOIN behandling b ON br.behandling_id = b.id
JOIN fagsak f ON b.fagsak_id = f.id
WHERE br.fakturaserie_referanse IS NOT NULL
AND f.saksnummer = :saksnummer;
SELECT aa.*, br.id as behandlingsresultat_id, b.id as behandling_id
FROM aarsavregning aa
JOIN behandlingsresultat br ON aa.behandlingsresultat_id = br.id
JOIN behandling b ON br.behandling_id = b.id
WHERE aa.aar = :year
AND b.fagsak_id = :fagsakId;
SELECT pi.*, b.id as behandling_id, f.saksnummer
FROM prosessinstans pi
JOIN behandling b ON pi.behandling_id = b.id
JOIN fagsak f ON b.fagsak_id = f.id
WHERE pi.type = 'OPPRETT_NY_BEHANDLING_MANGLENDE_INNBETALING'
ORDER BY pi.registrert_dato DESC;
| Issue | Symptoms | Investigation |
|---|---|---|
| Avgift not calculated | Missing trygdeavgiftsperioder | Check TrygdeavgiftsberegningService logs |
| Wrong avgift amount | Unexpected invoice amount | Verify satser, inntekt, dekning |
| Fakturaserie not created | No fakturaserieReferanse | Check OPPRETT_FAKTURASERIE step |
| Årsavregning missing | No reconciliation for year | Check skattehendelser received |
| Double invoicing | Multiple fakturaseriereferanser | Check prosessinstans for duplicate vedtak |
| 25% rule not applied | Avgift too high | Verify TotalbeløpBeregner logic |
Rates are defined per year and depend on:
TotalbeløpBeregner