From 16dcdfe67bd7488a9b2ee1e0389602ec9dd7976b Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Mon, 3 Nov 2025 19:40:47 +0900
Subject: (김준회) dolce: Document Type 옆 숫자: project 필터링 대응하도록 개선
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../ship/enhanced-documents-table.tsx              | 32 ++++++++++++++++++----
 1 file changed, 26 insertions(+), 6 deletions(-)

(limited to 'lib/vendor-document-list/ship/enhanced-documents-table.tsx')

diff --git a/lib/vendor-document-list/ship/enhanced-documents-table.tsx b/lib/vendor-document-list/ship/enhanced-documents-table.tsx
index 5b3b392d..13f8f8d4 100644
--- a/lib/vendor-document-list/ship/enhanced-documents-table.tsx
+++ b/lib/vendor-document-list/ship/enhanced-documents-table.tsx
@@ -69,7 +69,7 @@ export function SimplifiedDocumentsTable({
   const statsData = React.useMemo(() => statsResult as Awaited<ReturnType<typeof getUserVendorDocumentStats>>, [statsResult])
   
   const { data, pageCount, drawingKind } = documentData
-  const { primaryDrawingKind, b4Stats: serverB4Stats, projectCodeStats: serverProjectCodeStats } = statsData
+  const { primaryDrawingKind, projectCodeStats: serverProjectCodeStats, projectB4Stats: serverProjectB4Stats } = statsData
 
   // 🔥 URL searchParams를 통한 필터 상태 관리
   const [{ b4FilterType, projectCode, page }, setQueryStates] = useQueryStates(
@@ -282,11 +282,31 @@ export function SimplifiedDocumentsTable({
     return activeDrawingKind ? DRAWING_KIND_INFO[activeDrawingKind] : null
   }, [activeDrawingKind])
 
-  // 🔥 B4 문서 통계 - 서버에서 받아온 전체 통계 사용
+  // 🔥 B4 문서 통계 - 프로젝트 필터링에 따라 동적으로 계산 (서버에서 받아온 전체 통계 기반)
   const b4Stats = React.useMemo(() => {
-    if (!hasB4Documents || !serverB4Stats) return null
-    return serverB4Stats
-  }, [hasB4Documents, serverB4Stats])
+    if (!hasB4Documents || !serverProjectB4Stats) return null
+
+    // 선택된 프로젝트에 따라 B4 통계 계산
+    if (projectCode === 'all') {
+      // 전체 프로젝트의 B4 통계
+      const totalGttDeliverable = serverProjectB4Stats.reduce((sum, stat) => sum + stat.gttDeliverableCount, 0)
+      const totalShiInput = serverProjectB4Stats.reduce((sum, stat) => sum + stat.shiInputCount, 0)
+      return {
+        gttDeliverableCount: totalGttDeliverable,
+        shiInputCount: totalShiInput,
+      }
+    } else {
+      // 특정 프로젝트의 B4 통계
+      const projectStats = serverProjectB4Stats.find(stat => stat.code === projectCode)
+      return projectStats ? {
+        gttDeliverableCount: projectStats.gttDeliverableCount,
+        shiInputCount: projectStats.shiInputCount,
+      } : {
+        gttDeliverableCount: 0,
+        shiInputCount: 0,
+      }
+    }
+  }, [hasB4Documents, serverProjectB4Stats, projectCode])
 
   return (
     <div className="w-full space-y-4">
@@ -325,7 +345,7 @@ export function SimplifiedDocumentsTable({
                   <span>All Projects</span>
                 </div>
               </SelectItem>
-              {projectCodeStats.filter(({ code }) => code !== 'Unknown').map(({ code, count }) => (
+              {projectCodeStats.filter(({ code }) => code !== 'Unknown').map(({ code }) => (
                 <SelectItem key={code} value={code}>
                   <div className="flex items-center justify-between w-full">
                     <span className="font-mono">{code}</span>
-- 
cgit v1.2.3

