feat: improve bank card expenses summary

This commit is contained in:
2026-09-12 20:54:57 +03:00
parent 9a65687d38
commit d3ac8c242d
7 changed files with 227 additions and 81 deletions
+2 -2
View File
@@ -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: "Название категории",
+17 -2
View File
@@ -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 {