* feat: add user locale preference to user_preferences table
- Introduced a new column 'locale' in the user_preferences table to store per-user UI language preferences.
- Added a CHECK constraint to ensure only supported locales ('sv', 'en') are allowed.
- Triggered a schema reload notification for the changes.
chore: declare CSS module support in TypeScript
- Added a declaration for CSS modules in globals.d.ts to enable TypeScript support for importing CSS files.
* feat: add Swish as an invoice payment method in company settings
94 lines
2.4 KiB
TypeScript
94 lines
2.4 KiB
TypeScript
import type { KPIPreferences } from '@/types'
|
|
|
|
export interface KPIDefinition {
|
|
id: string
|
|
// Translation key suffix; used as `kpi.def_<id>_label` / `_description` / `_formula` / `_accounts`.
|
|
defaultAccounts: string[]
|
|
customizableAccounts: boolean
|
|
defaultVisible: boolean
|
|
format: 'currency' | 'percentage' | 'days'
|
|
colorLogic: 'positive-good' | 'negative-good' | 'neutral'
|
|
}
|
|
|
|
export const KPI_DEFINITIONS: KPIDefinition[] = [
|
|
{
|
|
id: 'netResult',
|
|
defaultAccounts: [],
|
|
customizableAccounts: false,
|
|
defaultVisible: true,
|
|
format: 'currency',
|
|
colorLogic: 'positive-good',
|
|
},
|
|
{
|
|
id: 'cashPosition',
|
|
defaultAccounts: ['1910', '1920', '1930', '1940', '1950', '1960', '1970', '1980'],
|
|
customizableAccounts: true,
|
|
defaultVisible: true,
|
|
format: 'currency',
|
|
colorLogic: 'positive-good',
|
|
},
|
|
{
|
|
id: 'outstandingReceivables',
|
|
defaultAccounts: ['1510'],
|
|
customizableAccounts: false,
|
|
defaultVisible: true,
|
|
format: 'currency',
|
|
colorLogic: 'neutral',
|
|
},
|
|
{
|
|
id: 'vatLiability',
|
|
defaultAccounts: ['2611', '2621', '2631', '2641', '2645'],
|
|
customizableAccounts: true,
|
|
defaultVisible: true,
|
|
format: 'currency',
|
|
colorLogic: 'negative-good',
|
|
},
|
|
{
|
|
id: 'grossMargin',
|
|
defaultAccounts: [],
|
|
customizableAccounts: false,
|
|
defaultVisible: false,
|
|
format: 'percentage',
|
|
colorLogic: 'positive-good',
|
|
},
|
|
{
|
|
id: 'expenseRatio',
|
|
defaultAccounts: [],
|
|
customizableAccounts: false,
|
|
defaultVisible: false,
|
|
format: 'percentage',
|
|
colorLogic: 'negative-good',
|
|
},
|
|
{
|
|
id: 'avgPaymentDays',
|
|
defaultAccounts: [],
|
|
customizableAccounts: false,
|
|
defaultVisible: false,
|
|
format: 'days',
|
|
colorLogic: 'negative-good',
|
|
},
|
|
]
|
|
|
|
export const ALL_KPI_IDS = KPI_DEFINITIONS.map((d) => d.id)
|
|
|
|
export function getKPIDefinition(id: string): KPIDefinition | undefined {
|
|
return KPI_DEFINITIONS.find((d) => d.id === id)
|
|
}
|
|
|
|
export function getDefaultPreferences(): KPIPreferences {
|
|
return {
|
|
visibleKpis: KPI_DEFINITIONS.filter((d) => d.defaultVisible).map((d) => d.id),
|
|
kpiOrder: ALL_KPI_IDS,
|
|
accountOverrides: {},
|
|
}
|
|
}
|
|
|
|
export function mergeWithDefaults(prefs: Partial<KPIPreferences>): KPIPreferences {
|
|
const defaults = getDefaultPreferences()
|
|
return {
|
|
visibleKpis: prefs.visibleKpis ?? defaults.visibleKpis,
|
|
kpiOrder: prefs.kpiOrder ?? defaults.kpiOrder,
|
|
accountOverrides: prefs.accountOverrides ?? defaults.accountOverrides,
|
|
}
|
|
}
|