* fix(arsredovisning): make the aktiekapital note completable via company settings The annual report warned every AB that the aktiekapital note was missing and pointed at Installningar -> Foretag, but the referenced columns (aktiekapital, antal_aktier, kvotvarde) never existed and no settings UI was ever built, so the warning was a dead end and no AB could produce a complete note before Bolagsverket filing. - migration 20260723103000: company_settings.aktiekapital (numeric) and antal_aktier (integer) with positive CHECKs; kvotvarde is intentionally not stored since ABL 1 kap 6 defines it as aktiekapital / antal aktier - build-data.ts (K2 and K3 note paths): select only the two stored columns and derive kvotvarde with roundOre - UpdateSettingsSchema: aktiekapital (positive), antal_aktier (positive integer), both nullable to allow clearing - new ShareCapitalForm section on Installningar -> Foretag, rendered for aktiebolag only, with live derived kvotvarde display; wired through the existing CompanySettingsContent save path (empty string clears to null) - sv/en strings; settings route tests (round-trip, clear, 400 on invalid); builder tests for derived kvotvarde and the empty-settings warning Staging (metjnjrhvujscngnpzdv) already has the columns applied and the note verified end-to-end against a rehearsal company. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(arsredovisning): address PR review findings on the share-capital note - enforce aktiekapital/antal_aktier as an all-or-nothing pair (DB CHECK, K2/K3 note guard now requires both, partial pair warns instead) - numeric(15,2) column, .int() Zod constraint, maxFractionDigits 0 render - guard numberOrNull against NaN; align kvotvarde preview with schema - strengthen clearing test, add fractional and partial-pair tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
83 lines
2.7 KiB
TypeScript
83 lines
2.7 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import { Input } from '@/components/ui/input'
|
|
import { Label } from '@/components/ui/label'
|
|
import { roundOre } from '@/lib/money'
|
|
import { formatCurrency } from '@/lib/utils'
|
|
import type { CompanySettings } from '@/types'
|
|
|
|
interface ShareCapitalFormProps {
|
|
settings: CompanySettings
|
|
}
|
|
|
|
/**
|
|
* Registered share capital per Bolagsverket, feeding the statutory
|
|
* aktiekapital note in the annual report. Kvotvärde (ABL 1 kap 6 §:
|
|
* aktiekapital / antal aktier) is derived, never entered.
|
|
*/
|
|
export function ShareCapitalForm({ settings }: ShareCapitalFormProps) {
|
|
const t = useTranslations('settings_company')
|
|
const [aktiekapital, setAktiekapital] = useState(
|
|
settings.aktiekapital != null ? String(settings.aktiekapital) : '',
|
|
)
|
|
const [antalAktier, setAntalAktier] = useState(
|
|
settings.antal_aktier != null ? String(settings.antal_aktier) : '',
|
|
)
|
|
|
|
const capital = Number(aktiekapital)
|
|
const shares = Number(antalAktier)
|
|
// Mirror UpdateSettingsSchema: whole-krona capital > 0, positive integer
|
|
// share count. No preview for values the server would reject.
|
|
const kvotvarde =
|
|
Number.isSafeInteger(capital) && capital > 0 && Number.isSafeInteger(shares) && shares > 0
|
|
? roundOre(capital / shares)
|
|
: null
|
|
|
|
return (
|
|
<section className="space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
{t('share_capital_heading')}
|
|
</h2>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="aktiekapital">{t('aktiekapital_label')}</Label>
|
|
<Input
|
|
id="aktiekapital"
|
|
name="aktiekapital"
|
|
type="number"
|
|
inputMode="numeric"
|
|
min="1"
|
|
step="1"
|
|
value={aktiekapital}
|
|
onChange={(e) => setAktiekapital(e.target.value)}
|
|
/>
|
|
<p className="text-xs text-muted-foreground">{t('aktiekapital_help')}</p>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="antal_aktier">{t('antal_aktier_label')}</Label>
|
|
<Input
|
|
id="antal_aktier"
|
|
name="antal_aktier"
|
|
type="number"
|
|
inputMode="numeric"
|
|
min="1"
|
|
step="1"
|
|
value={antalAktier}
|
|
onChange={(e) => setAntalAktier(e.target.value)}
|
|
/>
|
|
<p className="text-xs text-muted-foreground">{t('antal_aktier_help')}</p>
|
|
</div>
|
|
</div>
|
|
|
|
{kvotvarde !== null && (
|
|
<p className="text-xs text-muted-foreground tabular-nums">
|
|
{t('kvotvarde_display', { value: formatCurrency(kvotvarde) })}
|
|
</p>
|
|
)}
|
|
</section>
|
|
)
|
|
}
|