CREATE TABLE IF NOT EXISTS `tbltenant_card_reader_orders` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint(20) unsigned NOT NULL,
  `tenant_name` varchar(255) DEFAULT NULL,
  `tenant_email` varchar(255) DEFAULT NULL,
  `tenant_mobile_no` varchar(20) DEFAULT NULL,
  `order_no` varchar(255) NOT NULL,
  `order_type` enum('free','paid') COLLATE utf8_unicode_ci DEFAULT NULL,
  `order_amount` decimal(15,2) NOT NULL DEFAULT 0.00 ,
  `order_status` enum('pending','failed','processing','cancelled','shipped','completed','refunded') COLLATE utf8_unicode_ci DEFAULT 'pending',
  `tracking_id` varchar(255) DEFAULT NULL,
  `number_of_devices` int NOT NULL DEFAULT '1',
  `shipping_street` varchar(200) DEFAULT NULL,
  `shipping_street_2` varchar(200) DEFAULT NULL,
  `shipping_city` varchar(100) DEFAULT NULL,
  `shipping_state` varchar(100) DEFAULT NULL,
  `shipping_state_id` bigint unsigned DEFAULT NULL,
  `shipping_zip` varchar(100) DEFAULT NULL,
  `shipping_country` bigint DEFAULT NULL,
  `contact_name` varchar(255) DEFAULT NULL,
  `contact_mobile_no` varchar(20) DEFAULT NULL,
  `signature` varchar(40) DEFAULT NULL,
  `added_on` datetime NOT NULL,
  `added_by` bigint unsigned NOT NULL,
  `updated_on` datetime DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `order_ipaddr` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `tenant_id` (`tenant_id`),
  KEY `order_no` (`order_no`),
  KEY `shipping_state_id` (`shipping_state_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;


CREATE TABLE IF NOT EXISTS `tbltenant_card_reader_order_status_history` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `order_id` bigint unsigned NOT NULL,
  `order_status` enum('pending','failed','processing','cancelled','shipped','completed','refunded') DEFAULT NULL,
  `status_comment` varchar(200) DEFAULT NULL,
  `added_by` bigint unsigned DEFAULT NULL,
  `added_on` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `order_id` (`order_id`),
  KEY `order_status` (`order_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;



-- CARD READER SERVICE APAD
INSERT INTO tblapad_options (TYPE,NAME,VALUE,autoload)
VALUES
('cp_card_reader_service','crs_order_number_format','1',1) ,
('cp_card_reader_service','next_crs_order_number','1',1),
('cp_card_reader_service','crs_order_prefix','CRS-',1);


ALTER TABLE tbltenant_card_reader_orders ADD UNIQUE KEY unique_order (order_no);
ALTER TABLE tbltenant_card_reader_orders ADD contact_mobile_no_code VARCHAR(6) DEFAULT NULL AFTER contact_mobile_no;