From 3f11179b2c50d7ee56b0cea38778191e3259b941 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 9 Dec 2025 04:40:34 +0000
Subject: (임수민) 정규업체 등록관리 등록요청 버튼 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ...regular-registrations-table-toolbar-actions.tsx | 58 +++++++++++++++++++---
 1 file changed, 50 insertions(+), 8 deletions(-)

(limited to 'lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx')

diff --git a/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx b/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx
index 20cd3427..79a5ae82 100644
--- a/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx
+++ b/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx
@@ -150,21 +150,22 @@ export function VendorRegularRegistrationsTableToolbarActions({
 
   // 등록요청 핸들러 - Step 1: 정보 입력
   const handleRegistrationRequest = () => {
-    const approvalReadyRows = selectedRows.filter(row => row.status === "approval_ready");
+    // 모든 항목이 완료된 행 필터링
+    const eligibleRows = selectedRows.filter(row => isAllItemsComplete(row));
     
-    if (approvalReadyRows.length === 0) {
-      toast.error("조건충족 상태의 벤더를 선택해주세요.");
+    if (eligibleRows.length === 0) {
+      toast.error("모든 항목이 완료된 벤더를 선택해주세요.");
       return;
     }
     
-    if (approvalReadyRows.length > 1) {
+    if (eligibleRows.length > 1) {
       toast.error("정규업체 등록 요청은 한 번에 하나씩만 가능합니다.");
       return;
     }
 
     setRegistrationRequestDialog({
       open: true,
-      registration: approvalReadyRows[0],
+      registration: eligibleRows[0],
     });
   };
 
@@ -241,8 +242,49 @@ export function VendorRegularRegistrationsTableToolbarActions({
   // CP검토 상태인 선택된 행들 개수
   const cpReviewCount = selectedRows.filter(row => row.status === "cp_review").length;
   
-  // 조건충족 상태인 선택된 행들 개수
-  const approvalReadyCount = selectedRows.filter(row => row.status === "approval_ready").length;
+  // 모든 항목 완료 여부 체크 함수 (table-columns.tsx의 진행현황 계산 로직과 동일)
+  const isAllItemsComplete = (registration: VendorRegularRegistration): boolean => {
+    // 문서 현황 계산 (국가별 요구사항 적용)
+    const isForeign = registration.country !== 'KR'
+    const requiredDocs = isForeign ? 4 : 3 // 외자: 4개(통장사본 포함), 내자: 3개(통장사본 제외)
+    const submittedDocs = Object.values(registration.documentSubmissions).filter(Boolean).length
+    const incompleteDocs = requiredDocs - submittedDocs
+    
+    // 기본계약 현황 계산
+    const totalContracts = registration.basicContracts?.length || 0
+    const completedContracts = registration.basicContracts?.filter(c => c.status === "VENDOR_SIGNED" || c.status === "COMPLETED").length || 0
+    const incompleteContracts = totalContracts - completedContracts
+    
+    // 추가정보 현황
+    const additionalInfoCompleted = registration.additionalInfo
+    
+    // 전체 미완료 항목 계산 (table-columns.tsx와 동일한 로직)
+    const totalIncomplete = 
+      (incompleteDocs > 0 ? 1 : 0) +
+      incompleteContracts +
+      (!additionalInfoCompleted ? 1 : 0)
+    
+    const result = totalIncomplete === 0
+    
+    // 디버깅 로그
+    if (selectedRows.some(r => r.id === registration.id)) {
+      console.log('등록요청 버튼 활성화 체크:', {
+        registrationId: registration.id,
+        companyName: registration.companyName,
+        status: registration.status,
+        incompleteDocs,
+        incompleteContracts,
+        additionalInfoCompleted,
+        totalIncomplete,
+        isAllComplete: result
+      })
+    }
+    
+    return result
+  }
+  
+  // 모든 항목이 완료된 선택된 행들 개수
+  const allItemsCompleteCount = selectedRows.filter(row => isAllItemsComplete(row)).length;
 
   return (
     <div className="flex items-center gap-2">
@@ -280,7 +322,7 @@ export function VendorRegularRegistrationsTableToolbarActions({
         variant="default"
         size="sm"
         onClick={handleRegistrationRequest}
-        disabled={syncLoading.registrationRequest || approvalReadyCount === 0}
+        disabled={syncLoading.registrationRequest || allItemsCompleteCount === 0}
       >
         <FileText className="mr-2 h-4 w-4" />
         {syncLoading.registrationRequest ? "처리 중..." : "등록요청"}
-- 
cgit v1.2.3

