거래처 품목정보 거래처품번/단가 입력 없이 저장되도록
This commit is contained in:
parent
64105bf525
commit
e08c50c771
|
|
@ -432,10 +432,25 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||||
const groups = componentConfig.fieldGroups || [];
|
const groups = componentConfig.fieldGroups || [];
|
||||||
const additionalFields = componentConfig.additionalFields || [];
|
const additionalFields = componentConfig.additionalFields || [];
|
||||||
|
|
||||||
itemsList.forEach((item) => {
|
itemsList.forEach((item, itemIndex) => {
|
||||||
// 각 그룹의 엔트리 배열들을 준비
|
// 각 그룹의 엔트리 배열들을 준비
|
||||||
const groupEntriesArrays: GroupEntry[][] = groups.map((group) => item.fieldGroups[group.id] || []);
|
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 재귀 함수
|
// Cartesian Product 재귀 함수
|
||||||
const cartesian = (arrays: GroupEntry[][], currentIndex: number, currentCombination: Record<string, any>) => {
|
const cartesian = (arrays: GroupEntry[][], currentIndex: number, currentCombination: Record<string, any>) => {
|
||||||
if (currentIndex === arrays.length) {
|
if (currentIndex === arrays.length) {
|
||||||
|
|
@ -446,7 +461,8 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||||
|
|
||||||
const currentGroupEntries = arrays[currentIndex];
|
const currentGroupEntries = arrays[currentIndex];
|
||||||
if (currentGroupEntries.length === 0) {
|
if (currentGroupEntries.length === 0) {
|
||||||
// 현재 그룹에 데이터가 없으면 빈 조합으로 다음 그룹 진행
|
// 🆕 현재 그룹에 데이터가 없으면 빈 조합으로 다음 그룹 진행
|
||||||
|
// (그룹이 비어있어도 다른 그룹의 데이터로 레코드 생성)
|
||||||
cartesian(arrays, currentIndex + 1, currentCombination);
|
cartesian(arrays, currentIndex + 1, currentCombination);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2112,7 +2112,20 @@ export class ButtonActionExecutor {
|
||||||
|
|
||||||
// 모든 그룹의 카티션 곱 생성
|
// 모든 그룹의 카티션 곱 생성
|
||||||
const entryArrays = groupArrays.map((g) => g.entries);
|
const entryArrays = groupArrays.map((g) => 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++) {
|
for (let i = 0; i < combinations.length; i++) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue