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++) {