Uecko_ERP/modules/customer-invoices/src/api/application/helpers/format-money-dto.ts

26 lines
607 B
TypeScript
Raw Normal View History

2025-09-18 08:49:32 +00:00
import { MoneyDTO } from "@erp/core";
import { MoneyValue } from "@repo/rdx-ddd";
2025-09-19 16:55:30 +00:00
export type FormatMoneyOptions = {
locale: string;
hideZeros?: boolean;
newScale?: number;
};
export function formatMoneyDTO(
amount: MoneyDTO,
{ locale, hideZeros = false, newScale = 2 }: FormatMoneyOptions
) {
if (hideZeros && (amount.value === "0" || amount.value === "")) {
return null;
2025-09-19 09:29:49 +00:00
}
2025-09-18 08:49:32 +00:00
const money = MoneyValue.create({
value: Number(amount.value),
currency_code: amount.currency_code,
scale: Number(amount.scale),
}).data;
2025-09-19 16:55:30 +00:00
return money.convertScale(newScale).format(locale);
2025-09-18 08:49:32 +00:00
}