feat(orders): 거래명세서 발주일자 수정 — REQUESTED/APPROVED 만 (date input + 자동저장)
Deploy momo-erp / deploy (push) Successful in 1m56s

This commit is contained in:
chpark
2026-05-15 01:50:21 +09:00
parent d6b81da946
commit c7d7bdfaea
2 changed files with 53 additions and 1 deletions
+24 -1
View File
@@ -651,7 +651,30 @@ function StatementPreview({
<div className="flex justify-between items-start gap-3 mt-3 text-[11px]">
<div className="space-y-0.5">
<div><b></b> · {order.ORDER_NO}</div>
<div><b></b> · {order.ORDER_DATE}</div>
<div className="inline-flex items-center gap-1">
<b></b> ·{" "}
{editable ? (
<input
type="date"
defaultValue={order.ORDER_DATE}
onBlur={async (e) => {
const v = e.target.value;
if (!v || v === order.ORDER_DATE) return;
const res = await fetch("/api/m/orders/update-date", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ objid: order.OBJID, orderDate: v }),
});
const j = await res.json();
if (j.success) { onReload(); onReloadList(); }
else Swal.fire({ icon: "error", title: "발주일 변경 실패", text: j.message });
}}
className="h-6 px-1.5 border border-slate-300 rounded text-[11px] bg-white js-no-export"
/>
) : (
order.ORDER_DATE
)}
{editable && <span className="text-slate-300 ml-1 js-no-export">( )</span>}
</div>
<div><b></b> · <span className="font-semibold">{STATUS_LABEL[order.STATUS] ?? order.STATUS}</span></div>
</div>
<table className="text-[11px] border border-slate-400 self-start" style={{borderCollapse:'collapse'}}>
+29
View File
@@ -0,0 +1,29 @@
// 발주일자(order_date) 변경 — admin 만, REQUESTED/APPROVED 만 허용.
import { NextRequest, NextResponse } from "next/server";
import { pool } from "@/lib/db";
import { requireMomoAdmin } from "@/lib/momo-guard";
export async function POST(req: NextRequest) {
const g = await requireMomoAdmin();
if (g instanceof NextResponse) return g;
const { objid, orderDate } = await req.json() as { objid?: string; orderDate?: string };
if (!objid || !orderDate) {
return NextResponse.json({ success: false, message: "필수 항목 누락" }, { status: 400 });
}
if (!/^\d{4}-\d{2}-\d{2}$/.test(orderDate)) {
return NextResponse.json({ success: false, message: "날짜 형식이 올바르지 않습니다 (YYYY-MM-DD)." }, { status: 400 });
}
const cur = await pool.query(`SELECT status FROM momo_orders WHERE objid = $1`, [objid]);
if (cur.rowCount === 0) return NextResponse.json({ success: false, message: "발주 없음" }, { status: 404 });
if (!["REQUESTED", "APPROVED"].includes(cur.rows[0].status)) {
return NextResponse.json({ success: false, message: "출고요청/출고완료 상태만 발주일 변경 가능합니다." }, { status: 400 });
}
await pool.query(
`UPDATE momo_orders SET order_date = $2::date, update_date = NOW() WHERE objid = $1`,
[objid, orderDate]
);
return NextResponse.json({ success: true });
}