Tasks — Super Agent → Agent
Spec: superagent-to-agent · Mockup: sell-credit (modal), list, detail
Hiện trạng: Đã có superAgentCreditDistributionBizService.distribute (debit SA wallet, credit agent, PaymentTransaction provider super_agent_cash). UI: SuperAgentAgentCreditTrigger trên Super Agent portal (chỉ amount). Chưa ghi cash_transactions, chưa form đầy đủ.
Phụ thuộc: Backend Phase 1 từ tasks Admin → SA + UI package UI.1–UI.7.
Phạm vi V1: Modal từ Agent detail (Super Agent portal). Status paid_full only. Detail view-only.
UI dùng chung: ui-package-cash-settlement — Super Agent portal chỉ wire API.
Phase 1 — Backend
| # | Task | Ghi chú |
|---|---|---|
| 1.1 | Thêm flow super_agent_agent vào cash_transactions | Reuse model từ luồng Admin→SA |
| 1.2 | Refactor superAgentCreditDistributionBizService.distribute | Tạo cash_transaction; payload: credits, cash_received, payment_method, received_at, external_ref?, note? |
| 1.3 | Cost rate snapshot = Agent buyer | expected = credits × agent.costRate |
| 1.4 | Validate SA có đủ credit trước transfer | Lỗi rõ ràng nếu insufficient balance |
| 1.5 | Validate agent thuộc SA + agent không terminated | Giữ assertManagedAgent |
| 1.6 | Ghi performed_by = super agent user id | |
| 1.7 | Link cash_transaction ↔ wallet debit/credit tx ↔ payment_transaction | |
| 1.8 | API POST /super-agent/agents/:id/cash-credits (hoặc mở rộng /credits/distribute) | Breaking change: cần version body hoặc field mới |
| 1.9 | Mở rộng GET /super-agent/cash-transactions | Filter flow=SA→Agent; scope theo SA đang login |
| 1.10 | GET /super-agent/cash-transactions/:id | View-only detail |
| 1.11 | Unit tests | Insufficient SA balance, wrong agent, snapshot rate |
Phase 2 — Super Agent portal wire
UI:
SellCreditsCashModal,PortalCashTransactionsLedger,PortalCashTransactionDetailtừ@kioskgaming/ui.
| # | Task | Ghi chú |
|---|---|---|
| 2.1 | Agent detail: SellCreditsCashModal | flow=super_agent_agent, buyer = agent đang xem |
| 2.2 | API hook + distributeCreditsToManagedAgent → payload mới | Thay SuperAgentAgentCreditTrigger logic |
| 2.3 | Route list/detail + menu Cash Transactions | Compose components package |
| 2.4 | Submit → refresh agent + SA wallet balance |
Tham chiếu: SuperAgentAgentCreditTrigger.tsx
Phase 3 — Admin visibility (optional V1)
| # | Task | Ghi chú |
|---|---|---|
| 3.1 | Admin list hiển thị thêm flow SA→Agent | Filter flow trên Admin ledger (đã generic) |
| 3.2 | Admin detail xem giao dịch SA→Agent | Cùng PortalCashTransactionDetail |
Phase 4 — QA
| # | Task | Ghi chú |
|---|---|---|
| 4.1 | SA bán credit → Agent wallet +, SA wallet − | |
| 4.2 | Agent USD wallet không tăng | Regression |
| 4.3 | List/detail SA portal + Admin | |
| 4.4 | Cập nhật spec nếu cần |
Liên quan
- Trước: Tasks Admin → SA
- Sau: Tasks Agent → Shop