feat(project): manual monthly sales target with weekly diff
Week target popup now has its own "month total" input at the top; the monthly target is saved as entered instead of being the sum of weeks. Bottom shows week sum and diff (month target - week sum), colored for remaining / over / even. Requests without `month` (stale cached JS) still fall back to the week sum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+23
-8
@@ -9231,8 +9231,9 @@
|
||||
node.classList.add("is-saved");
|
||||
}
|
||||
|
||||
// ── 주차별 매출 목표(020) — 매출 목표 칸을 누르면 그 달 주차 입력 창(body 에 붙음). 저장하면 주차 합계가 월 목표.
|
||||
// 관리자는 입력·저장, 보기만 하는 사람은 주차별 값 보기. 주차는 서버(store.month_weeks)가 정한다.
|
||||
// ── 주차별 매출 목표(020) — 매출 목표 칸을 누르면 그 달 입력 창(body 에 붙음). 월 목표는 맨 위에 직접 입력,
|
||||
// 아래에 주차별 목표, 맨 아래 주차 합계와 차이(월 목표 − 주차 합계). 주차 합계가 월 목표가 되지 않는다.
|
||||
// 관리자는 입력·저장, 보기만 하는 사람은 값 보기. 주차는 서버(store.month_weeks)가 정한다.
|
||||
const WEEKS = window.PJ_GOAL_WEEKS || null;
|
||||
let weekPop = null;
|
||||
function closeWeekPop() {
|
||||
@@ -9253,34 +9254,48 @@
|
||||
weekPop.className = "pj-goal-wkpop";
|
||||
weekPop.innerHTML = '<div class="pj-goal-wkpop-head">' + mo + "월 주차별 매출 목표" +
|
||||
(unit ? " <small>(" + escapeHtml(unit) + ")</small>" : "") + "</div>" +
|
||||
'<label class="pj-goal-wkpop-row pj-goal-wkpop-month"><span>' + mo + "월 전체 목표</span>" +
|
||||
'<input type="text" inputmode="decimal" autocomplete="off" data-month-total="1" value="' +
|
||||
escapeHtml((cell.tagName === "INPUT" ? cell.value : cell.textContent).trim()) + '"' +
|
||||
(edit ? "" : " readonly") + "></label>" +
|
||||
list.map(function (w) {
|
||||
return '<label class="pj-goal-wkpop-row"><span>' + w.n + "주차 <em>" + escapeHtml(w.label) + "</em>" +
|
||||
(w.days ? ' <i class="pj-goal-wkpop-days">' + w.days + "일</i>" : "") + "</span>" +
|
||||
'<input type="text" inputmode="decimal" autocomplete="off" data-start="' + w.start + '" value="' +
|
||||
escapeHtml(w.value || "") + '"' + (edit ? "" : " readonly") + "></label>";
|
||||
}).join("") +
|
||||
'<div class="pj-goal-wkpop-sum"><span>합계 = 월 목표</span><b></b></div>' +
|
||||
'<div class="pj-goal-wkpop-sum"><span>주차 합계</span><b data-sum="weeks"></b></div>' +
|
||||
'<div class="pj-goal-wkpop-sum pj-goal-wkpop-diff"><span>차이 <small>(월 목표 − 주차 합계)</small></span><b data-sum="diff"></b></div>' +
|
||||
(edit ? '<div class="pj-goal-wkpop-acts"><button type="button" class="pj-btn pj-btn-sm" data-act="cancel">취소</button>' +
|
||||
'<button type="button" class="pj-btn pj-btn-sm pj-btn-primary" data-act="save">저장</button></div>' : "");
|
||||
document.body.appendChild(weekPop);
|
||||
const r = cell.getBoundingClientRect(), vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight;
|
||||
weekPop.style.left = Math.max(8, Math.min(r.left, vw - weekPop.offsetWidth - 8)) + "px";
|
||||
weekPop.style.top = (r.bottom + 6 + weekPop.offsetHeight > vh ? Math.max(8, r.top - weekPop.offsetHeight - 6) : r.bottom + 6) + "px";
|
||||
const inputs = Array.from(weekPop.querySelectorAll("input"));
|
||||
const sumEl = weekPop.querySelector(".pj-goal-wkpop-sum b");
|
||||
const monthInput = weekPop.querySelector("input[data-month-total]");
|
||||
const inputs = Array.from(weekPop.querySelectorAll("input[data-start]"));
|
||||
const sumEl = weekPop.querySelector('[data-sum="weeks"]'), diffEl = weekPop.querySelector('[data-sum="diff"]');
|
||||
function paintSum() {
|
||||
let t = null;
|
||||
inputs.forEach(function (i) { const n = numOf(i); if (n != null) t = (t || 0) + n; });
|
||||
sumEl.textContent = t == null ? "—" : fmtNum(t);
|
||||
const total = numOf(monthInput);
|
||||
const d = total == null ? null : total - (t || 0);
|
||||
// 차이 + = 주차에 아직 못 나눈 금액, − = 주차 합계가 월 목표를 넘음, 0 = 딱 맞음
|
||||
diffEl.textContent = d == null ? "—" : (d > 0 ? "+" : "") + fmtNum(d);
|
||||
diffEl.classList.toggle("is-over", d != null && d < 0);
|
||||
diffEl.classList.toggle("is-left", d != null && d > 0);
|
||||
diffEl.classList.toggle("is-even", d != null && Math.abs(d) < 0.005);
|
||||
}
|
||||
inputs.forEach(function (i) { i.addEventListener("input", paintSum); });
|
||||
[monthInput].concat(inputs).forEach(function (i) { i.addEventListener("input", paintSum); });
|
||||
paintSum();
|
||||
async function save(btn) {
|
||||
const weeks = {};
|
||||
inputs.forEach(function (i) { weeks[i.dataset.start] = i.value; });
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const res = await api("PUT", "/project/api/goals/" + year + "/week-targets/" + mo, { weeks: weeks });
|
||||
const res = await api("PUT", "/project/api/goals/" + year + "/week-targets/" + mo,
|
||||
{ month: monthInput.value, weeks: weeks });
|
||||
list.forEach(function (w) { if (res.weeks && w.start in res.weeks) w.value = res.weeks[w.start]; });
|
||||
cell.value = res.label || "";
|
||||
recompute();
|
||||
@@ -9306,7 +9321,7 @@
|
||||
document.addEventListener("mousedown", onWeekDoc, true);
|
||||
document.addEventListener("keydown", onWeekKey, true);
|
||||
}, 0);
|
||||
if (edit && inputs.length) { inputs[0].focus(); inputs[0].select(); }
|
||||
if (edit) { monthInput.focus(); monthInput.select(); }
|
||||
}
|
||||
if (WEEKS) {
|
||||
table.addEventListener("click", function (e) {
|
||||
|
||||
Reference in New Issue
Block a user