feat(inout): 입출고 관리 모듈 — 공장 제작 발주 · 물류 입고 · 미입고/초과 관리

- 새 모듈 app/modules/inout(/inout/, 권한키 inout) + 새 DB inout_db(사용자 승인, scripts/sql/inout_db_init.sql — 멱등).
- 발주 담당이 공장에 발주서(PO-YYMMDD-NN, 제품 = itemcode_db 단품만 — 검색 + 저장 때 서버 재확인),
  입고 담당이 물류에 들어온 수량을 여러 번 나눠 입력 → 품목별 발주·입고·미입고, 진행률, 입고 예정일 지연.
- 미입고 현황: 제품별 합계 · 발주별(예정일 순) · 초과 입고. 잔량 종결/풀기, 입고 없는 발주 취소, 입고 기록 지우기.
- 초과 입고: 확인 화면(409, 입력 유지) 후 [초과 입고로 저장] — 트랜잭션 안에서 발주서 잠그고 판단, Enter 는 일반 저장.
- 옵션(ERP 관리자): 공장 목록, 발주 담당·입고 담당 지정(inout_roles). 관리자는 둘 다.
- 상태는 저장하지 않고 누적 입고로 계산(store.order_status). 이카운트 "발주 대비 미입고"·Odoo 분할 입고/종결 참고.
- 테스트: 순수 로직, 실제 PostgreSQL(앱 계정 inout_app — 권한 포함), 실제 앱 화면 흐름(권한별). 문서 INOUT_MODULE.md 등.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 15:21:05 +09:00
parent 80b7becd45
commit 6f3bffd840
26 changed files with 2712 additions and 0 deletions
+124
View File
@@ -0,0 +1,124 @@
/* 입출고 관리(inout) — ERP 공용(erp.css·erp-shell.css) 위에 이 화면만의 것 */
/* 공용 .erp-page 는 width:100% + 안쪽 여백(content-box)이라 표가 넓으면 48px 넘친다 — 이 화면에서만 테두리 기준으로 */
.erp-page:has(> .io) { box-sizing: border-box; }
.io { display: flex; flex-direction: column; gap: 14px; min-width: 0; } /* 넓은 표는 안에서 가로 스크롤(페이지가 화면보다 넓어지지 않게) */
.io-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.io-nav-gap { flex: 1 1 auto; }
.io-roles { display: inline-flex; gap: 4px; align-items: center; }
.io-flash { margin: 0; padding: 10px 14px; border-radius: 8px; background: #eef6ff; color: #0b4a8b; font-size: 13px; border: 1px solid #cfe3fb; }
.io-error { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; background: #fbe9e6; color: #a1261b; border: 1px solid #efc6bf; font-size: 13px; }
.io > .io-error { margin: 0; }
.io-hint { color: #a1261b; font-size: 12px; }
.io-help { margin: 0; padding: 12px 20px 0; font-size: 12.5px; color: var(--color-midtone-gray); line-height: 1.6; }
.io-foot { margin: 0; }
/* 거르기 줄 */
.io-filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.io-filter .erp-input, .io-filter .erp-select { width: auto; }
.io-search { min-width: 220px; }
.io-filter input[type="date"] { width: 150px; }
.io-date { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--color-midtone-gray); }
.io-seg { display: inline-flex; padding: 2px; border: 1px solid var(--color-subtle-ash); border-radius: 10px; background: #fff; }
.io-seg-btn { padding: 5px 12px; border-radius: 8px; font-size: 12.5px; color: var(--color-rich-black); text-decoration: none; white-space: nowrap; }
.io-seg-btn:hover { background: var(--color-ghost-gray); }
.io-seg-btn.is-active, .io-seg-btn.is-active:hover { background: var(--color-deep-black); color: #fff; }
/* 표 */
.io-table td, .io-table th { white-space: nowrap; }
.io-table td.io-items { white-space: normal; min-width: 160px; }
.io-num { text-align: right !important; font-variant-numeric: tabular-nums; }
.io-code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.io-order-no { font-weight: 600; color: var(--color-rich-black); text-decoration: none; font-family: ui-monospace, Consolas, monospace; }
.io-order-no:hover { text-decoration: underline; }
.io-row-link { cursor: pointer; }
.io-row-link.is-late td:first-child { box-shadow: inset 3px 0 0 #d93025; }
.io-remaining { color: #b45309; font-weight: 600; }
.io-over, .io-over-sub { color: #d93025; font-weight: 600; }
.io-over-sub { font-size: 11px; }
.io-late { color: #d93025; font-weight: 600; font-size: 12px; }
.io-block { overflow: visible; }
/* 상태 배지 */
.io-badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.io-st-open, .io-st-none { background: #eef0f2; color: #3d4148; }
.io-st-partial { background: #fff4e0; color: #9a5b00; border-color: #f6dcae; }
.io-st-done { background: #e6f8e9; color: #1e7a34; border-color: #c2efc8; }
.io-st-over { background: #fbe9e6; color: #b3261e; border-color: #efc6bf; }
.io-st-closed { background: #f4f4f5; color: #6b6f76; border-color: #dcdde0; }
.io-st-cancelled { background: #fff; color: #9aa0a6; border-color: #dcdde0; text-decoration: line-through; }
/* 진행률 */
.io-progress { display: inline-block; width: 80px; height: 6px; border-radius: 999px; background: #eceef1; overflow: hidden; vertical-align: middle; }
.io-progress-bar { display: block; height: 100%; background: #1e8e3e; border-radius: inherit; }
.io-progress-bar.is-over { background: #d93025; }
.io-progress-pct { margin-left: 6px; font-size: 12px; color: var(--color-midtone-gray); font-variant-numeric: tabular-nums; }
/* 요약 숫자 */
.io-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.io-kpi-remaining .erp-summary-value { color: #b45309; }
.io-kpi-over .erp-summary-value { color: #d93025; }
/* 발주서 머리 */
.io-head { padding: 16px 20px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 20px; overflow: visible; }
.io-head-title { display: flex; align-items: center; gap: 10px; }
.io-head-title h2 { margin: 0; font-size: 18px; font-family: ui-monospace, Consolas, monospace; }
.io-head-meta { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 12px 0 0; }
.io-head-meta dt { font-size: 11.5px; color: var(--color-midtone-gray); }
.io-head-meta dd { margin: 2px 0 0; font-size: 13.5px; }
.io-head-meta .io-wide { flex-basis: 100%; }
.io-kpis-head { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); align-self: start; min-width: 320px; }
.io-head-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 12px; border-top: 1px solid var(--color-subtle-ash); }
.io-head-actions form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.io-close-reason { width: 200px; }
/* 입고 입력 */
.io-col-no { width: 36px; color: var(--color-midtone-gray); }
.io-col-recv { width: 130px; background: #f6fbf7; }
.io-table thead th.io-col-recv { background: #eaf6ee; color: #1e7a34; font-weight: 600; }
.io-qty { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.io-receipt-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--color-subtle-ash); background: #fafbfc; }
.io-receipt-bar .erp-field input { min-width: 150px; }
.io-grow { flex: 1 1 260px; }
.io-default-submit { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.io-over-box { margin: 12px 20px 0; padding: 12px 16px; border-radius: 8px; background: #fbe9e6; border: 1px solid #efc6bf; color: #7a1d14; font-size: 13px; }
.io-over-box ul { margin: 6px 0 10px; padding-left: 18px; }
.io-chip { display: inline-block; margin: 2px 6px 2px 0; padding: 1px 8px; border-radius: 6px; background: var(--color-ghost-gray); font-size: 12px; white-space: nowrap; }
/* 발주서 폼 */
.io-order-form { overflow: visible; }
.io-lines .io-col-qty { width: 130px; }
.io-lines .io-col-del { width: 48px; text-align: center; }
.io-lines tfoot td { padding: 10px 16px; border-top: 1px solid var(--color-subtle-ash); }
.io-item-cell { position: relative; min-width: 320px; }
.io-item-search { width: 100%; }
.io-item-search.is-invalid { border-color: #d93025; box-shadow: 0 0 0 3px rgba(217, 48, 37, .12); }
.io-item-search[readonly] { background: var(--color-ghost-gray); }
.io-total { margin-left: 12px; }
.io-form-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--color-subtle-ash); }
/* 검색 드롭다운 — 표 가로 스크롤 상자에 잘리지 않게 화면 기준(fixed), 위치는 inout.js 가 입력칸에 맞춤 */
.io-suggest { position: fixed; z-index: 1000; max-height: 280px; overflow-y: auto;
background: #fff; border: 1px solid var(--color-subtle-ash); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }
.io-suggest-item { padding: 7px 12px; font-size: 13px; cursor: pointer; white-space: normal; }
.io-suggest-item:hover, .io-suggest-item.is-active { background: #eef6ff; }
.io-suggest-empty { padding: 10px 12px; font-size: 12.5px; color: var(--color-midtone-gray); white-space: normal; }
/* 옵션 */
.io-settings { display: flex; flex-direction: column; gap: 14px; }
.io-col-check { width: 90px; text-align: center !important; }
.io-factories { padding: 6px 12px 12px; }
.io-factory-row { display: grid; grid-template-columns: minmax(140px, 1.2fr) minmax(140px, 1.2fr) minmax(120px, 1.5fr) 70px 50px 60px auto;
gap: 8px; align-items: center; padding: 6px 8px; margin: 0; border-bottom: 1px solid var(--color-subtle-ash); }
.io-factory-head { font-size: 12px; color: var(--color-midtone-gray); font-weight: 500; }
.io-factory-row .erp-input { width: 100%; min-width: 0; }
.io-factory-row.io-inactive .erp-input { color: var(--color-midtone-gray); background: var(--color-ghost-gray); }
.io-new-factory { border-bottom: 0; background: #fafbfc; border-radius: 8px; }
.io-factory-btns { display: inline-flex; gap: 6px; justify-content: flex-end; }
.io-check { display: inline-flex; justify-content: center; }
@media (max-width: 900px) {
.io-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.io-head { grid-template-columns: 1fr; }
.io-kpis-head { min-width: 0; }
.io-factory-row { grid-template-columns: 1fr 1fr; }
.io-factory-head { display: none; }
}
+227
View File
@@ -0,0 +1,227 @@
/* 입출고 관리(inout) 화면 스크립트 — 화면 전환·저장은 서버(폼)가 하고, 여기는 입력을 돕기만 한다.
· 목록 줄 누르기 = 발주서로
· 발주서 폼: 제품 줄 추가·지우기·번호·합계, 코드표 단품 검색(GET /inout/api/items?q=) 드롭다운
· 발주서 화면: [남은 수량 모두 채우기], 이번 입고 합계
· data-erp-confirm-btn: 버튼별 확인(formaction 이 있는 버튼 — 공용 data-erp-confirm 은 form.submit() 이라 누른 버튼이 사라짐) */
(function () {
"use strict";
function confirmMsg(msg) {
return window.erpConfirm ? window.erpConfirm(msg) : Promise.resolve(window.confirm(msg));
}
function alertMsg(msg) {
return window.erpAlert ? window.erpAlert(msg) : Promise.resolve(window.alert(msg));
}
function num(v) {
const n = parseInt(String(v || "").replace(/[,\s]/g, ""), 10);
return Number.isFinite(n) && n > 0 ? n : 0;
}
function fmt(n) { return n.toLocaleString("ko-KR"); }
// ── 목록 줄 누르기 → 발주서 ──
document.addEventListener("click", function (e) {
const row = e.target.closest(".io-row-link");
if (!row || e.target.closest("a, button, input, select, label")) return;
if (window.getSelection && String(window.getSelection())) return; // 글자 고르는 중
location.href = row.dataset.href;
});
// ── 버튼별 확인 ──
document.addEventListener("click", function (e) {
const btn = e.target.closest("[data-erp-confirm-btn]");
if (!btn || btn.dataset.confirmed === "1") return;
e.preventDefault();
confirmMsg(btn.dataset.erpConfirmBtn).then(function (ok) {
if (!ok) return;
btn.dataset.confirmed = "1";
if (btn.form.requestSubmit) btn.form.requestSubmit(btn); else btn.click();
});
});
// ── 발주서 폼 ──
const form = document.getElementById("io-order-form");
if (form) initOrderForm(form);
function initOrderForm(form) {
const body = form.querySelector("#io-lines tbody");
const tpl = document.getElementById("io-line-tpl");
const totalQty = document.getElementById("io-total-qty");
const totalLines = document.getElementById("io-total-lines");
function renumber() {
let q = 0, k = 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; }
});
totalQty.textContent = fmt(q);
totalLines.textContent = fmt(k);
}
function addLine(focus) {
const tr = tpl.content.firstElementChild.cloneNode(true);
body.appendChild(tr);
wireSearch(tr.querySelector(".io-item-search"));
renumber();
if (focus) tr.querySelector(".io-item-search").focus();
return tr;
}
form.querySelector("#io-add-line").addEventListener("click", function () { addLine(true); });
body.addEventListener("click", function (e) {
const del = e.target.closest(".io-del");
if (!del) return;
const tr = del.closest(".io-line");
const search = tr.querySelector(".io-item-search");
if (search && search._ioBox) search._ioBox.remove(); // body 에 붙은 드롭다운도 함께
tr.remove();
if (!body.querySelector(".io-line")) addLine(false);
renumber();
});
body.addEventListener("input", renumber); // 수량을 바꾸거나 제품 글을 고치면(고른 것 풀림) 다시 셈
body.addEventListener("io-chosen", renumber); // 검색 목록에서 제품을 고르면
body.querySelectorAll(".io-item-search").forEach(wireSearch);
if (!body.querySelector(".io-line")) { addLine(false); addLine(false); addLine(false); }
renumber();
form.addEventListener("submit", function (e) {
// 검색 글만 있고 목록에서 고르지 않은 줄, 같은 제품 두 줄 — 서버도 막지만 여기서 먼저 알려 준다
const codes = [];
let bad = null;
body.querySelectorAll(".io-line").forEach(function (tr) {
const code = tr.querySelector('input[name="item_code"]').value;
const text = tr.querySelector(".io-item-search").value.trim();
if (!code && text && !bad) bad = { tr: tr, msg: "'" + text + "' — 검색 목록에서 제품을 골라 주세요." };
if (code && codes.indexOf(code) >= 0 && !bad) bad = { tr: tr, msg: code + " — 같은 제품이 두 줄에 있습니다. 한 줄로 합쳐 주세요." };
if (code) codes.push(code);
});
if (bad) {
e.preventDefault();
bad.tr.querySelector(".io-item-search").classList.add("is-invalid");
alertMsg(bad.msg).then(function () { bad.tr.querySelector(".io-item-search").focus(); });
}
});
}
// 코드표 단품 검색 드롭다운 — 고르면 숨은 칸(코드·이름)을 채우고 수량 칸으로. 글을 다시 고치면 고른 것을 지운다.
function wireSearch(input) {
if (!input || input.readOnly || input.dataset.wired) return;
input.dataset.wired = "1";
const cell = input.closest(".io-item-cell");
const codeEl = cell.querySelector('input[name="item_code"]');
const nameEl = cell.querySelector('input[name="item_name"]');
const box = document.createElement("div");
box.className = "io-suggest";
box.setAttribute("role", "listbox");
box.hidden = true;
document.body.appendChild(box); // 표 가로 스크롤 상자 밖(fixed) — 아래 줄에서도 잘리지 않게
input._ioBox = box;
let timer = 0, seq = 0, items = [], active = -1;
function place() {
const r = input.getBoundingClientRect();
const below = window.innerHeight - r.bottom;
box.style.left = r.left + "px";
box.style.width = Math.max(r.width, 320) + "px";
if (below < 200 && r.top > below) { box.style.top = ""; box.style.bottom = (window.innerHeight - r.top + 2) + "px"; }
else { box.style.bottom = ""; box.style.top = (r.bottom + 2) + "px"; }
}
window.addEventListener("resize", function () { if (!box.hidden) place(); });
document.addEventListener("scroll", function () { if (!box.hidden) place(); }, true);
function close() { box.hidden = true; active = -1; input.setAttribute("aria-expanded", "false"); }
function paint() {
box.innerHTML = "";
if (!items.length) {
const empty = document.createElement("div");
empty.className = "io-suggest-empty";
empty.textContent = box.dataset.message || "맞는 단품이 없습니다.";
box.appendChild(empty);
}
items.forEach(function (it, i) {
const opt = document.createElement("div");
opt.className = "io-suggest-item" + (i === active ? " is-active" : "");
opt.setAttribute("role", "option");
const c = document.createElement("span");
c.className = "io-code";
c.textContent = it.code;
opt.appendChild(c);
opt.appendChild(document.createTextNode(" " + it.name));
opt.addEventListener("mousedown", function (e) { e.preventDefault(); choose(i); });
box.appendChild(opt);
});
box.hidden = false;
place();
input.setAttribute("aria-expanded", "true");
}
function choose(i) {
const it = items[i];
if (!it) return;
codeEl.value = it.code;
nameEl.value = it.name;
input.value = it.code + " · " + it.name;
input.classList.remove("is-invalid");
close();
const qty = input.closest("tr").querySelector(".io-qty");
if (qty) qty.focus();
input.dispatchEvent(new Event("io-chosen", { bubbles: true }));
}
async function search(q) {
const my = ++seq;
try {
const res = await fetch("/inout/api/items?q=" + encodeURIComponent(q), { headers: { Accept: "application/json" } });
const data = await res.json();
if (my !== seq) return;
items = data.items || [];
box.dataset.message = data.enabled === false ? (data.message || "코드표가 연결되지 않았습니다.") : "";
active = items.length ? 0 : -1;
paint();
} catch (_) {
if (my !== seq) return;
items = [];
box.dataset.message = "검색하지 못했습니다. 잠시 뒤 다시 입력하세요.";
paint();
}
}
input.setAttribute("aria-autocomplete", "list");
input.addEventListener("input", function () {
codeEl.value = ""; // 글을 고치면 고른 제품은 풀린다(다시 골라야 저장)
nameEl.value = "";
clearTimeout(timer);
const q = input.value.trim();
if (!q) { close(); return; }
timer = setTimeout(function () { search(q); }, 200);
});
input.addEventListener("keydown", function (e) {
if (box.hidden) return;
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
e.preventDefault();
if (!items.length) return;
active = (active + (e.key === "ArrowDown" ? 1 : items.length - 1)) % items.length;
paint();
} else if (e.key === "Enter") {
e.preventDefault(); // 고르기만 — 폼 저장 아님
choose(active < 0 ? 0 : active);
} else if (e.key === "Escape") {
close();
}
});
input.addEventListener("blur", function () { setTimeout(close, 120); });
}
// ── 발주서 화면: 입고 입력 ──
const recvForm = document.getElementById("io-receipt-form");
if (recvForm) {
const total = document.getElementById("io-recv-total");
const inputs = Array.from(recvForm.querySelectorAll(".io-recv"));
const paintTotal = function () {
const t = inputs.reduce(function (s, i) { return s + num(i.value); }, 0);
if (total) total.textContent = t ? "(" + fmt(t) + "개)" : "";
};
recvForm.addEventListener("input", paintTotal);
const fill = document.getElementById("io-fill-remaining");
if (fill) fill.addEventListener("click", function () {
inputs.forEach(function (i) { if (!i.value.trim() && num(i.dataset.remaining)) i.value = i.dataset.remaining; });
paintTotal();
});
paintTotal();
}
})();