# Commission Management Specification

## ADDED Requirements

### Requirement: Withdrawal Request List

The system SHALL provide a paginated list of all commission withdrawal requests with filtering capabilities.

#### Scenario: View all withdrawal requests

- **WHEN** administrator accesses the withdrawal approval page
- **THEN** the system displays all withdrawal requests with pagination
- **AND** shows withdrawal number, shop name, amount, status, and timestamps

#### Scenario: Filter by status

- **WHEN** administrator filters by withdrawal status (pending/approved/rejected/completed)
- **THEN** the system displays only matching withdrawal requests

#### Scenario: Search by withdrawal number or shop name

- **WHEN** administrator searches by withdrawal number or shop name
- **THEN** the system displays matching records

### Requirement: Withdrawal Request Approval

The system SHALL allow administrators to approve withdrawal requests.

#### Scenario: Approve withdrawal request

- **WHEN** administrator clicks approve on a pending withdrawal request
- **THEN** the system marks the request as approved
- **AND** updates the processor information and timestamp

### Requirement: Withdrawal Request Rejection

The system SHALL allow administrators to reject withdrawal requests with a reason.

#### Scenario: Reject withdrawal request

- **WHEN** administrator clicks reject and provides a rejection reason
- **THEN** the system marks the request as rejected
- **AND** stores the rejection reason and processor information

### Requirement: Withdrawal Settings Configuration

The system SHALL provide configuration for withdrawal rules including minimum amount, fee rate, daily limits, and arrival days.

#### Scenario: Create withdrawal settings

- **WHEN** administrator creates new withdrawal settings
- **THEN** the system stores the configuration with minimum amount, fee rate, daily limit, and arrival days
- **AND** records the creator information

#### Scenario: View current active settings

- **WHEN** administrator requests current withdrawal settings
- **THEN** the system displays the currently active withdrawal configuration

### Requirement: Withdrawal Settings List

The system SHALL display all withdrawal settings configurations with their status.

#### Scenario: View all settings

- **WHEN** administrator accesses withdrawal settings page
- **THEN** the system displays all configurations with active status indicator

### Requirement: My Commission Records

The system SHALL allow agents to view their detailed commission transaction records.

#### Scenario: View commission records

- **WHEN** agent accesses my commission page
- **THEN** the system displays all commission records with amount, type, status, and order information
- **AND** supports filtering by commission type and status

### Requirement: My Commission Summary

The system SHALL provide agents with an overview of their commission balances.

#### Scenario: View commission summary

- **WHEN** agent accesses commission overview
- **THEN** the system displays total commission, available balance, frozen amount, withdrawing amount, and withdrawn total

### Requirement: My Withdrawal Requests

The system SHALL allow agents to view their withdrawal request history.

#### Scenario: View my withdrawals

- **WHEN** agent accesses withdrawal history
- **THEN** the system displays all their withdrawal requests with status and amounts

### Requirement: Submit Withdrawal Request

The system SHALL allow agents to submit new withdrawal requests.

#### Scenario: Create withdrawal request

- **WHEN** agent submits a withdrawal request with amount and payment details
- **THEN** the system validates available balance
- **AND** creates a withdrawal request with status pending
- **AND** calculates fees based on current settings

#### Scenario: Insufficient balance

- **WHEN** agent requests withdrawal exceeding available balance
- **THEN** the system rejects the request with insufficient balance error

### Requirement: Agent Commission Records

The system SHALL allow administrators to view detailed commission records for any shop.

#### Scenario: View shop commission records

- **WHEN** administrator selects a shop and views commission records
- **THEN** the system displays all commission transactions for that shop
- **AND** includes order details, ICCID, device number, and balance information

### Requirement: Agent Commission Summary List

The system SHALL provide administrators with a summary view of all shops' commissions.

#### Scenario: View all shop commissions

- **WHEN** administrator accesses agent commission management
- **THEN** the system displays all shops with their commission summaries
- **AND** shows total, available, frozen, withdrawing, and withdrawn amounts per shop

### Requirement: Agent Withdrawal History

The system SHALL allow administrators to view withdrawal history for any shop.

#### Scenario: View shop withdrawals

- **WHEN** administrator selects a shop and views withdrawal history
- **THEN** the system displays all withdrawal requests for that shop

### Requirement: Customer Account Management

The system SHALL support creating and managing customer accounts for both agents and enterprises.

#### Scenario: Create agent account

- **WHEN** administrator creates a new agent account
- **THEN** the system creates the account with username, phone, associated shop, and initial password
- **AND** sets user type as agent (3)

#### Scenario: Create enterprise account

- **WHEN** administrator creates a new enterprise account
- **THEN** the system creates the account with username, phone, associated enterprise, and initial password
- **AND** sets user type as enterprise (4)

#### Scenario: Update account status

- **WHEN** administrator enables or disables an account
- **THEN** the system updates the account status (0=disabled, 1=enabled)

#### Scenario: Reset account password

- **WHEN** administrator resets an account password
- **THEN** the system updates the password and notifies the user

### Requirement: Enterprise Customer Management

The system SHALL support creating and managing enterprise customer records.

#### Scenario: Create enterprise

- **WHEN** administrator creates a new enterprise
- **THEN** the system stores enterprise details including business license, legal person, contact info, and address
- **AND** associates with an owner shop

#### Scenario: Update enterprise information

- **WHEN** administrator updates enterprise details
- **THEN** the system updates the enterprise record

#### Scenario: Update enterprise status

- **WHEN** administrator enables or disables an enterprise
- **THEN** the system updates the enterprise status

#### Scenario: Reset enterprise password

- **WHEN** administrator resets enterprise login password
- **THEN** the system updates the password for the associated login account

### Requirement: Commission Navigation Structure

The system SHALL provide a "Commission Management" section under "Account Management" with sub-menus for all commission features.

#### Scenario: Access commission menus

- **WHEN** user navigates to Account Management
- **THEN** the system displays "Commission Management" menu
- **AND** shows sub-menus: Withdrawal Approval, Withdrawal Settings, My Commission, Agent Commission
