fix: [자재투입] 입고 로트번호 표시 및 로트별 수량 투입으로 변경

- MaterialForInput 타입: stockLotId, lotNo, lotAvailableQty 추가
- 로트번호 컬럼에 실제 입고 로트번호(lot_no) 표시
- 수량 컬럼을 가용수량(lotAvailableQty)으로 변경
- 가용수량 초과 검증 추가
- registerMaterialInput: stock_lot_id+qty 로트별 투입 방식으로 변경
This commit is contained in:
2026-02-07 05:06:34 +09:00
parent a523bb482e
commit 1fca5ed477
2 changed files with 110 additions and 67 deletions

View File

@@ -277,13 +277,17 @@ export async function completeWorkOrder(
}
}
// ===== 자재 목록 조회 (BOM 기준) =====
// ===== 자재 목록 조회 (로트 기준) =====
export interface MaterialForInput {
id: number;
stockLotId: number | null; // StockLot ID (null이면 재고 없음)
itemId: number;
lotNo: string | null; // 실제 입고 로트번호
materialCode: string;
materialName: string;
specification: string;
unit: string;
currentStock: number;
requiredQty: number; // 필요 수량
lotAvailableQty: number; // 로트별 가용 수량
fifoRank: number;
}
@@ -330,20 +334,28 @@ export async function getMaterialsForWorkOrder(
};
}
// API 응답을 MaterialForInput 형식으로 변환
// API 응답을 MaterialForInput 형식으로 변환 (로트 단위)
const materials: MaterialForInput[] = (result.data || []).map((item: {
id: number;
stock_lot_id: number | null;
item_id: number;
lot_no: string | null;
material_code: string;
material_name: string;
specification: string;
unit: string;
current_stock: number;
required_qty: number;
lot_available_qty: number;
fifo_rank: number;
}) => ({
id: item.id,
stockLotId: item.stock_lot_id,
itemId: item.item_id,
lotNo: item.lot_no,
materialCode: item.material_code,
materialName: item.material_name,
specification: item.specification ?? '',
unit: item.unit,
currentStock: item.current_stock,
requiredQty: item.required_qty,
lotAvailableQty: item.lot_available_qty,
fifoRank: item.fifo_rank,
}));
@@ -362,17 +374,17 @@ export async function getMaterialsForWorkOrder(
}
}
// ===== 자재 투입 등록 =====
// ===== 자재 투입 등록 (로트별 수량) =====
export async function registerMaterialInput(
workOrderId: string,
materialIds: number[]
inputs: { stock_lot_id: number; qty: number }[]
): Promise<{ success: boolean; error?: string }> {
try {
const { response, error } = await serverFetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/work-orders/${workOrderId}/material-inputs`,
{
method: 'POST',
body: JSON.stringify({ material_ids: materialIds }),
body: JSON.stringify({ inputs }),
}
);