diff --git a/src/components/production/WorkerScreen/MaterialInputModal.tsx b/src/components/production/WorkerScreen/MaterialInputModal.tsx index f5e85204..449ef9b0 100644 --- a/src/components/production/WorkerScreen/MaterialInputModal.tsx +++ b/src/components/production/WorkerScreen/MaterialInputModal.tsx @@ -203,15 +203,20 @@ export function MaterialInputModal({ const allocations = useMemo(() => { const result = new Map(); - // 물리 LOT별 최대 가용량 초기화 + // 물리 LOT별 실제 가용량: lotAvailableQty + SUM(모든 그룹의 lotInputtedQty) const physicalAvail = new Map(); + const lotBaseAvail = new Map(); for (const group of materialGroups) { for (const lot of group.lots) { if (!lot.stockLotId) continue; const itemInput = lot as unknown as MaterialForItemInput; - const totalAvail = lot.lotAvailableQty + (itemInput.lotInputtedQty ?? 0); - const current = physicalAvail.get(lot.stockLotId) ?? 0; - if (totalAvail > current) physicalAvail.set(lot.stockLotId, totalAvail); + const inputted = itemInput.lotInputtedQty ?? 0; + if (!lotBaseAvail.has(lot.stockLotId)) { + lotBaseAvail.set(lot.stockLotId, lot.lotAvailableQty); + physicalAvail.set(lot.stockLotId, lot.lotAvailableQty + inputted); + } else { + physicalAvail.set(lot.stockLotId, (physicalAvail.get(lot.stockLotId) ?? 0) + inputted); + } } } const physicalUsed = new Map(); @@ -301,19 +306,22 @@ export function MaterialInputModal({ const handleAutoFill = useCallback(() => { const newSelected = new Set(); const newAllocations = new Map(); - // 물리 LOT별 실제 가용량 추적 (lotAvailableQty 기준, 기투입분 포함 복원량으로 초기화) - const physicalAvail = new Map(); - // 1차: 물리 LOT별 최대 가용량 초기화 (lotAvailableQty + 전체 기투입량) + // 물리 LOT별 실제 가용량 계산: lotAvailableQty + SUM(모든 그룹의 lotInputtedQty) + // replace 모드에서 기투입분이 복원되므로 모든 그룹의 기투입을 합산 + const physicalAvail = new Map(); + const lotBaseAvail = new Map(); + for (const group of materialGroups) { for (const lot of group.lots) { if (!lot.stockLotId) continue; const itemInput = lot as unknown as MaterialForItemInput; - const totalAvail = lot.lotAvailableQty + (itemInput.lotInputtedQty ?? 0); - // 같은 stockLotId의 최대값 유지 (기투입이 가장 큰 값이 실제 원래 가용량) - const current = physicalAvail.get(lot.stockLotId) ?? 0; - if (totalAvail > current) { - physicalAvail.set(lot.stockLotId, totalAvail); + const inputted = itemInput.lotInputtedQty ?? 0; + if (!lotBaseAvail.has(lot.stockLotId)) { + lotBaseAvail.set(lot.stockLotId, lot.lotAvailableQty); + physicalAvail.set(lot.stockLotId, lot.lotAvailableQty + inputted); + } else { + physicalAvail.set(lot.stockLotId, (physicalAvail.get(lot.stockLotId) ?? 0) + inputted); } } }