Skip to content

Dimensjoner: avdeling og prosjekt

This content is not available in your language yet.

Cost/revenue follow-up per avdeling and prosjekt, as first-class, hash-covered data on entry lines. Foundation for timeføring (#38), budsjett (#41) and prosjektrapporter.

dimension (migration 0018): per company, kind (avdeling|prosjekt), code, name, active. Lifecycle is insert + rename + open/close only, enforced by trigger and column grants:

  • The code is permanent — it is inside the v3 voucher hash of every posting that references it; changing it would break chain verification. The trigger rejects identity changes for every role.
  • The name may change (it is not hashed) and a rename does not disturb verification — tested.
  • Avsluttet (active = false) rejects new postings, exactly like a locked period: corrections happen via open dimensions. History on a closed dimension keeps reporting and verifying forever. Reopening is one update — no data is ever deleted.

A prosjekt may carry the customer it is for: party_id (migration 0047), editable metadata on par with the name — never part of the chain (the hash covers the code, not the row). Rules:

  • Same company, enforced by a composite FK (company_id, party_id); actually being a kunde (not a leverandør) is checked at the lookup, since a partial unique index cannot be an FK target.
  • Only prosjekter — an avdeling with a customer is refused (check constraint + code).
  • One customer per project: a project for several customers is two projects.

The link is what lets hours be traced to the customer: the fakturagrunnlag carries it as a suggested recipient (docs/timer.md), and prosjektlønnsomhet per kunde (#71) will read the same link. Set at creation or via PUT …/dimensions/prosjekt/{code} (kunde: absent = unchanged, "" = clear, party_no = link).

Entries carry optional avdeling_id/prosjekt_id; the voucher hash covers the codes (marker "v3", then per line: … party, avdeling, prosjekt — empty when none). v1/v2 history verifies unchanged forever; golden tests pin all three digests (docs/ledger.md). Verification re-reads the codes via join, exactly as it does party numbers.

post_voucher resolves each referenced dimension up front: it must exist for the company, be of the right kind, and be active — a typo or an avsluttet prosjekt fails the whole voucher with a clear message before anything is written.

  • Resultat per dimension: GET …/reports/resultat?from=&to= takes optional avdeling= / prosjekt= codes — the same pure SUM query, filtered. (Balanse is not filtered: dimensions are optional per line, so a per-dimension balanse would not balance.)
  • Kontospesifikasjon rows carry the line’s avdeling/prosjekt.
  • SAF-T: the registry exports as AnalysisTypeTable (type codes AVD/PRO, closed dimensions marked Status=Closed) and each line’s codes as Analysis elements with the amount on the line’s side — validated against Skatteetatens XSD in tests and CI.
Endpoint Purpose
GET /companies/{id}/dimensions the registry
POST /companies/{id}/dimensions create (kind, code, name)
PUT /companies/{id}/dimensions/{kind}/{code} rename, open/close, kunde, fakturerbar_default
GET/POST …/dimensions/prosjekt/{code}/satser dated timesatser (docs/timer.md, TIMER_SATS_SKRIV)

Lines accept avdeling/prosjekt codes on: innboks bokføring (…/inbox/{id}/bokfor) and faktura revenue lines (POST …/invoices; the codes are stored on invoice_line, so a kreditnota reverses revenue on the same dimensions).

Portal: the registry is its own Prosjekter section (it lived at the bottom of Bilag until 2026-08-04 — the last place someone thinking in projects would look): prosjekter with kunde-link, per-project hours and unbilled value for the year, rename (the API always supported it, the UI finally offers it), avslutt/gjenåpne, and an Avdelinger card with the same rules minus the customer. Pickers remain in the innboks bokfør form and the faktura form; resultat filter in Rapporter.

Siden 2026-11-15 er registeret en liste, ikke en tabell med ni kolonner: hver rad viser kode og navn, og under det kunde, fakturerbar, din timesats, timer i år og ufakturert beløp. Det passer på en telefon. «Endre» åpner ett panel under raden med navn, kunde og fakturerbar-standard (lagres i ÉTT kall), avslutt/åpne igjen og timesatsene. Enter lagrer, Esc lukker, og fokus går tilbake til radens knapp. Avsluttede ligger bak «Vis avsluttede (n)».

To ting skal ikke skje igjen. (a) Et tomt satsfelt ble lest som 0 kr, og fra den datoen ble hver fakturerbar time fakturert til null — nå nektes tomt og ugyldig beløp før noe sendes (lesSats, testet). (b) Satsen ved opprettelse er et eget kall etter selve prosjektet; en ugyldig sats etterlot et halvt opprettet prosjekt, og neste forsøk feilet på koden som nå fantes. Satsen sjekkes derfor FØR prosjektet opprettes, og skjemaet tømmes så snart prosjektet finnes. Serverens meldinger er norske (kode i bruk gjenkjennes på SQLSTATE 23505, tomt navn nektes før databasen svarer), testet i a_project_carries_its_customer. Etter en endring hentes bare registeret på nytt — ikke kundelisten eller et års timer — og medlemslisten (for personsatser) hentes bare for MEDLEM_ADMIN, når satsene åpnes.

Visibility follows the rettigheter: the section is readable for everyone with DIMENSJON_LES (including ansatte — they log hours against the projects), while every writing control renders only with DIMENSJON_SKRIV. The portal learns this from /me, which carries the resolved rettighet slugs per company — DISPLAY ONLY, the server’s guard still decides (docs/auth.md). Project-shaped views elsewhere (DimRegisterLenke) point at the section, and the project picker in timeføring explains its own absence instead of vanishing silently when the registry is empty (DimSelect’s tomHint). The report filters keep the silent behaviour: there, empty is just empty.

  • Mandatory dimensions per account (policy config, later).
  • More than two dimension kinds.
  • Dimension import from SAF-T files (the importer ignores Analysis elements for now).
  • regnmed-core/src/hash.rs — golden digests v1/v2/v3; moving a dimension code or swapping avdeling↔prosjekt changes the v3 hash; v2/v3 never collide.
  • regnmed-core/src/saft.rs — AnalysisTypeTable + Analysis rendering, XSD-validated.
  • regnmed-api/tests/grupper/dimensions.rs (real Postgres, also CI) — registry over HTTP (duplicate/bad kind rejected), v3 postings mixed with dimension-free vouchers verify from genesis, unknown/avsluttet codes rejected at posting, resultat filters sum correctly per dimension, kontospesifikasjon carries the codes, SAF-T export contains the Analysis elements, the code column is immutable while rename is not.