mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +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 handleAnalyze = () => {
|
||||
const handleAnalyze = async () => {
|
||||
if (status === "loading") return;
|
||||
|
||||
// Reset Visuel Immédiat
|
||||
@@ -35,6 +35,20 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
|
||||
const allRows = useGridStore.getState().rows;
|
||||
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
|
||||
const regScore = Object.values(row.sales12m || {}).filter((v: any) => v > 0).length;
|
||||
const weight = (row.workingStores?.length || 1) === 1 ? 2 : 1;
|
||||
@@ -94,6 +108,7 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
|
||||
totalFournisseurCa: row.totalFournisseurCa,
|
||||
codeFournisseur: row.codeFournisseur,
|
||||
totalMagasins: 2,
|
||||
supplierContext: supplierContext,
|
||||
scoring: {
|
||||
compositeScore: scoringResult.compositeScore,
|
||||
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 sc = r.workingStores?.length || 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,
|
||||
lastMonthWithSale: lastMonth,
|
||||
inactivityMonths: inactivity,
|
||||
supplierContext: supplierContext
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ export function SupplierAiContextModal({ codeFournisseur, nomFournisseur }: Supp
|
||||
Règles IA
|
||||
</Button>
|
||||
</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>
|
||||
<DialogTitle>Contexte IA - {nomFournisseur || codeFournisseur}</DialogTitle>
|
||||
<DialogDescription>
|
||||
|
||||
Reference in new issue
Block a user