chore: repo-wide bloat sweep, remove dead code and fold duplicate helpers (#2150)
* chore: repo-wide bloat sweep, remove dead code and fold duplicate helpers Remove 33 dead files, ~270 unreferenced exports/types, 13 dead i18n namespaces and 4 unused dependencies; fold byte-identical helper copies into one canonical home each (lib/utils chunk/sleep/utcDateStamp, lib/dates/iso, lib/invariants/uuid, lib/xml/escape, lib/reports/sru/format, lib/pdf/number-text, lib/browser/panel-request, lib/api/v1/body + v1ValidationError rolled out to ~55 v1 routes, booking-template schemas). No behaviour change: v1 bodies and status codes, MCP tool schemas, DB writes and money math are untouched. Naive ore rounding was deliberately not swapped for roundOre; see DECISIONS.md 2026-09-02 for the full list of things left alone on purpose. tsc, lint, 19588 unit tests and check:guards green; antipattern baseline ratcheted (naive-ore-round 622 -> 620, hand-rolled-invariant 115 -> 113). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * test(transactions): import RawTransaction from @/types after the ingest re-export removal CI's type ratchet (check:types, full tsconfig) caught the one test file that still imported the type through lib/transactions/ingest. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
Jakob Wennberg
parent
18cbc4c30a
commit
f266c386f3
@@ -1,95 +0,0 @@
|
||||
// Chat types for AI chatbot
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
session_id: string
|
||||
user_id: string
|
||||
role: 'user' | 'assistant'
|
||||
content: string
|
||||
sources: SourceReference[]
|
||||
artifact?: ArtifactSpec | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface ChatSession {
|
||||
id: string
|
||||
user_id: string
|
||||
title: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface SourceReference {
|
||||
id: string
|
||||
source_file: string
|
||||
title: string
|
||||
section_title: string | null
|
||||
similarity: number
|
||||
}
|
||||
|
||||
export interface KnowledgeDocument {
|
||||
id: string
|
||||
source_file: string
|
||||
title: string
|
||||
section_title: string | null
|
||||
content: string
|
||||
content_hash: string
|
||||
embedding: number[] | null
|
||||
metadata: Record<string, unknown>
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface ChatRequest {
|
||||
message: string
|
||||
session_id?: string
|
||||
}
|
||||
|
||||
export interface ChatResponse {
|
||||
message: ChatMessage
|
||||
session_id: string
|
||||
}
|
||||
|
||||
export interface StreamChunk {
|
||||
type: 'content' | 'sources' | 'done' | 'error' | 'tool_start' | 'artifact'
|
||||
content?: string
|
||||
sources?: SourceReference[]
|
||||
error?: string
|
||||
toolName?: string
|
||||
artifact?: ArtifactSpec
|
||||
}
|
||||
|
||||
// ── Artifact Types ──────────────────────────────────────────────
|
||||
|
||||
export type ArtifactSpec =
|
||||
| ChartArtifact
|
||||
| TableArtifact
|
||||
| KpiCardsArtifact
|
||||
| AgingBucketsArtifact
|
||||
|
||||
export interface ChartArtifact {
|
||||
type: 'bar_chart' | 'line_chart' | 'pie_chart' | 'stacked_bar'
|
||||
title: string
|
||||
data: { label: string; value: number; color?: string }[]
|
||||
unit?: string
|
||||
subtitle?: string
|
||||
}
|
||||
|
||||
export interface TableArtifact {
|
||||
type: 'table'
|
||||
title: string
|
||||
columns: { key: string; label: string; align?: 'left' | 'right' }[]
|
||||
rows: Record<string, string | number>[]
|
||||
summary_row?: Record<string, string | number>
|
||||
}
|
||||
|
||||
export interface KpiCardsArtifact {
|
||||
type: 'kpi_cards'
|
||||
title?: string
|
||||
cards: { label: string; value: string; trend?: 'up' | 'down' | 'flat'; change?: string }[]
|
||||
}
|
||||
|
||||
export interface AgingBucketsArtifact {
|
||||
type: 'aging_buckets'
|
||||
title: string
|
||||
buckets: { label: string; amount: number; count: number }[]
|
||||
total: number
|
||||
}
|
||||
+1
-683
@@ -10,10 +10,6 @@ export type AccountingFramework = 'k2' | 'k3'
|
||||
// Company role for multi-tenant access
|
||||
export type CompanyRole = 'owner' | 'admin' | 'member' | 'viewer'
|
||||
|
||||
// Team (consulting firm) roles and source tracking
|
||||
export type TeamRole = 'owner' | 'admin' | 'member'
|
||||
export type MemberSource = 'direct' | 'team'
|
||||
|
||||
// Team (consulting firm grouping). 'personal' teams are the implicit
|
||||
// one-per-user grouping; 'byra' teams are ops-created accounting-firm
|
||||
// tenants (WL-08) with invites, a brand, and cockpit access.
|
||||
@@ -163,18 +159,6 @@ export interface FiscalYearResetRpcResult {
|
||||
period_name?: string
|
||||
}
|
||||
|
||||
// User preferences (cross-company)
|
||||
export interface UserPreferences {
|
||||
id: string
|
||||
user_id: string
|
||||
active_company_id: string | null
|
||||
// Client-driven UI preferences (nav collapse/fold state, last-used create
|
||||
// modes). jsonb DEFAULT '{}'. Cosmetic only, never load-bearing.
|
||||
ui_state?: UserUiState
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Shape of user_preferences.ui_state. All fields optional: the bag grows
|
||||
// as UI surfaces add preferences (UI migration plan PR 2/3).
|
||||
export interface UserUiState {
|
||||
@@ -296,23 +280,6 @@ export type ProcessingHistoryAggregateType =
|
||||
| 'Migration'
|
||||
| 'System'
|
||||
|
||||
export interface ProcessingHistoryEvent {
|
||||
event_id: string
|
||||
seq: number
|
||||
company_id: string
|
||||
correlation_id: string
|
||||
causation_id: string | null
|
||||
aggregate_type: ProcessingHistoryAggregateType
|
||||
aggregate_id: string
|
||||
event_type: string // open type: validated at runtime against processing_event_types registry
|
||||
payload: Record<string, unknown>
|
||||
payload_schema_version: number
|
||||
actor: ProcessingHistoryActor
|
||||
rubric_version: string | null
|
||||
occurred_at: string
|
||||
appended_at: string
|
||||
}
|
||||
|
||||
// Bank connection status
|
||||
// 'pending_selection' = PSD2 consent granted, awaiting user to pick which
|
||||
// accounts to actually sync. No transactions are pulled in this state.
|
||||
@@ -340,16 +307,6 @@ export interface InvoicePaymentAccount {
|
||||
foreign_account_number?: string | null
|
||||
}
|
||||
|
||||
// Profile (extends auth.users)
|
||||
export interface Profile {
|
||||
id: string
|
||||
email: string
|
||||
full_name: string | null
|
||||
avatar_url: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Editable invoice email texts (standard invoices only; sv + en).
|
||||
// Missing / whitespace-only fields fall back to the hardcoded defaults in
|
||||
// lib/email/invoice-templates.ts. Supports the fixed placeholder set
|
||||
@@ -694,17 +651,6 @@ export interface CashAccount {
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Import source identifiers
|
||||
export type ImportSource =
|
||||
| 'enable_banking'
|
||||
| 'csv_nordea'
|
||||
| 'csv_seb'
|
||||
| 'csv_swedbank'
|
||||
| 'csv_handelsbanken'
|
||||
| 'csv_generic'
|
||||
| 'camt053'
|
||||
| 'manual'
|
||||
|
||||
/**
|
||||
* Closed vocabulary for HOW money moved (the payment rail), classified at
|
||||
* ingest by classifyTransactionMethod() (lib/transactions/transaction-method.ts).
|
||||
@@ -845,25 +791,6 @@ export interface Transaction {
|
||||
// (upsert on company_id + file_hash) and moves it back to 'processing'.
|
||||
export type BankFileImportStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'undone'
|
||||
|
||||
export interface BankFileImport {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string
|
||||
filename: string
|
||||
file_hash: string
|
||||
file_format: string
|
||||
transaction_count: number
|
||||
imported_count: number
|
||||
duplicate_count: number
|
||||
matched_count: number
|
||||
date_from: string | null
|
||||
date_to: string | null
|
||||
status: BankFileImportStatus
|
||||
error_message: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Customer
|
||||
export interface Customer {
|
||||
id: string
|
||||
@@ -1508,41 +1435,6 @@ export type RotRutPayoutRequestStatus =
|
||||
| 'rejected'
|
||||
| 'cancelled'
|
||||
|
||||
export interface RotRutPayoutRequest {
|
||||
id: string
|
||||
company_id: string
|
||||
user_id: string
|
||||
deduction_type: 'rot' | 'rut'
|
||||
/** NamnPaBegaran in the file: 1-16 chars, shown in Skatteverkets e-tjänst. */
|
||||
name: string
|
||||
status: RotRutPayoutRequestStatus
|
||||
requested_total: number
|
||||
decided_total: number | null
|
||||
file_name: string
|
||||
file_document_id: string | null
|
||||
settlement_journal_entry_id: string | null
|
||||
submitted_at: string | null
|
||||
decided_at: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
|
||||
// Relations (populated when fetched)
|
||||
items?: RotRutPayoutRequestItem[]
|
||||
}
|
||||
|
||||
export interface RotRutPayoutRequestItem {
|
||||
id: string
|
||||
request_id: string
|
||||
invoice_id: string
|
||||
requested_amount: number
|
||||
decided_amount: number | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
|
||||
// Relations (populated when fetched)
|
||||
invoice?: Invoice
|
||||
}
|
||||
|
||||
// Recurring Invoice Schedule (template + monthly cadence)
|
||||
export type RecurringInvoiceScheduleStatus = 'active' | 'paused'
|
||||
|
||||
@@ -1607,24 +1499,6 @@ export interface RecurringInvoiceScheduleItem {
|
||||
created_at: string
|
||||
}
|
||||
|
||||
// Tax Rates (reference table)
|
||||
export interface TaxRate {
|
||||
id: string
|
||||
|
||||
// Type
|
||||
rate_type: 'egenavgifter' | 'bolagsskatt' | 'arbetsgivaravgifter' | 'vat' | 'municipal'
|
||||
|
||||
// Rate
|
||||
rate: number
|
||||
|
||||
// Validity
|
||||
valid_from: string
|
||||
valid_to: string | null
|
||||
|
||||
// Description
|
||||
description: string
|
||||
}
|
||||
|
||||
// Form types for creating/updating
|
||||
|
||||
export interface CreateCustomerInput {
|
||||
@@ -1674,91 +1548,6 @@ export interface CreateSupplierInput {
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface CreateSupplierInvoiceInput {
|
||||
supplier_id: string
|
||||
supplier_invoice_number: string
|
||||
invoice_date: string
|
||||
due_date: string
|
||||
delivery_date?: string
|
||||
currency?: string
|
||||
exchange_rate?: number
|
||||
vat_treatment?: VatTreatment
|
||||
reverse_charge?: boolean
|
||||
payment_reference?: string
|
||||
notes?: string
|
||||
/** Per-invoice öresavrundning override (display-only). Omitted = null (off). */
|
||||
ore_rounding?: boolean
|
||||
items: CreateSupplierInvoiceItemInput[]
|
||||
}
|
||||
|
||||
export interface CreateSupplierInvoiceItemInput {
|
||||
description: string
|
||||
amount: number
|
||||
account_number: string
|
||||
vat_rate?: number
|
||||
// Manual override. See CreateSupplierInvoiceItemSchema for rationale.
|
||||
vat_amount?: number
|
||||
// Self-assessed VAT rate for omvänd skattskyldighet (0.06/0.12/0.25). When
|
||||
// set, the engine books fiktiv moms at this rate while vat_rate stays 0.
|
||||
reverse_charge_rate?: number
|
||||
// Särskild löneskatt på pensionskostnader: injects 7533 D / 2514 K at
|
||||
// 24.26 % of the line amount. Only valid on 741x pension accounts.
|
||||
apply_slp?: boolean
|
||||
vat_code?: string
|
||||
// Legacy fields (backward compat, ignored when amount is set)
|
||||
quantity?: number
|
||||
unit?: string
|
||||
unit_price?: number
|
||||
}
|
||||
|
||||
export interface CreateInvoiceInput {
|
||||
customer_id: string
|
||||
invoice_date: string
|
||||
due_date: string
|
||||
currency: Currency
|
||||
document_type?: InvoiceDocumentType
|
||||
your_reference?: string
|
||||
our_reference?: string
|
||||
/** Fakturamärkning: buyer-required marking, separate from your_reference. */
|
||||
invoice_marking?: string
|
||||
notes?: string
|
||||
/** Optional https link where the customer can pay online (e.g. a Stripe Payment Link). */
|
||||
payment_link_url?: string
|
||||
/** Plaintext personnummer: encrypted server-side before storage. */
|
||||
deduction_personnummer?: string
|
||||
/** Fastighetsbeteckning. Required when any item carries deduction_type === 'rot'. */
|
||||
deduction_housing_designation?: string
|
||||
/** Save as an unnumbered draft (no F-number, no invoice.created) until the
|
||||
* user finalizes via "Granska & skapa". Lets the draft be hard-deleted. */
|
||||
save_as_draft?: boolean
|
||||
/** Per-invoice öresavrundning override (display-only). Omitted = null (inherit company setting). */
|
||||
ore_rounding?: boolean
|
||||
items: CreateInvoiceItemInput[]
|
||||
}
|
||||
|
||||
export interface CreateInvoiceItemInput {
|
||||
/** 'text' rows carry only a description (may be empty for a spacer) and are
|
||||
* excluded from totals and bookkeeping. Defaults to 'product'. */
|
||||
line_type?: 'product' | 'text'
|
||||
description: string
|
||||
quantity: number
|
||||
unit: string
|
||||
unit_price: number
|
||||
/** Percentage discount on the line (0-100). Omitted/null = 0. */
|
||||
discount_percent?: number | null
|
||||
vat_rate?: number
|
||||
/** Source article (optional). Free-text lines omit it. */
|
||||
article_id?: string | null
|
||||
/** BAS class 1-3 posting account override copied from the article. null = derive from VAT treatment. */
|
||||
revenue_account?: string | null
|
||||
/** ROT/RUT toggle. null/undefined = no deduction. */
|
||||
deduction_type?: 'rot' | 'rut' | null
|
||||
labor_hours?: number | null
|
||||
work_type?: string | null
|
||||
housing_designation?: string | null
|
||||
apartment_number?: string | null
|
||||
}
|
||||
|
||||
export interface CreateTransactionInput {
|
||||
date: string
|
||||
description: string
|
||||
@@ -1783,14 +1572,6 @@ export interface ArchiveEstimate {
|
||||
within_limit: boolean
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[]
|
||||
count: number
|
||||
page: number
|
||||
pageSize: number
|
||||
totalPages: number
|
||||
}
|
||||
|
||||
// VAT validation response
|
||||
export interface VatValidationResult {
|
||||
valid: boolean
|
||||
@@ -1808,54 +1589,6 @@ export interface ExchangeRate {
|
||||
date: string
|
||||
}
|
||||
|
||||
// Dashboard summary types
|
||||
export interface DashboardSummary {
|
||||
// Income
|
||||
total_income_ytd: number
|
||||
total_income_mtd: number
|
||||
|
||||
// Expenses
|
||||
total_expenses_ytd: number
|
||||
total_expenses_mtd: number
|
||||
|
||||
// Net
|
||||
net_income_ytd: number
|
||||
net_income_mtd: number
|
||||
|
||||
// Tax estimates
|
||||
estimated_tax: TaxEstimate
|
||||
|
||||
// Alerts
|
||||
uncategorized_count: number
|
||||
unpaid_invoices_count: number
|
||||
unpaid_invoices_total: number
|
||||
overdue_invoices_count: number
|
||||
|
||||
// Bank
|
||||
bank_balance: number | null
|
||||
available_balance: number | null // After tax reservations
|
||||
}
|
||||
|
||||
export interface TaxEstimate {
|
||||
// For EF
|
||||
egenavgifter?: number
|
||||
income_tax?: number // Municipal tax (kommunalskatt)
|
||||
state_tax?: number // State tax (statlig skatt) - 20% on high incomes
|
||||
grundavdrag?: number // Basic deduction applied
|
||||
|
||||
// For AB
|
||||
bolagsskatt?: number
|
||||
|
||||
// Common
|
||||
moms_to_pay: number
|
||||
total_tax_liability: number
|
||||
|
||||
// Comparison with preliminary
|
||||
preliminary_paid_ytd: number
|
||||
difference: number // Positive = underpaying
|
||||
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// BAS Kontoplan & Bookkeeping Types
|
||||
// ============================================================
|
||||
@@ -2245,24 +1978,6 @@ export interface BookingTemplateLibrary {
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Account Balance (cached)
|
||||
export interface AccountBalance {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string
|
||||
fiscal_period_id: string
|
||||
account_number: string
|
||||
account_id: string | null
|
||||
opening_debit: number
|
||||
opening_credit: number
|
||||
period_debit: number
|
||||
period_credit: number
|
||||
closing_debit: number
|
||||
closing_credit: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Report types
|
||||
export interface TrialBalanceRow {
|
||||
account_number: string
|
||||
@@ -2477,12 +2192,6 @@ export interface CreateJournalEntryLineInput {
|
||||
project?: string
|
||||
}
|
||||
|
||||
export interface CreateFiscalPeriodInput {
|
||||
name: string
|
||||
period_start: string
|
||||
period_end: string
|
||||
}
|
||||
|
||||
// ── Pending Operations ────────────────────────────────────────
|
||||
|
||||
export type PendingOperationType =
|
||||
@@ -2703,44 +2412,6 @@ export interface InitialSetupState {
|
||||
dismissedAt: string | null
|
||||
}
|
||||
|
||||
// Onboarding step data
|
||||
export interface OnboardingStepData {
|
||||
step1?: {
|
||||
entity_type: EntityType
|
||||
}
|
||||
step2?: {
|
||||
company_name: string
|
||||
org_number?: string
|
||||
address_line1?: string
|
||||
postal_code?: string
|
||||
city?: string
|
||||
}
|
||||
step3?: {
|
||||
f_skatt: boolean
|
||||
fiscal_year_start_month: number
|
||||
is_first_fiscal_year?: boolean
|
||||
first_year_start?: string
|
||||
first_year_end?: string
|
||||
vat_registered: boolean
|
||||
vat_number?: string
|
||||
moms_period?: MomsPeriod
|
||||
}
|
||||
step4?: {
|
||||
preliminary_tax_monthly?: number
|
||||
}
|
||||
step5?: {
|
||||
bank_name?: string
|
||||
clearing_number?: string
|
||||
account_number?: string
|
||||
iban?: string
|
||||
bic?: string
|
||||
}
|
||||
step6?: {
|
||||
bank_connected: boolean
|
||||
bank_connection_id?: string
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Calendar & Deadline Types
|
||||
// ============================================================
|
||||
@@ -2846,40 +2517,10 @@ export interface Deadline {
|
||||
customer?: Customer
|
||||
}
|
||||
|
||||
// Input for creating a deadline
|
||||
export interface CreateDeadlineInput {
|
||||
title: string
|
||||
due_date: string
|
||||
due_time?: string
|
||||
deadline_type: DeadlineType
|
||||
priority?: DeadlinePriority
|
||||
customer_id?: string
|
||||
notes?: string
|
||||
// Tax deadline fields
|
||||
tax_deadline_type?: TaxDeadlineType
|
||||
tax_period?: string
|
||||
source?: DeadlineSource
|
||||
linked_report_type?: string
|
||||
linked_report_period?: Record<string, unknown>
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Push Notification Types
|
||||
// ============================================================
|
||||
|
||||
// Push subscription for Web Push API
|
||||
export interface PushSubscription {
|
||||
id: string
|
||||
user_id: string
|
||||
endpoint: string
|
||||
p256dh: string
|
||||
auth: string
|
||||
user_agent: string | null
|
||||
is_active: boolean
|
||||
last_used_at: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
// Notification settings per user
|
||||
export interface NotificationSettings {
|
||||
id: string
|
||||
@@ -2916,18 +2557,6 @@ export type NotificationType =
|
||||
| 'skv_connection_expired'
|
||||
| 'bookkeeping_digest'
|
||||
|
||||
// Notification log entry
|
||||
export interface NotificationLog {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string | null
|
||||
notification_type: NotificationType
|
||||
reference_id: string
|
||||
days_before: number
|
||||
sent_at: string
|
||||
delivery_status: 'pending' | 'sent' | 'delivered' | 'failed'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Calendar Feed Types (ICS)
|
||||
// ============================================================
|
||||
@@ -2947,90 +2576,6 @@ export interface CalendarFeed {
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// Input for creating/updating calendar feed
|
||||
export interface UpdateCalendarFeedInput {
|
||||
include_tax_deadlines?: boolean
|
||||
include_invoices?: boolean
|
||||
}
|
||||
|
||||
// Swedish labels for deadline status
|
||||
export const DEADLINE_STATUS_LABELS: Record<DeadlineStatus, string> = {
|
||||
upcoming: 'Kommande',
|
||||
action_needed: 'Åtgärd krävs',
|
||||
in_progress: 'Pågår',
|
||||
submitted: 'Inskickad',
|
||||
confirmed: 'Bekräftad',
|
||||
overdue: 'Försenad'
|
||||
}
|
||||
|
||||
// Swedish labels for tax deadline types
|
||||
export const TAX_DEADLINE_TYPE_LABELS: Record<TaxDeadlineType, string> = {
|
||||
moms_monthly: 'Momsdeklaration (månad)',
|
||||
moms_quarterly: 'Momsdeklaration (kvartal)',
|
||||
moms_yearly: 'Momsdeklaration (år)',
|
||||
f_skatt: 'Preliminärskatt (F-skatt)',
|
||||
arbetsgivardeklaration: 'Arbetsgivardeklaration',
|
||||
skatteinbetalning: 'Skatteinbetalning (storföretag)',
|
||||
inkomstdeklaration_ef: 'Inkomstdeklaration EF',
|
||||
inkomstdeklaration_ab: 'Inkomstdeklaration AB',
|
||||
arsredovisning: 'Årsredovisning',
|
||||
arsstamma: 'Årsstämma',
|
||||
periodisk_sammanstallning: 'Periodisk sammanställning',
|
||||
kontrolluppgifter: 'Kontrolluppgifter (KU)',
|
||||
rot_rut_begaran: 'ROT/RUT-begäran om utbetalning',
|
||||
oss_quarterly: 'OSS-deklaration',
|
||||
ioss_monthly: 'IOSS-deklaration',
|
||||
intrastat_monthly: 'Intrastat',
|
||||
punktskatt_monthly: 'Punktskattedeklaration',
|
||||
fyllnadsinbetalning: 'Fyllnadsinbetalning',
|
||||
kvarskatt: 'Kvarskatt'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// SIE Import Types
|
||||
// ============================================================
|
||||
|
||||
// SIE import status
|
||||
export type SIEImportStatus = 'pending' | 'mapped' | 'completed' | 'failed'
|
||||
|
||||
// SIE import record
|
||||
export interface SIEImport {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string
|
||||
filename: string
|
||||
file_hash: string
|
||||
org_number: string | null
|
||||
company_name: string | null
|
||||
sie_type: number
|
||||
fiscal_year_start: string | null
|
||||
fiscal_year_end: string | null
|
||||
accounts_count: number
|
||||
transactions_count: number
|
||||
opening_balance_total: number | null
|
||||
status: SIEImportStatus
|
||||
error_message: string | null
|
||||
fiscal_period_id: string | null
|
||||
opening_balance_entry_id: string | null
|
||||
imported_at: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// SIE account mapping record
|
||||
export interface SIEAccountMapping {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string
|
||||
source_account: string
|
||||
source_name: string | null
|
||||
target_account: string
|
||||
confidence: number
|
||||
match_type: 'exact' | 'name' | 'class' | 'manual'
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Invoice Inbox Types
|
||||
// ============================================================
|
||||
@@ -3411,68 +2956,12 @@ export interface ExtractedLineItem {
|
||||
confidence?: number
|
||||
}
|
||||
|
||||
// Match candidate for receipt-to-transaction matching
|
||||
export interface ReceiptMatchCandidate {
|
||||
transaction: Transaction
|
||||
confidence: number
|
||||
matchReasons: string[]
|
||||
dateVariance: number
|
||||
amountVariance: number
|
||||
}
|
||||
|
||||
// Input for creating a receipt
|
||||
export interface CreateReceiptInput {
|
||||
image_url: string
|
||||
image_thumbnail_url?: string
|
||||
}
|
||||
|
||||
// Input for confirming receipt line items
|
||||
export interface ConfirmReceiptInput {
|
||||
line_items: ConfirmLineItemInput[]
|
||||
matched_transaction_id?: string
|
||||
representation_persons?: number
|
||||
representation_purpose?: string
|
||||
}
|
||||
|
||||
export interface ConfirmLineItemInput {
|
||||
id: string
|
||||
is_business: boolean
|
||||
category?: TransactionCategory
|
||||
bas_account?: string
|
||||
}
|
||||
|
||||
// Receipt queue summary
|
||||
export interface ReceiptQueueSummary {
|
||||
unmatched_receipts_count: number
|
||||
unmatched_transactions_count: number
|
||||
pending_review_count: number
|
||||
streak_count: number
|
||||
}
|
||||
|
||||
// Camera quality feedback
|
||||
export interface CameraQualityFeedback {
|
||||
lightingOk: boolean
|
||||
distanceOk: boolean
|
||||
focusOk: boolean
|
||||
readyToCapture: boolean
|
||||
message?: string
|
||||
}
|
||||
|
||||
// Swedish labels for receipt status
|
||||
export const RECEIPT_STATUS_LABELS: Record<ReceiptStatus, string> = {
|
||||
pending: 'Väntar',
|
||||
processing: 'Analyserar',
|
||||
extracted: 'Extraherat',
|
||||
confirmed: 'Bekräftat',
|
||||
error: 'Fel'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// VAT Declaration Types (Momsdeklaration)
|
||||
// ============================================================
|
||||
|
||||
// VAT period type
|
||||
export type VatPeriodType = 'monthly' | 'quarterly' | 'yearly'
|
||||
export type VatPeriodType = MomsPeriod
|
||||
|
||||
// VAT declaration rutor (boxes) according to SKV 4700
|
||||
// Complete set of all 30 boxes in the momsdeklaration form.
|
||||
@@ -3606,13 +3095,6 @@ export interface VatDeclaration {
|
||||
}
|
||||
}
|
||||
|
||||
// VAT declaration request parameters
|
||||
export interface VatDeclarationRequest {
|
||||
periodType: VatPeriodType
|
||||
year: number
|
||||
period: number
|
||||
}
|
||||
|
||||
// Labels for VAT rutor
|
||||
export const VAT_RUTA_LABELS: Record<keyof VatDeclarationRutor, string> = {
|
||||
ruta05: 'Momspliktig försäljning',
|
||||
@@ -3655,52 +3137,6 @@ export interface CreditNote extends Invoice {
|
||||
credited_invoice_id: string
|
||||
}
|
||||
|
||||
/** Generic key-value store record for extensions */
|
||||
export interface ExtensionDataRecord {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string
|
||||
extension_id: string
|
||||
key: string
|
||||
value: Record<string, unknown>
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Tax Code Types
|
||||
// ============================================================
|
||||
|
||||
// Tax code identifiers (standard Swedish codes)
|
||||
export type TaxCodeId =
|
||||
| 'MP1' | 'MP2' | 'MP3' // Output VAT 25%, 12%, 6%
|
||||
| 'MPI' | 'MPI12' | 'MPI6' // Input VAT 25%, 12%, 6%
|
||||
| 'IV' // Intra-EU acquisition
|
||||
| 'EUS' // EU sale (reverse charge)
|
||||
| 'IP' // Import
|
||||
| 'EXP' // Export outside EU
|
||||
| 'OSS' // One Stop Shop
|
||||
| 'NONE' // VAT exempt
|
||||
|
||||
export interface TaxCode {
|
||||
id: string
|
||||
user_id: string | null
|
||||
code: string
|
||||
description: string
|
||||
rate: number
|
||||
moms_basis_boxes: string[]
|
||||
moms_tax_boxes: string[]
|
||||
moms_input_boxes: string[]
|
||||
is_output_vat: boolean
|
||||
is_reverse_charge: boolean
|
||||
is_eu: boolean
|
||||
is_export: boolean
|
||||
is_oss: boolean
|
||||
is_system: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Document Archive Types
|
||||
// ============================================================
|
||||
@@ -3741,17 +3177,6 @@ export interface DocumentAttachment {
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface CreateDocumentAttachmentInput {
|
||||
storage_path: string
|
||||
file_name: string
|
||||
file_size_bytes?: number
|
||||
mime_type?: string
|
||||
sha256_hash: string
|
||||
upload_source?: DocumentUploadSource
|
||||
journal_entry_id?: string
|
||||
journal_entry_line_id?: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Audit Log Types
|
||||
// ============================================================
|
||||
@@ -3791,32 +3216,6 @@ export interface AuditLogEntry {
|
||||
created_at: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Dimension Types (Kostnadsställen & Projekt)
|
||||
// ============================================================
|
||||
|
||||
export interface CostCenter {
|
||||
id: string
|
||||
company_id: string
|
||||
code: string
|
||||
name: string
|
||||
is_active: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: string
|
||||
company_id: string
|
||||
code: string
|
||||
name: string
|
||||
is_active: boolean
|
||||
start_date: string | null
|
||||
end_date: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Voucher Gap Detection
|
||||
// ============================================================
|
||||
@@ -3827,19 +3226,6 @@ export interface VoucherGap {
|
||||
series: string
|
||||
}
|
||||
|
||||
export interface VoucherGapExplanation {
|
||||
id: string
|
||||
company_id: string
|
||||
user_id: string
|
||||
fiscal_period_id: string
|
||||
voucher_series: string
|
||||
gap_start: number
|
||||
gap_end: number
|
||||
explanation: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface SequenceMismatch {
|
||||
series: string
|
||||
sequenceCounter: number
|
||||
@@ -4057,19 +3443,6 @@ export interface Asset {
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface DepreciationSchedule {
|
||||
id: string
|
||||
user_id: string
|
||||
company_id: string
|
||||
asset_id: string
|
||||
fiscal_period_id: string
|
||||
planned_depreciation: number
|
||||
journal_entry_id: string | null
|
||||
posted_at: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// IB/UB Continuity Check Types (Avstämning ingående/utgående balans)
|
||||
// ============================================================
|
||||
@@ -4121,15 +3494,6 @@ export interface CurrencyRevaluationResult {
|
||||
preview: CurrencyRevaluationPreview
|
||||
}
|
||||
|
||||
export interface PeriodStatus {
|
||||
is_locked: boolean
|
||||
is_closed: boolean
|
||||
has_closing_entry: boolean
|
||||
has_opening_balances: boolean
|
||||
draft_count: number
|
||||
next_period_exists: boolean
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Invoice Reminder Types (Betalningspåminnelser)
|
||||
// ============================================================
|
||||
@@ -4160,20 +3524,6 @@ export interface InvoiceReminder {
|
||||
fee_journal_entry_id: string | null
|
||||
}
|
||||
|
||||
// Swedish labels for reminder levels
|
||||
export const REMINDER_LEVEL_LABELS: Record<1 | 2 | 3, string> = {
|
||||
1: 'Vänlig påminnelse',
|
||||
2: 'Andra påminnelsen',
|
||||
3: 'Slutlig påminnelse'
|
||||
}
|
||||
|
||||
// Reminder level descriptions
|
||||
export const REMINDER_LEVEL_DESCRIPTIONS: Record<1 | 2 | 3, string> = {
|
||||
1: '15 dagar efter förfallodatum',
|
||||
2: '30 dagar efter förfallodatum',
|
||||
3: '45 dagar efter förfallodatum'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Transaction Ingestion Types (re-exported for extension use)
|
||||
// ============================================================
|
||||
@@ -4504,13 +3854,6 @@ export type SalaryType = 'monthly' | 'hourly'
|
||||
export type FSkattStatus = 'a_skatt' | 'f_skatt' | 'fa_skatt' | 'not_verified'
|
||||
export type VacationRule = 'procentregeln' | 'sammaloneregeln' | 'none' | 'semesterersattning'
|
||||
export type SalaryRunStatus = 'draft' | 'review' | 'approved' | 'paid' | 'booked' | 'corrected'
|
||||
export type AGIStatus =
|
||||
| 'generated' // XML built from a salary run; nothing sent to SKV yet
|
||||
| 'pending_signature' // underlag accepted into Eget utrymme; awaiting BankID
|
||||
| 'exported' // legacy: manual XML download path
|
||||
| 'submitted' // kvittens received; AGI is filed
|
||||
| 'accepted' // reserved (SKV does not currently expose this)
|
||||
| 'rejected' // reserved (kontrollresultat DONE_REJECTED could land here)
|
||||
|
||||
export type SalaryLineItemType =
|
||||
| 'monthly_salary' | 'hourly_salary'
|
||||
@@ -4722,31 +4065,6 @@ export interface SalaryLineItem {
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface AGIDeclaration {
|
||||
id: string
|
||||
company_id: string
|
||||
user_id: string
|
||||
salary_run_id: string | null
|
||||
period_year: number
|
||||
period_month: number
|
||||
xml_content: string
|
||||
status: AGIStatus
|
||||
individuppgifter: Record<string, unknown>[]
|
||||
total_gross: number
|
||||
total_tax: number
|
||||
total_avgifter_basis: number
|
||||
total_avgifter: number
|
||||
employee_count: number
|
||||
kvittensnummer: string | null
|
||||
submitted_at: string | null
|
||||
submitted_by: string | null
|
||||
response_data: Record<string, unknown> | null
|
||||
is_correction: boolean
|
||||
corrects_agi_id: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* A `pending_operations` row a chat conversation staged and nobody has answered
|
||||
* yet, as returned by GET /api/agent/conversations/[id] and by the /chat/[id]
|
||||
|
||||
@@ -41,28 +41,6 @@ export interface StoredSkattekontoTransaction {
|
||||
suggested_at?: string | null
|
||||
}
|
||||
|
||||
/** Row shape for the `skattekonto_file_imports` tracking table (DB → app). */
|
||||
export interface SkattekontoFileImportRecord {
|
||||
id: string
|
||||
company_id: string
|
||||
/** Importing user; null after that user's account is deleted. */
|
||||
user_id: string | null
|
||||
filename: string
|
||||
file_hash: string
|
||||
file_variant: 'csv' | 'skv'
|
||||
row_count: number
|
||||
imported_count: number
|
||||
duplicate_count: number
|
||||
promoted_count: number
|
||||
date_from: string | null
|
||||
date_to: string | null
|
||||
closing_saldo: number | null
|
||||
status: 'pending' | 'processing' | 'completed' | 'failed'
|
||||
error_message: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Single best candidate verifikat for an unmatched SKV row. Attached by
|
||||
* the `/skattekonto/transaktioner` endpoint when exactly one strong match
|
||||
|
||||
Reference in New Issue
Block a user