Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import type { VatPeriodType } from '@/types'
|
|
|
|
/**
|
|
* Convert a Accounted org_number to Skatteverket's 12-digit "redovisare" format.
|
|
*
|
|
* Rules:
|
|
* - Organisationsnummer (10 digits, e.g. 5020000013): prefix with "16" → 165020000013
|
|
* - Personnummer (10 digits, e.g. 8501011234): prefix with "19" or "20" based on century
|
|
* - Strip any hyphens before processing
|
|
*/
|
|
export function formatRedovisare(
|
|
orgNumber: string,
|
|
entityType: 'enskild_firma' | 'aktiebolag'
|
|
): string {
|
|
const clean = orgNumber.replace(/-/g, '')
|
|
|
|
if (clean.length === 12) return clean
|
|
|
|
if (clean.length !== 10) {
|
|
throw new Error(`Ogiltigt organisationsnummer: ${orgNumber} (förväntar 10 eller 12 siffror)`)
|
|
}
|
|
|
|
if (entityType === 'aktiebolag') return `16${clean}`
|
|
|
|
// Enskild firma: personnummer
|
|
const yearDigits = parseInt(clean.substring(0, 2), 10)
|
|
const currentTwoDigitYear = new Date().getFullYear() % 100
|
|
const prefix = yearDigits > currentTwoDigitYear ? '19' : '20'
|
|
return `${prefix}${clean}`
|
|
}
|
|
|
|
/**
|
|
* Convert Accounted period parameters to Skatteverket's YYYYMM format.
|
|
*
|
|
* Skatteverket expects the last month of the period.
|
|
* - monthly period 3, year 2025 → "202503"
|
|
* - quarterly period 1, year 2025 → "202503" (Q1 ends in March)
|
|
* - yearly period 1, year 2025 → "202512"
|
|
*/
|
|
export function formatRedovisningsperiod(
|
|
periodType: VatPeriodType,
|
|
year: number,
|
|
period: number
|
|
): string {
|
|
let lastMonth: number
|
|
|
|
switch (periodType) {
|
|
case 'monthly':
|
|
lastMonth = period
|
|
break
|
|
case 'quarterly':
|
|
lastMonth = period * 3
|
|
break
|
|
case 'yearly':
|
|
lastMonth = 12
|
|
break
|
|
}
|
|
|
|
return `${year}${String(lastMonth).padStart(2, '0')}`
|
|
}
|