CREATE TABLE agent_voucher_sales (
id INTEGER PRIMARY KEY AUTOINCREMENT,
agent_id INTEGER NOT NULL,
voucher_code TEXT UNIQUE NOT NULL,
package_id TEXT NOT NULL,
package_name TEXT NOT NULL,
customer_phone TEXT,
customer_name TEXT,
price DECIMAL(10,2) NOT NULL,
commission DECIMAL(10,2) DEFAULT 0.00,
status TEXT DEFAULT 'active' CHECK (status IN ('active', 'used', 'expired', 'cancelled')),
sold_at DATETIME DEFAULT CURRENT_TIMESTAMP,
used_at DATETIME,
notes TEXT,
agent_price DECIMAL(10,2) DEFAULT 0.00,
commission_amount DECIMAL(10,2) DEFAULT 0.00,
FOREIGN KEY (agent_id) REFERENCES agents(id) ON DELETE CASCADE
)