fix(boletos): diferencia pagamentos e recebimentos

This commit is contained in:
Felipe Coutinho
2026-05-31 15:18:55 -03:00
parent 35abe1b0bf
commit 99bc049cf4
10 changed files with 130 additions and 58 deletions

View File

@@ -1,18 +1,28 @@
import type { DashboardBill } from "@/features/dashboard/bills/bills-queries";
import type { PaymentDialogState } from "@/features/dashboard/payments/use-payment-dialog-controller";
import { getBusinessDateString, isDateOnlyPast } from "@/shared/utils/date";
import {
getBusinessDateString,
isDateOnlyPast,
parseUtcDateString,
toDateOnlyString,
} from "@/shared/utils/date";
import {
buildFinancialStatusLabel,
buildRelativeFinancialStatusLabel,
formatFinancialDateLabel,
formatRelativeFinancialDateLabel,
} from "@/shared/utils/financial-dates";
export type BillDialogState = PaymentDialogState;
type BillStatusDateItem = Pick<
DashboardBill,
"dueDate" | "boletoPaymentDate" | "isSettled"
"dueDate" | "boletoPaymentDate" | "isSettled" | "transactionType"
>;
export const isIncomeBill = (bill: Pick<DashboardBill, "transactionType">) => {
return bill.transactionType === "Receita";
};
export const formatBillDateLabel = (value: string | null, prefix?: string) => {
return formatFinancialDateLabel(value, prefix);
};
@@ -22,10 +32,15 @@ export const buildBillStatusLabel = (bill: BillStatusDateItem) => {
isSettled: bill.isSettled,
dueDate: bill.dueDate,
paidAt: bill.boletoPaymentDate,
paidPrefix: isIncomeBill(bill) ? "Recebido em" : "Pago em",
});
};
export const buildBillWidgetStatusLabel = (bill: BillStatusDateItem) => {
if (bill.isSettled && isIncomeBill(bill)) {
return formatRelativeFinancialDateLabel(bill.boletoPaymentDate, "received");
}
return buildRelativeFinancialStatusLabel({
isSettled: bill.isSettled,
dueDate: bill.dueDate,
@@ -43,6 +58,34 @@ export const isBillOverdue = (bill: DashboardBill) => {
return isDateOnlyPast(bill.dueDate);
};
export const formatBillWidgetOverdueLabel = (
bill: Pick<DashboardBill, "dueDate" | "isSettled" | "transactionType">,
): string | null => {
if (bill.isSettled) {
return null;
}
const dueDateValue = toDateOnlyString(bill.dueDate);
const todayValue = getBusinessDateString();
if (!dueDateValue || dueDateValue >= todayValue) {
return null;
}
const dueDate = parseUtcDateString(dueDateValue);
const today = parseUtcDateString(todayValue);
if (!dueDate || !today) {
return null;
}
const overdueDays = Math.round(
(today.getTime() - dueDate.getTime()) / (24 * 60 * 60 * 1000),
);
const overdueLabel = isIncomeBill(bill) ? "Atrasada" : "Atrasado";
return overdueDays === 1
? `${overdueLabel} · venceu ontem`
: `${overdueLabel} · venceu há ${overdueDays} dias`;
};
export const getBillStatusBadgeVariant = (
statusLabel: string,
): "success" | "info" => {