feat: Add outsourcing outbound functionality
- Introduced a new controller for managing outsourcing outbound processes, including automatic candidate retrieval and outbound list management. - Implemented API routes for fetching candidates, listing outsourcing outbounds, and creating new outbound records. - Enhanced the SQL queries to ensure proper filtering by company code and to utilize existing outbound management tables effectively. - Added new routes for handling outsourcing outbound operations in the Express application, improving the overall functionality of the logistics module.
This commit is contained in:
@@ -394,7 +394,30 @@ export async function getProductionPlanSource(req: AuthenticatedRequest, res: Re
|
||||
const pool = getPool();
|
||||
const cnt = await pool.query(`SELECT COUNT(*) AS total FROM production_plan_mng p WHERE ${w}`, params);
|
||||
params.push(pageSize, offset);
|
||||
const rows = await pool.query(`SELECT p.id, p.plan_no, p.item_code, COALESCE(p.item_name,'') AS item_name, COALESCE(p.plan_qty,0) AS plan_qty, p.start_date, p.end_date, p.status, COALESCE(p.equipment_name,'') AS equipment_name FROM production_plan_mng p WHERE ${w} ORDER BY p.created_date DESC LIMIT $${idx} OFFSET $${idx+1}`, params);
|
||||
// work_instruction_detail에서 해당 계획에 이미 내린 작업지시 수량 합계 → applied_qty, remain_qty
|
||||
const rows = await pool.query(
|
||||
`SELECT p.id, p.plan_no, p.item_code,
|
||||
COALESCE(p.item_name,'') AS item_name,
|
||||
COALESCE(p.plan_qty,0) AS plan_qty,
|
||||
p.start_date, p.end_date, p.status,
|
||||
COALESCE(p.equipment_name,'') AS equipment_name,
|
||||
COALESCE(wi.applied_qty, 0) AS applied_qty,
|
||||
(COALESCE(CAST(NULLIF(p.plan_qty::text, '') AS numeric), 0)
|
||||
- COALESCE(wi.applied_qty, 0)) AS remain_qty
|
||||
FROM production_plan_mng p
|
||||
LEFT JOIN (
|
||||
SELECT source_id,
|
||||
SUM(COALESCE(CAST(NULLIF(qty, '') AS numeric), 0)) AS applied_qty
|
||||
FROM work_instruction_detail
|
||||
WHERE source_table = 'production_plan_mng'
|
||||
AND company_code = $1
|
||||
GROUP BY source_id
|
||||
) wi ON wi.source_id = p.id::text
|
||||
WHERE ${w}
|
||||
ORDER BY p.created_date DESC
|
||||
LIMIT $${idx} OFFSET $${idx+1}`,
|
||||
params,
|
||||
);
|
||||
return res.json({ success: true, data: rows.rows, totalCount: parseInt(cnt.rows[0].total), page, pageSize });
|
||||
} catch (error: any) { return res.status(500).json({ success: false, message: error.message }); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user