Remove 6 componentes não utilizados (dashboard-grid, expenses/income by category widgets, installment analysis panels, fatura-warning-dialog). Remove funções/tipos não utilizados: successResult, generateApiToken, validateApiToken, getTodayUTC/Local, formatDateForDb, getDateInfo, calculatePercentage, roundToDecimals, safeParseInt/Float, isPeriodValid, getLastPeriods, normalizeWhitespace, formatCurrency wrapper, InboxItemInput, InboxBatchInput, ProcessInboxInput, DiscardInboxInput, LancamentosColumnId, 5 funções de anticipation-helpers. Redireciona imports de formatCurrency para lib/lancamentos/formatting-helpers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import type { EligibleInstallment } from "./anticipation-types";
|
|
|
|
/**
|
|
* Formata o resumo de parcelas antecipadas
|
|
* Exemplo: "Parcelas 1-3 de 12" ou "Parcela 5 de 12"
|
|
*/
|
|
export function formatAnticipatedInstallmentsRange(
|
|
installments: EligibleInstallment[],
|
|
): string {
|
|
const numbers = installments
|
|
.map((inst) => inst.currentInstallment)
|
|
.filter((num): num is number => num !== null)
|
|
.sort((a, b) => a - b);
|
|
|
|
if (numbers.length === 0) return "";
|
|
if (numbers.length === 1) {
|
|
const total = installments[0]?.installmentCount ?? 0;
|
|
return `Parcela ${numbers[0]} de ${total}`;
|
|
}
|
|
|
|
const first = numbers[0];
|
|
const last = numbers[numbers.length - 1];
|
|
const total = installments[0]?.installmentCount ?? 0;
|
|
|
|
// Se as parcelas são consecutivas
|
|
const isConsecutive = numbers.every((num, i) => {
|
|
if (i === 0) return true;
|
|
return num === (numbers[i - 1] ?? 0) + 1;
|
|
});
|
|
|
|
if (isConsecutive) {
|
|
return `Parcelas ${first}-${last} de ${total}`;
|
|
} else {
|
|
return `${numbers.length} parcelas de ${total}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Calcula quantas parcelas restam após uma antecipação
|
|
*/
|
|
export function calculateRemainingInstallments(
|
|
totalInstallments: number,
|
|
anticipatedCount: number,
|
|
): number {
|
|
return Math.max(0, totalInstallments - anticipatedCount);
|
|
}
|
|
|
|
/**
|
|
* Gera descrição automática para o lançamento de antecipação
|
|
*/
|
|
export function generateAnticipationDescription(
|
|
lancamentoName: string,
|
|
installmentCount: number,
|
|
): string {
|
|
return `Antecipação de ${installmentCount} ${
|
|
installmentCount === 1 ? "parcela" : "parcelas"
|
|
} - ${lancamentoName}`;
|
|
}
|
|
|
|
/**
|
|
* Formata nota automática para antecipação
|
|
*/
|
|
export function generateAnticipationNote(
|
|
installments: EligibleInstallment[],
|
|
): string {
|
|
const range = formatAnticipatedInstallmentsRange(installments);
|
|
return `Antecipação: ${range}`;
|
|
}
|