Wenche.SkattemeldingPersonligXml (wenche v0.5.0)

Copy Markdown View Source

XML generation for the personlig skattemelding (ENK — enkeltpersonforetak) submission to Skatteetaten.

An ENK owner files a personal tax return. The business numbers go in the same naeringsspesifikasjon (v6) used for AS, but the outer document is the personlig skattemelding (skattemelding v13) rather than skattemeldingUpersonlig. Skatteetaten pre-fills the personal sections (bank, housing, employment) and derives the næring figures from the næringsspesifikasjon, so the personlig shell is normally minimal: partsreferanse + inntektsaar, which is all the XSD requires.

Per skattemelding_v13_ekstern.xsd (urn:no:skatteetaten:fastsetting:formueinntekt:skattemelding:ekstern:v13, "Skattemelding personlige skattepliktige v13", income year 2025).

The næringsspesifikasjon and request envelope are produced by Wenche.SkattemeldingXml with skattepliktig_type: :personlig and skattemelding_dokumenttype: "skattemeldingPersonlig" respectively — see Wenche.SkattemeldingPersonlig for the full orchestration.

Fremførbar negativ personinntekt (carry-forward of negative personinntekt)

An ENK is not a separate taxpayer, so it has no AS-style corporate loss carryforward. Two distinct mechanisms apply to the owner instead:

  • Underskudd til fremføring (alminnelig inntekt, skatteloven § 14-6). The business loss is first samordnet against the owner's other personal income the same year; any remainder carries forward against future alminnelig inntekt. Skatteetaten assesses and pre-fills this — callers do not submit it for an ENK.

  • Fremførbar negativ personinntekt (skatteloven § 12-13). Beregnet personinntekt (foretaksmodellen — the base for trygdeavgift + trinnskatt) can be negative. Negative personinntekt can never offset personinntekt outside the business; it carries forward only against future positive beregnet personinntekt from the same virksomhet, and the right lapses if not claimed the first year it can be (§ 12-13 second paragraph). This value is not erAvledet in the XSD — i.e. it is a taxpayer input, not pre-filled — so the filing system must persist the unused balance and submit it the following year.

When :fremfoerbar_negativ_personinntekt is supplied (a positive integer — the magnitude of the carried-forward negative personinntekt), this generator emits the otherwise-minimal shell plus a single naering/naeringsinntektMv entry carrying it at naering/naeringsinntektMv/samordnetPersoninntekt/fremfoerbarNegativPersoninntektFraTidligereAar/beloep/beloepSomHeltall. Skatteetaten derives everything else in samordnetPersoninntekt (fordeltBeregnetPersoninntektFraNaeringsspesifikasjon, the samordning, and the final personinntekt — all erAvledet="true"). The entry is joined to the næringsspesifikasjon's beregnetPersoninntekt/fordeltBeregnetPersoninntekt via identifikatorForFordeltBeregnetPersoninntekt ("1" for the single ENK virksomhet — see Wenche.SkattemeldingXml). naeringstype defaults to "annenNaering" (the kodeliste code for an ordinary, non-primary-industry ENK); SKD overrides it from the næringsspesifikasjon as it is erAvledet.

Partsreferanse

partsreferanse is Skatteetaten's internal integer ID for the taxpayer. It must be fetched from the pre-filled draft API before generating the XML for actual submission. When called without :partsreferanse, the generator falls back to aarsregnskap.selskap.org_nummer as a placeholder (passes XSD validation, but Skatteetaten rejects the submission unless replaced with the real partsreferanse).

Summary

Functions

Generates the personlig skattemelding XML document (v13).

Extracts the partsreferanse from a personlig skattemelding XML document.

Functions

generer_skattemelding_personlig_xml(regnskap, opts \\ [])

@spec generer_skattemelding_personlig_xml(
  Wenche.Models.Aarsregnskap.t(),
  keyword()
) :: String.t()

Generates the personlig skattemelding XML document (v13).

Minimal by design — partsreferanse + inntektsaar — unless a :fremfoerbar_negativ_personinntekt carry-forward is supplied, in which case a single naering/naeringsinntektMv/samordnetPersoninntekt entry is added (see the moduledoc). The rest of the business detail lives in the næringsspesifikasjon; the remaining personal sections are pre-filled by Skatteetaten.

Options

  • :partsreferanse — Skatteetaten's integer ID for the taxpayer. Defaults to aarsregnskap.selskap.org_nummer.
  • :fremfoerbar_negativ_personinntekt — positive integer kroner of negative beregnet personinntekt carried forward from earlier years (skatteloven § 12-13). When nil, 0 (or negative), no naering block is emitted and the shell stays minimal.
  • :naeringstype — kodeliste code for the virksomhet. Defaults to "annenNaering".
  • :fordeling_identifikator — join key to the næringsspesifikasjon's fordeltBeregnetPersoninntekt. Defaults to "1".

hent_partsreferanse(xml)

@spec hent_partsreferanse(binary()) ::
  {:ok, integer()} | {:error, :partsreferanse_not_found}

Extracts the partsreferanse from a personlig skattemelding XML document.

Used after fetching the pre-filled draft to learn Skatteetaten's internal ID for the taxpayer. The personlig draft uses <partsreferanse> where the upersonlig draft uses <partsnummer>.

Returns {:ok, integer} or {:error, :partsreferanse_not_found}.