CREATE TABLE `File` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(1024) NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `filename` varchar(1024) NOT NULL,
  `store_filename` varchar(1024) NOT NULL,
  `orig_filename` varchar(1024) NOT NULL,
  `subfolder` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `create_by` int NOT NULL,
  `edit_by` int NOT NULL,
  `create` int NOT NULL,
  `edit` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `Order` (
  `id` int NOT NULL AUTO_INCREMENT,
  `owner_id` int DEFAULT NULL,
  `billingaddress_id` int DEFAULT NULL,
  `order_date` int NOT NULL,
  `finish_date` int DEFAULT NULL COMMENT 'timestamp',
  `billing_type` enum('invoice','sepa') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `bank_account_bank` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `bank_account_owner` varchar(1024) NOT NULL,
  `bank_account_iban` varchar(255) NOT NULL,
  `bank_account_bic` varchar(64) NOT NULL,
  `allow_contact` tinyint NOT NULL DEFAULT '0',
  `allow_spin` tinyint NOT NULL DEFAULT '0',
  `note` text NOT NULL,
  `create_by` int NOT NULL,
  `edit_by` int NOT NULL,
  `create` int NOT NULL,
  `edit` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `OrderFile` (
  `id` int NOT NULL AUTO_INCREMENT,
  `order_id` int NOT NULL,
  `file_id` int NOT NULL,
  `name` varchar(1024) NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `create_by` int NOT NULL,
  `edit_by` int NOT NULL,
  `create` int NOT NULL,
  `edit` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `OrderProduct` (
  `id` int NOT NULL AUTO_INCREMENT,
  `order_id` int NOT NULL,
  `product_id` int NOT NULL,
  `amount` decimal(9,6) NOT NULL DEFAULT '1.000000',
  `pos` int NOT NULL,
  `description` text NOT NULL,
  `price` int NOT NULL DEFAULT '0',
  `price_setup` int NOT NULL DEFAULT '0',
  `billing_delay` int NOT NULL DEFAULT '0' COMMENT 'in months',
  `billing_period` int NOT NULL COMMENT 'in months',
  `note` text NOT NULL,
  `create_by` int NOT NULL,
  `edit_by` int NOT NULL,
  `create` int NOT NULL,
  `edit` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;