feat(performance): 광고비 탭(구글·메타·쿠팡 윙/로켓) + 탭 개편·설정 톱니
- 탭: [매출 실적](검정) · [광고비](주황) 큰 탭 + 맨 오른쪽 설정 톱니(Material Symbols settings)
- /performance/ads: 연·월·일 표(채널 × 날짜)·추이·비중·월/연 누적, 매출 대비 광고비 KPI
- 날짜 칸 직접 입력(PUT /api/ad-spend/{channel}/{day}), 쿠팡(로켓) 광고 보고서 업로드
(CSV/엑셀, 1열 날짜·19열 청구금액(+부가가치세), 잘못된 줄 있으면 전부 거절)
- performance_db 마이그레이션 005 perf_ad_spend
- 설정 화면 쇼핑몰 순서 jsdom 기대값을 003 열 순서로 갱신(기존 실패)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -236,15 +236,20 @@
|
||||
const data = JSON.parse((document.getElementById("perf-data") || {}).textContent || "{}");
|
||||
const METRIC_NAMES = { gross: "총매출", commission: "수수료", net: "수수료 차감 매출" };
|
||||
const KEY = "perf_metric";
|
||||
const FIXED_METRIC = root.dataset.fixedMetric || ""; // 광고비 화면 = 금액 하나(gross)뿐
|
||||
const MANUAL_API = data.manual_api || "/performance/api/manual-sales/";
|
||||
const MANUAL_WORD = data.manual_word || "총매출";
|
||||
const EMPTY_TEXT = data.empty_text || "기간 내 매출이 없습니다.";
|
||||
|
||||
// 표시 기준 전환 — 서버가 세 값을 다 그려 두었고 CSS 가 하나만 보인다.
|
||||
function setMetric(m) {
|
||||
if (FIXED_METRIC) m = FIXED_METRIC;
|
||||
if (!METRIC_NAMES[m]) m = "gross";
|
||||
root.dataset.metric = m;
|
||||
root.querySelectorAll(".perf-metric .perf-seg").forEach(function (b) {
|
||||
b.classList.toggle("is-active", b.dataset.metric === m);
|
||||
});
|
||||
try { localStorage.setItem(KEY, m); } catch (_) {}
|
||||
if (!FIXED_METRIC) { try { localStorage.setItem(KEY, m); } catch (_) {} }
|
||||
drawDaily(m);
|
||||
drawShare(m);
|
||||
root.querySelectorAll(".perf-metric-name").forEach(function (n) { n.textContent = METRIC_NAMES[m]; });
|
||||
@@ -311,6 +316,69 @@
|
||||
});
|
||||
});
|
||||
|
||||
// 광고비 파일 업로드 — 채널(양식이 정해진 채널만)을 고르고 파일을 올리면 파일에 있는 날만 덮어쓴다.
|
||||
// 잘못된 줄이 있으면 서버가 아무것도 저장하지 않고 줄 위치 목록을 돌려준다.
|
||||
const adUploadBtn = document.getElementById("perf-ad-upload");
|
||||
if (adUploadBtn) adUploadBtn.addEventListener("click", function () {
|
||||
let saved = false;
|
||||
const chans = data.upload_channels || [];
|
||||
const m = openModal("광고비 파일 업로드", { narrow: true, onClose: function () { if (saved) location.reload(); } });
|
||||
m.body.innerHTML =
|
||||
'<label class="perf-muted" style="display:block;margin:0 0 4px">채널</label>' +
|
||||
'<select class="erp-input perf-ad-channel" style="width:100%;margin:0 0 6px">' + chans.map(function (c) {
|
||||
return '<option value="' + esc(c.code) + '">' + esc(c.name) + "</option>";
|
||||
}).join("") + "</select>" +
|
||||
'<p class="perf-muted perf-ad-help" style="margin:0 0 10px"></p>' +
|
||||
'<input type="file" class="erp-input perf-upload-file" accept=".csv,.xlsx,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" aria-label="광고 보고서 파일" />' +
|
||||
'<div class="perf-upload-result"></div>';
|
||||
const sel = m.body.querySelector(".perf-ad-channel");
|
||||
const help = m.body.querySelector(".perf-ad-help");
|
||||
function showHelp() {
|
||||
const c = chans.filter(function (x) { return x.code === sel.value; })[0];
|
||||
help.textContent = c ? c.help : "";
|
||||
}
|
||||
sel.addEventListener("change", showHelp);
|
||||
showHelp();
|
||||
const fileInput = m.body.querySelector(".perf-upload-file");
|
||||
const out = m.body.querySelector(".perf-upload-result");
|
||||
const go = el("button", { type: "button", class: "erp-btn erp-btn-primary" }, "업로드");
|
||||
const cancel = el("button", { type: "button", class: "erp-btn erp-btn-ghost" }, "닫기");
|
||||
m.foot.appendChild(cancel);
|
||||
m.foot.appendChild(go);
|
||||
cancel.addEventListener("click", m.close);
|
||||
go.addEventListener("click", async function () {
|
||||
const f = fileInput.files && fileInput.files[0];
|
||||
if (!f) { out.innerHTML = '<p class="perf-notice is-warn">파일을 고르세요.</p>'; return; }
|
||||
go.disabled = true;
|
||||
out.innerHTML = '<p class="perf-muted">올리는 중…</p>';
|
||||
const fd = new FormData();
|
||||
fd.append("file", f);
|
||||
let res, body = null;
|
||||
try {
|
||||
res = await fetch("/performance/api/ad-spend/upload?channel=" + encodeURIComponent(sel.value),
|
||||
{ method: "POST", credentials: "same-origin", body: fd });
|
||||
try { body = await res.json(); } catch (_) { body = null; }
|
||||
} catch (err) {
|
||||
out.innerHTML = '<p class="perf-notice is-warn">업로드 실패: ' + esc(err.message) + "</p>";
|
||||
go.disabled = false;
|
||||
return;
|
||||
}
|
||||
go.disabled = false;
|
||||
if (!res.ok) {
|
||||
const detail = body && typeof body.detail === "string" ? body.detail : "업로드 실패 (" + res.status + ")";
|
||||
const errs = body && body.errors && body.errors.length
|
||||
? '<ul class="perf-upload-errors">' + body.errors.map(function (e) { return "<li>" + esc(e) + "</li>"; }).join("") + "</ul>" : "";
|
||||
out.innerHTML = '<p class="perf-notice is-warn">' + esc(detail) + "</p>" + errs;
|
||||
return;
|
||||
}
|
||||
saved = body.saved > 0;
|
||||
out.innerHTML = '<p class="perf-notice is-ok">' + esc(body.name) + " " + fmt(body.saved) + "일 반영 (" +
|
||||
esc(body.from === body.to ? body.from : body.from + " ~ " + body.to) + ") · 합계 " + fmt(body.total) + "원</p>" +
|
||||
'<p class="perf-muted" style="margin:6px 0 0">창을 닫으면 표·합계·그래프가 다시 계산됩니다.</p>';
|
||||
fileInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
// 직접선택 / 쇼핑몰 필터
|
||||
const customBtn = document.getElementById("perf-custom-btn");
|
||||
const customForm = document.getElementById("perf-custom");
|
||||
@@ -413,13 +481,15 @@
|
||||
if (raw !== "" && !/^-?\d+$/.test(raw)) return Promise.reject(new Error("숫자(원)만 입력하세요."));
|
||||
if (raw === was) return Promise.resolve(false); // 바뀐 것 없음(빈 칸 그대로 포함)
|
||||
const job = manualChain.then(function () {
|
||||
return api("PUT", "/performance/api/manual-sales/" + encodeURIComponent(td.dataset.manualCode) + "/" +
|
||||
return api("PUT", MANUAL_API + encodeURIComponent(td.dataset.manualCode) + "/" +
|
||||
encodeURIComponent(td.dataset.date), { amount: raw === "" ? null : Number(raw) });
|
||||
}).then(function (res) {
|
||||
const manual = res.manual == null ? "" : String(res.manual);
|
||||
td.dataset.manualValue = manual;
|
||||
td.classList.toggle("is-manual", manual !== "");
|
||||
td.title = manual !== "" ? "수동 입력값 — 눌러 고치기(비우고 저장하면 API 값)" : "눌러 총매출 직접 입력";
|
||||
td.classList.remove("is-upload");
|
||||
td.title = manual !== "" ? "직접 입력값 — 눌러 고치기(비우고 저장하면 " + (FIXED_METRIC ? "지움" : "API 값") + ")"
|
||||
: "눌러 " + MANUAL_WORD + " 직접 입력";
|
||||
const g = td.querySelector(".v-gross");
|
||||
if (g) g.innerHTML = won(res.amount);
|
||||
td.classList.add("is-stale"); // 수수료·차감 매출은 새로고침 때 다시 계산
|
||||
@@ -432,10 +502,10 @@
|
||||
function editManual(td) {
|
||||
if (td.querySelector(".perf-manual-input")) return;
|
||||
const input = el("input", { type: "text", inputmode: "numeric", class: "perf-manual-input",
|
||||
"aria-label": ((data.names || {})[td.dataset.manualCode] || "") + " " + td.dataset.date + " 총매출" });
|
||||
"aria-label": ((data.names || {})[td.dataset.manualCode] || "") + " " + td.dataset.date + " " + MANUAL_WORD });
|
||||
input.value = digitsOf(td);
|
||||
const g = td.querySelector(".v-gross");
|
||||
input.placeholder = digitsOf(td) ? "" : (g ? g.textContent.trim().replace(/[–-]/, "") : "") || "총매출";
|
||||
input.placeholder = digitsOf(td) ? "" : (g ? g.textContent.trim().replace(/[–-]/, "") : "") || MANUAL_WORD;
|
||||
td.classList.add("is-editing");
|
||||
td.appendChild(input);
|
||||
input.focus();
|
||||
@@ -529,7 +599,7 @@
|
||||
const pts = data.daily || [];
|
||||
const vals = pts.map(function (p) { return p[metric] || 0; });
|
||||
if (!pts.length || vals.every(function (v) { return !v; })) {
|
||||
box.innerHTML = '<div class="perf-chart-empty">기간 내 매출이 없습니다.</div>';
|
||||
box.innerHTML = '<div class="perf-chart-empty">' + esc(EMPTY_TEXT) + "</div>";
|
||||
return;
|
||||
}
|
||||
const W = 640, H = 230, L = 48, R = 8, T = 10, B = 26;
|
||||
@@ -560,7 +630,7 @@
|
||||
if (!box) return;
|
||||
const rows = (data.share || []).slice().sort(function (a, b) { return (b[metric] || 0) - (a[metric] || 0); });
|
||||
const total = rows.reduce(function (s, r) { return s + Math.max(0, r[metric] || 0); }, 0);
|
||||
if (!rows.length || total <= 0) { box.innerHTML = '<div class="perf-chart-empty">기간 내 매출이 없습니다.</div>'; return; }
|
||||
if (!rows.length || total <= 0) { box.innerHTML = '<div class="perf-chart-empty">' + esc(EMPTY_TEXT) + "</div>"; return; }
|
||||
const W = 640, rowH = 22, L = 120, R = 150, H = rows.length * rowH + 6;
|
||||
const maxV = Math.max.apply(null, rows.map(function (r) { return Math.max(0, r[metric] || 0); })) || 1;
|
||||
let g = "";
|
||||
|
||||
Reference in New Issue
Block a user