feat(lancamentos): aprimora parcelamentos e protecoes

This commit is contained in:
Felipe Coutinho
2026-05-21 13:47:14 +00:00
parent b6659ef66e
commit 4e8f9cc5fa
16 changed files with 275 additions and 66 deletions

View File

@@ -80,6 +80,7 @@ export type TransactionFormState = {
cardId: string | undefined;
categoryId: string | undefined;
installmentCount: string;
startInstallment: string;
recurrenceCount: string;
dueDate: string;
boletoPaymentDate: string;
@@ -92,6 +93,7 @@ export type TransactionFormState = {
*/
type TransactionFormOverrides = {
defaultCardId?: string | null;
defaultAccountId?: string | null;
defaultPaymentMethod?: string | null;
defaultPurchaseDate?: string | null;
defaultName?: string | null;
@@ -178,7 +180,9 @@ export function buildTransactionInitialState(
? undefined
: isImporting
? undefined
: (transaction?.accountId ?? undefined),
: (transaction?.accountId ??
overrides?.defaultAccountId ??
undefined),
cardId:
paymentMethod === "Cartão de crédito"
? isImporting
@@ -191,6 +195,12 @@ export function buildTransactionInitialState(
installmentCount: transaction?.installmentCount
? String(transaction.installmentCount)
: "",
startInstallment:
isImporting &&
transaction?.condition === "Parcelado" &&
transaction.currentInstallment
? String(transaction.currentInstallment)
: "1",
recurrenceCount: transaction?.recurrenceCount
? String(transaction.recurrenceCount)
: "",
@@ -252,12 +262,25 @@ export function applyFieldDependencies(
if (key === "condition" && typeof value === "string") {
if (value !== "Parcelado") {
updates.installmentCount = "";
updates.startInstallment = "1";
}
if (value !== "Recorrente") {
updates.recurrenceCount = "";
}
}
if (key === "installmentCount" && typeof value === "string" && value) {
const nextCount = Number.parseInt(value, 10);
const currentStart = Number.parseInt(currentState.startInstallment, 10);
if (
!Number.isNaN(nextCount) &&
!Number.isNaN(currentStart) &&
currentStart > nextCount
) {
updates.startInstallment = String(nextCount);
}
}
// When payment method changes, adjust related fields
if (key === "paymentMethod" && typeof value === "string") {
if (value === "Cartão de crédito") {