mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-22 06:28:09 +02:00
feat: add supplier AI context modal and bulk product AI analysis component
This commit is contained in:
1 parent
9d8ef0e4db
commit
174b7fa36c
3 files changed
+32
-2
No files matched your search
@@ -25,7 +25,7 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
|
|||||||
|
|
||||||
const status = insight?.status ?? "idle";
|
const status = insight?.status ?? "idle";
|
||||||
|
|
||||||
const handleAnalyze = () => {
|
const handleAnalyze = async () => {
|
||||||
if (status === "loading") return;
|
if (status === "loading") return;
|
||||||
|
|
||||||
// Reset Visuel Immédiat
|
// Reset Visuel Immédiat
|
||||||
@@ -35,6 +35,20 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
|
|||||||
const allRows = useGridStore.getState().rows;
|
const allRows = useGridStore.getState().rows;
|
||||||
const rayonRows = allRows.filter(r => r.libelleNiveau2 === row.libelleNiveau2);
|
const rayonRows = allRows.filter(r => r.libelleNiveau2 === row.libelleNiveau2);
|
||||||
|
|
||||||
|
// Fetch local context if needed
|
||||||
|
let supplierContext = "";
|
||||||
|
if (row.codeFournisseur) {
|
||||||
|
try {
|
||||||
|
const ctxRes = await fetch(`/api/ai/context?fournisseur=${row.codeFournisseur}`);
|
||||||
|
if (ctxRes.ok) {
|
||||||
|
const data = await ctxRes.json();
|
||||||
|
supplierContext = data.context || "";
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to load supplier context for AI", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Préparation du ScoringEngine
|
// Préparation du ScoringEngine
|
||||||
const regScore = Object.values(row.sales12m || {}).filter((v: any) => v > 0).length;
|
const regScore = Object.values(row.sales12m || {}).filter((v: any) => v > 0).length;
|
||||||
const weight = (row.workingStores?.length || 1) === 1 ? 2 : 1;
|
const weight = (row.workingStores?.length || 1) === 1 ? 2 : 1;
|
||||||
@@ -94,6 +108,7 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
|
|||||||
totalFournisseurCa: row.totalFournisseurCa,
|
totalFournisseurCa: row.totalFournisseurCa,
|
||||||
codeFournisseur: row.codeFournisseur,
|
codeFournisseur: row.codeFournisseur,
|
||||||
totalMagasins: 2,
|
totalMagasins: 2,
|
||||||
|
supplierContext: supplierContext,
|
||||||
scoring: {
|
scoring: {
|
||||||
compositeScore: scoringResult.compositeScore,
|
compositeScore: scoringResult.compositeScore,
|
||||||
decision: scoringResult.decision.recommendation,
|
decision: scoringResult.decision.recommendation,
|
||||||
|
|||||||
@@ -61,6 +61,20 @@ export function BulkAiAnalyzer() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 1. Fetch AI Context for the Supplier
|
||||||
|
let supplierContext = "";
|
||||||
|
if (supplierCode) {
|
||||||
|
try {
|
||||||
|
const ctxRes = await fetch(`/api/ai/context?fournisseur=${supplierCode}`);
|
||||||
|
if (ctxRes.ok) {
|
||||||
|
const data = await ctxRes.json();
|
||||||
|
supplierContext = data.context || "";
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to load supplier context for AI", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const initialPayloads: ProductAnalysisInput[] = rows.map((r) => {
|
const initialPayloads: ProductAnalysisInput[] = rows.map((r) => {
|
||||||
const sc = r.workingStores?.length || 1;
|
const sc = r.workingStores?.length || 1;
|
||||||
const weight = sc === 1 ? 2 : 1;
|
const weight = sc === 1 ? 2 : 1;
|
||||||
@@ -108,6 +122,7 @@ export function BulkAiAnalyzer() {
|
|||||||
projectedTotalCa: regScore > 0 ? (r.totalCa || 0) * weight * (12 / regScore) : (r.totalCa || 0) * weight,
|
projectedTotalCa: regScore > 0 ? (r.totalCa || 0) * weight * (12 / regScore) : (r.totalCa || 0) * weight,
|
||||||
lastMonthWithSale: lastMonth,
|
lastMonthWithSale: lastMonth,
|
||||||
inactivityMonths: inactivity,
|
inactivityMonths: inactivity,
|
||||||
|
supplierContext: supplierContext
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export function SupplierAiContextModal({ codeFournisseur, nomFournisseur }: Supp
|
|||||||
Règles IA
|
Règles IA
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className="sm:max-w-[500px]">
|
<DialogContent className="sm:max-w-[500px] bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 shadow-xl">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Contexte IA - {nomFournisseur || codeFournisseur}</DialogTitle>
|
<DialogTitle>Contexte IA - {nomFournisseur || codeFournisseur}</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
|
|||||||
Reference in new issue
Block a user