CREATE TABLE invoices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_id INTEGER NOT NULL,
package_id INTEGER NOT NULL,
invoice_number TEXT UNIQUE NOT NULL,
amount DECIMAL(10,2) NOT NULL,
due_date DATE NOT NULL,
status TEXT DEFAULT 'unpaid',
payment_date DATETIME,
payment_method TEXT,
payment_gateway TEXT,
payment_token TEXT,
payment_url TEXT,
payment_status TEXT DEFAULT 'pending',
notes TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
description TEXT NULL,
invoice_type TEXT DEFAULT 'monthly' CHECK (invoice_type IN ('monthly', 'voucher', 'manual')),
package_name TEXT NULL,
base_amount DECIMAL(10,2),
tax_rate DECIMAL(5,2),
FOREIGN KEY (customer_id) REFERENCES customers (id),
FOREIGN KEY (package_id) REFERENCES packages (id)
)