feat(dashboard): painel Rafael — meta, comissão, inativos, pedidos recentes (C7)
GET /dashboard/rep retorna meta mensal, comissão (fixa + FLEX), clientes inativos >30 dias e pedidos dos últimos 7 dias. RepTarget model com migration. RafaelPainel conectado à API real via useRepDashboard(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "RepTarget" (
|
||||
"repId" TEXT NOT NULL,
|
||||
"year" INTEGER NOT NULL,
|
||||
"month" INTEGER NOT NULL,
|
||||
"targetAmount" DECIMAL(15,2) NOT NULL,
|
||||
"commissionRate" DECIMAL(5,2) NOT NULL DEFAULT 3,
|
||||
"flexRate" DECIMAL(5,2) NOT NULL DEFAULT 1,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "RepTarget_pkey" PRIMARY KEY ("repId","year","month")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "RepTarget_repId_idx" ON "RepTarget"("repId");
|
||||
@@ -171,6 +171,26 @@ model Product {
|
||||
@@index([deletedAt])
|
||||
}
|
||||
|
||||
// ─── RepTarget (C7) ──────────────────────────────────────────────────────────
|
||||
//
|
||||
// Meta mensal e taxas de comissão por rep. Uma linha por rep/mês.
|
||||
// commissionRate: % aplicada sobre o total aprovado+faturado do mês.
|
||||
// flexRate: % bônus adicional quando atingido >= targetAmount.
|
||||
|
||||
model RepTarget {
|
||||
repId String
|
||||
year Int
|
||||
month Int // 1–12
|
||||
targetAmount Decimal @db.Decimal(15, 2)
|
||||
commissionRate Decimal @default(3) @db.Decimal(5, 2)
|
||||
flexRate Decimal @default(1) @db.Decimal(5, 2)
|
||||
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@id([repId, year, month])
|
||||
@@index([repId])
|
||||
}
|
||||
|
||||
// ─── RepDiscountLimit (C4) ───────────────────────────────────────────────────
|
||||
//
|
||||
// Alçada de desconto por rep e por linha de produto (OQ-2 resolvida 2026-05-27).
|
||||
|
||||
@@ -988,6 +988,35 @@ async function main() {
|
||||
}
|
||||
console.log(`${repDiscountLimits.length} alçadas configuradas.`);
|
||||
|
||||
// Metas mensais (C7)
|
||||
const now = new Date();
|
||||
const repTargets = [
|
||||
{
|
||||
repId: DEV_REP_ID,
|
||||
year: now.getFullYear(),
|
||||
month: now.getMonth() + 1,
|
||||
targetAmount: 60000,
|
||||
commissionRate: 3,
|
||||
flexRate: 1,
|
||||
},
|
||||
{
|
||||
repId: DEV_REP2_ID,
|
||||
year: now.getFullYear(),
|
||||
month: now.getMonth() + 1,
|
||||
targetAmount: 40000,
|
||||
commissionRate: 3,
|
||||
flexRate: 1,
|
||||
},
|
||||
];
|
||||
for (const t of repTargets) {
|
||||
await prisma.repTarget.upsert({
|
||||
where: { repId_year_month: { repId: t.repId, year: t.year, month: t.month } },
|
||||
create: t,
|
||||
update: { targetAmount: t.targetAmount },
|
||||
});
|
||||
}
|
||||
console.log(`${repTargets.length} metas mensais configuradas.`);
|
||||
|
||||
// Upsert clients (sem lastOrderAt/openOrdersCount — calculados depois)
|
||||
for (const data of clientDefs) {
|
||||
await prisma.client.upsert({
|
||||
|
||||
Reference in New Issue
Block a user