54e4e08802
광고비 탭 오른쪽에 틱톡 탭 추가. 일자별 ROAS, 광고비, 매출을 광고비 탭과 같은 틀로 보여 준다. 실적 설정 광고 API 연동에 틱톡 추가(광고 계정 ID, 액세스 토큰, 선택 틱톡샵 ID). 채널 표(CHANNELS)에 넣지 않아 매출 실적·광고비 탭 합계에는 들어가지 않는다. DB 변경 없음. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
227 lines
14 KiB
HTML
227 lines
14 KiB
HTML
{% extends "erp_base.html" %}
|
||
|
||
{% block head_extra %}<link rel="stylesheet" href="/static/performance.css?v=20261105a" />{% endblock %}
|
||
|
||
{#- ROAS 덧붙임 — "광고비(ROAS%)". 광고비가 없으면 아무것도 안 붙는다. -#}
|
||
{%- macro roas(p) -%}{%- if p is not none -%}<span class="perf-roas">({{ "{:,}".format(p) }}%)</span>{%- endif -%}{%- endmacro -%}
|
||
|
||
{%- macro won(v) -%}
|
||
{%- if v is none -%}<span class="perf-na"></span>
|
||
{%- elif v == 0 -%}<span class="perf-zero">–</span>
|
||
{%- else -%}{{ "{:,}".format(v) }}{%- endif -%}
|
||
{%- endmacro -%}
|
||
|
||
{% block content %}
|
||
{#- 광고비 — 매출 실적과 같은 기간 이동·표·그래프. 날짜 칸을 눌러 직접 입력(파란 숫자), 업로드로 들어온 값은 주황 숫자. -#}
|
||
<section class="perf perf-ads" id="perf-dash" data-metric="gross" data-fixed-metric="gross">
|
||
{% include "performance/_tabs.html" %}
|
||
|
||
<div class="perf-toolbar">
|
||
<div class="perf-quick" role="group" aria-label="기간 선택">
|
||
{% for q in nav.quick %}
|
||
<a class="perf-seg{% if q.active %} is-active{% endif %}" href="{{ q.url }}">{{ q.label }}</a>
|
||
{% endfor %}
|
||
<button type="button" class="perf-seg{% if period_kind == 'custom' %} is-active{% endif %}" id="perf-custom-btn">직접선택</button>
|
||
</div>
|
||
|
||
{% include "performance/_period_nav.html" %}
|
||
|
||
<form class="perf-custom" id="perf-custom" method="get" action="/performance/ads"{% if period_kind != 'custom' %} hidden{% endif %}>
|
||
<input type="hidden" name="period" value="custom" />
|
||
<input class="erp-input perf-date" type="date" name="from" value="{{ period.start.isoformat() }}" required />
|
||
<span class="perf-muted">~</span>
|
||
<input class="erp-input perf-date" type="date" name="to" value="{{ period.end.isoformat() }}" required />
|
||
<button class="erp-btn erp-btn-outline" type="submit">조회</button>
|
||
</form>
|
||
|
||
{% include "performance/_ad_update.html" %}
|
||
</div>
|
||
<div class="perf-notice" id="perf-sync-result" hidden></div>
|
||
|
||
{% if migration_needed %}
|
||
<div class="perf-notice is-warn">광고비 저장 표가 아직 없습니다. 관리자가 performance_db 마이그레이션 005
|
||
(scripts/sql/performance_db_005_ad_spend.sql)를 적용하면 입력할 수 있습니다.</div>
|
||
{% endif %}
|
||
|
||
<!-- ── KPI — 한 줄(2026-10-30, 매출 실적처럼): 광고비 · 매출 대비 광고비 · 연 누적 ── -->
|
||
<div class="perf-kpi-line">
|
||
{% for k in kpis %}
|
||
<span class="perf-kpi-item">
|
||
<span class="perf-muted">{{ k.label }}</span>
|
||
{% if k.key == 'ratio' %}
|
||
<b class="perf-kpi-line-value{% if not k.primary %} is-sub{% endif %}">{% if k.pct is none %}–{% else %}{{ "%.1f" | format(k.pct) }}%{% endif %}</b>
|
||
<span class="perf-muted">{{ k.note }}</span>
|
||
{% else %}
|
||
<b class="perf-kpi-line-value{% if not k.primary %} is-sub{% endif %}">₩{{ "{:,}".format(k.value) }}</b>
|
||
{% if k.delta is none %}<span class="perf-muted">{{ k.cmp }} 비교 없음</span>
|
||
{% else %}
|
||
{% set up = k.delta > 0 %}
|
||
<span class="perf-delta {% if k.delta == 0 %}is-flat{% elif up != (k.invert or false) %}is-up{% else %}is-down{% endif %}">
|
||
{% if k.delta > 0 %}▲{% elif k.delta < 0 %}▼{% else %}–{% endif %} {{ "%.1f" | format(k.delta | abs) }}%</span>
|
||
<span class="perf-muted">{{ k.cmp }} 대비</span>
|
||
{% endif %}
|
||
{% endif %}
|
||
</span>
|
||
{% endfor %}
|
||
</div>
|
||
|
||
<!-- ── 일자 × 채널 ── -->
|
||
<div class="erp-card perf-card">
|
||
<div class="perf-card-head">
|
||
<h2 class="perf-h">{% if period_kind == 'year' %}월별 × 광고 채널{% else %}일자별 × 광고 채널{% endif %}</h2>
|
||
<div class="perf-ad-actions">
|
||
{% if upload_channels %}
|
||
<button type="button" class="erp-btn erp-btn-outline erp-btn-sm perf-manual-upload-btn perf-ad-upload-btn" id="perf-ad-upload"
|
||
title="광고 보고서 파일로 일별 광고비를 한 번에 입력">파일 업로드</button>
|
||
{% endif %}
|
||
</div>
|
||
</div>
|
||
<div class="erp-table-wrap perf-table-wrap perf-main-wrap">
|
||
{#- perf-main-wrap(2026-10-26) = 표 안에서 세로 스크롤 — 제목 행·기간 합계 행 고정 -#}
|
||
{#- perf-autofit(2026-10-22) = 열 너비는 내용 길이만큼, 날짜 열은 가로 스크롤해도 고정(매출 실적 표와 같음) -#}
|
||
{#- 열 너비(2026-10-27, 실적 설정 "보기 설정" 쿠키 perf_colw) — manual = 머리글 경계 드래그로 조절, 너비는 이 브라우저에 기억(th data-col 별) -#}
|
||
<table class="perf-table perf-main perf-autofit{% if colw == 'manual' %} perf-colw-manual{% endif %}" data-colw-key="ads">
|
||
<thead>
|
||
<tr>
|
||
<th class="perf-th-label" data-col="label">{% if period_kind == 'year' %}월{% else %}날짜{% endif %}</th>
|
||
<th class="perf-th-total" data-col="total">{% if period_kind == 'year' %}월 합계{% else %}일 합계{% endif %}</th>
|
||
{% for c in codes %}{% if c in detail_channels %}<th class="perf-th-detail" data-col="{{ c }}" title="{{ names[c] }} — 눌러 일자별 광고 보고서 항목 보기. 괄호 = {% if c == 'google' %}구글 광고 ROAS(전환 가치 ÷ 비용){% elif c == 'meta' %}메타 광고 구매 ROAS(구매 전환값 ÷ 지출 금액){% else %}보고서 ROAS(구매완료 광고수익률){% endif %}"><button type="button" class="perf-detail-btn" data-detail-channel="{{ c }}">{{ names[c] }} <span class="material-symbols-outlined" aria-hidden="true">table_view</span></button></th>{% else %}<th data-col="{{ c }}" title="{{ names[c] }} — 날짜 칸을 눌러 광고비 입력.{% if roas_basis[c] %} 괄호 = ROAS({{ roas_basis[c] }} 매출 ÷ 광고비){% else %} ROAS 는 계산하지 않음(따로 입력){% endif %}">{{ names[c] }} <span class="perf-manual-mark" aria-hidden="true">✎</span></th>{% endif %}{% endfor %}
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{% for r in table %}
|
||
<tr class="perf-row-{{ r.kind }}{% if r.weekday == 5 %} is-sat{% endif %}{% if r.weekday == 6 or r.holiday %} is-sun{% endif %}{% if r.today %} is-today{% endif %}{% if r.future %} is-future{% endif %}">
|
||
<th class="perf-td-label" scope="row">
|
||
{{ r.label }}{% if r.holiday %}<small class="perf-hol">{{ r.holiday }}</small>{% endif %}
|
||
</th>
|
||
<td class="perf-num perf-td-total"><span class="v v-gross">{{ won(r.total.gross) }}</span>{{ roas(r.roas_total) }}</td>
|
||
{% for c in codes %}
|
||
{% set v = r.cells[c].gross %}
|
||
{% if r.kind == 'day' and not migration_needed %}
|
||
{% set up = (r.date ~ '|' ~ c) in upload_cells %}
|
||
{% set ap = (r.date ~ '|' ~ c) in api_cells %}
|
||
{% set fx = (formula_cells or {}).get(r.date ~ '|' ~ c) if not up and not ap else none %}
|
||
{% set memo = (memo_cells or {}).get(r.date ~ '|' ~ c) %}{#- 메모(010) -#}
|
||
<td class="perf-num is-manual-cell{% if v and not up and not ap %} is-manual{% endif %}{% if fx %} is-formula{% endif %}{% if up %} is-upload{% endif %}{% if ap %} is-api{% endif %}{% if memo %} has-memo{% endif %}"
|
||
data-manual-code="{{ c }}" data-date="{{ r.date }}" data-memo-code="{{ c }}" data-manual-value="{{ v if v else '' }}"{% if fx %} data-formula="{{ fx }}"{% endif %}{% if memo %} data-memo="{{ memo }}"{% endif %} tabindex="0"><span class="v v-gross">{{ won(v) }}</span>{{ roas(r.roas[c]) }}</td>
|
||
{% else %}
|
||
<td class="perf-num"><span class="v v-gross">{{ won(v) }}</span>{{ roas(r.roas[c]) }}</td>
|
||
{% endif %}
|
||
{% endfor %}
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
{% if period_kind != 'year' %}
|
||
<p class="perf-muted perf-manual-help">날짜 칸을 눌러 그날 <b>광고비</b>를 직접 입력합니다 — Enter 저장 후 아래 칸, Esc 취소, 비우고 저장하면 지움.
|
||
칸은 <b>광고비(ROAS%)</b> — ROAS = 그 쇼핑몰 매출 실적 총매출 ÷ 광고비(합계 열은 전체 매출). 메타는 메타 광고 API 의 구매 ROAS(구매 전환값 ÷ 지출 금액),
|
||
네이버는 광고 보고서의 ROAS(구매완료 광고수익률), 구글은 구글 광고 API 의 ROAS(전환 가치 ÷ 비용)를 씁니다 — 네이버·구글·메타 머리글을 누르면 일자별 보고서 항목.
|
||
파란 숫자 = 직접 입력, 파랑 굵은 숫자 = 계산식(1000+2000 처럼 = 없이 입력하면 바로 계산), 주황 숫자 = 파일 업로드 값, 초록 숫자 = 광고 API 값. 쿠팡(윙)·쿠팡(로켓)·네이버는 [파일 업로드]로 광고 보고서를 올리면 날짜별로 한 번에 들어갑니다.
|
||
구글·메타는 [구글 광고 불러오기]·[메타 광고 불러오기](관리자가 실적 설정 → 광고 API 연동을 마친 뒤) 또는 매출 자동 업데이트 때 들어옵니다.</p>
|
||
{% endif %}
|
||
</div>
|
||
|
||
<!-- ── 그래프 ── -->
|
||
<div class="perf-grid2">
|
||
<div class="erp-card perf-card">
|
||
<div class="perf-card-head"><h2 class="perf-h">{% if period_kind == 'year' %}월별{% else %}일별{% endif %} 광고비 추이</h2></div>
|
||
<div class="perf-chart" id="perf-chart-daily"></div>
|
||
</div>
|
||
<div class="erp-card perf-card">
|
||
<div class="perf-card-head"><h2 class="perf-h">채널별 비중</h2>
|
||
<span class="perf-muted">{{ period.label }}</span></div>
|
||
<div class="perf-chart" id="perf-chart-share"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ── 월 누적 · 연간 누적 ── -->
|
||
<div class="perf-grid2">
|
||
<div class="erp-card perf-card">
|
||
<div class="perf-card-head"><h2 class="perf-h">{{ month.label }} 채널별 광고비</h2></div>
|
||
<div class="erp-table-wrap">
|
||
<table class="perf-table">
|
||
<thead><tr><th class="perf-th-label">채널</th><th>광고비</th><th>ROAS</th><th>비중</th></tr></thead>
|
||
<tbody>
|
||
{% for r in month.rows %}
|
||
<tr>
|
||
<th class="perf-td-label" scope="row">{{ names[r.code] }}</th>
|
||
<td class="perf-num">{{ won(r.gross) }}</td>
|
||
<td class="perf-num">{% if r.roas is not none %}{{ "{:,}".format(r.roas) }}%{% else %}<span class="perf-zero">–</span>{% endif %}</td>
|
||
<td class="perf-num perf-share">
|
||
{% if r.share is not none %}<span class="perf-bar" style="--w: {{ [r.share, 0] | max }}%"></span>{{ "%.1f" | format(r.share) }}%{% else %}<span class="perf-zero">–</span>{% endif %}
|
||
</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr class="perf-row-total">
|
||
<th class="perf-td-label" scope="row">합계</th>
|
||
<td class="perf-num">{{ won(month.total.gross) }}</td>
|
||
<td class="perf-num">{% if month.total.roas is not none %}{{ "{:,}".format(month.total.roas) }}%{% else %}<span class="perf-zero">–</span>{% endif %}</td>
|
||
<td class="perf-num">{% if month.total.share is not none %}100%{% else %}<span class="perf-zero">–</span>{% endif %}</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="erp-card perf-card">
|
||
<div class="perf-card-head"><h2 class="perf-h">{{ year.year }}년 누적 광고비</h2></div>
|
||
<div class="perf-year-sum">
|
||
<div><span>광고비</span><b>₩{{ "{:,}".format(year.total.gross) }}</b></div>
|
||
</div>
|
||
<div class="erp-table-wrap">
|
||
<table class="perf-table perf-year">
|
||
<thead><tr><th class="perf-th-label">월</th><th>광고비</th><th>ROAS</th></tr></thead>
|
||
<tbody>
|
||
{% for r in year.rows %}
|
||
<tr class="{% if r.future %}is-future{% endif %}">
|
||
<th class="perf-td-label" scope="row">{{ r.label }}</th>
|
||
<td class="perf-num">{{ won(r.gross) }}</td>
|
||
<td class="perf-num">{% if r.roas is not none %}{{ "{:,}".format(r.roas) }}%{% elif not r.future %}<span class="perf-zero">–</span>{% endif %}</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr class="perf-row-total">
|
||
<th class="perf-td-label" scope="row">합계</th>
|
||
<td class="perf-num">{{ won(year.total.gross) }}</td>
|
||
<td class="perf-num">{% if year.total.roas is not none %}{{ "{:,}".format(year.total.roas) }}%{% else %}<span class="perf-zero">–</span>{% endif %}</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<p class="perf-foot perf-muted">
|
||
광고비 기준: 쿠팡(윙)·쿠팡(로켓)은 광고 보고서의 청구금액(+부가가치세), 구글은 구글 광고 비용 + 부가세 10%(부가세 포함), 메타는 지출 금액 그대로(이미 부가세 포함).
|
||
ROAS = 그 쇼핑몰 매출 ÷ 광고비 × 100(네이버·구글·메타는 광고 쪽 값).
|
||
매출 대비 광고비 = 같은 기간 광고비 ÷ 매출 실적 총매출.
|
||
구글·메타는 [광고비 업데이트]·자동 업데이트(매출과 같은 시각)로 광고 API 에서 가져옵니다.
|
||
</p>
|
||
</section>
|
||
|
||
<script type="application/json" id="perf-data">{{ {
|
||
"names": names,
|
||
"codes": codes,
|
||
"daily": chart_daily,
|
||
"share": chart_share,
|
||
"period_kind": period_kind,
|
||
"memo_kind": "ad",
|
||
"today": today,
|
||
"manual_api": "/performance/api/ad-spend/",
|
||
"manual_word": "광고비",
|
||
"period_start": period.start.isoformat(),
|
||
"period_end": period.end.isoformat(),
|
||
"period_label": period.label,
|
||
"empty_text": "기간 내 광고비가 없습니다.",
|
||
"upload_channels": upload_channels,
|
||
"auto_sync": auto_sync,
|
||
"update_watch": update_watch
|
||
} | tojson }}</script>
|
||
{% endblock %}
|
||
|
||
{% block scripts %}<script src="/static/performance.js?v=20261105a" defer></script>{% endblock %}
|