feat(purchase): 구매신청 검색/직접입력/사진첨부/HEIC 지원/마스터 자동등록

- 소모품 select → 검색형 드롭다운 (debounce + 키보드 탐색)
- 미등록 품목 직접 입력 + 분류 선택 지원
- 사진 첨부 (base64 업로드, HEIC→JPEG 프론트 변환)
- 구매 처리 시 미등록 품목 소모품 마스터 자동 등록
- item_id NULL 허용, LEFT JOIN, custom_item_name/custom_category/photo_path 컬럼
- DB 마이그레이션 필요: ALTER TABLE purchase_requests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-13 21:49:41 +09:00
parent 13e177e818
commit cae735f243
8 changed files with 414 additions and 69 deletions

View File

@@ -2,14 +2,16 @@
const { getDb } = require('../dbPool');
const PurchaseRequestModel = {
// 구매신청 목록 (소모품 정보 JOIN)
// 구매신청 목록 (소모품 정보 LEFT JOIN — item_id NULL 허용)
async getAll(filters = {}) {
const db = await getDb();
let sql = `
SELECT pr.*, ci.item_name, ci.maker, ci.category, ci.base_price, ci.unit, ci.photo_path,
SELECT pr.*, ci.item_name, ci.maker, ci.category, ci.base_price, ci.unit,
ci.photo_path AS ci_photo_path, pr.photo_path AS pr_photo_path,
pr.custom_item_name, pr.custom_category,
su.name AS requester_name
FROM purchase_requests pr
JOIN consumable_items ci ON pr.item_id = ci.item_id
LEFT JOIN consumable_items ci ON pr.item_id = ci.item_id
LEFT JOIN sso_users su ON pr.requester_id = su.user_id
WHERE 1=1
`;
@@ -17,7 +19,10 @@ const PurchaseRequestModel = {
if (filters.status) { sql += ' AND pr.status = ?'; params.push(filters.status); }
if (filters.requester_id) { sql += ' AND pr.requester_id = ?'; params.push(filters.requester_id); }
if (filters.category) { sql += ' AND ci.category = ?'; params.push(filters.category); }
if (filters.category) {
sql += ' AND (ci.category = ? OR pr.custom_category = ?)';
params.push(filters.category, filters.category);
}
if (filters.from_date) { sql += ' AND pr.request_date >= ?'; params.push(filters.from_date); }
if (filters.to_date) { sql += ' AND pr.request_date <= ?'; params.push(filters.to_date); }
@@ -30,10 +35,12 @@ const PurchaseRequestModel = {
async getById(requestId) {
const db = await getDb();
const [rows] = await db.query(`
SELECT pr.*, ci.item_name, ci.maker, ci.category, ci.base_price, ci.unit, ci.photo_path,
SELECT pr.*, ci.item_name, ci.maker, ci.category, ci.base_price, ci.unit,
ci.photo_path AS ci_photo_path, pr.photo_path AS pr_photo_path,
pr.custom_item_name, pr.custom_category,
su.name AS requester_name
FROM purchase_requests pr
JOIN consumable_items ci ON pr.item_id = ci.item_id
LEFT JOIN consumable_items ci ON pr.item_id = ci.item_id
LEFT JOIN sso_users su ON pr.requester_id = su.user_id
WHERE pr.request_id = ?
`, [requestId]);
@@ -44,9 +51,10 @@ const PurchaseRequestModel = {
async create(data) {
const db = await getDb();
const [result] = await db.query(
`INSERT INTO purchase_requests (item_id, quantity, requester_id, request_date, notes)
VALUES (?, ?, ?, ?, ?)`,
[data.item_id, data.quantity || 1, data.requester_id, data.request_date, data.notes || null]
`INSERT INTO purchase_requests (item_id, custom_item_name, custom_category, quantity, requester_id, request_date, notes, photo_path)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[data.item_id || null, data.custom_item_name || null, data.custom_category || null,
data.quantity || 1, data.requester_id, data.request_date, data.notes || null, data.photo_path || null]
);
return this.getById(result.insertId);
},
@@ -80,6 +88,15 @@ const PurchaseRequestModel = {
return this.getById(requestId);
},
// item_id 업데이트 (마스터 등록 후)
async updateItemId(requestId, itemId) {
const db = await getDb();
await db.query(
`UPDATE purchase_requests SET item_id = ? WHERE request_id = ?`,
[itemId, requestId]
);
},
// 삭제 (admin only, pending 상태만)
async delete(requestId) {
const db = await getDb();