From 3929ec17f256c012efcc41b45274127f59773d77 Mon Sep 17 00:00:00 2001 From: SeongHyun Kim Date: Tue, 7 Apr 2026 11:07:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20BOM=20=EC=9E=90=EC=9E=AC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20=ED=88=AC=EC=9E=85?= =?UTF-8?q?=EB=9F=89=20=ED=95=A9=EC=82=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getBomMaterials에서 input_qty: 0 하드코딩 → process_work_result에서 실제 투입량 SUM - child_item_id별 투입 합산으로 정확한 잔여량 표시 --- .../src/controllers/popProductionController.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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, }; });