fix: [자재투입] physicalAvail을 SUM으로 수정 — 모든 그룹의 기투입 합산
- max() → SUM: 같은 LOT의 기투입(lotInputtedQty)을 모든 그룹에서 합산 - replace 모드에서 각 그룹의 기투입이 복원되므로 합산이 정확 - 예: 가용4 + 상부덮개기투입3 + 마구리기투입1 = 총8 (max는 7로 부정확)
This commit is contained in:
@@ -203,15 +203,20 @@ export function MaterialInputModal({
|
||||
const allocations = useMemo(() => {
|
||||
const result = new Map<string, number>();
|
||||
|
||||
// 물리 LOT별 최대 가용량 초기화
|
||||
// 물리 LOT별 실제 가용량: lotAvailableQty + SUM(모든 그룹의 lotInputtedQty)
|
||||
const physicalAvail = new Map<number, number>();
|
||||
const lotBaseAvail = new Map<number, number>();
|
||||
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<number, number>();
|
||||
@@ -301,19 +306,22 @@ export function MaterialInputModal({
|
||||
const handleAutoFill = useCallback(() => {
|
||||
const newSelected = new Set<string>();
|
||||
const newAllocations = new Map<string, number>();
|
||||
// 물리 LOT별 실제 가용량 추적 (lotAvailableQty 기준, 기투입분 포함 복원량으로 초기화)
|
||||
const physicalAvail = new Map<number, number>();
|
||||
|
||||
// 1차: 물리 LOT별 최대 가용량 초기화 (lotAvailableQty + 전체 기투입량)
|
||||
// 물리 LOT별 실제 가용량 계산: lotAvailableQty + SUM(모든 그룹의 lotInputtedQty)
|
||||
// replace 모드에서 기투입분이 복원되므로 모든 그룹의 기투입을 합산
|
||||
const physicalAvail = new Map<number, number>();
|
||||
const lotBaseAvail = new Map<number, number>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user