feat(inout): 박스 입수·파렛트 계산·상품 그룹 탭·달력 다시 그리기 줄임

- 옵션 상품 그룹을 별도 탭으로, 상품 정보 제목 행 가운데·굵게·110%
- 상품 정보에 통 수량(박스)·뚜껑 수량(박스)(마이그레이션 007, 뚜껑 없으면 빈칸)
- 새 발주서: 줄마다 통·뚜껑 박스 수와 공배수 힌트, 합계 박스 → 파렛트(30박스) 계산
  (화면 계산만, 발주 메일은 그대로)
- 메뉴를 옮겨도 달력은 sessionStorage 에서 바로 복원, 서버 값이 바뀔 때만 다시 그림

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 15:13:47 +09:00
parent 16515e9095
commit cc68d5be67
16 changed files with 315 additions and 45 deletions
+21 -3
View File
@@ -126,7 +126,7 @@
.io-factory-who { display: block; font-size: 12px; color: var(--color-midtone-gray); margin-top: 2px; }
/* 옵션 팝업 */
.io-dlg { width: min(1180px, calc(100vw - 40px)); max-height: min(760px, calc(100vh - 40px)); padding: 0; border: 1px solid var(--color-subtle-ash);
.io-dlg { width: min(1440px, calc(100vw - 40px)); max-height: min(760px, calc(100vh - 40px)); padding: 0; border: 1px solid var(--color-subtle-ash);
border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, .2); color: var(--color-rich-black); overflow: hidden; }
.io-dlg[open] { display: flex; flex-direction: column; }
.io-dlg:focus { outline: none; }
@@ -411,8 +411,6 @@
.io-swatch.is-none { background: #fff !important; border-style: dashed; border-color: #b9bdc3; }
.io-color { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.io-color .io-color-select { width: auto; min-width: 96px; }
.io-groups { margin: 12px 20px 0; border: 1px solid #e6e8eb; border-radius: 10px; padding: 8px 10px; background: #fbfbfc; }
.io-groups > summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: 2px 0 6px; }
.io-group-table col.w-gname { width: auto; }
.io-group-table col.w-num { width: 120px; }
.io-group-table col.w-color { width: 170px; }
@@ -427,3 +425,23 @@
.io-prod-table tr.is-grouped .io-group-val { display: inline-flex; }
.io-prod-table tr.is-grouped .io-group-val.io-r { display: block; padding-right: 9px; font-variant-numeric: tabular-nums; }
.io-prod-table tr.is-grouped td:has(> .io-group-val) { background: #f6f8fb; }
/* ── 옵션 → 상품 정보: 제목 행 가운데·110%·굵게, 통·뚜껑 박스 입수 열(2026-10-21, 007). 그룹은 따로 "상품 그룹" 탭 ── */
.io-prod-table thead th, .io-prod-table thead th.io-r { text-align: center; font-size: 13.2px; /* 예전 제목 12px × 110% */ font-weight: 700; color: var(--color-rich-black, #1d1d1f); }
.io-prod-table col.w-box { width: 96px; }
.io-prod-table col.w-num { width: 108px; }
.io-prod-table col.w-group { width: 120px; }
.io-prod-table col.w-color { width: 140px; }
.io-dlg-pane[data-pane="groups"] .io-group-table { margin-top: 12px; }
/* ── 새 발주서: 통·뚜껑 박스·파렛트(2026-10-21, 007) — 화면 계산만 ── */
.io-lines .io-col-box { min-width: 190px; white-space: normal !important; font-size: 12.5px; }
.io-box-main b { font-variant-numeric: tabular-nums; }
.io-box-hint { margin-top: 2px; font-size: 11.5px; color: var(--color-midtone-gray, #666); display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.io-box-ok { color: #1e7a34; font-weight: 600; }
.io-box-pick { border: 1px solid #cfe0fb; background: #f0f6ff; color: #1d4f91; border-radius: 6px; padding: 0 6px; height: 20px; font-size: 11.5px; cursor: pointer; }
.io-box-pick:hover { background: #dce9ff; }
.io-pallet { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; font-size: 13px; }
.io-pallet b { font-variant-numeric: tabular-nums; }
.io-pallet-main { font-size: 14px; font-weight: 600; }
.io-pallet-main b { font-size: 16px; color: #1d4f91; }
+81 -8
View File
@@ -52,8 +52,41 @@
const totalLines = document.getElementById("io-total-lines");
const totalAmount = document.getElementById("io-total-amount"), noPrice = document.getElementById("io-total-noprice");
// 박스·파렛트(2026-10-21, 007) — 통·뚜껑 박스 입수(상품 정보)로 줄마다 박스 수(올림), 합계 → 파렛트(1파렛트 = data-pallet-boxes, 올림).
// 힌트 = 통·뚜껑 입수의 최소공배수(둘 다 박스가 꽉 차는 수량 단위)와 지금 수량에 가까운 그 배수(누르면 수량 칸에 넣음).
const palletBoxes = parseInt(form.dataset.palletBoxes || "0", 10);
const pallet = document.getElementById("io-pallet");
const gcd = function (a, b) { while (b) { const t = a % b; a = b; b = t; } return a; };
const lcm = function (a, b) { return a / gcd(a, b) * b; };
function boxCell(tr, n, has) {
const cell = tr.querySelector(".io-box");
const body = parseInt(tr.dataset.bodyBox || "0", 10) || 0, lid = parseInt(tr.dataset.lidBox || "0", 10) || 0;
const out = { body: 0, lid: 0, unset: has && !body };
if (!cell) return out;
if (!has) { cell.innerHTML = "-"; return out; }
if (!body) { cell.innerHTML = '<span class="erp-muted" title="옵션 → 상품 정보에서 통 수량(박스)을 넣으면 계산합니다">박스 입수 미설정</span>'; return out; }
out.body = n ? Math.ceil(n / body) : 0;
out.lid = n && lid ? Math.ceil(n / lid) : 0;
const unit = lid ? lcm(body, lid) : body; // 통·뚜껑이 모두 꽉 차는 수량 단위
let html = '<div class="io-box-main">통 <b>' + fmt(out.body) + "</b>박스" +
(lid ? ' · 뚜껑 <b>' + fmt(out.lid) + "</b>박스" : ' · <span class="erp-muted">뚜껑 없음</span>') + "</div>";
const per = "통 " + fmt(body) + "개/박스" + (lid ? " · 뚜껑 " + fmt(lid) + "개/박스" : "");
let hint;
if (n && n % unit === 0) {
hint = '<span class="io-box-ok">✓ ' + (lid ? "통·뚜껑 박스가 모두 꽉 찹니다" : "박스가 꽉 찹니다") + "</span>";
} else {
const lo = Math.floor(n / unit) * unit, hi = (Math.floor(n / unit) + 1) * unit;
const picks = [lo, hi].filter(function (v) { return v > 0; }).map(function (v) {
return '<button type="button" class="io-box-pick" data-qty="' + v + '" title="수량을 ' + fmt(v) + '개로">' + fmt(v) + "</button>";
}).join("");
hint = "<span>" + (lid ? "공배수" : "박스 단위") + " <b>" + fmt(unit) + "</b>개" + (picks ? " ·" : "") + "</span>" + picks;
}
cell.innerHTML = html + '<div class="io-box-hint" title="' + per + '">' + hint + "</div>";
return out;
}
function renumber() {
let q = 0, k = 0, amount = 0, missing = 0;
let bodyBoxes = 0, lidBoxes = 0, unset = 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);
@@ -63,7 +96,16 @@
// 금액 = 수량 × 단가(상품 정보 단가, 이미 있던 품목은 발주 당시 단가) — 표시만, 저장은 서버가 단가 사본으로
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; }
const bx = boxCell(tr, n, has);
bodyBoxes += bx.body; lidBoxes += bx.lid; if (bx.unset) unset++;
});
if (pallet && palletBoxes > 0) {
const all = bodyBoxes + lidBoxes, pallets = Math.ceil(all / palletBoxes), last = all % palletBoxes;
const set = function (key, v) { pallet.querySelector('[data-k="' + key + '"]').textContent = v; };
set("body", fmt(bodyBoxes)); set("lid", fmt(lidBoxes)); set("boxes", fmt(all)); set("pallets", fmt(pallets));
set("note", "1파렛트 = " + palletBoxes + "박스" + (all && last ? " · 마지막 파렛트 " + last + "박스(" + (palletBoxes - last) + "박스 더 실을 수 있음)" : "") +
(unset ? " · 박스 입수 미설정 " + unset + "종 제외" : ""));
}
totalQty.textContent = fmt(q);
totalLines.textContent = fmt(k);
if (totalAmount) totalAmount.textContent = (Math.round(amount * 100) / 100).toLocaleString("ko-KR");
@@ -90,6 +132,14 @@
});
body.addEventListener("input", renumber); // 수량을 바꾸거나 제품 글을 고치면(고른 것 풀림) 다시 셈
body.addEventListener("io-chosen", renumber); // 검색 목록에서 제품을 고르면
body.addEventListener("click", function (e) { // 공배수 힌트 숫자 = 그 수량으로
const pick = e.target.closest(".io-box-pick");
if (!pick) return;
const qty = pick.closest(".io-line").querySelector(".io-qty");
qty.value = Number(pick.dataset.qty).toLocaleString("ko-KR");
renumber();
qty.focus();
});
body.querySelectorAll(".io-item-search").forEach(wireSearch);
if (!body.querySelector(".io-line")) { addLine(false); addLine(false); addLine(false); }
renumber();
@@ -174,8 +224,9 @@
if (!it) return;
codeEl.value = it.code;
const row = input.closest("tr");
if (row) { // 단가(상품 정보) — 금액 계산용
if (row) { // 단가(상품 정보) — 금액 계산용, 박스 입수(007) — 박스·파렛트 계산용
row.dataset.price = it.price === null || it.price === undefined ? "" : String(it.price);
if ("bodyBox" in row.dataset) { row.dataset.bodyBox = it.body_per_box || ""; row.dataset.lidBox = it.lid_per_box || ""; }
const pc = row.querySelector(".io-price");
if (pc) pc.textContent = it.unit_price || "-";
}
@@ -452,6 +503,7 @@
const v = function (k) { return tr.querySelector('[data-key="' + k + '"]').value.trim(); };
const row = { code: tr.dataset.code, unit_price: v("unit_price"), weight_g: v("weight_g"), silver_pct: v("silver_pct") };
if (tr.querySelector('[data-key="group_id"]')) { row.group_id = v("group_id"); row.color = v("color"); } // 006
if (tr.querySelector('[data-key="body_per_box"]')) { row.body_per_box = v("body_per_box"); row.lid_per_box = v("lid_per_box"); } // 007
return row;
});
if (rows.length) await act("/inout/settings/products/save", { rows: rows });
@@ -745,9 +797,23 @@
const calEl = document.getElementById("io-cal");
if (calEl) initCalendar(calEl);
// 화면을 옮길 때마다 달력이 새로 그려지지 않게(2026-10-21) — 마지막으로 그린 달력(달·API 응답·칸 HTML)을 sessionStorage 에 두고,
// _calendar.html 의 인라인 스크립트가 페이지를 그리기 전에 그대로 붙인다. 여기서는 서버 값을 다시 받아 **바뀐 게 있을 때만** 다시 그린다.
function initCalendar(cal) {
const CAL_KEY = "io_cal_v1"; // 함수 안에 — 위에서 initCalendar 를 먼저 부르므로 바깥 const 는 아직 못 읽는다(TDZ)
const daysEl = cal.querySelector(".io-cal-days"), titleEl = cal.querySelector(".io-cal-title");
let month = cal.dataset.month, data = null, pop = null, seq = 0;
let month = cal.dataset.month, data = null, pop = null, seq = 0, shown = "";
try {
const saved = JSON.parse(sessionStorage.getItem(CAL_KEY) || "null");
if (saved && saved.month && saved.json && cal.dataset.restored === "1") { // 인라인 스크립트가 이미 붙여 놓음
month = saved.month;
data = JSON.parse(saved.json);
shown = saved.json;
}
} catch (_) {}
function remember() {
try { sessionStorage.setItem(CAL_KEY, JSON.stringify({ month: month, json: shown, title: titleEl.textContent, html: daysEl.innerHTML })); } catch (_) {}
}
const pad = function (n) { return String(n).padStart(2, "0"); };
const isoOf = function (d) { return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate()); };
const escH = function (v) { const d = document.createElement("div"); d.textContent = v == null ? "" : String(v); return d.innerHTML; };
@@ -758,22 +824,29 @@
return d.getFullYear() + "-" + pad(d.getMonth() + 1);
}
function closePop() { if (pop) { pop.remove(); pop = null; } }
async function load() {
closePop();
// quiet = 이미 그려진 달력을 확인만(화면 이동 직후) — 흐리게 하지 않고, 받은 값이 같으면 그대로 둔다
async function load(quiet) {
if (!quiet) closePop();
const p = month.split("-").map(Number);
titleEl.textContent = p[0] + "년 " + p[1] + "월";
const mine = ++seq; // 빠르게 넘기면 늦게 온 앞 달 응답이 덮지 않게
cal.classList.add("is-loading");
if (!quiet) cal.classList.add("is-loading");
try {
const res = await fetch("/inout/api/calendar?month=" + encodeURIComponent(month));
if (!res.ok) throw new Error("HTTP " + res.status);
const got = await res.json();
const text = await res.text();
if (mine !== seq) return;
data = got;
if (text === shown && data) return; // 바뀐 것 없음 — 다시 그리지 않는다
data = JSON.parse(text);
shown = text;
closePop();
render();
remember();
} catch (_) {
if (mine !== seq) return;
if (quiet && data) return; // 확인만 실패 — 붙여 둔 달력 그대로
data = null;
shown = "";
daysEl.innerHTML = '<p class="io-cal-err">달력을 불러오지 못했습니다.</p>';
} finally {
if (mine === seq) cal.classList.remove("is-loading");
@@ -851,6 +924,6 @@
});
document.addEventListener("keydown", function (e) { if (e.key === "Escape") closePop(); });
window.addEventListener("resize", closePop);
load();
load(!!data);
}
})();