CREATE TABLE `ticket` (
  `ticket_id` bigint(20) unsigned NOT NULL,
  `handle` char(9) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
  `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  `castka` decimal(10,2) unsigned NOT NULL DEFAULT '0.00',
  `castka_cash` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT 'castka zaokrouhlena na platidlo',
  `zalozen` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `vyplacen` smallint(5) unsigned NOT NULL DEFAULT '0',
  `zruseno` smallint(5) unsigned NOT NULL DEFAULT '0',
  `is_loss` tinyint(1) NOT NULL,
  `zrusil_bookmaker_id` int(10) unsigned DEFAULT NULL,
  `duvod_zruseni` varchar(255) DEFAULT NULL,
  `system` smallint(5) unsigned NOT NULL DEFAULT '0',
  `type` varchar(45) DEFAULT NULL,
  `win` decimal(15,2) unsigned DEFAULT NULL,
  `rate` decimal(15,2) unsigned DEFAULT NULL,
  `rate_real` decimal(15,2) unsigned DEFAULT NULL,
  `win_real` decimal(15,2) unsigned DEFAULT NULL,
  `stats` smallint(5) unsigned NOT NULL DEFAULT '0',
  `stats_user` smallint(5) unsigned NOT NULL DEFAULT '0',
  `vyplacen_date` datetime NOT NULL,
  `vyplacen_bookmaker_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `mail` smallint(6) DEFAULT '1',
  `group_count` int(10) unsigned DEFAULT NULL,
  `group_t` tinyint(1) DEFAULT '0',
  `tickethash` varchar(32) CHARACTER SET ascii NOT NULL,
  `host_id` int(10) unsigned DEFAULT NULL,
  `cash` tinyint(1) NOT NULL,
  `collection_time` datetime DEFAULT NULL,
  `collection_host_id` int(10) unsigned DEFAULT NULL,
  `collection_account_user_id` int(11) DEFAULT NULL,
  `forced_collection_host_id` int(10) unsigned DEFAULT NULL,
  `cancel_time` datetime DEFAULT NULL,
  `admin_id` int(10) unsigned DEFAULT NULL,
  `coupon_id` int(10) unsigned NOT NULL,
  `point_type_id` int(10) unsigned DEFAULT NULL,
  `rate_advance` decimal(10,2) DEFAULT NULL,
  `forfeit` datetime DEFAULT NULL,
  `mp` decimal(10,3) NOT NULL DEFAULT '0.000',
  `mp_win` decimal(10,3) NOT NULL DEFAULT '0.000',
  `mp_amount` decimal(10,2) DEFAULT NULL,
  `mp_win_amount` decimal(10,2) DEFAULT NULL,
  `cancel_allowed` tinyint(1) DEFAULT NULL,
  `cached_data` text,
  `coupon_admin_id` int(10) unsigned DEFAULT NULL,
  `confirm_date` datetime DEFAULT NULL,
  `confirm_bookmaker_id` int(10) unsigned DEFAULT NULL,
  `point_create` int(11) DEFAULT NULL,
  `point_branch_visit` int(11) DEFAULT NULL,
  `castka_body` decimal(10,2) DEFAULT NULL,
  `sms` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`ticket_id`),
  UNIQUE KEY `handle` (`handle`),
  KEY `FK_ticket_1` (`user_id`),
  KEY `tickethash` (`tickethash`),
  KEY `collection_branch_id` (`collection_host_id`),
  KEY `fk__ticket__point_type_id` (`point_type_id`),
  KEY `forced_collection_host_id` (`forced_collection_host_id`),
  KEY `forfeit` (`forfeit`),
  KEY `zalozen` (`zalozen`),
  KEY `vyplacen` (`vyplacen`),
  KEY `zruseno` (`zruseno`),
  KEY `is_loss` (`is_loss`),
  KEY `vyplacen_date` (`vyplacen_date`),
  KEY `host_id` (`host_id`),
  KEY `cash` (`cash`),
  KEY `collection_time` (`collection_time`),
  KEY `i__ticket__coupon_id` (`coupon_id`),
  KEY `cancel_time` (`cancel_time`),
  KEY `realWinNetto` (`user_id`,`vyplacen`,`win_real`,`castka`),
  KEY `host_zal` (`host_id`,`zalozen`),
  KEY `user_zal_zrus_host` (`user_id`,`zalozen`,`zruseno`,`host_id`),
  CONSTRAINT `FK_ticket_1` FOREIGN KEY (`user_id`) REFERENCES `uzivatel` (`user_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk__ticket__point_type_id` FOREIGN KEY (`point_type_id`) REFERENCES `point_type` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `sazky` (
  `sazka_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `platna_od` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `platna_do` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status` smallint(5) unsigned NOT NULL DEFAULT '0',
  `status_ext` smallint(5) unsigned DEFAULT NULL,
  `live` smallint(5) unsigned NOT NULL DEFAULT '0',
  `bookmaker_id` int(10) unsigned NOT NULL DEFAULT '0',
  `udalost_id` int(10) unsigned NOT NULL DEFAULT '0',
  `typ_id` int(10) unsigned NOT NULL DEFAULT '0',
  `real_typ_id` int(10) unsigned DEFAULT NULL,
  `podtyp_id` int(10) unsigned NOT NULL DEFAULT '0',
  `overena` smallint(5) unsigned NOT NULL DEFAULT '0',
  `text` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `ticket_text` varchar(64) CHARACTER SET utf8 DEFAULT NULL,
  `jednoducha` smallint(5) unsigned NOT NULL DEFAULT '0',
  `vysledek` varchar(250) NOT NULL DEFAULT '',
  `proplacena` smallint(5) unsigned NOT NULL DEFAULT '0',
  `proplatil_bookmaker` int(11) DEFAULT '0',
  `info` varchar(800) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `message` varchar(400) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `ako` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'AKO sazka',
  `parent_id` int(10) unsigned DEFAULT NULL,
  `alias` int(11) DEFAULT NULL,
  `alias_released` tinyint(1) DEFAULT NULL,
  `score` varchar(128) CHARACTER SET utf8 DEFAULT NULL,
  `text_note` varchar(16) CHARACTER SET utf8 DEFAULT NULL,
  `score_note` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  `translation` text CHARACTER SET utf8,
  PRIMARY KEY (`sazka_id`),
  UNIQUE KEY `u__sazky__parent_id_real_typ_id` (`parent_id`,`real_typ_id`),
  KEY `FK_sazky_1` (`bookmaker_id`),
  KEY `FK_sazky_2` (`udalost_id`),
  KEY `FK_sazky_3` (`typ_id`),
  KEY `FK_sazky_4` (`podtyp_id`),
  KEY `FK_sazky_5` (`vysledek`),
  KEY `datumod` (`platna_od`),
  KEY `datumdo` (`platna_do`),
  KEY `parent_id` (`parent_id`),
  KEY `alias` (`alias`),
  KEY `status` (`status`),
  KEY `proplacena` (`proplacena`),
  KEY `overena_status` (`overena`,`status`),
  KEY `udalost_status` (`udalost_id`,`status`),
  KEY `udalost_typ_podtyp` (`udalost_id`,`typ_id`,`podtyp_id`),
  KEY `status_do` (`status`,`platna_do`),
  KEY `typ_status` (`typ_id`,`status`),
  KEY `udalost_typ_do` (`udalost_id`,`typ_id`,`platna_do`,`live`),
  KEY `do_id_status_udalost` (`platna_do`,`sazka_id`,`status`,`udalost_id`),
  KEY `udalost_do_id_status` (`udalost_id`,`platna_do`,`sazka_id`,`status`),
  CONSTRAINT `FK_sazky_2` FOREIGN KEY (`udalost_id`) REFERENCES `udalost` (`udalost_id`) ON UPDATE CASCADE,
  CONSTRAINT `FK_sazky_3` FOREIGN KEY (`typ_id`) REFERENCES `typ` (`typ_id`) ON UPDATE CASCADE,
  CONSTRAINT `FK_sazky_4` FOREIGN KEY (`podtyp_id`) REFERENCES `podtyp` (`podtyp_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3921224 DEFAULT CHARSET=latin1;
