feat(expenses): add import functionality for expenses and total pending calculation

This commit is contained in:
Jose Selesan
2026-05-29 14:30:10 -03:00
parent 4b17940134
commit b1968cece9
11 changed files with 600 additions and 19 deletions

View File

@@ -39,7 +39,7 @@ export function getCurrentYearMonthUTC(): { year: number; month: number } {
export async function listPeriodicExpenses() {
return prisma.periodicExpense.findMany({
where: { isDeleted: false },
orderBy: { createdAt: "desc" },
orderBy: { description: "asc" },
});
}
@@ -163,6 +163,15 @@ export async function getMonthlyTotals(year: number, month: number) {
};
}
export async function getTotalPending() {
const expenses = await prisma.expense.findMany({
where: { status: PaymentStatus.PENDING },
select: { amount: true },
});
const total = expenses.reduce((sum, e) => sum + Number(e.amount), 0);
return { total };
}
export async function generateExpensesForCurrentMonth() {
const { year, month } = getCurrentYearMonthUTC();