mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-06-10 07:16:01 +00:00
feat(relatorios): refina indicadores e filtros
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import type { InstallmentExpense } from "@/features/dashboard/expenses/installment-expenses-queries";
|
||||
import {
|
||||
calculateLastInstallmentDate,
|
||||
formatLastInstallmentDate,
|
||||
} from "@/shared/lib/installments/utils";
|
||||
import { calculateLastInstallmentDate } from "@/shared/lib/installments/utils";
|
||||
import { capitalize } from "@/shared/utils/string";
|
||||
|
||||
type InstallmentExpenseDisplay = {
|
||||
compactLabel: string | null;
|
||||
isLast: boolean;
|
||||
remainingLabel: "Próx." | "Aberto";
|
||||
remainingInstallments: number;
|
||||
remainingAmount: number;
|
||||
endDate: string | null;
|
||||
@@ -38,21 +37,30 @@ const isInstallmentLast = (
|
||||
const calculateInstallmentRemainingCount = (
|
||||
currentInstallment: number | null,
|
||||
installmentCount: number | null,
|
||||
isSettled: boolean | null,
|
||||
) => {
|
||||
if (!currentInstallment || !installmentCount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.max(0, installmentCount - currentInstallment);
|
||||
const includeCurrentInstallment = isSettled !== true;
|
||||
const currentOffset = includeCurrentInstallment ? 1 : 0;
|
||||
|
||||
return Math.max(0, installmentCount - currentInstallment + currentOffset);
|
||||
};
|
||||
|
||||
const calculateInstallmentRemainingAmount = (
|
||||
amount: number,
|
||||
currentInstallment: number | null,
|
||||
installmentCount: number | null,
|
||||
isSettled: boolean | null,
|
||||
) =>
|
||||
amount *
|
||||
calculateInstallmentRemainingCount(currentInstallment, installmentCount);
|
||||
calculateInstallmentRemainingCount(
|
||||
currentInstallment,
|
||||
installmentCount,
|
||||
isSettled,
|
||||
);
|
||||
|
||||
const formatInstallmentEndDate = (
|
||||
period: string,
|
||||
@@ -69,7 +77,12 @@ const formatInstallmentEndDate = (
|
||||
installmentCount,
|
||||
);
|
||||
|
||||
return formatLastInstallmentDate(lastDate);
|
||||
const month = new Intl.DateTimeFormat("pt-BR", {
|
||||
month: "short",
|
||||
timeZone: "UTC",
|
||||
}).format(lastDate);
|
||||
|
||||
return `${capitalize(month)} de ${lastDate.getFullYear()}`;
|
||||
};
|
||||
|
||||
const buildInstallmentProgress = (
|
||||
@@ -89,7 +102,8 @@ const buildInstallmentProgress = (
|
||||
export const buildInstallmentExpenseDisplay = (
|
||||
expense: InstallmentExpense,
|
||||
): InstallmentExpenseDisplay => {
|
||||
const { amount, currentInstallment, installmentCount, period } = expense;
|
||||
const { amount, currentInstallment, installmentCount, isSettled, period } =
|
||||
expense;
|
||||
|
||||
return {
|
||||
compactLabel: buildInstallmentCompactLabel(
|
||||
@@ -97,14 +111,17 @@ export const buildInstallmentExpenseDisplay = (
|
||||
installmentCount,
|
||||
),
|
||||
isLast: isInstallmentLast(currentInstallment, installmentCount),
|
||||
remainingLabel: isSettled === true ? "Próx." : "Aberto",
|
||||
remainingInstallments: calculateInstallmentRemainingCount(
|
||||
currentInstallment,
|
||||
installmentCount,
|
||||
isSettled,
|
||||
),
|
||||
remainingAmount: calculateInstallmentRemainingAmount(
|
||||
amount,
|
||||
currentInstallment,
|
||||
installmentCount,
|
||||
isSettled,
|
||||
),
|
||||
endDate: formatInstallmentEndDate(
|
||||
period,
|
||||
|
||||
Reference in New Issue
Block a user