feat: bulk delete com escopo para mesma série + recorrente só consome limite após data

Aproveitamento parcial da PR #18 (fechada):

- Bulk delete: quando todos os selecionados pertencem à mesma série
  (parcelado/recorrente), abre dialog de escopo com 3 opções ao invés
  de deletar direto
- Recorrente no cartão: despesa recorrente só consome limite quando
  purchaseDate <= current_date (cartões ativos, inativos e relatório)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Felipe Coutinho
2026-02-28 13:54:08 +00:00
parent f77f729b14
commit 15b2ee18e1
5 changed files with 50 additions and 4 deletions

View File

@@ -1,4 +1,16 @@
import { and, eq, gte, ilike, inArray, lte, not, sum } from "drizzle-orm";
import {
and,
eq,
gte,
ilike,
inArray,
lte,
ne,
not,
or,
sql,
sum,
} from "drizzle-orm";
import {
cartoes,
categorias,
@@ -97,7 +109,7 @@ export async function fetchCartoesReportData(
const cardIds = allCards.map((c) => c.id);
// Fetch current period usage by card
// Fetch current period usage by card (recorrente só conta quando a data da ocorrência já passou)
const currentUsageData = await db
.select({
cartaoId: lancamentos.cartaoId,
@@ -112,6 +124,10 @@ export async function fetchCartoesReportData(
eq(pagadores.role, PAGADOR_ROLE_ADMIN),
eq(lancamentos.transactionType, DESPESA),
inArray(lancamentos.cartaoId, cardIds),
or(
ne(lancamentos.condition, "Recorrente"),
sql`${lancamentos.purchaseDate} <= current_date`,
),
),
)
.groupBy(lancamentos.cartaoId);