
CREATE TABLE IF NOT EXISTS `sale_returns` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` int(10) unsigned NOT NULL,
  `return_no` varchar(30) NOT NULL,
  `customer_id` int(10) unsigned NOT NULL,
  `total_refund` bigint(20) unsigned NOT NULL DEFAULT 0,
  `reason` text DEFAULT NULL,
  `battery_condition` enum('healthy','defective') NOT NULL DEFAULT 'healthy',
  `refund_method` varchar(30) NOT NULL DEFAULT 'cash',
  `voucher_id` int(10) unsigned DEFAULT NULL,
  `created_by` int(10) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_return_no` (`return_no`),
  KEY `idx_order` (`order_id`),
  KEY `idx_customer` (`customer_id`),
  KEY `fk_sret_created_by` (`created_by`),
  CONSTRAINT `fk_sale_returns_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_sret_created_by` FOREIGN KEY (`created_by`) REFERENCES `admin_users` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  CONSTRAINT `fk_sret_customer` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
