Files
accounted/lib/vat/vat-rate-unit.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

22 lines
1.0 KiB
TypeScript

// Leaf module on purpose: imported by extension entry graphs (arcim-migration
// entity mapper) where pulling in supplier-invoice-line-checks' dependencies
// (lib/money) shifted the server chunk graph into a Turbopack chunk-name hash
// collision ("Two or more assets with different content were emitted to the
// same output path", first seen on the #1385 merge). Keep this file free of
// imports; supplier-invoice-line-checks re-exports it for all other callers.
/**
* Convert a supplier-invoice VAT rate to the database's decimal-fraction
* unit without changing the underlying rate. Values above 1 are interpreted
* as percentages, while values already between 0 and 1 pass through. This is
* intentionally a unit normalizer, not a Swedish-rate validator: imported
* foreign VAT such as 19 % must remain 0.19 instead of being rewritten.
*/
export function normalizeVatRateToFraction(rate: unknown): number {
const n = Number(rate)
if (!Number.isFinite(n) || n < 0) return 0
const fraction = n > 1 ? n / 100 : n
return fraction <= 1 ? fraction : 0
}