feat(inout): 옵션 상품 정보 탭 — 단가·무게(PP)·은 함유량, 발주서·메일 금액, 입고 담당 화면 줄이기

- 마이그레이션 004: inout_products(단가·개당 무게 g·은 함유량 %), inout_products_excluded(지운 단품),
  inout_order_lines 에 발주할 때 값 사본(unit_price·weight_g·silver_pct)
- 옵션 → 상품 정보: [단품 불러오기](값을 넣은 상품은 그대로, 지운 단품은 다음에도 빠짐), 바뀐 줄만 저장,
  은 g = 무게 × % 자동, 지우기·되살리기
- 상품 정보가 있으면 발주서 제품은 그 목록에서(단가 함께), 금액 = 수량 × 단가 실시간 합계
- 발주서 화면(발주 담당)·발주 메일에 단가·금액·PP(g/개)·은 함유량과 합계(금액·PP kg·은 g)
- 입고 담당(발주 담당 아님)은 품목을 제품 이름·발주 수량(+ 이번 입고)만, 입고 기록 칩도 이름
- 고침: 그날 100번째 발주서부터 번호가 겹치던 문제(순번 숫자 비교), 시각을 DB 시간대와 무관하게 KST 로 읽음

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 00:59:45 +09:00
parent dcc6cd27b6
commit a475f0b2f6
21 changed files with 1031 additions and 76 deletions
+103 -2
View File
@@ -51,15 +51,23 @@
const totalQty = document.getElementById("io-total-qty");
const totalLines = document.getElementById("io-total-lines");
const totalAmount = document.getElementById("io-total-amount"), noPrice = document.getElementById("io-total-noprice");
function renumber() {
let q = 0, k = 0;
let q = 0, k = 0, amount = 0, missing = 0;
body.querySelectorAll(".io-line").forEach(function (tr, i) {
tr.querySelector(".io-col-no").textContent = String(i + 1);
const n = num(tr.querySelector(".io-qty").value);
if (tr.querySelector('input[name="item_code"]').value) { k++; q += n; }
const has = !!tr.querySelector('input[name="item_code"]').value;
const price = tr.dataset.price === "" || tr.dataset.price === undefined ? null : parseFloat(tr.dataset.price);
const cell = tr.querySelector(".io-amount");
// 금액 = 수량 × 단가(상품 정보 단가, 이미 있던 품목은 발주 당시 단가) — 표시만, 저장은 서버가 단가 사본으로
if (cell) cell.textContent = has && price !== null && n ? (Math.round(price * n * 100) / 100).toLocaleString("ko-KR") : "-";
if (has) { k++; q += n; if (price === null) missing++; else amount += price * n; }
});
totalQty.textContent = fmt(q);
totalLines.textContent = fmt(k);
if (totalAmount) totalAmount.textContent = (Math.round(amount * 100) / 100).toLocaleString("ko-KR");
if (noPrice) noPrice.textContent = missing ? " (단가 없는 " + missing + "종 제외)" : "";
}
function addLine(focus) {
const tr = tpl.content.firstElementChild.cloneNode(true);
@@ -148,6 +156,12 @@
c.textContent = it.code;
opt.appendChild(c);
opt.appendChild(document.createTextNode(" " + it.name));
if (it.unit_price) {
const pr = document.createElement("span");
pr.className = "io-suggest-price";
pr.textContent = it.unit_price + "원";
opt.insertBefore(pr, c); // float:right 는 글자보다 앞에 둬야 같은 줄 오른쪽
}
opt.addEventListener("mousedown", function (e) { e.preventDefault(); choose(i); });
box.appendChild(opt);
});
@@ -159,6 +173,12 @@
const it = items[i];
if (!it) return;
codeEl.value = it.code;
const row = input.closest("tr");
if (row) { // 단가(상품 정보) — 금액 계산용
row.dataset.price = it.price === null || it.price === undefined ? "" : String(it.price);
const pc = row.querySelector(".io-price");
if (pc) pc.textContent = it.unit_price || "-";
}
nameEl.value = it.name;
input.value = it.code + " · " + it.name;
input.classList.remove("is-invalid");
@@ -187,6 +207,8 @@
input.setAttribute("aria-autocomplete", "list");
input.addEventListener("input", function () {
codeEl.value = ""; // 글을 고치면 고른 제품은 풀린다(다시 골라야 저장)
const row0 = input.closest("tr");
if (row0 && row0.dataset.price !== undefined) { row0.dataset.price = ""; const pc0 = row0.querySelector(".io-price"); if (pc0) pc0.textContent = "-"; }
nameEl.value = "";
clearTimeout(timer);
const q = input.value.trim();
@@ -307,6 +329,85 @@
buttons.forEach(function (b) { if (b.isConnected) b.disabled = false; });
}
});
// ── 상품 정보 탭(004) — 단가·무게·은 함유량, 바뀐 줄만 [변경 저장], 불러오기·지우기·되살리기 ──
function dirtyRows() {
return Array.from(body.querySelectorAll(".io-prod-table tbody tr")).filter(function (tr) {
return Array.from(tr.querySelectorAll("input[data-key]")).some(function (i) { return i.value.trim() !== i.defaultValue.trim(); });
});
}
function paintDirty() {
const n = dirtyRows().length;
const save = body.querySelector("#io-prod-save"), badge = body.querySelector("#io-prod-dirty");
if (save) save.disabled = !n;
if (badge) badge.textContent = n ? "(" + n + ")" : "";
}
function dec(v) { const n = parseFloat(String(v || "").replace(/[,%\s]/g, "")); return Number.isFinite(n) ? n : null; }
async function postJSON(url, payload) {
const res = await fetch(url, { method: "POST", headers: { "X-Inout-Options": "1", "Content-Type": "application/json" },
body: payload === undefined ? "{}" : JSON.stringify(payload) });
let out = {};
try { out = await res.json(); } catch (_) {}
return { ok: res.ok && out.ok !== false, message: out.message || out.detail || (res.ok ? "" : "HTTP " + res.status) };
}
async function act(url, payload) {
const r = await postJSON(url, payload);
if (r.ok) { changed = true; await load(); }
say(r.message || (r.ok ? "저장했습니다." : "저장하지 못했습니다."), !r.ok);
return r.ok;
}
body.addEventListener("input", function (e) {
const inp = e.target;
if (inp.id === "io-prod-search") {
const q = inp.value.trim().toLowerCase();
let shown = 0;
body.querySelectorAll(".io-prod-table tbody tr").forEach(function (tr) {
const hit = !q || tr.dataset.search.indexOf(q) >= 0;
tr.hidden = !hit;
if (hit) shown++;
});
const cnt = body.querySelector("#io-prod-count");
if (cnt) cnt.dataset.base = cnt.dataset.base || cnt.textContent;
if (cnt) cnt.textContent = q ? shown + "개 찾음" : cnt.dataset.base;
return;
}
if (!inp.dataset || !inp.dataset.key) return;
const tr = inp.closest("tr");
const w = dec(tr.querySelector('[data-key="weight_g"]').value), pct = dec(tr.querySelector('[data-key="silver_pct"]').value);
const ag = tr.querySelector(".io-ag");
if (ag) ag.textContent = w !== null && pct !== null ? (Math.round(w * pct / 100 * 10000) / 10000).toLocaleString("ko-KR", { maximumFractionDigits: 4 }) : "-";
tr.classList.toggle("is-dirty", Array.from(tr.querySelectorAll("input[data-key]")).some(function (i) { return i.value.trim() !== i.defaultValue.trim(); }));
paintDirty();
});
body.addEventListener("click", async function (e) {
const t = e.target;
if (t.id === "io-prod-import") {
if (dirtyRows().length && !(await confirmMsg("저장 안 한 변경이 있습니다. 버리고 불러올까요?"))) return;
t.disabled = true;
say("코드표에서 단품을 불러오는 중…");
try { await act("/inout/settings/products/import"); } finally { t.disabled = false; }
} else if (t.closest("#io-prod-save")) {
const rows = dirtyRows().map(function (tr) {
const v = function (k) { return tr.querySelector('[data-key="' + k + '"]').value.trim(); };
return { code: tr.dataset.code, unit_price: v("unit_price"), weight_g: v("weight_g"), silver_pct: v("silver_pct") };
});
if (rows.length) await act("/inout/settings/products/save", { rows: rows });
} else if (t.dataset && t.dataset.exclude) {
if (await confirmMsg(t.dataset.exclude + " 를 상품 정보에서 지울까요? 다음 불러오기에서도 빠집니다(지난 발주서는 그대로)."))
await act("/inout/settings/products/" + encodeURIComponent(t.dataset.exclude) + "/exclude");
} else if (t.dataset && t.dataset.restore) {
await act("/inout/settings/products/" + encodeURIComponent(t.dataset.restore) + "/restore");
}
});
// 저장 안 한 상품 정보가 있으면 닫기 전에 묻는다(✕·취소·Esc)
dlg.addEventListener("cancel", function (e) {
if (dirtyRows().length) { e.preventDefault(); confirmMsg("저장 안 한 상품 정보 변경이 있습니다. 닫을까요?").then(function (ok) { if (ok) dlg.close(); }); }
});
dlg.addEventListener("click", function (e) {
if (e.target.closest("[data-close]") && dirtyRows().length) {
e.stopImmediatePropagation();
confirmMsg("저장 안 한 상품 정보 변경이 있습니다. 닫을까요?").then(function (ok) { if (ok) dlg.close(); });
}
}, true);
if (btn.dataset.open === "1") open();
}