feat: improve bank card expenses summary
This commit is contained in:
@@ -52,7 +52,7 @@ const ru = {
|
||||
save: "Сохранить",
|
||||
cancel: "Отмена",
|
||||
close: "Закрыть",
|
||||
summary: "Расходы за месяц",
|
||||
summary: "Расходы",
|
||||
allSummary: "Расходы по всем картам",
|
||||
month: "Месяц",
|
||||
expenses: "Потрачено",
|
||||
@@ -60,7 +60,7 @@ const ru = {
|
||||
net: "После возвратов",
|
||||
summaryHint:
|
||||
"Возвраты учитываются в месяце получения. Итог может быть отрицательным.",
|
||||
noExpenses: "Расходов и возвратов за месяц нет.",
|
||||
noExpenses: "За этот месяц операций по расходам нет.",
|
||||
categories: "Категории",
|
||||
category: "Категория",
|
||||
categoryName: "Название категории",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
type Money = { currency: string; value: string };
|
||||
type FormatMoneyOptions = {
|
||||
withZeroCents?: boolean;
|
||||
};
|
||||
|
||||
function formatDecimal(value: string): string {
|
||||
const [integer, fraction] = value.split(".");
|
||||
@@ -10,9 +13,21 @@ function formatDecimal(value: string): string {
|
||||
return `${sign}${grouped}${fraction ? `,${fraction}` : ""}`;
|
||||
}
|
||||
|
||||
function formatMoney(money: Money | null): string {
|
||||
function formatMoney(
|
||||
money: Money | null,
|
||||
{ withZeroCents = false }: FormatMoneyOptions = {},
|
||||
): string {
|
||||
if (!money) return "—";
|
||||
return `${formatDecimal(money.value)} ${money.currency === "RUB" ? "₽" : money.currency}`;
|
||||
const [integerPart, fractionPart = ""] = money.value.split(".");
|
||||
const normalizedFraction =
|
||||
withZeroCents && !fractionPart
|
||||
? "00"
|
||||
: withZeroCents && fractionPart.length === 1
|
||||
? `${fractionPart}0`
|
||||
: fractionPart;
|
||||
return `${formatDecimal(
|
||||
`${integerPart}${normalizedFraction ? `.${normalizedFraction}` : ""}`,
|
||||
)} ${money.currency === "RUB" ? "₽" : money.currency}`;
|
||||
}
|
||||
|
||||
function formatDate(value: string): string {
|
||||
|
||||
Reference in New Issue
Block a user