diff --git a/client/src/pages/InvoicesBAP.tsx b/client/src/pages/InvoicesBAP.tsx index 5def1a4..0187713 100644 --- a/client/src/pages/InvoicesBAP.tsx +++ b/client/src/pages/InvoicesBAP.tsx @@ -390,14 +390,26 @@ export default function InvoicesBAP() { return true; }); + // Factures filtrées par période uniquement (sans filtre de statut) pour les compteurs + const invoicesInPeriod = invoices?.filter((inv) => { + if (selectedYear === "all") return true; + const invDate = inv.invoiceDate ? new Date(inv.invoiceDate) : null; + const fallbackDate = inv.createdAt ? new Date(inv.createdAt) : null; + const dateToUse = invDate || fallbackDate; + if (!dateToUse) return false; + if (dateToUse.getFullYear() !== parseInt(selectedYear)) return false; + if (selectedMonth !== "all" && (dateToUse.getMonth() + 1) !== parseInt(selectedMonth)) return false; + return true; + }) || []; + const statusCounts = { - all: invoices?.length || 0, - exported: invoices?.filter(inv => inv.exportStatus === "exported").length || 0, - not_exported: invoices?.filter(inv => inv.exportStatus === "not_exported").length || 0, - export_error: invoices?.filter(inv => inv.exportStatus === "export_error").length || 0, - bap_validated: invoices?.filter(inv => inv.bapValidated === 1).length || 0, - bap_pending: invoices?.filter(inv => inv.bapValidated !== 1).length || 0, - to_complete: invoices?.filter(inv => isToComplete(inv)).length || 0, + all: invoicesInPeriod.length, + exported: invoicesInPeriod.filter(inv => inv.exportStatus === "exported").length, + not_exported: invoicesInPeriod.filter(inv => inv.exportStatus === "not_exported").length, + export_error: invoicesInPeriod.filter(inv => inv.exportStatus === "export_error").length, + bap_validated: invoicesInPeriod.filter(inv => inv.bapValidated === 1).length, + bap_pending: invoicesInPeriod.filter(inv => inv.bapValidated !== 1).length, + to_complete: invoicesInPeriod.filter(inv => isToComplete(inv)).length, }; // Old filter logic (to be removed)