fix: compteurs statusCounts respectent le filtre de période (cohérence avec la liste affichée)
This commit is contained in:
@@ -390,14 +390,26 @@ export default function InvoicesBAP() {
|
|||||||
return true;
|
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 = {
|
const statusCounts = {
|
||||||
all: invoices?.length || 0,
|
all: invoicesInPeriod.length,
|
||||||
exported: invoices?.filter(inv => inv.exportStatus === "exported").length || 0,
|
exported: invoicesInPeriod.filter(inv => inv.exportStatus === "exported").length,
|
||||||
not_exported: invoices?.filter(inv => inv.exportStatus === "not_exported").length || 0,
|
not_exported: invoicesInPeriod.filter(inv => inv.exportStatus === "not_exported").length,
|
||||||
export_error: invoices?.filter(inv => inv.exportStatus === "export_error").length || 0,
|
export_error: invoicesInPeriod.filter(inv => inv.exportStatus === "export_error").length,
|
||||||
bap_validated: invoices?.filter(inv => inv.bapValidated === 1).length || 0,
|
bap_validated: invoicesInPeriod.filter(inv => inv.bapValidated === 1).length,
|
||||||
bap_pending: invoices?.filter(inv => inv.bapValidated !== 1).length || 0,
|
bap_pending: invoicesInPeriod.filter(inv => inv.bapValidated !== 1).length,
|
||||||
to_complete: invoices?.filter(inv => isToComplete(inv)).length || 0,
|
to_complete: invoicesInPeriod.filter(inv => isToComplete(inv)).length,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Old filter logic (to be removed)
|
// Old filter logic (to be removed)
|
||||||
|
|||||||
Reference in New Issue
Block a user