-- Alembic Revision: TODO

CREATE TABLE `sales_reports` (
  `_cache_id` varchar(128) COLLATE utf8_bin NOT NULL,
  `id` varchar(64) COLLATE utf8_bin NOT NULL,
  `generated_at` datetime NOT NULL,
  `gross_sales_total` int(11) DEFAULT NULL,
  `reductions_total` int(11) DEFAULT NULL,
  `net_sales` int(11) DEFAULT NULL,
  `taxes` int(11) DEFAULT NULL,
  `deferred_sales_total` int(11) DEFAULT NULL,
  `service_charges_total` int(11) DEFAULT NULL,
  `revenue` int(11) DEFAULT NULL,
  `payments_total` int(11) DEFAULT NULL,
  `payouts_total` int(11) DEFAULT NULL,
  PRIMARY KEY (`_cache_id`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `sales_report_payments` (
  `_cache_id` varchar(128) COLLATE utf8_bin NOT NULL,
  `report_id` varchar(64) COLLATE utf8_bin NOT NULL,
  `id` varchar(64) COLLATE utf8_bin NOT NULL,
  `name` varchar(128) COLLATE utf8_bin DEFAULT NULL,
  `amount` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  `tender_type_id` varchar(64) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`_cache_id`,`report_id`,`id`),
  UNIQUE KEY `idx_sales_report_payments_report_id_id` (`_cache_id`,`report_id`,`id`),
  CONSTRAINT `fk_sales_report_payment_sales_report` FOREIGN KEY (`_cache_id`, `report_id`) REFERENCES `sales_reports` (`_cache_id`, `id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `sales_report_payouts` (
  `_cache_id` varchar(128) COLLATE utf8_bin NOT NULL,
  `report_id` varchar(64) COLLATE utf8_bin NOT NULL,
  `id` varchar(64) COLLATE utf8_bin NOT NULL,
  `name` varchar(128) COLLATE utf8_bin DEFAULT NULL,
  `amount` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  PRIMARY KEY (`_cache_id`,`report_id`,`id`),
  UNIQUE KEY `idx_sales_report_payouts_report_id_id` (`_cache_id`,`report_id`,`id`),
  CONSTRAINT `fk_sales_report_payout_sales_report` FOREIGN KEY (`_cache_id`, `report_id`) REFERENCES `sales_reports` (`_cache_id`, `id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
