Checkpoint: Ajout du récapitulatif annuel BAP et abonnements au tableau de bord, et de Budget réel par fournisseur avec filtres Année/Mois et ventilation abonnements/hors abonnement.

This commit is contained in:
Manus
2026-08-29 22:15:35 +00:00
parent 43fc8d523c
commit 5128322a6d
9 changed files with 265 additions and 5 deletions

View File

@@ -50,6 +50,7 @@ import {
WebImportSource
} from "../drizzle/schema";
import { ENV } from './_core/env';
import { buildAnnualInvoiceSummary } from "@shared/invoiceAnalytics";
let _db: ReturnType<typeof drizzle> | null = null;
@@ -332,7 +333,7 @@ export async function searchInvoices(userId: number | null, query: string): Prom
.orderBy(desc(invoices.createdAt));
}
export async function getInvoiceStats(userId: number) {
export async function getInvoiceStats(userId?: number) {
const db = await getDb();
if (!db) return {
total: 0,
@@ -346,10 +347,12 @@ export async function getInvoiceStats(userId: number) {
topSuppliers: [],
suppliersList: [],
topRecipients: [],
recipientsList: []
recipientsList: [],
annualSummary: [],
};
const allInvoices = await getInvoicesByUserId(userId);
// Le tableau de bord est global pour les administrateurs, comme les listes Factures.
const allInvoices = userId ? await getInvoicesByUserId(userId) : await getAllInvoices();
// Calculate basic stats
const completed = allInvoices.filter(i => i.status === "completed");
@@ -458,7 +461,8 @@ export async function getInvoiceStats(userId: number) {
topSuppliers,
suppliersList,
topRecipients,
recipientsList
recipientsList,
annualSummary: buildAnnualInvoiceSummary(allInvoices),
};
}