Add/bokslut (#718)

* feat(arcim-migration): Briox provider with SIE-over-API import

- Briox auth via account ID + application token (no app-level
  credentials); both tokens rotate on refresh and are persisted
- New sie-fetcher pulls the general ledger as SIE through the
  provider API for Fortnox, Briox and Bjorn Lunden
- Wizard stops on a failed SIE import and surfaces the real errors
  instead of proceeding to the misleading migrate-guard message
- PROVIDER_SIE_ONLY_FORTNOX renamed to PROVIDER_SIE_NOT_SUPPORTED;
  new PROVIDER_TOKEN_INVALID for rejected provider credentials

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(bookkeeping): per-line accruals (periodisering) on invoices and supplier invoices

Defer revenue/costs per invoice line to 29xx/17xx interim accounts with
automatic monthly dissolution (nightly cron + catch-up at registration),
schedule cancellation on credit, year-end auto-detect exclusion for
already-scheduled invoices, invoice-inbox service-period extraction for
prefill, and an MCP tool to list schedules.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(bokslut): iXBRL arsredovisning generation and Bolagsverket digital filing

Generate the annual report as iXBRL from a generated taxonomy registry
(K2 element lists, taxonomy:generate/check scripts + CI guard), expose it
via the fiscal-period API, and add the bolagsverket extension for digital
submission to eget utrymme with webhook-driven status tracking
(submissions table + pg tests, lifecycle events, year-end wizard UI).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(mcp): raise origin-guard test timeout to 20s

The dynamic import pulls in the full server module; the parse alone
flirts with the 5s default under full-suite parallel load.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add new scripts and documentation for K2 AB taxonomy generation and validation

- Introduced `generate-taxonomy-registry.ts` to automate the generation of the iXBRL taxonomy concept registry from official element lists and tuple models.
- Added `validate-ixbrl.mjs` for validating generated iXBRL reports against the official taxonomy package using Arelle.
- Included new documentation files:
  - `k2-ab-arsredovisning-elementlista-2024-09-12_rev20250312_sv.xlsx`
  - `tuple-innehallsmodell-arsredovisning-k2-2024-09-12.xlsx`
  - `taxonomi-paket-2024-09-12_rev20250312.zip`

* Add tests for bookkeeping accruals dissolution and supplier invoices

- Implement tests for the POST /api/bookkeeping/accruals/[id]/dissolve route, covering success and error scenarios.
- Add tests for the DELETE /api/supplier-invoices/[id] route, including authentication checks and validation of invoice deletion conditions.
- Introduce tests for the Arcim migration provider client, ensuring token handling and error classification.
- Create tests for the Bolagsverket extension, validating submission role enforcement and environment settings.
- Add Zod schemas for Bolagsverket response payloads to ensure proper validation.
- Implement tests for MCP server's list accrual schedules, confirming registration and scope mapping.
- Add consistency tests for IXBRL document generation, ensuring duplicate facts and XML escaping are handled correctly.
- Introduce typed domain errors for accrual schedules to improve error handling in the service.
- Add tests for resolving consent with Briox token refresh concurrency, ensuring proper token management and error handling.

* fix(tests): update payload size guard comments to reflect recent changes in tool descriptions and ceiling adjustments

* fix(gitattributes): mark generated JSON files in bokslut taxonomy as linguist-generated

* feat(migrations): add backfill for invoices.journal_entry_id and fallback for next_voucher_number user_id

* feat(bokslut): enhance compliance and financial processing features with new submission details and security measures

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Mattsson
2026-06-12 16:35:30 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent 8e8b63a200
commit db8983ba9e
131 changed files with 33796 additions and 340 deletions
@@ -0,0 +1,170 @@
'use client'
import { useTranslations } from 'next-intl'
import { X } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { formatCurrency } from '@/lib/utils'
import {
computeInstallmentAmounts,
countCalendarMonths,
} from '@/lib/bookkeeping/accruals/compute'
import type { AccrualDirection } from '@/types'
export interface AccrualFormValue {
start: string
end: string
balanceAccount: string
}
// The statutory BAS interim accounts per direction — a fixed list reads
// better than a full account combobox and mirrors the DB CHECK (17xx/29xx).
const BALANCE_ACCOUNT_OPTIONS: Record<AccrualDirection, Array<{ value: string; label: string }>> = {
expense: [
{ value: '1710', label: '1710 Förutbetalda hyreskostnader' },
{ value: '1720', label: '1720 Förutbetalda leasingavgifter' },
{ value: '1730', label: '1730 Förutbetalda försäkringspremier' },
{ value: '1740', label: '1740 Förutbetalda räntekostnader' },
{ value: '1790', label: '1790 Övriga förutbetalda kostnader' },
],
revenue: [
{ value: '2970', label: '2970 Förutbetalda intäkter' },
{ value: '2971', label: '2971 Förutbetalda hyresintäkter' },
{ value: '2972', label: '2972 Förutbetalda medlemsavgifter' },
{ value: '2979', label: '2979 Övriga förutbetalda intäkter' },
],
}
/**
* Per-line periodisering panel for the invoice editors: service period +
* interim balance account + a live "N månader × X kr" preview. The parent
* owns the toggle; this renders only while periodisering is active on the
* line. VAT is never affected — only the net amount is deferred.
*/
export default function AccrualPeriodControl({
direction,
amount,
value,
onChange,
onRemove,
idPrefix,
}: {
direction: AccrualDirection
/** Net line amount (ex VAT) — drives the preview and the K2 hint. */
amount: number
value: AccrualFormValue
onChange: (next: AccrualFormValue) => void
onRemove: () => void
idPrefix: string
}) {
const t = useTranslations('accruals')
let preview: string | null = null
let previewInvalid: string | null = null
if (value.start && value.end) {
if (value.end < value.start) {
previewInvalid = t('preview_invalid_period')
} else {
try {
const months = countCalendarMonths(value.start, value.end)
if (months < 2) {
previewInvalid = t('preview_min_months')
} else if (amount > 0) {
const amounts = computeInstallmentAmounts(amount, months)
preview = t('preview', {
months,
amount: formatCurrency(amounts[0]),
})
}
} catch {
previewInvalid = t('preview_invalid_period')
}
}
}
const showK2Hint = amount > 0 && amount < 5000
return (
<div className="rounded-md border bg-muted/30 p-3 space-y-3">
<div className="flex items-center justify-between">
<span className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
{t('panel_title')}
</span>
<Button
type="button"
variant="ghost"
size="icon"
className="h-7 w-7"
onClick={onRemove}
aria-label={t('remove_aria')}
>
<X className="h-3.5 w-3.5 text-muted-foreground" />
</Button>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div className="space-y-1.5">
<Label htmlFor={`${idPrefix}-start`} className="text-xs">
{t('start_label')}
</Label>
<Input
id={`${idPrefix}-start`}
type="date"
className="h-9"
value={value.start}
onChange={(e) => onChange({ ...value, start: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`${idPrefix}-end`} className="text-xs">
{t('end_label')}
</Label>
<Input
id={`${idPrefix}-end`}
type="date"
className="h-9"
value={value.end}
onChange={(e) => onChange({ ...value, end: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label className="text-xs">{t('account_label')}</Label>
<Select
value={value.balanceAccount}
onValueChange={(account) => onChange({ ...value, balanceAccount: account })}
>
<SelectTrigger className="h-9" aria-label={t('account_label')}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{BALANCE_ACCOUNT_OPTIONS[direction].map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
{(preview || previewInvalid) && (
<p
className={
previewInvalid ? 'text-xs text-destructive' : 'text-xs text-muted-foreground tabular-nums'
}
>
{previewInvalid ?? preview}
</p>
)}
{showK2Hint && (
<p className="text-xs text-muted-foreground">{t('k2_hint')}</p>
)}
</div>
)
}
@@ -64,14 +64,17 @@ export function DispositionsStep({ periodId, onBack, onContinue }: DispositionsS
const data = body.data as DispositionsProposal
setProposal(data)
const selections: UiState['selections'] = {}
for (const p of data.proposals) {
const key = proposalKey(p)
data.proposals.forEach((p, index) => {
// Key must match the render loop and buildPostItems, which both pass
// the array index — omitting it here defaulted every non-ateforing
// key to ":0", so only the first proposal card ever rendered.
const key = proposalKey(p, index)
selections[key] = {
accept: true,
overrideAmount: p.amount,
lockedSkip: Boolean(p.required),
}
}
})
setUi({ selections })
} catch {
setFetchError('Kunde inte ladda dispositioner')