-- CHECKLABS Hotel Restaurant POS customization (2026-11-30)
-- Run once against the existing hotel POS database if you are not running Laravel migrations.
ALTER TABLE `restaurant_orders`
  ADD COLUMN `seating_type` VARCHAR(20) NOT NULL DEFAULT 'open' AFTER `sale_type`,
  ADD COLUMN `vip_percentage` DECIMAL(5,2) NOT NULL DEFAULT 0.00 AFTER `seating_type`,
  ADD COLUMN `delivery_name` VARCHAR(255) NULL,
  ADD COLUMN `delivery_phone` VARCHAR(40) NULL,
  ADD COLUMN `delivery_address` TEXT NULL,
  ADD COLUMN `delivery_fee` DECIMAL(12,2) NOT NULL DEFAULT 0.00,
  ADD COLUMN `rider_name` VARCHAR(255) NULL,
  ADD COLUMN `delivery_status` VARCHAR(30) NULL;

ALTER TABLE `order_items`
  ADD COLUMN `base_unit_price` DECIMAL(12,2) NULL AFTER `unit_price`;

UPDATE `restaurant_orders` SET `seating_type` = 'delivery' WHERE `sale_type` = 'delivery';

-- This installation is hotel restaurant only; hide legacy bar department/section/printers.
UPDATE `departments` SET `is_active` = 0 WHERE `slug` = 'bar';
UPDATE `sections` SET `is_active` = 0 WHERE `type` = 'bar';
UPDATE `printers` SET `is_active` = 0 WHERE `type` IN ('bar', 'bar_receipt');
UPDATE `products` SET `kitchen_station` = 'Choma Zone' WHERE LOWER(`kitchen_station`) IN ('grill', 'grill station', 'choma');
UPDATE `products` SET `kitchen_station` = 'Juice Bar' WHERE LOWER(`kitchen_station`) IN ('bar', 'juice', 'juice bar');
UPDATE `categories` SET `kitchen_station` = 'Choma Zone' WHERE LOWER(`kitchen_station`) IN ('grill', 'grill station', 'choma');
UPDATE `categories` SET `kitchen_station` = 'Juice Bar' WHERE LOWER(`kitchen_station`) IN ('bar', 'juice', 'juice bar');
UPDATE `printers` SET `station` = 'Choma Zone' WHERE LOWER(`station`) IN ('grill', 'grill station', 'choma');
UPDATE `printers` SET `station` = 'Juice Bar' WHERE LOWER(`station`) IN ('bar', 'juice', 'juice bar');
UPDATE `order_items` SET `destination` = 'kitchen', `kitchen_station` = 'Juice Bar' WHERE `destination` = 'bar';
UPDATE `order_items` SET `kitchen_station` = 'Main Kitchen' WHERE `destination` = 'kitchen' AND `kitchen_station` IS NULL;

INSERT INTO `settings` (`group`, `key`, `value`, `type`, `created_at`, `updated_at`)
VALUES ('restaurant', 'vip_percentage', '0', 'number', NOW(), NOW())
ON DUPLICATE KEY UPDATE `updated_at` = VALUES(`updated_at`);
