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:
@@ -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()}})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user