- Updated the `getOrderSummary` function to use `NULLIF` for `due_date` to ensure proper handling of empty values. - Added pagination state management in the Equipment Inspection Record page across multiple company components, including `page`, `pageSize`, and `total` state variables. This refactor improves data accuracy and user experience in the production planning and equipment inspection modules.
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
/**
|
|
* 수주 등록/수정 모달 — 품목별 등록 포장재 옵션 조회
|
|
* - pkg_unit_item에서 item_number로 매핑된 포장재 + 입수수량
|
|
* - pkg_unit JOIN으로 포장재 이름·종류 함께 반환
|
|
*/
|
|
|
|
import { Response } from "express";
|
|
import { AuthenticatedRequest } from "../types/auth";
|
|
import { getPool } from "../database/db";
|
|
import { logger } from "../utils/logger";
|
|
|
|
export async function getPackagingOptions(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const companyCode = req.user!.companyCode;
|
|
const itemNumber = (req.params.itemNumber || "").trim();
|
|
if (!itemNumber) {
|
|
return res.status(400).json({ success: false, message: "itemNumber가 필요합니다" });
|
|
}
|
|
|
|
const pool = getPool();
|
|
const result = await pool.query(
|
|
`SELECT
|
|
pui.pkg_code,
|
|
pui.pkg_qty,
|
|
pu.pkg_name,
|
|
pu.pkg_type
|
|
FROM pkg_unit_item pui
|
|
LEFT JOIN pkg_unit pu
|
|
ON pu.pkg_code = pui.pkg_code AND pu.company_code = pui.company_code
|
|
WHERE pui.company_code = $1
|
|
AND pui.item_number = $2
|
|
ORDER BY pui.created_date ASC`,
|
|
[companyCode, itemNumber]
|
|
);
|
|
|
|
const options = result.rows.map((r: any) => ({
|
|
pkg_code: r.pkg_code,
|
|
pkg_name: r.pkg_name || r.pkg_code,
|
|
pkg_type: r.pkg_type || "",
|
|
pkg_qty_per_unit: Number(r.pkg_qty) || 0, // 1 포장당 입수 수량
|
|
}));
|
|
|
|
return res.json({
|
|
success: true,
|
|
itemNumber,
|
|
total: options.length,
|
|
options,
|
|
});
|
|
} catch (error: any) {
|
|
logger.error("품목별 포장재 옵션 조회 실패", { error: error.message });
|
|
return res.status(500).json({ success: false, message: error.message });
|
|
}
|
|
}
|