Files
accounted/components/bookkeeping/correction-line-description.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

33 lines
1.3 KiB
TypeScript

/**
* Decide the line description to show when a correction line's account changes.
*
* The correction dialog pre-fills each line's description from the original
* entry. If the user then switches the account (e.g. from 2393 "Lån från
* närstående personer, långfristig del" to 2893, the kortfristig account), the
* carried-over description would otherwise stay stale on the new account. We
* refresh it to the newly chosen account's name, but only when the current
* description is empty or still equals the previously selected account's name:
* a memo the user typed themselves is preserved.
*/
export interface AccountNameLookup {
account_number: string
account_name: string
}
export function nextLineDescriptionForAccountChange(
currentDescription: string,
previousAccountNumber: string,
newAccountNumber: string,
accounts: AccountNameLookup[],
): string {
if (!newAccountNumber) return currentDescription
const newAccount = accounts.find((a) => a.account_number === newAccountNumber)
if (!newAccount) return currentDescription
const previousAccount = accounts.find((a) => a.account_number === previousAccountNumber)
const isAutoFilled = !currentDescription || currentDescription === previousAccount?.account_name
return isAutoFilled ? newAccount.account_name : currentDescription
}