Skip to content

Nhập dữ liệu lịch sử ​

Quick Reference — Trang /admin/history-import → upload file → preview → confirm.

Khi nào cần? ​

  • Setup ban đầu (cần ≥ 90 ngày để có baseline đúng)
  • Khi onboard khách mới
  • Khi data warehouse có gap / điều chỉnh hồi tố

Bước thực hiện ​

#▶✅
1Vào sidebar → Lập kế hoạch → Dữ liệu lịch sửMở /admin/history-import
2Bấm "Tải template"Download historical-orders-template.xlsx
3Điền data theo cột–
4UploadPreview hiện tổng dòng + tổng qty
5Soát: số dòng, ngày min/max, # khách, # kho–
6Confirm "Nhập"Toast "Đã nhập N dòng"
7(optional) Bấm "Rerun engine" để cập nhật baselineNightly chạy ngay

Template — các cột ​

CộtBắt buộcVí dụGhi chú
customer_code✅LOREAL_VN–
warehouse_code✅HCM_01–
order_date✅2026-03-15–
qty✅1240Số đơn ngày đó
event_type–NORMALMặc định NORMAL
pk_breakdown–SB:60,MIX:25,HVY:15Nếu có thông tin

Cách xử lý duplicate ​

  • Engine định nghĩa unique key = (customer_code, warehouse_code, order_date)
  • Upload lại cùng key → upsert (override qty cũ)
  • Log audit action=IMPORT_HISTORICAL cho cả batch

Sanity check sau import ​

CheckKỳ vọng
Tổng dòng = tổng dòng Excel🟢
Min(order_date) ≤ today − 90d🟢
Max(order_date) ≤ today🟢 (không có ngày tương lai)
# (cust × wh) pairs khớp DB🟢

Lỗi thường gặp ​

"Customer/warehouse code chưa tồn tại"

Tạo trước ở /admin/warehouses và danh mục customer (admin module).

"Date format sai"

Excel có thể tự convert ngày → chữ. Format cell = YYYY-MM-DD text trước khi upload.

"Tổng qty preview lệch file gốc"

Có dòng bị trim do qty ≤ 0 hoặc duplicate trong file. Xem report parser hiển thị bên cạnh preview.