Merge branch 'feat/week-target-month-manual'
This commit is contained in:
@@ -3090,7 +3090,7 @@ class ProjectStore:
|
||||
return {"sales_unit": head["sales_unit"] if head else "", "sales_target": vals.get(("sales", "target")),
|
||||
"sales_actual": vals.get(("sales", "actual")), "roas_target": vals.get(("roas", "target"))}
|
||||
|
||||
# ── 주차별 매출 목표(020) — 목표 표 매출 단위 그대로, 월 목표 = 그 달 주차 합계 ──
|
||||
# ── 주차별 매출 목표(020) — 목표 표 매출 단위 그대로, 월 목표는 따로 직접 입력(주차 합계와 다를 수 있음) ──
|
||||
def week_targets_enabled(self) -> bool:
|
||||
with self._pool.connection() as conn:
|
||||
return self._table_exists(conn, "goal_week_targets")
|
||||
@@ -3107,10 +3107,13 @@ class ProjectStore:
|
||||
return {r["week_start"].isoformat(): float(r["value"]) for r in rows}
|
||||
|
||||
def set_goal_week_targets(
|
||||
self, *, year: int, month: int, values: dict[date, float | None], updated_by: str = ""
|
||||
self, *, year: int, month: int, values: dict[date, float | None], month_value: float | None,
|
||||
updated_by: str = ""
|
||||
) -> float | None:
|
||||
"""그 달 주차별 목표 저장(None = 지움) → 그 달 주차 합계를 매출 목표(goal_metrics sales/target)로.
|
||||
주차가 모두 비면 월 목표도 지운다(월 목표 = 주차 합계). 합계를 돌려준다(없으면 None)."""
|
||||
"""그 달 주차별 목표 저장(None = 지움) + 월 매출 목표(goal_metrics sales/target)는 month_value 그대로
|
||||
(None = 지움). 월 목표는 주차 합계와 따로 — 차이는 화면이 계산한다. 그 달 주차 합계를 돌려준다(없으면 None)."""
|
||||
if month_value is not None and month_value < 0:
|
||||
raise ValueError("월 목표는 0 이상이어야 합니다.")
|
||||
m = store.validate_goal_month(month)
|
||||
periods = {a for a, _ in store.month_weeks(year, m)}
|
||||
if any(d not in periods for d in values):
|
||||
@@ -3139,7 +3142,7 @@ class ProjectStore:
|
||||
(year, m),
|
||||
).fetchone()
|
||||
total = float(row["total"]) if row["n"] else None
|
||||
if total is None:
|
||||
if month_value is None:
|
||||
conn.execute("DELETE FROM goal_metrics WHERE year=%s AND metric='sales' AND kind='target' AND month=%s",
|
||||
(year, m))
|
||||
else:
|
||||
@@ -3147,7 +3150,7 @@ class ProjectStore:
|
||||
"INSERT INTO goal_metrics (year, metric, kind, month, value, updated_by) "
|
||||
"VALUES (%s,'sales','target',%s,%s,%s) ON CONFLICT (year, metric, kind, month) DO UPDATE "
|
||||
"SET value = EXCLUDED.value, updated_by = EXCLUDED.updated_by, updated_at = now()",
|
||||
(year, m, total, who),
|
||||
(year, m, month_value, who),
|
||||
)
|
||||
return total
|
||||
|
||||
|
||||
@@ -2697,7 +2697,7 @@ def goals_page(request: Request, year: int) -> HTMLResponse:
|
||||
for area in board["areas"]:
|
||||
_goal_area_layout(area["rows"], this_month)
|
||||
_goal_label_spans(area["rows"])
|
||||
# 주차별 매출 목표(020) — 월 매출 목표 칸을 누르면 그 달 주차별 입력 창(합계 = 월 목표)
|
||||
# 주차별 매출 목표(020) — 월 매출 목표 칸을 누르면 그 달 월 목표·주차별 입력 창(월 목표는 직접 입력)
|
||||
week_targets = None
|
||||
if board and st.week_targets_enabled():
|
||||
saved = st.goal_week_targets(start=date(year, 1, 1), end=date(year, 12, 31))
|
||||
@@ -2739,15 +2739,23 @@ def goals_page(request: Request, year: int) -> HTMLResponse:
|
||||
|
||||
@router.put("/api/goals/{year}/week-targets/{month}")
|
||||
def api_set_goal_week_targets(request: Request, year: int, month: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
"""그 달 주차별 매출 목표 {weeks: {주차 시작일: 값|""}} — 합계가 그 달 매출 목표가 된다(관리자)."""
|
||||
"""그 달 주차별 매출 목표 {month: 월 목표|"", weeks: {주차 시작일: 값|""}} — 월 목표는 직접 입력(관리자).
|
||||
month 가 없으면(예전 화면) 주차 합계를 월 목표로."""
|
||||
user = _require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
raw = payload.get("weeks")
|
||||
if not isinstance(raw, dict) or len(raw) > 6:
|
||||
raise HTTPException(status_code=400, detail="weeks 가 올바르지 않습니다.")
|
||||
values = {_goal_call(store.validate_period_start, k): _goal_call(store.validate_goal_value, v) for k, v in raw.items()}
|
||||
total = _goal_call(st.set_goal_week_targets, year=year, month=month, values=values, updated_by=user["email"])
|
||||
return JSONResponse({"ok": True, "value": total, "label": _goal_label("sales", total),
|
||||
if "month" in payload:
|
||||
month_value = _goal_call(store.validate_goal_value, payload.get("month"))
|
||||
else:
|
||||
filled = [v for v in values.values() if v is not None]
|
||||
month_value = sum(filled) if filled else None
|
||||
week_total = _goal_call(st.set_goal_week_targets, year=year, month=month, values=values,
|
||||
month_value=month_value, updated_by=user["email"])
|
||||
return JSONResponse({"ok": True, "value": month_value, "label": _goal_label("sales", month_value),
|
||||
"week_total": week_total,
|
||||
"weeks": {k.isoformat(): _goal_label("sales", v) for k, v in values.items()}})
|
||||
|
||||
|
||||
|
||||
@@ -56,14 +56,14 @@
|
||||
{% set rm = board.metrics.roas %}
|
||||
{# 월 칸은 pj-goal-m + data-h(분기 1~4) — 분기 접기(initGoals)가 이걸로 숨긴다.
|
||||
분기 칸 클래스는 예전 이름 pj-goal-half-col 그대로(연간 칸처럼 굵게·회색 합계) #}
|
||||
{# 매출 목표 칸(020) — 누르면 그 달 주차별 목표 입력 창(project.js initGoalWeekTargets), 합계 = 월 목표 #}
|
||||
{# 매출 목표 칸(020) — 누르면 그 달 월 목표(직접 입력)·주차별 목표 입력 창, 맨 아래 차이(월 목표 − 주차 합계) #}
|
||||
{% macro num_cell(metric, kind, labels, mo) -%}
|
||||
{%- set weekly = week_targets and metric == 'sales' and kind == 'target' -%}
|
||||
<td class="pj-goal-numtd pj-goal-m{% if mo == this_month %} is-now{% endif %}{% if weekly %} is-weekly{% endif %}" data-h="{{ (mo - 1) // 3 + 1 }}">
|
||||
{%- if is_admin -%}
|
||||
<input type="text" class="pj-goal-num" inputmode="decimal" autocomplete="off"
|
||||
data-metric="{{ metric }}" data-kind="{{ kind }}" data-month="{{ mo }}"
|
||||
{%- if weekly %} readonly data-weekly="1" title="{{ mo }}월 주차별 목표 입력(합계 = 월 목표)"{% endif %}
|
||||
{%- if weekly %} readonly data-weekly="1" title="{{ mo }}월 목표·주차별 목표 입력"{% endif %}
|
||||
value="{{ labels.get(mo, '') }}" />
|
||||
{%- else -%}
|
||||
<span class="pj-goal-num" data-metric="{{ metric }}" data-kind="{{ kind }}" data-month="{{ mo }}"
|
||||
|
||||
@@ -518,7 +518,7 @@
|
||||
<h3 id="goals-metrics">매출·로아스 입력과 달성률 계산</h3>
|
||||
<table class="pjh-table">
|
||||
<tr><th>칸</th><th>입력·계산 방법</th></tr>
|
||||
<tr><td>매출 목표</td><td>월 칸을 누르면 그 달 <b>주차별 목표</b> 입력 창이 열립니다. 주차마다 금액(매출 단위)을 넣고 <span class="pjh-ui">저장</span>하면 주차 합계가 그 달 매출 목표가 됩니다. 주차는 <a href="#meetings-week">주간 회의록 주차</a>와 같습니다. 주차를 모두 비우고 저장하면 월 목표도 지워집니다.</td></tr>
|
||||
<tr><td>매출 목표</td><td>월 칸을 누르면 그 달 입력 창이 열립니다. 맨 위 <b>월 전체 목표</b>를 직접 넣고, 아래에 <b>주차별 목표</b>(매출 단위)를 넣은 뒤 <span class="pjh-ui">저장</span>합니다. 월 목표는 주차 합계와 따로 저장되고, 맨 아래에 <b>주차 합계</b>와 <b>차이(월 목표 − 주차 합계)</b>가 나옵니다 — +면 아직 주차에 못 나눈 금액, −면 주차 합계가 월 목표를 넘은 것입니다. 주차는 <a href="#meetings-week">주간 회의록 주차</a>와 같습니다.</td></tr>
|
||||
<tr><td>매출 실적</td><td>관리자가 월별 숫자를 직접 입력합니다. 목표 표의 실적은 회의록의 자동 매출과 별도로 관리하므로 실적 모듈에서 자동으로 채워지지 않습니다.</td></tr>
|
||||
<tr><td>매출 단위</td><td>예를 들어 단위가 <b>백만원</b>이면 30은 30,000,000원입니다. 단위를 바꿔도 이미 적은 숫자는 자동 환산되지 않으므로 숫자와 단위를 함께 확인하세요.</td></tr>
|
||||
<tr><td>연간·분기 매출</td><td>해당 기간에 입력한 월 숫자의 합계입니다. 합계 칸에 따로 입력하지 않습니다.</td></tr>
|
||||
|
||||
@@ -2853,6 +2853,14 @@ input.pj-meet-amount::placeholder { color: rgba(0, 0, 0, .28); }
|
||||
.pj-goal-wkpop-row input[readonly] { background: #f7f8f9; }
|
||||
.pj-goal-wkpop-sum { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--pj-border); }
|
||||
.pj-goal-wkpop-sum b { font-variant-numeric: tabular-nums; }
|
||||
/* 월 전체 목표(직접 입력) — 주차 줄과 구분선 */
|
||||
.pj-goal-wkpop-month { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--pj-border); font-weight: 700; }
|
||||
/* 차이 = 월 목표 − 주차 합계 — 남음(+) 주황, 넘음(−) 빨강, 딱 맞음 초록 */
|
||||
.pj-goal-wkpop-diff { margin-top: 4px; padding-top: 0; border-top: 0; }
|
||||
.pj-goal-wkpop-diff small { font-size: 11px; color: var(--pj-ink-soft); }
|
||||
.pj-goal-wkpop-diff b.is-left { color: #c2410c; }
|
||||
.pj-goal-wkpop-diff b.is-over { color: #dc2626; }
|
||||
.pj-goal-wkpop-diff b.is-even { color: #16a34a; }
|
||||
.pj-goal-wkpop-acts { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
|
||||
|
||||
/* 나를 태그·작업 배정 알림 — 화면 가운데 아래 큰 팝업(body 에 붙음), 닫기 전까지 깜박인다(2026-10-07) */
|
||||
|
||||
+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) {
|
||||
|
||||
@@ -883,9 +883,11 @@ description 을 항상 HTML로 취급하기 때문). 두 번 실행하면 이중
|
||||
`result_note` — 020, `.pj-meet-rnote` textarea, 0.8초 멈춤·칸 떠남 저장, 초안 `pj_draft:meet:item:{지난 줄}:result_note`) |
|
||||
**전주 목표**(지난 주차 `target_amount`) | **결과**(금액, 지난 주차 `result_amount`). 020 미적용이면 결과 글 칸은 보기만, API 503.
|
||||
- **주차별 매출 목표**(`goal_week_targets(week_start PK, year FK goal_years CASCADE, month, value NUMERIC)` — 목표 표 매출 단위 그대로):
|
||||
연간 목표 표 매출 **목표** 월 칸(`data-weekly`, readonly)을 누르면 그 달 주차 입력 창(`.pj-goal-wkpop`, body 에 붙음, 보기만 하는 사람은 값만).
|
||||
`PUT /project/api/goals/{연도}/week-targets/{월} {weeks: {주차 시작일: 값|""}}`(관리자) → 저장 후 그 달 주차 합계를
|
||||
`goal_metrics(sales, target)` 에 쓴다(모두 비면 월 목표도 지움). 020 미적용이면 예전처럼 월 칸 직접 입력.
|
||||
연간 목표 표 매출 **목표** 월 칸(`data-weekly`, readonly)을 누르면 그 달 입력 창(`.pj-goal-wkpop`, body 에 붙음, 보기만 하는 사람은 값만).
|
||||
맨 위 **월 전체 목표**(직접 입력) → 주차별 목표 → 맨 아래 **주차 합계**·**차이(월 목표 − 주차 합계**, + 주황 = 덜 나눔,
|
||||
− 빨강 = 넘침, 0 초록). `PUT /project/api/goals/{연도}/week-targets/{월} {month: 월 목표|"", weeks: {주차 시작일: 값|""}}`
|
||||
(관리자) → 주차 저장 + `goal_metrics(sales, target)` 에 `month` 그대로(빈값 = 지움, 주차 합계와 무관). `month` 가 없는 요청(예전
|
||||
화면 캐시)만 주차 합계를 월 목표로. 020 미적용이면 예전처럼 월 칸 직접 입력.
|
||||
- **020 마이그레이션**(`scripts/sql/project_db_020_meeting_periods.sql`, 멱등): ① `goal_meeting_items.result_note` ② `goal_meetings`
|
||||
월요일 CHECK 제거 ③ `goal_week_targets` ④ 새 주차에 흡수된 월요일 회의록(1일이 토·일인 달의 2·3일 월요일 → 1일, 말일이 월·화인 달의
|
||||
마지막 월요일 → 7일 전 월요일)을 옮김 — 옮길 자리에 회의록이 있으면 옮기지 않고 NOTICE. 이미 쓰던 9/28(월) 회의록은 9월 마지막 주차
|
||||
|
||||
Reference in New Issue
Block a user