diff --git a/src/components/production/WorkerScreen/MaterialInputModal.tsx b/src/components/production/WorkerScreen/MaterialInputModal.tsx index 64d3ce49..2b1d4131 100644 --- a/src/components/production/WorkerScreen/MaterialInputModal.tsx +++ b/src/components/production/WorkerScreen/MaterialInputModal.tsx @@ -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(); - const physicalUsed = new Map(); // 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(); const newAllocations = new Map(); - const physicalUsed = new Map(); // 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); } } }