* feat(bookkeeping): make blocked fiscal-year creation actionable When creating a new räkenskapsår is blocked because a prior period is still open, the "Skapa räkenskapsår" dialog no longer dead-ends on an English toast. The API now returns the canonical bilingual error envelope with the blocking periods (id/name/dates) under details, and the dialog renders a Swedish panel that locks them inline (reversible locked_at) via the existing /lock endpoint and retries creation. The guard rule is unchanged and remains BFL-compliant: BFL 6 kap allows löpande bokföring of the new year in parallel with the prior year's bokslut, so a lock (not a full close) is sufficient and reversible. - Add PERIOD_CREATE_BLOCKED_BY_OPEN_PERIODS structured error code - Return envelope + details.blockingPeriods from the 409 (was English string) - CreatePeriodDialog: inline "lås och skapa" panel + lock-and-retry - Update route tests for the new envelope shape Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(ui): prevent mouse wheel from mutating number inputs A focused <input type="number"> would change its value on scroll, silently turning e.g. a 20000 salary into 19998. Blur number inputs on wheel so the page scrolls instead of editing the value. Applied at the Input primitive so all number fields are protected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(salary): auto-derive skattetabell and kolumn for employees Replace the opaque manual "Skattetabell (29-42)" and "Kolumn (1-6)" inputs on the employee form with a self-deriving flow: the user picks their folkbokföringskommun from a searchable dropdown and the tax table fills itself in, while the column derives from the personnummer we already collect. - Add a searchable municipality picker (MunicipalityCombobox) backed by a new cached GET /api/salary/tax-tables/kommuner endpoint. - Wrap the whole "Skatt" card in a self-contained EmployeeTaxCard used by both the create and edit pages, with InfoTooltips and named column options. - deriveTaxColumn(): auto-select column 1 for under-66 employees; leave the ambiguous 66+ case (pension vs working senior) to a clearly-named manual choice. - Fix fetchKommunTaxRates() to page through all ~1300 församling rows instead of a single 500-row page (which silently dropped ~200 kommuner, incl. Göteborg) and normalize the uppercase names to title case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(import): correct CSV amount-column guess and surface skipped rows Manual CSV column-mapping auto-guess walked each data row right-to-left and picked the first numeric cell as the amount, so on the common ...;Belopp;Saldo layout it grabbed the trailing running-balance column. Extract the guess into a pure, tested suggestColumnMapping(): match header labels first (belopp/amount -> amount, saldo/balance -> balance), auto-fill the balance field, and fall back to value heuristics that skip the balance column and prefer a column carrying negative values. Also surface stats.skipped_rows + parse warnings in BankFileConfirmStep - the manual-mapping path skips the preview step that was the only place they showed, so skipped rows were silently dropped from view. Add a unit test reproducing the Saldo-as-amount regression. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: add "Save as draft" functionality for invoices - Implemented a new feature to allow users to save invoices as unnumbered drafts without generating an invoice number until finalized. - Added a `save_as_draft` flag to the CreateInvoiceInput schema to handle draft saving logic. - Updated the invoice creation API to skip number allocation when saving as a draft. - Introduced a new endpoint for finalizing drafts, which allocates an invoice number and emits an `invoice.created` event. - Enhanced the UI to include a "Save as draft" button, with loading states and tooltips. - Updated tests to cover the new draft saving and finalization logic, including race conditions for concurrent modifications. - Added relevant error handling for draft finalization and deletion scenarios. * feat(employee): add employment start and end date fields to employee forms * feat: enhance invoice and salary run handling with improved validation and event logging --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58 lines
2.7 KiB
TypeScript
58 lines
2.7 KiB
TypeScript
import { extractBirthDate } from './personnummer'
|
|
|
|
/**
|
|
* Skattetabell columns (1-6) per Skatteverket. The numbering matches the
|
|
* column order in the imported tax-table data (lib/salary/tax-tables-fallback.ts)
|
|
* and the project payroll reference (.claude/skills/swedish-payroll/references/tax-tables.md).
|
|
*/
|
|
export interface TaxColumnOption {
|
|
value: number
|
|
/** Short label for the select option. */
|
|
label: string
|
|
/** One-line clarification shown under the select / in the option. */
|
|
description: string
|
|
}
|
|
|
|
export const TAX_COLUMN_OPTIONS: TaxColumnOption[] = [
|
|
{ value: 1, label: 'Anställd under 66 år', description: 'Standard — det vanligaste valet' },
|
|
{ value: 2, label: 'Pensionär 66+ år', description: 'Pension till den som fyllt 66 år vid årets ingång' },
|
|
{ value: 3, label: 'Anställd 66+ år', description: 'Lön med förhöjt jobbskatteavdrag' },
|
|
{ value: 4, label: 'Sjuk- eller aktivitetsersättning, under 66 år', description: 'Ersättning från Försäkringskassan' },
|
|
{ value: 5, label: 'Kolumn 5 (särskilda fall)', description: 'Varierar per år enligt SKVFS' },
|
|
{ value: 6, label: 'Pension före 65 år', description: 'Född 1951 eller senare' },
|
|
]
|
|
|
|
export function getTaxColumnOption(value: number): TaxColumnOption | undefined {
|
|
return TAX_COLUMN_OPTIONS.find((o) => o.value === value)
|
|
}
|
|
|
|
/**
|
|
* Derive the tax column for a salaried EMPLOYEE from their birth year.
|
|
*
|
|
* Only the unambiguous, dominant case is auto-derived: an employee who has NOT
|
|
* turned 66 by the start of the income year → column 1. Skatteverket draws this
|
|
* line by birth year ("född 1960 eller senare" = kolumn 1 för inkomståret 2026),
|
|
* so we compare birth year, not exact date.
|
|
*
|
|
* For 66+ the column is genuinely ambiguous from age alone — column 2 (pension)
|
|
* vs column 3 (working senior with förhöjt jobbskatteavdrag) depends on the
|
|
* income type, which the system can't infer. In that case this returns null and
|
|
* the UI asks the user to pick from the named column list.
|
|
*
|
|
* @param personnummer Full (YYYYMMDDNNNN) or masked (YYYYMMDD-XXXX) — only the
|
|
* leading 8 birthdate digits are used.
|
|
* @param year The income/payment year the column applies to.
|
|
* @returns 1 for a confidently-under-66 employee, otherwise null.
|
|
*/
|
|
export function deriveTaxColumn(personnummer: string, year: number): number | null {
|
|
const digits = personnummer.replace(/\D/g, '')
|
|
if (digits.length < 8) return null
|
|
|
|
const { year: birthYear } = extractBirthDate(personnummer)
|
|
if (!birthYear || birthYear < 1900 || birthYear > year) return null
|
|
|
|
// "fyllt 66 år vid årets ingång" → 66+ group. Born in (year - 66) or later
|
|
// means they have not turned 66 by Jan 1 of `year` → column 1.
|
|
return birthYear >= year - 66 ? 1 : null
|
|
}
|