diff --git a/backend-node/src/controllers/popProductionController.ts b/backend-node/src/controllers/popProductionController.ts index 61d81716..e118921b 100644 --- a/backend-node/src/controllers/popProductionController.ts +++ b/backend-node/src/controllers/popProductionController.ts @@ -2813,13 +2813,27 @@ export const getBomMaterials = async (req: AuthenticatedRequest, res: Response) ); const baseQty = parseFloat(bomBase.rows[0]?.base_qty || "1") || 1; + // 기존 투입량 조회 (child_item_id별 합산) + const inputResult = await pool.query( + `SELECT detail_content as child_item_id, SUM(CAST(NULLIF(result_value, '') AS numeric)) as total_input + FROM process_work_result + WHERE work_order_process_id = $1 AND company_code = $2 AND detail_type = 'material_input' + GROUP BY detail_content`, + [processId, companyCode] + ); + const inputMap = new Map(); + for (const row of inputResult.rows) { + inputMap.set(String(row.child_item_id), parseFloat(row.total_input) || 0); + } + const materials = bomResult.rows.map((bd: Record) => { const bomQty = parseFloat(String(bd.quantity || "0")) || 0; const lossRate = parseFloat(String(bd.loss_rate || "0")) || 0; const requiredQty = Math.ceil((processQty / baseQty) * bomQty * (1 + lossRate / 100)); + const childItemId = String(bd.child_item_id || ""); return { id: bd.id, - child_item_id: bd.child_item_id, + child_item_id: childItemId, child_item_code: bd.child_item_code || "", child_item_name: bd.child_item_name || "", bom_qty: bomQty, @@ -2827,7 +2841,7 @@ export const getBomMaterials = async (req: AuthenticatedRequest, res: Response) process_type: bd.process_type || "", loss_rate: lossRate, required_qty: requiredQty, - input_qty: 0, + input_qty: inputMap.get(childItemId) || 0, }; });