Tasks — Agent → Shop
Spec: agent-to-shop · Mockup: sell-credit (modal), list, detail
Hiện trạng: Đã có creditDistributionBizService.distribute (debit agent, credit shop, PaymentTransaction provider agent_cash). UI: DistributeCreditsTrigger trên Agent portal và Super Agent portal (chỉ amount + shop select trên SA portal). 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ừ Shop detail (Agent portal). Status paid_full only. Detail view-only.
UI dùng chung: ui-package-cash-settlement — Agent portal chỉ wire API.
Phase 1 — Backend
| # | Task | Ghi chú |
|---|---|---|
| 1.1 | Thêm flow agent_shop vào cash_transactions | |
| 1.2 | Refactor creditDistributionBizService.distribute | Tạo cash_transaction; payload mới đầy đủ field |
| 1.3 | Cost rate snapshot = Shop buyer | expected = credits × shop.costRate |
| 1.4 | Validate agent có đủ credit | Insufficient balance error |
| 1.5 | Validate shop thuộc agent | Giữ check shop.agentId |
| 1.6 | Ghi performed_by = agent user id | |
| 1.7 | Link cash_transaction ↔ wallet txs ↔ payment_transaction | |
| 1.8 | API POST /agent/shops/:id/cash-credits (hoặc mở rộng /credits/distribute) | Shop id từ URL — không cần shopId trong body khi mở từ detail |
| 1.9 | GET /agent/cash-transactions + GET /agent/cash-transactions/:id | Scope agent đang login |
| 1.10 | Unit tests | Shop wrong agent, zero cost rate, balance |
Phase 2 — Agent portal wire
UI từ
@kioskgaming/ui— không duplicate component.
| # | Task | Ghi chú |
|---|---|---|
| 2.1 | Shop detail: SellCreditsCashModal | flow=agent_shop, buyer = shop đang xem |
| 2.2 | API hook + extend distributeCredits | Thay logic DistributeCreditsTrigger |
| 2.3 | Route list/detail + menu | PortalCashTransactionsLedger / Detail |
| 2.4 | Submit → refresh shop + agent wallet |
Tham chiếu: kioskgaming_agent/.../DistributeCreditsTrigger.tsx
Phase 3 — Super Agent portal (distribution path)
Super Agent portal cũng có DistributeCreditsTrigger (chọn shop + amount) — quyết định V1:
| # | Task | Ghi chú |
|---|---|---|
| 3.1 | Option A: Chỉ Agent portal bán Agent→Shop | Khuyến nghị |
| 3.2 | Option B: SA portal proxy distribute shop | Cần PM confirm |
| 3.3 | Option A: ẩn distribute shop trên SA portal | Tránh duplicate |
Phase 4 — Admin visibility (optional V1)
| # | Task | Ghi chú |
|---|---|---|
| 4.1 | Admin list/detail flow Agent→Shop | Generic UI package |
Phase 5 — QA
| # | Task | Ghi chú |
|---|---|---|
| 5.1 | Agent bán → Shop wallet +, Agent wallet − | |
| 5.2 | Shop USD wallet không đổi | |
| 5.3 | List/detail Agent portal |
Liên quan
- Trước: Tasks Super Agent → Agent
- Nền tảng: Tasks Admin → SA