CREATE TABLE IF NOT EXISTS `#__sr_commission_rates` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `state` tinyint(1) NOT NULL DEFAULT '0',
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `percentage` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `value` decimal(12,2) unsigned NOT NULL DEFAULT '0.00',
  `user_groups` text COLLATE utf8_unicode_ci NOT NULL,
  `created` datetime NOT NULL,
  `created_by` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_commissions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `state` tinyint(1) NOT NULL DEFAULT '1',
  `reservation_id` int(10) unsigned NOT NULL DEFAULT '0',
  `created` datetime NOT NULL,
  `created_by` int(10) unsigned NOT NULL,
  `reservation_history` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `revenues` decimal(12,2) unsigned NOT NULL,
  `commissions` decimal(12,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_coupons` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(125) COLLATE utf8_unicode_ci NOT NULL,
  `published` tinyint(1) NOT NULL DEFAULT '1',
  `ordering` int(10) unsigned NOT NULL DEFAULT '1',
  `coupon_code` varchar(225) COLLATE utf8_unicode_ci NOT NULL,
  `coupon_value` float unsigned NOT NULL DEFAULT '0',
  `percent` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `valid_from` datetime NOT NULL,
  `valid_to` datetime NOT NULL,
  `user_group` text COLLATE utf8_unicode_ci NOT NULL,
  `level_id` int(10) unsigned NOT NULL DEFAULT '0',
  `quantity` int(10) unsigned NOT NULL DEFAULT '1',
  `forever` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime NOT NULL,
  `created_by` int(10) unsigned NOT NULL,
  `checked_out` int(10) unsigned NOT NULL,
  `checked_out_time` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_emails` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `level_id` int(10) unsigned NOT NULL DEFAULT '0',
  `key` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `admin` text COLLATE utf8_unicode_ci NOT NULL,
  `published` tinyint(1) NOT NULL DEFAULT '1',
  `subject` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
  `body` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `created_by` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out_time` datetime NOT NULL,
  `ordering` int(10) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_levels` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `image` varchar(1024) COLLATE utf8_unicode_ci NOT NULL,
  `published` tinyint(4) DEFAULT NULL,
  `description` text COLLATE utf8_unicode_ci,
  `duration` int(10) unsigned NOT NULL DEFAULT '365',
  `price` float NOT NULL DEFAULT '0',
  `tax` int(11) DEFAULT NULL,
  `forever` tinyint(1) unsigned DEFAULT '0',
  `fee` float unsigned NOT NULL DEFAULT '0',
  `expire_date` datetime NOT NULL,
  `return_article_id` int(10) unsigned DEFAULT NULL,
  `cancel_article_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out` int(10) unsigned NOT NULL,
  `checked_out_time` datetime DEFAULT NULL,
  `ordering` int(11) NOT NULL DEFAULT '0',
  `params` mediumtext COLLATE utf8_unicode_ci,
  `notify_1` int(11) DEFAULT NULL,
  `notify_2` int(11) DEFAULT NULL,
  `frequency` int(10) unsigned DEFAULT NULL,
  `hotel_number` int(10) unsigned NOT NULL DEFAULT '10',
  `recurring` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `trial_period` tinyint(1) unsigned DEFAULT '0',
  `first_period` decimal(10,2) DEFAULT NULL,
  `first_period_duration` int(10) unsigned DEFAULT NULL,
  `first_period_unit` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
  `second_period` decimal(10,2) DEFAULT NULL,
  `second_period_duration` int(10) unsigned DEFAULT NULL,
  `second_period_unit` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_upgrades` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `published` tinyint(1) NOT NULL DEFAULT '1',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `created_by` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out_time` datetime NOT NULL,
  `from_level_id` int(10) unsigned NOT NULL DEFAULT '0',
  `to_level_id` int(10) unsigned NOT NULL DEFAULT '0',
  `min_presence` int(5) unsigned NOT NULL,
  `max_presence` int(5) unsigned NOT NULL,
  `type` char(15) COLLATE utf8_unicode_ci NOT NULL,
  `value` float unsigned NOT NULL,
  `combine` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `ordering` int(10) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_subscriptions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_num` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `created` datetime NOT NULL,
  `created_by` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out` int(10) unsigned DEFAULT '0',
  `checked_out_time` datetime DEFAULT NULL,
  `level_id` int(10) unsigned NOT NULL,
  `level_history` text COLLATE utf8_unicode_ci NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `customer_history` text COLLATE utf8_unicode_ci NOT NULL,
  `payment_id` int(10) unsigned NOT NULL DEFAULT '0',
  `payment_status` tinyint(1) unsigned NOT NULL DEFAULT '2',
  `payment_history` text COLLATE utf8_unicode_ci,
  `transaction_id` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL,
  `published` tinyint(1) NOT NULL DEFAULT '0',
  `price` float NOT NULL,
  `discount` float unsigned DEFAULT '0',
  `tax` float unsigned NOT NULL DEFAULT '0',
  `valid_from` datetime DEFAULT NULL,
  `valid_to` datetime DEFAULT NULL,
  `note` text COLLATE utf8_unicode_ci,
  `bussiness_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `vat_num` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `bussiness_address` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL,
  `xref_id` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;