diff --git a/app/modules/performance/CLAUDE.md b/app/modules/performance/CLAUDE.md
index 94d6f60..7fd78a3 100644
--- a/app/modules/performance/CLAUDE.md
+++ b/app/modules/performance/CLAUDE.md
@@ -43,7 +43,11 @@
## 매출 실적 화면 (2026-10-19)
-- 일자별 표 매출 칸 아래 **광고비(ROAS%)** 주황 줄(`--perf-ad`, `dashboard._ad_lines`) — 광고비 탭과 같은 값(`ad_spend.channel_roas`). 쇼핑몰 → 광고 채널은 `dashboard.sales_ad_channels`: 카페24 = 구글·메타 두 줄(이름 붙임), 네이버 = 네이버, 나머지는 `ROAS_SALES_CODE`(쿠팡 ← 쿠팡(윙)). 일 합계 = 보이는 쇼핑몰 광고비 합(ROAS = 매출 합 ÷ 광고비 합). 광고비 표 없으면 줄 없음.
+- KPI 는 **수수료 차감 매출 하나만** 화면 왼쪽 한 줄(`.perf-kpi-line` — 금액 + 비교 기간 대비 %, 모든 기간 공통). 총매출·수수료·월/연 누적 카드는 뺐다.
+- 일자별 표 기본 보기 = **수수료 차감 매출**(라우터 기본 `metric=net`, 예전에 고른 보기 localStorage 는 안 씀).
+- 마지막 업데이트 옆 **다음 업데이트까지 남은 시간** 초 단위 실시간(`router._auto_sync_ctx` → `performance.js initNextUpdate`, 자동 업데이트 규칙 `auto_sync.next_slot` 과 같게 화면이 다음 회차 계산, 서버 시각으로 PC 시계 보정, 자동 업데이트 꺼지면 숨김).
+
+- 일자별 표 매출 칸 아래 **광고비(ROAS%)** 주황 줄(`--perf-ad`, `dashboard._ad_lines`) — 광고비 탭과 같은 값(`ad_spend.channel_roas`). 쇼핑몰 → 광고 채널은 `dashboard.sales_ad_channels`: 카페24 = 구글·메타 두 줄(이름 붙임), 네이버 = 네이버, 나머지는 `ROAS_SALES_CODE`(쿠팡 ← 쿠팡(윙)). 일 합계 = 보이는 쇼핑몰 광고비 합, ROAS = **일 합계 금액 ÷ 일 합계 광고비**(2026-10-19 — 예전엔 광고비 있는 쇼핑몰 매출만 더했다; `roas` 총매출·`roas_net` 수수료 차감 매출 기준, 보기 기준에 따라 하나만). 광고비 표 없으면 줄 없음.
- **매출 단위** 원·천원·백만원 — 설정 "보기 설정"(누구나, 이 브라우저 쿠키 `perf_unit`), 서버가 `amount_text`(천원 정수·백만원 소수 한 자리)로 그림(`router._unit_ctx` → 템플릿 `amt`). 광고비 탭은 원 그대로.
- 설정의 진단 카드(쇼핑몰 원본 데이터 확인·카페24 매출 대조·일별 한 번에 비교)는 2026-10-19 화면에서 뺐다(서버 API `marketplaces/{code}/reconcile`·`daily-check` 는 진단용으로 남김).
diff --git a/app/modules/performance/dashboard.py b/app/modules/performance/dashboard.py
index d736cf6..98fcf2f 100644
--- a/app/modules/performance/dashboard.py
+++ b/app/modules/performance/dashboard.py
@@ -53,7 +53,9 @@ def amount_text(value: Any, unit: str = "won") -> str:
def _ad_lines(store: Any, table: list[dict[str, Any]], codes: Sequence[str], cells: Mapping[Any, Any],
period: Any, q_start: date, q_end: date) -> None:
"""매출 칸 아래 광고비(ROAS%) — 광고비 화면과 같은 값(ROAS = 그 쇼핑몰 매출 ÷ 광고비, 구글·메타·네이버는 보고서 ROAS).
- 카페24 = 구글·메타 두 줄. 행마다 r["ads"][쇼핑몰] = [{label, amount, roas}], r["ads_total"] = 보이는 쇼핑몰 광고비 합(ROAS = 매출 합 ÷ 광고비 합).
+ 카페24 = 구글·메타 두 줄. 행마다 r["ads"][쇼핑몰] = [{label, amount, roas}], r["ads_total"] = 보이는 쇼핑몰 광고비 합.
+ 일 합계 ROAS 는 단순하게 일 합계 금액 ÷ 일 합계 광고비(2026-10-19) — roas = 총매출 기준, roas_net = 수수료 차감 매출 기준
+ (화면 표시 기준에 따라 하나만 보인다). 예전엔 광고비가 있는 쇼핑몰 매출만 더해 일 합계 금액과 맞지 않았다.
광고비 표(005)가 없거나 읽기 실패면 줄 없음."""
from . import ad_spend # noqa: WPS433
@@ -87,7 +89,7 @@ def _ad_lines(store: Any, table: list[dict[str, Any]], codes: Sequence[str], cel
for r in table:
s = date.fromisoformat(r["from"]) if r.get("from") else period.start
e = date.fromisoformat(r["to"]) if r.get("to") else period.end
- tot_spend = tot_sales = 0
+ tot_spend = 0
for c in codes:
lines = []
for ch, label in by_code.get(c, ()):
@@ -100,9 +102,10 @@ def _ad_lines(store: Any, table: list[dict[str, Any]], codes: Sequence[str], cel
tot_spend += amt
if lines:
r["ads"][c] = lines
- tot_sales += sales(c, s, e)
if tot_spend:
- r["ads_total"] = {"amount": tot_spend, "roas": ad_spend.roas(tot_sales, tot_spend)}
+ tot = r.get("total") or {}
+ r["ads_total"] = {"amount": tot_spend, "roas": ad_spend.roas(tot.get("gross") or 0, tot_spend),
+ "roas_net": ad_spend.roas(tot.get("net") or 0, tot_spend)}
def sales_ad_channels() -> dict[str, tuple[tuple[str, str], ...]]:
@@ -152,28 +155,16 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
cur = calc.sum_range(cells, codes, period.start, period.end)
prev = calc.sum_range(cells, codes, cmp_start, cmp_end)
- mtd = calc.sum_range(cells, codes, month_period.start, month_period.end)
- m_prev = calc.sum_range(cells, codes, m_cmp_start, m_cmp_end)
- ytd = calc.sum_range(cells, codes, year_period.start, year_period.end)
- y_prev = calc.sum_range(cells, codes, y_cmp_start, y_cmp_end)
- has_prev = prev.gross != 0 or prev.commission != 0
period_word = {"day": "오늘" if period.start == today else "해당일", "week": "이번주" if period.start <= today <= period.end else "해당 주",
"month": "이번달" if period.start <= today <= period.end else "해당 월",
"year": "올해" if period.start <= today <= period.end else "해당 연도",
"custom": "선택 기간"}[period.kind]
+ # KPI 는 수수료 차감 매출 하나만(2026-10-19) — 화면 왼쪽 한 줄(금액 + 비교 기간 대비 %).
+ # 총매출·수수료·월 누적·연 누적 카드는 뺐다(아래 표·월/연 누적 카드에 같은 값이 있다).
kpis = [
- {"key": "gross", "label": f"{period_word} 총매출", "value": cur.gross, "primary": True,
- "delta": calc.pct_change(cur.gross, prev.gross), "cmp": cmp_label},
{"key": "net", "label": f"{period_word} 수수료 차감 매출", "value": cur.net, "primary": True,
"delta": calc.pct_change(cur.net, prev.net), "cmp": cmp_label},
- {"key": "commission", "label": f"{period_word} 수수료", "value": cur.commission,
- "delta": calc.pct_change(cur.commission, prev.commission) if has_prev else None, "cmp": cmp_label,
- "invert": True},
- {"key": "mtd", "label": f"{month_period.label} 누적 매출", "value": mtd.gross,
- "delta": calc.pct_change(mtd.gross, m_prev.gross), "cmp": m_cmp_label},
- {"key": "ytd", "label": f"{year_period.label} 누적 매출", "value": ytd.gross,
- "delta": calc.pct_change(ytd.gross, y_prev.gross), "cmp": y_cmp_label},
]
share = calc.by_code(cells, codes, period.start, period.end)
diff --git a/app/modules/performance/router.py b/app/modules/performance/router.py
index 0f379b9..2285d73 100644
--- a/app/modules/performance/router.py
+++ b/app/modules/performance/router.py
@@ -116,7 +116,7 @@ def dashboard_page(
from_: str | None = Query(None, alias="from"),
to: str | None = None,
m: list[str] = Query(default=[]),
- metric: str = "gross",
+ metric: str = "net",
):
from app.main import render_template # noqa: WPS433
@@ -134,11 +134,27 @@ def dashboard_page(
custom_from=_parse_date(from_), custom_to=_parse_date(to), selected=m,
holidays=_holidays(), configured=creds.configured_codes(list(all_adapters())),
)
- ctx["metric"] = metric if metric in ("gross", "commission", "net") else "gross"
+ ctx["metric"] = metric if metric in ("gross", "commission", "net") else "net"
+ ctx["auto_sync"] = _auto_sync_ctx()
_unit_ctx(request, ctx)
return render_template(request, "performance/index.html", {**common.base_ctx(user, active_tab="dashboard"), **ctx})
+def _auto_sync_ctx() -> dict[str, Any] | None:
+ """다음 자동 업데이트까지 남은 시간(2026-10-19) — 화면이 초 단위로 센다. 회차가 지나면 화면이 같은 규칙
+ (hours·slot, KST)으로 다음 회차를 계산한다. 서버 시각(now)으로 PC 시계 차이를 보정. 자동 업데이트가 꺼져 있으면 None."""
+ from app.timezone import now_kst # noqa: WPS433
+
+ from . import auto_sync # noqa: WPS433
+
+ if not auto_sync.enabled():
+ return None
+ hours = auto_sync.hour_window()
+ now = now_kst()
+ return {"next_at": auto_sync.next_slot(now, hours).isoformat(), "now": now.isoformat(timespec="milliseconds"),
+ "hours": list(hours), "slot": auto_sync.SLOT_MINUTES}
+
+
def _unit_ctx(request: Request, ctx: dict[str, Any]) -> None:
"""매출 단위(원·천원·백만원) — 실적 설정 "보기 설정"이 이 브라우저 쿠키(perf_unit)에 둔다. 템플릿은 amt(v) 로 그린다."""
from .dashboard import UNIT_COOKIE, UNITS, amount_text, normalize_unit # noqa: WPS433
diff --git a/app/modules/performance/templates/performance/ads.html b/app/modules/performance/templates/performance/ads.html
index bf0e758..06044d5 100644
--- a/app/modules/performance/templates/performance/ads.html
+++ b/app/modules/performance/templates/performance/ads.html
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
-{% block head_extra %}{% endblock %}
+{% block head_extra %}{% endblock %}
{#- ROAS 덧붙임 — "광고비(ROAS%)". 광고비가 없으면 아무것도 안 붙는다. -#}
{%- macro roas(p) -%}{%- if p is not none -%}({{ "{:,}".format(p) }}%){%- endif -%}{%- endmacro -%}
@@ -224,4 +224,4 @@
} | tojson }}
{% endblock %}
-{% block scripts %}{% endblock %}
+{% block scripts %}{% endblock %}
diff --git a/app/modules/performance/templates/performance/index.html b/app/modules/performance/templates/performance/index.html
index 940a9dd..c85b2ca 100644
--- a/app/modules/performance/templates/performance/index.html
+++ b/app/modules/performance/templates/performance/index.html
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
-{% block head_extra %}{% endblock %}
+{% block head_extra %}{% endblock %}
{%- macro won(v) -%}
{%- if v is none -%}
@@ -16,6 +16,14 @@
{%- for a in lines or [] -%}{% if a.label %}{{ a.label }}{% endif %}{{ amt(a.amount) }}{% if a.roas is not none %}({{ "{:,}".format(a.roas) }}%){% endif %}{%- endfor -%}
{%- endmacro -%}
+{#- 일 합계 광고비(ROAS%) — ROAS = 일 합계 금액 ÷ 일 합계 광고비. 수수료 차감 매출 보기면 차감 매출 기준, 그 밖엔 총매출 기준 -#}
+{%- macro adl_total(a) -%}
+ {%- for key, cls in (("roas", "for-gross"), ("roas_net", "for-net")) -%}
+ {%- set rs = a[key] -%}
+ {{ amt(a.amount) }}{% if rs is not none %}({{ "{:,}".format(rs) }}%){% endif %}
+ {%- endfor -%}
+{%- endmacro -%}
+
{#- 한 칸에 총매출/수수료/차감매출 세 값을 넣고, 보기 전환은 CSS(data-metric)로. -#}
{%- macro m3(m) -%}
{{ won(m.gross) }}{{ won(m.commission) }}{{ won(m.net) }}
@@ -72,6 +80,10 @@
마지막 업데이트
{{ (last_update_at or '')[:16] | replace('T', ' ') or '—' }}
+ {% if auto_sync %}
+ {# 다음 자동 업데이트까지 남은 시간 — 초 단위로 실시간(performance.js initNextUpdate, 2026-10-19) #}
+ 다음 업데이트까지 —
+ {% endif %}
{# 업데이트 중에도 누를 수 있다 — 진행 중인 업데이트(수동·자동)의 진행 창을 다시 연다(2026-10-19) #}