diff --git a/backend-node/src/controllers/popProductionController.ts b/backend-node/src/controllers/popProductionController.ts index 3100adef..8d0af7c5 100644 --- a/backend-node/src/controllers/popProductionController.ts +++ b/backend-node/src/controllers/popProductionController.ts @@ -2813,35 +2813,36 @@ export const getBomMaterials = async (req: AuthenticatedRequest, res: Response) ); const baseQty = parseFloat(bomBase.rows[0]?.base_qty || "1") || 1; - // 기존 투입량 조회 (child_item_id별 합산) + // 기존 투입량 조회 (item_code별 합산 — detail_content에 item_code 저장됨) const inputResult = await pool.query( - `SELECT detail_content as child_item_id, SUM(CAST(NULLIF(result_value, '') AS numeric)) as total_input + `SELECT detail_content as item_code, 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' + AND result_value IS NOT NULL AND result_value != '' 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); + inputMap.set(String(row.item_code), 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 || ""); + const childItemCode = String(bd.child_item_code || ""); return { id: bd.id, - child_item_id: childItemId, - child_item_code: bd.child_item_code || "", + child_item_id: bd.child_item_id, + child_item_code: childItemCode, child_item_name: bd.child_item_name || "", bom_qty: bomQty, unit: bd.unit || bd.item_unit || "", process_type: bd.process_type || "", loss_rate: lossRate, required_qty: requiredQty, - input_qty: inputMap.get(childItemId) || 0, + input_qty: inputMap.get(childItemCode) || 0, }; });