Pure currency-conversion utilities that preserve journal balance, handle rounding residuals, and compute realized/unrealized FX legs.
// Source: https://github.com/dubbl-org/dubbl | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { convertAmount } from "@/lib/currency/converter";
const RATE_SCALE = 1_000_000;
export interface ConvertibleLine {
debitAmount: number;
creditAmount: number;
}
/**
* Convert a balanced set of journal lines from document currency to the base
* currency at `rate` (integer, 6 decimal places), **preserving balance**.
*
* Converting each line independently and rounding can leave total debits != total
* credits by a minor unit or two. To keep the entry balanced, each side is
* converted line-by-line and the rounding residual is absorbed into the largest
* line on that side
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key