

ALTER TABLE hold_orders 
ADD COLUMN token_number INT DEFAULT NULL AFTER id,
ADD COLUMN shift_id INT DEFAULT NULL AFTER token_number,
ADD INDEX idx_token_shift (shift_id, token_number),
ADD INDEX idx_shift_id (shift_id);


INSERT INTO `settings` (`store_id`, `category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`) 
SELECT NULL, 1, 'Print Complete Shift Summary Report', 'print_complete_shift_summary', 'boolean', '0', '0', 'When enabled, prints the complete detailed shift summary report. When disabled (default), prints a short condensed summary.', 1
WHERE NOT EXISTS (SELECT 1 FROM settings WHERE code = 'print_complete_shift_summary');




INSERT INTO `settings` 
(`store_id`, `category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`) 
SELECT NULL, 1, 'Print Customer Previous Balance', 'print_cus_previous_balance', 'boolean', '0', '0', 'When enabled, the receipt will display the customer\'s outstanding balance/dues before the current transaction', 1
WHERE NOT EXISTS (SELECT 1 FROM settings WHERE code = 'print_cus_previous_balance');




-- Add currency setting to system_settings category
INSERT INTO `settings` (`category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`) 
SELECT 
    (SELECT id FROM setting_categories WHERE code = 'system_settings' LIMIT 1),
    'System Currency',
    'system_currency',
    'select',
    'Rs',
    'Rs',
    'Select the default currency symbol to be used throughout the system',
    1
WHERE NOT EXISTS (SELECT 1 FROM settings WHERE code = 'system_currency');

-- Add currency options
INSERT INTO `setting_options` (`setting_id`, `option_label`, `option_value`) 
SELECT 
    (SELECT id FROM settings WHERE code = 'system_currency' LIMIT 1),
    'Pakistani Rupee (Rs)',
    'Rs'
WHERE NOT EXISTS (SELECT 1 FROM setting_options WHERE setting_id = (SELECT id FROM settings WHERE code = 'system_currency') AND option_value = 'Rs');

INSERT INTO `setting_options` (`setting_id`, `option_label`, `option_value`) 
SELECT 
    (SELECT id FROM settings WHERE code = 'system_currency' LIMIT 1),
    'Saudi Riyal (SR)',
    'SR'
WHERE NOT EXISTS (SELECT 1 FROM setting_options WHERE setting_id = (SELECT id FROM settings WHERE code = 'system_currency') AND option_value = 'SR');

INSERT INTO `setting_options` (`setting_id`, `option_label`, `option_value`) 
SELECT 
    (SELECT id FROM settings WHERE code = 'system_currency' LIMIT 1),
    'US Dollar ($)',
    '$'
WHERE NOT EXISTS (SELECT 1 FROM setting_options WHERE setting_id = (SELECT id FROM settings WHERE code = 'system_currency') AND option_value = '$');

INSERT INTO `setting_options` (`setting_id`, `option_label`, `option_value`) 
SELECT 
    (SELECT id FROM settings WHERE code = 'system_currency' LIMIT 1),
    'Euro (€)',
    '€'
WHERE NOT EXISTS (SELECT 1 FROM setting_options WHERE setting_id = (SELECT id FROM settings WHERE code = 'system_currency') AND option_value = '€');

INSERT INTO `setting_options` (`setting_id`, `option_label`, `option_value`) 
SELECT 
    (SELECT id FROM settings WHERE code = 'system_currency' LIMIT 1),
    'UAE Dirham (AED)',
    'AED'
WHERE NOT EXISTS (SELECT 1 FROM setting_options WHERE setting_id = (SELECT id FROM settings WHERE code = 'system_currency') AND option_value = 'AED');




-- Create the sync_settings table
CREATE TABLE IF NOT EXISTS `sync_settings` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sync_allow` tinyint(1) DEFAULT 0 COMMENT 'Enable/disable synchronization',
  `db_prefix` varchar(50) DEFAULT NULL COMMENT 'Branch database prefix',
  `sync_mode` varchar(50) DEFAULT 'HO' COMMENT 'HO=Head Office, RM=Remote',
  `server_name` varchar(100) DEFAULT NULL COMMENT 'Head office server IP/hostname',
  `database_name` varchar(100) DEFAULT NULL COMMENT 'Head office database name',
  `username` varchar(100) DEFAULT NULL COMMENT 'Database username',
  `password` varchar(255) DEFAULT NULL COMMENT 'Database password (encrypted)',
  `last_sync_date` datetime DEFAULT NULL COMMENT 'Last successful sync',
  `sync_status` enum('success','failed','pending') DEFAULT 'pending',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- Insert default settings row (if table is empty)
INSERT INTO `sync_settings` (`sync_allow`, `sync_mode`) 
SELECT 0, 'HO'
WHERE NOT EXISTS (SELECT 1 FROM `sync_settings` LIMIT 1);




