From e08c50c771a5de38cd9313373a8a3a3750b0154c Mon Sep 17 00:00:00 2001 From: hjjeong Date: Tue, 6 Jan 2026 15:01:50 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B1=B0=EB=9E=98=EC=B2=98=20=ED=92=88?= =?UTF-8?q?=EB=AA=A9=EC=A0=95=EB=B3=B4=20=EA=B1=B0=EB=9E=98=EC=B2=98?= =?UTF-8?q?=ED=92=88=EB=B2=88/=EB=8B=A8=EA=B0=80=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EC=97=86=EC=9D=B4=20=EC=A0=80=EC=9E=A5=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectedItemsDetailInputComponent.tsx | 20 +++++++++++++++++-- frontend/lib/utils/buttonActions.ts | 15 +++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/frontend/lib/registry/components/selected-items-detail-input/SelectedItemsDetailInputComponent.tsx b/frontend/lib/registry/components/selected-items-detail-input/SelectedItemsDetailInputComponent.tsx index 925ca174..e91d34f4 100644 --- a/frontend/lib/registry/components/selected-items-detail-input/SelectedItemsDetailInputComponent.tsx +++ b/frontend/lib/registry/components/selected-items-detail-input/SelectedItemsDetailInputComponent.tsx @@ -432,10 +432,25 @@ export const SelectedItemsDetailInputComponent: React.FC { + itemsList.forEach((item, itemIndex) => { // 각 그룹의 엔트리 배열들을 준비 const groupEntriesArrays: GroupEntry[][] = groups.map((group) => item.fieldGroups[group.id] || []); + // 🆕 모든 그룹이 비어있는지 확인 + const allGroupsEmpty = groupEntriesArrays.every((arr) => arr.length === 0); + + if (allGroupsEmpty) { + // 🆕 모든 그룹이 비어있으면 품목 기본 정보만으로 레코드 생성 + // (거래처 품번/품명, 기간별 단가 없이도 저장 가능) + console.log("📝 [generateCartesianProduct] 모든 그룹이 비어있음 - 품목 기본 레코드 생성", { + itemIndex, + itemId: item.id, + }); + // 빈 객체를 추가하면 parentKeys와 합쳐져서 기본 레코드가 됨 + allRecords.push({}); + return; + } + // Cartesian Product 재귀 함수 const cartesian = (arrays: GroupEntry[][], currentIndex: number, currentCombination: Record) => { if (currentIndex === arrays.length) { @@ -446,7 +461,8 @@ export const SelectedItemsDetailInputComponent: React.FC g.entries); - const combinations = cartesianProduct(entryArrays); + + // 🆕 모든 그룹이 비어있는지 확인 + const allGroupsEmpty = entryArrays.every((arr) => arr.length === 0); + + let combinations: any[][]; + if (allGroupsEmpty) { + // 🆕 모든 그룹이 비어있으면 빈 조합 하나 생성 (품목 기본 정보만으로 저장) + console.log("📝 [handleBatchSave] 모든 그룹이 비어있음 - 기본 레코드 생성"); + combinations = [[]]; + } else { + // 빈 그룹을 필터링하여 카티션 곱 계산 (빈 그룹은 무시) + const nonEmptyArrays = entryArrays.filter((arr) => arr.length > 0); + combinations = nonEmptyArrays.length > 0 ? cartesianProduct(nonEmptyArrays) : [[]]; + } // 각 조합을 개별 레코드로 저장 for (let i = 0; i < combinations.length; i++) { -- 2.43.0