diff --git a/src/controllers/00-stats-controller.ts b/src/controllers/00-stats-controller.ts index 5a0c871..330759c 100644 --- a/src/controllers/00-stats-controller.ts +++ b/src/controllers/00-stats-controller.ts @@ -201,12 +201,25 @@ export class StatsController extends Controller { }, }); + const order = await prisma.quotationProductServiceList.groupBy({ + _count: true, + by: "productId", + where: { + quotation: { + createdAt: { gte: startDate, lte: endDate }, + registeredBranch: { OR: permissionCondCompany(req.user) }, + }, + productId: { in: record.map((v) => v.id) }, + }, + }); + return record.map((v) => ({ document: "product", code: v.code, name: v.name, sale: v._count.quotationProductServiceList, did: doing.find((item) => item.productId === v.id)?._count || 0, + order: order.find((item) => item.productId === v.id)?._count || 0, createdAt: v.createdAt, updatedAt: v.updatedAt, }));