mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat(grid): exclude current month from grid and scoring calculations
This commit is contained in:
1 parent
1c5fe4499a
commit
c1bd0ae097
2 files changed
+14
-1
No files matched your search
@@ -14,6 +14,14 @@ interface GetProductRowsInput {
|
||||
export async function getProductRows(input: GetProductRowsInput): Promise<ProductRow[]> {
|
||||
const { codeFournisseur, magasin = "TOTAL" } = input;
|
||||
|
||||
// Calculer les 12 derniers mois COMPLETS (excluant le mois en cours)
|
||||
const allowedPeriods = new Set<string>();
|
||||
const now = new Date();
|
||||
for (let i = 12; i >= 1; i--) {
|
||||
const d = new Date(now.getFullYear(), now.getMonth() - i, 1);
|
||||
allowedPeriods.add(`${d.getFullYear()}${String(d.getMonth() + 1).padStart(2, "0")}`);
|
||||
}
|
||||
|
||||
// Get all rows for this supplier (excluding the synthetic TOTAL period)
|
||||
const rows = await db
|
||||
.select()
|
||||
@@ -30,6 +38,9 @@ export async function getProductRows(input: GetProductRowsInput): Promise<Produc
|
||||
const productMap = new Map<string, ProductRow>();
|
||||
|
||||
for (const row of rows) {
|
||||
// Ignorer les données qui ne font pas partie des 12 mois complets
|
||||
if (!allowedPeriods.has(row.periode)) continue;
|
||||
|
||||
const existing = productMap.get(row.codein);
|
||||
const monthKey = row.periode;
|
||||
const qty = Math.abs(parseFloat(row.quantite?.toString() ?? "0"));
|
||||
|
||||
@@ -24,7 +24,9 @@ import { AiInsightBlock } from "@/features/ai-copilot/components/ai-insight-bloc
|
||||
function getLast12Months(): string[] {
|
||||
const months: string[] = [];
|
||||
const now = new Date();
|
||||
for (let i = 11; i >= 0; i--) {
|
||||
// On commence à i=12 (il y a 12 mois) et on finit à i=1 (le mois dernier)
|
||||
// pour exclure le mois en cours (i=0)
|
||||
for (let i = 12; i >= 1; i--) {
|
||||
const d = new Date(now.getFullYear(), now.getMonth() - i, 1);
|
||||
months.push(`${d.getFullYear()}${String(d.getMonth() + 1).padStart(2, "0")}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user