fix: [자재투입] 자동입력 배정수량 버그 수정 — 그룹별 독립 계산
- physicalUsed 교차그룹 추적 제거: 같은 물리 LOT가 다른 BOM 그룹에서 사용될 때 lotInputtedQty가 그룹마다 달라 부정확한 차감 발생 - 각 그룹의 LOT 가용량을 독립적으로 계산 (lotAvailableQty + lotInputtedQty) - allocations useMemo도 동일하게 수정
This commit is contained in:
@@ -199,10 +199,9 @@ export function MaterialInputModal({
|
||||
return group.alreadyInputted > 0 ? group.requiredQty : group.effectiveRequiredQty;
|
||||
}, []);
|
||||
|
||||
// 배정 수량 계산 (manual 우선 → 나머지 FIFO 자동배분, 물리LOT 교차그룹 추적)
|
||||
// 배정 수량 계산 (manual 우선 → 나머지 FIFO 자동배분, 그룹별 독립)
|
||||
const allocations = useMemo(() => {
|
||||
const result = new Map<string, number>();
|
||||
const physicalUsed = new Map<number, number>(); // stockLotId → 그룹 간 누적 사용량
|
||||
|
||||
for (const group of materialGroups) {
|
||||
const targetQty = getGroupTargetQty(group);
|
||||
@@ -215,24 +214,18 @@ export function MaterialInputModal({
|
||||
const val = manualAllocations.get(lotKey)!;
|
||||
result.set(lotKey, val);
|
||||
remaining -= val;
|
||||
physicalUsed.set(lot.stockLotId, (physicalUsed.get(lot.stockLotId) || 0) + val);
|
||||
}
|
||||
}
|
||||
|
||||
// 2차: non-manual 선택 로트 FIFO 자동배분 (물리LOT 가용량 고려)
|
||||
// 2차: non-manual 선택 로트 FIFO 자동배분 (그룹 내 독립 계산)
|
||||
for (const lot of group.lots) {
|
||||
const lotKey = getLotKey(lot, group.groupKey);
|
||||
if (selectedLotKeys.has(lotKey) && lot.stockLotId && !manualAllocations.has(lotKey)) {
|
||||
const itemInput = lot as unknown as MaterialForItemInput;
|
||||
const maxAvail = lot.lotAvailableQty + (itemInput.lotInputtedQty ?? 0);
|
||||
const used = physicalUsed.get(lot.stockLotId) || 0;
|
||||
const effectiveAvail = Math.max(0, maxAvail - used);
|
||||
const alloc = remaining > 0 ? Math.min(effectiveAvail, remaining) : 0;
|
||||
const alloc = remaining > 0 ? Math.min(maxAvail, remaining) : 0;
|
||||
result.set(lotKey, alloc);
|
||||
remaining -= alloc;
|
||||
if (alloc > 0) {
|
||||
physicalUsed.set(lot.stockLotId, used + alloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,11 +279,10 @@ export function MaterialInputModal({
|
||||
});
|
||||
}, []);
|
||||
|
||||
// FIFO 자동입력 (물리LOT 교차그룹 가용량 추적)
|
||||
// FIFO 자동입력 (그룹별 독립 배정 — 각 그룹의 LOT 가용량 독립 계산)
|
||||
const handleAutoFill = useCallback(() => {
|
||||
const newSelected = new Set<string>();
|
||||
const newAllocations = new Map<string, number>();
|
||||
const physicalUsed = new Map<number, number>(); // stockLotId → 그룹 간 누적 사용량
|
||||
|
||||
for (const group of materialGroups) {
|
||||
const targetQty = getGroupTargetQty(group);
|
||||
@@ -301,15 +293,13 @@ export function MaterialInputModal({
|
||||
if (!lot.stockLotId || remaining <= 0) continue;
|
||||
const lotKey = getLotKey(lot, group.groupKey);
|
||||
const itemInput = lot as unknown as MaterialForItemInput;
|
||||
// 해당 그룹에서의 LOT 가용량 = 현재 가용 + 이 그룹에서 기투입된 수량
|
||||
const maxAvail = lot.lotAvailableQty + (itemInput.lotInputtedQty ?? 0);
|
||||
const used = physicalUsed.get(lot.stockLotId) || 0;
|
||||
const effectiveAvail = Math.max(0, maxAvail - used);
|
||||
const alloc = Math.min(effectiveAvail, remaining);
|
||||
const alloc = Math.min(maxAvail, remaining);
|
||||
if (alloc > 0) {
|
||||
newSelected.add(lotKey);
|
||||
newAllocations.set(lotKey, alloc);
|
||||
remaining -= alloc;
|
||||
physicalUsed.set(lot.stockLotId, used + alloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user