CREATE TABLE IF NOT EXISTS `#__sr_facilities` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `scope_id` TINYINT(3) UNSIGNED NOT NULL,
  `title` VARCHAR(45) NULL,
  `description` TEXT NULL,
  `ordering` INT(11) NOT NULL DEFAULT 0,
  `state` TINYINT(3) NOT NULL,
  `icon` VARCHAR(50) NULL,
  PRIMARY KEY (`id`))
  ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `#__sr_facility_reservation_asset_xref` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `facility_id` INT(11) UNSIGNED NOT NULL,
  `reservation_asset_id` INT(11) UNSIGNED NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sr_facility_reservation_asset_xref_sr_reservatio_idx` (`reservation_asset_id` ASC),
  INDEX `fk_sr_facility_reservation_asset_xref_sr_facilities_idx` (`facility_id` ASC),
  CONSTRAINT `fk_sr_facility_reservation_asset_xref_sr_reservation_1`
  FOREIGN KEY (`reservation_asset_id`)
  REFERENCES `#__sr_reservation_assets` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_sr_facility_reservation_asset_xref_sr_facilities1`
  FOREIGN KEY (`facility_id`)
  REFERENCES `#__sr_facilities` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
  ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `#__sr_facility_room_type_xref` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `facility_id` INT(11) UNSIGNED NOT NULL,
  `room_type_id` INT(11) UNSIGNED NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sr_facility_room_type_xref_sr_room_types1_idx` (`room_type_id` ASC),
  INDEX `fk_sr_facility_room_type_xref_sr_facilities1_idx` (`facility_id` ASC),
  CONSTRAINT `fk_sr_facility_room_type_xref_sr_room_types1`
  FOREIGN KEY (`room_type_id`)
  REFERENCES `#__sr_room_types` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_sr_facility_room_type_xref_sr_facilities1`
  FOREIGN KEY (`facility_id`)
  REFERENCES `#__sr_facilities` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
  ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `#__sr_themes` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(255) NULL,
  `description` TEXT NULL,
  `ordering` INT(11) NOT NULL DEFAULT 0,
  `state` TINYINT(3) NOT NULL,
  PRIMARY KEY (`id`))
  ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `#__sr_reservation_asset_theme_xref` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `reservation_asset_id` INT(11) UNSIGNED NOT NULL,
  `theme_id` INT(11) UNSIGNED NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sr_reservation_asset_theme_xref_sr_reservation_a_idx` (`reservation_asset_id` ASC),
  INDEX `fk_sr_reservation_asset_theme_xref_sr_themes1_idx` (`theme_id` ASC),
  CONSTRAINT `fk_sr_reservation_asset_theme_xref_sr_reservation_ass1`
  FOREIGN KEY (`reservation_asset_id`)
  REFERENCES `#__sr_reservation_assets` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_sr_reservation_asset_theme_xref_sr_themes1`
  FOREIGN KEY (`theme_id`)
  REFERENCES `#__sr_themes` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
  ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

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) NOT NULL,
  `percentage` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
  `value` DECIMAL(12,2) UNSIGNED NOT NULL DEFAULT '0.00',
  `user_groups` TEXT NOT NULL,
  `scope` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
  `created` DATETIME NOT NULL,
  `created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0,
  `type` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`))
ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__sr_commission_rate_property_xref` (
  `commission_rate_id` INT(11) UNSIGNED NOT NULL,
  `property_id` INT(11) UNSIGNED NOT NULL,
  PRIMARY KEY (`commission_rate_id`, `property_id`),
  INDEX `fk_com_property_xref_res_asset_idx` (`property_id` ASC),
  CONSTRAINT `fk_com_property_xref_com_rates1`
    FOREIGN KEY (`commission_rate_id`)
    REFERENCES `#__sr_commission_rates` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_com_property_xref_reservation_assets1`
   FOREIGN KEY (`property_id`)
    REFERENCES `#__sr_reservation_assets` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

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 DEFAULT 0,
  `reservation_history` MEDIUMTEXT NOT NULL,
  `revenues` DECIMAL(12,2) UNSIGNED NOT NULL,
  `commissions` DECIMAL(12,2) NOT NULL,
  `scope` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
  `rate_type` INT(11) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`))
ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_coupons` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(125) NOT NULL,
  `published` TINYINT(1) NOT NULL DEFAULT '1',
  `ordering` INT(10) UNSIGNED NOT NULL DEFAULT '1',
  `coupon_code` VARCHAR(225) 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 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 DEFAULT 0,
  `checked_out` INT(10) UNSIGNED NOT NULL DEFAULT 0,
  `checked_out_time` DATETIME NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

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) NOT NULL,
  `admin` TEXT NOT NULL,
  `published` TINYINT(1) NOT NULL DEFAULT '1',
  `subject` VARCHAR(500) NOT NULL,
  `body` MEDIUMTEXT 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 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_levels` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(255) NOT NULL,
  `image` VARCHAR(1024) NOT NULL,
  `published` TINYINT(4) NULL DEFAULT NULL,
  `description` TEXT NULL DEFAULT NULL,
  `duration` INT(10) UNSIGNED NOT NULL DEFAULT '365',
  `price` FLOAT NOT NULL DEFAULT '0',
  `tax` INT(11) NULL DEFAULT NULL,
  `forever` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  `fee` FLOAT UNSIGNED NOT NULL DEFAULT '0',
  `expire_date` DATETIME NOT NULL,
  `return_article_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `cancel_article_id` VARCHAR(255) NULL DEFAULT NULL,
  `created` DATETIME NOT NULL,
  `created_by` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `checked_out` INT(10) UNSIGNED NOT NULL DEFAULT 0,
  `checked_out_time` DATETIME NULL DEFAULT NULL,
  `ordering` INT(11) NOT NULL DEFAULT '0',
  `params` MEDIUMTEXT NULL DEFAULT NULL,
  `notify_1` INT(11) NULL DEFAULT NULL,
  `notify_2` INT(11) NULL DEFAULT NULL,
  `frequency` INT(10) UNSIGNED NULL DEFAULT NULL,
  `hotel_number` INT(10) UNSIGNED NOT NULL DEFAULT '10',
  `tour_number` INT(10) UNSIGNED NOT NULL DEFAULT '10',
  `recurring` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
  `trial_period` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  `first_period` DECIMAL(10,2) NULL DEFAULT NULL,
  `first_period_duration` INT(10) UNSIGNED NULL DEFAULT NULL,
  `first_period_unit` CHAR(1) NULL DEFAULT NULL,
  `second_period` DECIMAL(10,2) NULL DEFAULT NULL,
  `second_period_duration` INT(10) UNSIGNED NULL DEFAULT NULL,
  `second_period_unit` CHAR(1) NULL DEFAULT NULL,
  `scope` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`))
ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__sr_subscription_upgrades` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(255) 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) 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 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__sr_subscriptions` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `invoice_num` VARCHAR(50) NOT NULL,
  `created` DATETIME NOT NULL,
  `created_by` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `checked_out` INT(10) UNSIGNED NULL DEFAULT '0',
  `checked_out_time` DATETIME NULL DEFAULT NULL,
  `level_id` INT(10) UNSIGNED NOT NULL,
  `level_history` TEXT NOT NULL,
  `user_id` INT(10) UNSIGNED NOT NULL,
  `customer_history` TEXT NOT NULL,
  `payment_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `payment_status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '2',
  `payment_history` TEXT NULL DEFAULT NULL,
  `transaction_id` VARCHAR(1000) NULL DEFAULT NULL,
  `published` TINYINT(1) NOT NULL DEFAULT '0',
  `price` FLOAT NOT NULL,
  `discount` FLOAT UNSIGNED NULL DEFAULT '0',
  `tax` FLOAT UNSIGNED NOT NULL DEFAULT '0',
  `valid_from` DATETIME NULL DEFAULT NULL,
  `valid_to` DATETIME NULL DEFAULT NULL,
  `note` TEXT NULL DEFAULT NULL,
  `business` TINYINT(1) NOT NULL DEFAULT '0',
  `business_name` VARCHAR(255) NOT NULL DEFAULT '',
  `vat_num` VARCHAR(100) NOT NULL DEFAULT '',
  `business_address` VARCHAR(1000) NOT NULL DEFAULT '',
  `xref_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`))
ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;