Skip to content

Auditor · Truy vết & Audit

Quick Reference — Read-only. Vào trang forecast → click 1 dòng → tab Audit Timeline → đọc trình tự sự kiện.

Use case 1 · Truy vết "số final ngày X = Y"

#
1Vào /planner/forecast/customer/:idBảng forecast theo khách
2Click ngày XDrawer mở bên phải
3Tab "Audit Timeline"Hiện chuỗi event theo thời gian
4Đọc từ dưới lên: baseline → adjustment → state → final
5Verify mỗi event có actor_id, reason🟢

Use case 2 · Báo cáo kỳ (tháng/quý)

Query audit_log WHERE created_at BETWEEN ...Hệ thống chưa có UI export → Admin chạy SQL trên Supabase
Count actions theo type
Spot anomalies: actor lạ, decision không note, gap thời gian

SQL ví dụ

sql
select date_trunc('day', created_at) as day,
       action,
       count(*) as n,
       count(*) filter (where reason is null) as no_reason
from audit_log
where created_at >= date_trunc('month', current_date)
group by 1,2
order by 1 desc, 2;

Use case 3 · Cross-check raw vs final

FieldSo với
historical_orders.qtyforecast_result.baseline_avg
forecast_adjustments.qty (ACCEPTED)forecast_result.audited_qty
config_values (snapshot tại thời điểm)Multiplier dùng trong baseline

Nếu 1 lệch → đọc audit_log đoạn thời gian liên quan.

Yêu cầu compliance MVP

  • ✅ Mọi adjustment có ≥ 2 audit row khi ACCEPTED (state change + qty edit)
  • ✅ Mọi config change có audit row với before/after JSON
  • Δ > 30% decisions phải có reason non-empty
  • ✅ Không có gap > 5 phút giữa state changes liên tiếp của cùng adjustment (anti-rush check)

Quyền

Auditor có:

  • READ trên mọi bảng (RLS policy: is_auditor())
  • KHÔNG insert/update/delete

Output báo cáo audit

Template báo cáo gợi ý:

markdown
## Audit Report — (Tháng/Quý)

### 1. Tổng quan
- # adjustments: 
- # ACCEPTED / REJECTED: 
- # decisions Δ > 30%: 
- # decisions không note (vi phạm): 

### 2. Anomalies
- 

### 3. Recommendations
-

Lỗi thường gặp

"Không có audit row cho 1 adjustment ACCEPTED"

⚠️ Compliance gap — báo Admin ngay. Có thể do:

  • Service quên ghi audit (bug → log Sentry)
  • Hoặc adjustment được tạo trước khi audit table có policy