-- Add new columns to QUICKPURCHASEORDERS table for tax and discount support
-- Run this script manually if migration doesn't work automatically

-- Add tax column
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN tax DECIMAL(5, 2) DEFAULT 0.00 COMMENT 'نسبة الضريبة (%)';

-- Add discount column  
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN discount DECIMAL(5, 2) DEFAULT 0.00 COMMENT 'نسبة الخصم (%)';

-- Add debit account column
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN debitAccount INT NULL COMMENT 'الحساب المدين';

-- Add credit account column
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN creditAccount INT NULL COMMENT 'الحساب الدائن';

-- Add currency column
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN currency VARCHAR(10) DEFAULT 'EGP' COMMENT 'العملة';

-- Add exchange rate column
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN exchangeRate DECIMAL(10, 4) DEFAULT 1.0000 COMMENT 'سعر الصرف';

-- Add order type column
ALTER TABLE QUICKPURCHASEORDERS ADD COLUMN orderType ENUM('quick', 'accounting') DEFAULT 'quick' COMMENT 'نوع الطلب';

-- Update existing records to have default values
UPDATE QUICKPURCHASEORDERS SET 
  tax = 0.00, 
  discount = 0.00, 
  currency = 'EGP', 
  exchangeRate = 1.0000, 
  orderType = 'quick' 
WHERE tax IS NULL OR discount IS NULL OR currency IS NULL OR exchangeRate IS NULL OR orderType IS NULL;

-- Show the updated table structure
DESCRIBE QUICKPURCHASEORDERS;
