feat: Implement automatic equipment code generation and allocation in equipment registration
- Enhanced the equipment registration process to support automatic code generation based on predefined numbering rules. - Integrated API calls to fetch and preview numbering rules, allowing for dynamic equipment code assignment. - Added error handling to manage failures in code allocation, ensuring a smoother user experience during equipment registration. - Updated the input field for equipment code to reflect automatic generation status, improving clarity for users. - These changes aim to streamline the equipment management process and enhance usability across multiple company implementations.
This commit is contained in:
@@ -188,13 +188,25 @@ export async function save(req: AuthenticatedRequest, res: Response) {
|
||||
wiId = insertRes.rows[0].id;
|
||||
}
|
||||
|
||||
let totalQty = 0;
|
||||
let firstRouting: string | null = null;
|
||||
for (const item of items) {
|
||||
const itemRouting = item.routing || null;
|
||||
if (!firstRouting && itemRouting) firstRouting = itemRouting;
|
||||
totalQty += Number(item.qty || 0);
|
||||
await client.query(
|
||||
`INSERT INTO work_instruction_detail (id,company_code,work_instruction_no,work_instruction_id,item_number,qty,remark,source_table,source_id,part_code,routing_version_id,created_date,writer) VALUES (gen_random_uuid()::text,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,NOW(),$11)`,
|
||||
[companyCode, wiNo, wiId, item.itemNumber||item.itemCode||"", item.qty||"0", item.remark||"", item.sourceTable||"", item.sourceId||"", item.partCode||item.itemNumber||item.itemCode||"", item.routing||null, userId]
|
||||
[companyCode, wiNo, wiId, item.itemNumber||item.itemCode||"", item.qty||"0", item.remark||"", item.sourceTable||"", item.sourceId||"", item.partCode||item.itemNumber||item.itemCode||"", itemRouting, userId]
|
||||
);
|
||||
}
|
||||
|
||||
// 마스터 qty/routing 자동 동기화 (디테일 합계 + 첫 번째 라우팅)
|
||||
const effectiveRouting = routingVersionId || firstRouting;
|
||||
await client.query(
|
||||
`UPDATE work_instruction SET qty = $1, routing = COALESCE(routing, $2) WHERE id = $3`,
|
||||
[String(totalQty), effectiveRouting, wiId]
|
||||
);
|
||||
|
||||
await client.query("COMMIT");
|
||||
return res.json({ success: true, data: { id: wiId, workInstructionNo: wiNo } });
|
||||
} catch (txErr) { await client.query("ROLLBACK"); throw txErr; }
|
||||
|
||||
Reference in New Issue
Block a user