diff --git a/components/ui/account-number.tsx b/components/ui/account-number.tsx index de899096..d143bf05 100644 --- a/components/ui/account-number.tsx +++ b/components/ui/account-number.tsx @@ -1,7 +1,9 @@ 'use client' +import { useMemo } from 'react' import { getAccountDescription, type AccountType } from '@/lib/bookkeeping/account-descriptions' import { useBasReference } from '@/lib/bookkeeping/use-bas-reference' +import { useAccounts } from '@/lib/reference-data/hooks' import { Tooltip, TooltipTrigger, @@ -45,11 +47,21 @@ export function AccountNumber({ // Loads the BAS chart chunk after mount and re-renders once names and // descriptions for non-hardcoded accounts are available. useBasReference() + // Inactive accounts included: historical verifikat keep referencing them + // long after they leave the active chart. + const { accounts } = useAccounts(false) + const companyName = useMemo( + () => accounts.find((a) => a.account_number === number)?.account_name, + [accounts, number], + ) const desc = getAccountDescription(number) // The company's own account name wins over the BAS reference name: a chart // row is user-editable data and must never be visually overridden by our - // hardcoded copy. The tooltip still shows the BAS name as reference. - const displayName = name || desc?.name + // hardcoded copy. Call sites that already know the row pass `name`; the + // rest (verifikat views) fall back to the shared reference-data cache, so + // off-catalog accounts (e.g. SIE-imported 1580) still get their names. + // The tooltip still shows the BAS name as reference. + const displayName = name || companyName || desc?.name const numberElement = (