-- Fix missing columns in invoices table for POS transactions
-- Date: 2026-02-21

ALTER TABLE invoices ADD COLUMN IF NOT EXISTS transaction_no VARCHAR(50) DEFAULT NULL AFTER id;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS register_session_id INT(11) DEFAULT NULL;
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.000;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS loyalty_points_earned DECIMAL(15,3) DEFAULT 0.000;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS loyalty_points_redeemed DECIMAL(15,3) DEFAULT 0.000;
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS created_by INT(11) DEFAULT NULL;

-- Ensure indexes for better performance
ALTER TABLE invoices ADD INDEX IF NOT EXISTS idx_transaction_no (transaction_no);
ALTER TABLE invoices ADD INDEX IF NOT EXISTS idx_register_session (register_session_id);
