feat(performance): upload manual-input sales from an Excel file

- [엑셀 업로드] button on the daily x marketplace table opens a popup with
  a sample download (module upload_sample.xlsx) and a file picker
- Format: column 1 = date, columns 2+ = marketplace names as headers
  (setting name / short name / code, spaces and case ignored)
- Only filled cells of marketplaces with manual input ON are saved
  (overwrite same day, blank cells keep existing values); other columns
  are skipped and reported
- Any bad cell (not a number, unreadable/future date, duplicate day) rejects
  the whole file with cell references; saving is one transaction
- Ignore Excel lock files (~$*)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 04:58:00 +09:00
parent 410d4fe05c
commit 1d3573a44a
13 changed files with 503 additions and 8 deletions
+6
View File
@@ -75,6 +75,12 @@ a.perf-seg.is-active, a.perf-seg.is-active:link, a.perf-seg.is-active:visited {
.perf-notice[hidden] { display: none; }
.perf-notice.is-warn { background: #fff7f5; border-color: #f3d2ca; }
.perf-notice.is-ok { background: #f3fbf5; border-color: #cdeccf; }
/* 수동 입력 엑셀 업로드 — 버튼은 표시 기준 버튼 바로 왼쪽, 창 안 파일 칸·오류 목록 */
.perf-manual-upload-btn { margin-left: auto; }
.perf-upload-file { width: 100%; box-sizing: border-box; }
.perf-upload-result { margin-top: 10px; }
.perf-upload-result .perf-notice { margin: 0; display: block; line-height: 1.6; }
.perf-upload-errors { margin: 6px 0 0; padding-left: 18px; max-height: 220px; overflow-y: auto; font-size: 12px; line-height: 1.6; color: #b42318; }
.perf-problem { padding: 1px 8px; border-radius: 999px; background: #fbe9e6; color: var(--perf-down); font-weight: 500; }
/* KPI */
+58
View File
@@ -253,6 +253,64 @@
b.addEventListener("click", function () { setMetric(b.dataset.metric); });
});
// 수동 입력 엑셀 업로드 — 1열 날짜, 2열부터 쇼핑몰 이름 머리글. 값이 있는 칸만 반영(빈 칸은 기존 값 그대로).
// 잘못된 칸이 있으면 서버가 아무것도 저장하지 않고 칸 위치 목록을 돌려준다.
const uploadBtn = document.getElementById("perf-manual-upload");
if (uploadBtn) uploadBtn.addEventListener("click", function () {
let saved = false;
const m = openModal("수동 입력 엑셀 업로드", { narrow: true, onClose: function () { if (saved) location.reload(); } });
const shops = (data.manual_upload_names || []).map(esc).join(", ");
m.body.innerHTML =
'<p class="perf-muted" style="margin:0 0 8px">1열에 <b>날짜</b>, 2열부터 <b>쇼핑몰 이름</b>을 머리글로 적고 그날 <b>총매출</b>을 넣습니다. ' +
"값이 있는 칸만 반영되고(같은 날 값은 덮어씀) 빈 칸은 기존 값 그대로입니다.</p>" +
'<p class="perf-muted" style="margin:0 0 10px">입력 가능한 쇼핑몰: ' + (shops || "없음") + "</p>" +
'<p style="margin:0 0 12px"><a class="erp-btn erp-btn-outline erp-btn-sm" href="/performance/api/manual-sales/sample.xlsx" download>' +
"샘플 파일 받기</a></p>" +
'<input type="file" class="erp-input perf-upload-file" accept=".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" aria-label="엑셀 파일" />' +
'<div class="perf-upload-result"></div>';
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/manual-sales/upload", { 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;
const ignored = body && body.ignored && body.ignored.length
? '<p class="perf-muted" style="margin:6px 0 0">건너뛴 열: ' + esc(body.ignored.join(", ")) + "</p>" : "";
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 + ignored;
return;
}
saved = body.saved > 0;
out.innerHTML = '<p class="perf-notice is-ok">' + (saved
? fmt(body.saved) + "칸 반영 (" + esc(body.from === body.to ? body.from : body.from + " ~ " + body.to) + ")<br>" +
esc(body.by_shop.map(function (s) { return s.name + " " + fmt(s.count) + "일"; }).join(" · "))
: "반영할 값이 없습니다(값이 있는 칸이 없음).") + "</p>" + ignored +
(saved ? '<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");