From 40250c61031263606dd073ce7056a3e8e27f18d0 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Tue, 14 Oct 2025 14:25:28 +0900
Subject: (김준회) AVL 구매요구사항 수정 - AVL 상세 엑셀 익스포트 추가 - 레코드
 이동 멀티선택 추가 - 최종확정처리 오류 수정 - 프로젝트 AVL에 H/T 구분 추가
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/avl/table/avl-registration-area.tsx | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

(limited to 'lib/avl/table/avl-registration-area.tsx')

diff --git a/lib/avl/table/avl-registration-area.tsx b/lib/avl/table/avl-registration-area.tsx
index 6c7eba9d..1fa4ab5d 100644
--- a/lib/avl/table/avl-registration-area.tsx
+++ b/lib/avl/table/avl-registration-area.tsx
@@ -145,6 +145,7 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
 
   // 선택된 AVL에 따른 필터 값들
   const [currentProjectCode, setCurrentProjectCode] = React.useState<string>("")
+  const [currentProjectHtDivision, setCurrentProjectHtDivision] = React.useState<string>("") // 프로젝트 AVL의 H/T 구분
   const constructionSector = selectedAvlRecord?.constructionSector || ""
   const shipType = selectedAvlRecord?.shipType || ""
   const avlKind = selectedAvlRecord?.avlKind || ""
@@ -193,6 +194,11 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
     setCurrentProjectCode(projectCode)
   }, [])
 
+  // 프로젝트 H/T 구분 변경 핸들러
+  const handleProjectHtDivisionChange = React.useCallback((htDivision: string) => {
+    setCurrentProjectHtDivision(htDivision)
+  }, [])
+
   // 선택된 ID들을 가져오는 헬퍼 함수들
   const getSelectedIds = React.useCallback((tableType: 'project' | 'standard' | 'vendor') => {
     // 각 테이블 컴포넌트에서 선택된 행들의 ID를 가져오는 로직
@@ -223,16 +229,24 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
       return
     }
 
+    if (!currentProjectHtDivision) {
+      toast.error("프로젝트 AVL의 H/T 구분이 설정되지 않았습니다.")
+      return
+    }
+
     try {
       const result = await copyToProjectAvl(
         selectedIds,
         currentProjectCode,
+        currentProjectHtDivision,
         parseInt(avlListId) || 1,
         session?.user?.name || "unknown"
       )
 
       if (result.success) {
         toast.success(result.message)
+        // 프로젝트 AVL 데이터 리로드
+        setProjectAvlReloadTrigger(prev => prev + 1)
         // 선택 해제
         dispatch({ type: 'CLEAR_SELECTION' })
       } else {
@@ -242,7 +256,7 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
       console.error('프로젝트AVL로 복사 실패:', error)
       toast.error("복사 중 오류가 발생했습니다.")
     }
-  }, [selectedTable, selectedRowCount, getSelectedIds, currentProjectCode, avlListId, session])
+  }, [selectedTable, selectedRowCount, getSelectedIds, currentProjectCode, currentProjectHtDivision, avlListId, session])
 
   const handleCopyToStandard = React.useCallback(async () => {
     if (selectedTable !== 'project' || selectedRowCount === 0) return
@@ -327,10 +341,16 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
       return
     }
 
+    if (!currentProjectHtDivision) {
+      toast.error("프로젝트 AVL의 H/T 구분이 설정되지 않았습니다.")
+      return
+    }
+
     try {
       const result = await copyFromVendorPoolToProjectAvl(
         selectedIds,
         currentProjectCode,
+        currentProjectHtDivision,
         parseInt(avlListId) || 1,
         session?.user?.name || "unknown"
       )
@@ -348,7 +368,7 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
       console.error('벤더풀 → 프로젝트AVL 복사 실패:', error)
       toast.error("복사 중 오류가 발생했습니다.")
     }
-  }, [selectedTable, selectedRowCount, getSelectedIds, currentProjectCode, avlListId, session])
+  }, [selectedTable, selectedRowCount, getSelectedIds, currentProjectCode, currentProjectHtDivision, avlListId, session])
 
   const handleCopyFromVendorToStandard = React.useCallback(async () => {
     if (selectedTable !== 'vendor' || selectedRowCount === 0) return
@@ -444,6 +464,7 @@ export function AvlRegistrationArea({ disabled = false }: AvlRegistrationAreaPro
               projectCode={currentProjectCode}
               avlListId={parseInt(avlListId) || 1}
               onProjectCodeChange={handleProjectCodeChange}
+              onHtDivisionChange={handleProjectHtDivisionChange}
               reloadTrigger={projectAvlReloadTrigger}
             />
 
-- 
cgit v1.2.3

