From 503ff56f5471818472eeb44b74cb35c4f977e6d1 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Sun, 2 Nov 2025 17:49:22 +0900 Subject: (김준회) dolce: GTT(B4) 건수 계산을 현재 페이지가 아닌 DB 기준으로 변경 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enhanced-document-service.ts | 68 +++++++++++++--------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'lib/vendor-document-list/enhanced-document-service.ts') diff --git a/lib/vendor-document-list/enhanced-document-service.ts b/lib/vendor-document-list/enhanced-document-service.ts index 43eea6eb..e5cce1b1 100644 --- a/lib/vendor-document-list/enhanced-document-service.ts +++ b/lib/vendor-document-list/enhanced-document-service.ts @@ -1139,38 +1139,50 @@ export async function getDocumentDetails(documentId: number) { const companyId = session?.user?.companyId; - if (!companyId) { - return { stats: {}, totalDocuments: 0, primaryDrawingKind: null } - } + if (!companyId) { + return { stats: {}, totalDocuments: 0, primaryDrawingKind: null, b4Stats: { gttDeliverableCount: 0, shiInputCount: 0 } } + } - // DrawingKind별 통계 조회 - const documents = await db - .select({ - drawingKind: simplifiedDocumentsView.drawingKind, - }) - .from(simplifiedDocumentsView) - .where(eq(simplifiedDocumentsView.vendorId, Number(companyId))) - - // 통계 계산 - const stats = documents.reduce((acc, doc) => { - if (doc.drawingKind) { - acc[doc.drawingKind] = (acc[doc.drawingKind] || 0) + 1 - } - return acc - }, {} as Record) - - // 가장 많은 DrawingKind 찾기 - const primaryDrawingKind = Object.entries(stats) - .sort(([,a], [,b]) => b - a)[0]?.[0] as 'B3' | 'B4' | 'B5' | undefined - - return { - stats, - totalDocuments: documents.length, - primaryDrawingKind: primaryDrawingKind || null + // DrawingKind별 통계 조회 (B4의 경우 drawingMoveGbn도 함께 조회) + const documents = await db + .select({ + drawingKind: simplifiedDocumentsView.drawingKind, + drawingMoveGbn: simplifiedDocumentsView.drawingMoveGbn, + }) + .from(simplifiedDocumentsView) + .where(eq(simplifiedDocumentsView.vendorId, Number(companyId))) + + // 통계 계산 + const stats = documents.reduce((acc, doc) => { + if (doc.drawingKind) { + acc[doc.drawingKind] = (acc[doc.drawingKind] || 0) + 1 } + return acc + }, {} as Record) + + // B4 세부 통계 계산 (GTT Deliverable vs SHI Input) + const b4Stats = { + gttDeliverableCount: documents.filter(doc => + doc.drawingKind === 'B4' && doc.drawingMoveGbn === '도면입수' + ).length, + shiInputCount: documents.filter(doc => + doc.drawingKind === 'B4' && doc.drawingMoveGbn === '도면제출' + ).length, + } + + // 가장 많은 DrawingKind 찾기 + const primaryDrawingKind = Object.entries(stats) + .sort(([,a], [,b]) => b - a)[0]?.[0] as 'B3' | 'B4' | 'B5' | undefined + + return { + stats, + totalDocuments: documents.length, + primaryDrawingKind: primaryDrawingKind || null, + b4Stats, // B4 세부 통계 추가 + } } catch (err) { console.error("Error fetching user vendor document stats:", err) - return { stats: {}, totalDocuments: 0, primaryDrawingKind: null } + return { stats: {}, totalDocuments: 0, primaryDrawingKind: null, b4Stats: { gttDeliverableCount: 0, shiInputCount: 0 } } } } -- cgit v1.2.3