-- Unify POS and Sales Invoices
-- Date: 2026-02-20

ALTER TABLE invoices ADD COLUMN IF NOT EXISTS transaction_no VARCHAR(50) DEFAULT NULL AFTER id;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS is_pos TINYINT(1) DEFAULT 0;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS discount_amount DECIMAL(15,3) DEFAULT 0;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS loyalty_points_earned DECIMAL(15,3) DEFAULT 0;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS loyalty_points_redeemed DECIMAL(15,3) DEFAULT 0;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS created_by INT(11) DEFAULT NULL;

ALTER TABLE payments ADD COLUMN IF NOT EXISTS transaction_id INT(11) DEFAULT NULL;

ALTER TABLE invoices MODIFY COLUMN status ENUM('paid','unpaid','partially_paid','refunded','cancelled') DEFAULT 'unpaid';
