CREATE TABLE `brands` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `slug` varchar(255) NOT NULL,
  `name` varchar(100) NOT NULL,
  `companyname` varchar(100) DEFAULT NULL,
  `website` varchar(200) NOT NULL,
  `description` text,
  `logo` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `postcode` varchar(100) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `province` varchar(100) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `vat` varchar(100) DEFAULT NULL,
  `bank_name` varchar(255) DEFAULT NULL,
  `bank_IBAN` varchar(255) DEFAULT NULL,
  `bank_SWIFT` varchar(255) DEFAULT NULL,
  `email` varchar(100) NOT NULL,
  `telephone` varchar(100) DEFAULT NULL,
  `confirmation_email` varchar(100) NOT NULL,
  'order_conditions' text DEFAULT "",
  `active` int(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `brand_customer` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `customer_id` int(11) NOT NULL,
  `brand_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `brand_user` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `user_id` int(10) NOT NULL,
  `brand_id` int(10) NOT NULL,
  `season_lists` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_customer` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `user_id` int(10) NOT NULL,
  `customer_id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `customers` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `companyname` varchar(255) NOT NULL,
  `sign` varchar(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `vat` varchar(100) DEFAULT NULL,
  `address` varchar(255) NOT NULL,
  `city` varchar(100) DEFAULT NULL,
  `province` varchar(10) DEFAULT NULL,
  `postcode` varchar(100) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `telephone` varchar(100) DEFAULT NULL,
  `mobile` varchar(100) DEFAULT NULL,
  `fax` varchar(100) DEFAULT NULL,
  `email` varchar(255) NOT NULL,
  `language` varchar(20) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `suppliers` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `companyname` varchar(255) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `vat` varchar(100) DEFAULT NULL,
  `address` varchar(255) NOT NULL,
  `city` varchar(100) DEFAULT NULL,
  `province` varchar(10) DEFAULT NULL,
  `postcode` varchar(100) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `telephone` varchar(100) DEFAULT NULL,
  `mobile` varchar(100) DEFAULT NULL,
  `fax` varchar(100) DEFAULT NULL,
  `email` varchar(255) NOT NULL,
  `language` varchar(20) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `brand_supplier` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `supplier_id` int(11) NOT NULL,
  `brand_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `customer_deliveries` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `customer_id` int(11) NOT NULL,
  `receiver` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `city` varchar(100) DEFAULT NULL,
  `province` varchar(100) DEFAULT NULL,
  `postcode` varchar(50) DEFAULT NULL,
  `country` varchar(50) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `session_orders` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`order_id` int(20) NOT NULL, 
	`user_id` int(20) NOT NULL, 
  `brand_id` int(20) NOT NULL,
	`customer_id` int(20) NOT NULL,
	`season_id` int(20) NOT NULL, 
	`price_list_id` varchar(100) NOT NULL, 
	`season_delivery_id` int(20) NOT NULL, 
	`customer_delivery_id` int(20) NOT NULL, 
	`type` VARCHAR(20) NOT NULL, 
	`products_qty` int NOT NULL,
	`items_qty` int NOT NULL, 
	`subtotal` double(11,2) NOT NULL,
	`payment_id` int(20) NOT NULL, 
	`payment_action` VARCHAR(20), 
	`payment_amount` float,
	`total` double(11,2) NOT NULL,
	`note` TEXT,
	`status` varchar(20) NOT NULL DEFAULT "confirmed",
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_order_details` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`session_order_id` int(20) NOT NULL,
	`product_id` int(20) NOT NULL,
	`variation_id` int(20) NOT NULL,
	`item_id` int(20) NOT NULL,
	`description` TEXT,
	`qty` int,
	`price` double(11,2) NOT NULL,
	`source` varchar(10) NOT NULL,
	`discount` double(11,2) NOT NULL DEFAULT "0.00",
	`total` double(11,2) NOT NULL,
	`note` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_waybills` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `waybill_id` int(11) NOT NULL DEFAULT 0,
	`user_id` int(11) NOT NULL,
  `brand_id` int(20) NOT NULL,
	`customer_id` int(11) NOT NULL,
	`supplier_id` int(11) NOT NULL,
	`price_list_id` varchar(100),
	`order_id` int(11) NOT NULL DEFAULT 0,
	`number` int(11) NOT NULL,
	`year` int(4) NOT NULL,
	`charge` varchar(100),
	`carrier_code` varchar(10),
	`packages` int(10) NOT NULL DEFAULT 1,
  `items_qty` int(10) NOT NULL DEFAULT 0,
	`weight` int(10) NOT NULL DEFAULT 0,
	`delivery_date` DATETIME,
	`note` TEXT,
	`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`updated_at` DATETIME
);

CREATE TABLE `session_waybill_details` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`session_waybill_id` int(20) NOT NULL,
	`product_id` int(20) NOT NULL,
	`variation_id` int(20) NOT NULL,
	`item_id` int(20) NOT NULL,
	`description` TEXT,
	`qty` int,
	`price` double(11,2) NOT NULL,
	`source` varchar(10) NOT NULL,
	`discount` double(11,2) NOT NULL DEFAULT 0.00,
	`total` double(11,2) NOT NULL,
	`note` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_invoices` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`user_id` int(20) NOT NULL,
	`customer_id` int(20) NOT NULL DEFAULT 0,
	`invoice_id` int(20) NOT NULL DEFAULT 0,
	`supplier_id` int(20) NOT NULL DEFAULT 0,
	`order_id` int(20) NOT NULL DEFAULT 0,
	`waybill_id` int(20) NOT NULL DEFAULT 0,
	`type` TEXT,
	`price_list_id` TEXT,
	`number` int(20) NOT NULL,
	`year` int(5) NOT NULL,
	`items_qty` int(10) NOT NULL DEFAULT 0,
	`subtotal` REAL NOT NULL,
	`payment_id` int(20) NOT NULL, 
	`payment_date` DATETIME,
	`payment_action` TEXT, 
	`payment_amount` REAL,
	`tax_id` int(20) NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
	`status` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_invoice_details` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`session_invoice_id` int(20) NOT NULL,
	`product_id` int(20) NOT NULL,
	`variation_id` int(20) NOT NULL,
	`item_id` int(20) NOT NULL,
	`description` TEXT,
	`qty` INTEGER,
	`price` REAL NOT NULL,
	`source` TEXT NOT NULL,
	`discount` REAL NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_proforma` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`user_id` int(20) NOT NULL,
	`proforma_id` int(20) NOT NULL,
	`customer_id` int(20) NOT NULL DEFAULT 0,
	`supplier_id` int(20) NOT NULL DEFAULT 0,
	`order_id` int(20) NOT NULL DEFAULT 0,
	`waybill_id` int(20) NOT NULL DEFAULT 0,
	`type` TEXT,
	`price_list_id` TEXT,
	`number` int(10) NOT NULL,
	`year` int(5) NOT NULL,
	`items_qty` int(20) NOT NULL DEFAULT 0,
	`subtotal` REAL NOT NULL,
	`payment_id` int(20) NOT NULL, 
	`payment_date` DATETIME,
	`payment_action` TEXT, 
	`payment_amount` REAL,
	`tax_id` int(20) NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
	`status` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_proforma_details` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`session_proforma_id` int(20) NOT NULL,
	`product_id` int(20) NOT NULL,
	`variation_id` int(20) NOT NULL,
	`item_id` int(20) NOT NULL,
	`description` TEXT,
	`qty` INTEGER,
	`price` REAL NOT NULL,
	`source` TEXT NOT NULL,
	`discount` REAL NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_accomp_invoices` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`user_id` int(20) NOT NULL,
	`accomp_invoice_id` int(20) NOT NULL,
	`customer_id` int(20) NOT NULL DEFAULT 0,
	`supplier_id` int(20) NOT NULL DEFAULT 0,
	`order_id` int(20) NOT NULL DEFAULT 0,
	`waybill_id` int(20) NOT NULL DEFAULT 0,
	`type` TEXT,
	`price_list_id` TEXT,
	`number` int(10) NOT NULL,
	`year` int(5) NOT NULL,
	`charge` varchar(100),
	`carrier_code` varchar(10),
	`packages` int(10) NOT NULL DEFAULT 1,
	`weight` int(10) NOT NULL DEFAULT 0,
	`delivery_date` DATETIME,
	`items_qty` int(20) NOT NULL DEFAULT 0,
	`subtotal` REAL NOT NULL,
	`payment_id` int(20) NOT NULL, 
	`payment_date` DATETIME,
	`payment_action` TEXT, 
	`payment_amount` REAL,
	`tax_id` int(20) NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
	`status` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_accomp_invoice_details` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`session_accomp_invoice_id` int(20) NOT NULL,
	`product_id` int(20) NOT NULL,
	`variation_id` int(20) NOT NULL,
	`item_id` int(20) NOT NULL,
	`description` TEXT,
	`qty` INTEGER,
	`price` REAL NOT NULL,
	`source` TEXT NOT NULL,
	`discount` REAL NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);


CREATE TABLE `session_credit_notes` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`user_id` int(20) NOT NULL,
	`credit_note_id` int(20) NOT NULL,
	`customer_id` int(20) NOT NULL DEFAULT 0,
	`supplier_id` int(20) NOT NULL DEFAULT 0,
	`order_id` int(20) NOT NULL DEFAULT 0,
	`invoice_id` int(20) NOT NULL DEFAULT 0,
	`waybill_id` int(20) NOT NULL DEFAULT 0,
	`type` TEXT,
	`price_list_id` TEXT,
	`number` int(10) NOT NULL,
	`year` int(5) NOT NULL,
	`items_qty` int(20) NOT NULL DEFAULT 0,
	`subtotal` REAL NOT NULL,
	`payment_id` int(20) NOT NULL, 
	`payment_date` DATETIME,
	`payment_action` TEXT, 
	`payment_amount` REAL,
	`tax_id` int(20) NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
	`status` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `session_credit_note_details` (
	`id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
	`session_credit_note_id` int(20) NOT NULL,
	`product_id` int(20) NOT NULL,
	`variation_id` int(20) NOT NULL,
	`item_id` int(20) NOT NULL,
	`description` TEXT,
	`qty` INTEGER,
	`price` REAL NOT NULL,
	`source` TEXT NOT NULL,
	`discount` REAL NOT NULL,
	`total` REAL NOT NULL,
	`note` TEXT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
);

CREATE TABLE `migrations` (
  `migration` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `batch` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `password_resets` (
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `token` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


CREATE TABLE `permissions` (
  `id` int(10) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `permissions` ADD UNIQUE KEY `permissions_name_unique` (`name`);


CREATE TABLE `permission_role` (
  `permission_id` int(10) NOT NULL,
  `role_id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


CREATE TABLE `profiles` (
  `id` int(10) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `user_id` int(10) NOT NULL,
  `companyname` varchar(255) NOT NULL,
  `name` varchar(100) DEFAULT NULL,
  `surname` varchar(100) DEFAULT NULL,
  `avatar` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `province` varchar(100) DEFAULT NULL,
  `postcode` int(100) DEFAULT NULL,
  `country` varchar(255) DEFAULT NULL,
  `bio` text,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `roles` (
  `id` int(10) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `sessions` (
  `id` varchar(225) NOT NULL,
  `user_id` int(11) DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text,
  `payload` text NOT NULL,
  `last_activity` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `users` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `active` int(1) NOT NULL DEFAULT '1',
  `last_login` timestamp NULL DEFAULT NULL,
  `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER TABLE `users` ADD UNIQUE KEY `users_email_unique` (`email`);


CREATE TABLE `user_options` (
  `id` int(10) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `user_id` int(10) NOT NULL,
  `active_brand` int(11) NOT NULL,
  `active_type` int(10) DEFAULT '1',
  `visible_season` int(10) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `types` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `slug` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `active` int(1) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tickets` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `user_id` INT(10) NOT NULL,
  `title` varchar(255) NOT NULL,
  `status` varchar(20) NOT NULL,
  `to_read_staff` INT(1) NOT NULL DEFAULT '1',
  `to_read_user` INT(1) NOT NULL DEFAULT '1',
  `active_brand` varchar(225) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ticket_messages` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `ticket_id` INT(10) NOT NULL,
  `sender` TEXT(10) NOT NULL,
  `message` TEXT NOT NULL,
  `attachments` TEXT DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `implementation_tickets` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `user_id` INT(10) NOT NULL,
	`description` TEXT NOT NULL,
  `status` varchar(20) NOT NULL,
	`payment_id` varchar(100) DEFAULT NULL,
	`price` DECIMAL(10,2) DEFAULT 0.00,
  `to_read_staff` INT(1) NOT NULL DEFAULT '1',
  `to_read_user` INT(1) NOT NULL DEFAULT '1',
  `active_brand` varchar(225) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `implementation_ticket_messages` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `ticket_id` INT(10) NOT NULL,
  `sender` TEXT(10) NOT NULL,
  `message` TEXT NOT NULL,
  `attachments` TEXT DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `implementation_ticket_invoices` (
  `id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `implementation_ticket_id` INT(10) NOT NULL,
	`number` INT(10) NOT NULL,
	`year` INT(10) NOT NULL,
	`companyname` VARCHAR(100) NOT NULL,
	`address` varchar(255) DEFAULT NULL,
  `postcode` varchar(100) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `province` varchar(100) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `vat` varchar(100) DEFAULT NULL,
  `cf` varchar(100) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `types` (`id`, `slug`, `name`, `active`, `created_at`, `updated_at`) VALUES
(1, 'all', 'All', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(2, 'adult', 'Adult', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(3, 'kids', 'Kids', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(4, 'man', 'Man', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(5, 'woman', 'Woman', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(6, 'male kid', 'Male Kid', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(7, 'female kid', 'Female Kid', 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00');

ALTER TABLE `password_resets`
  ADD KEY `password_resets_email_index` (`email`),
  ADD KEY `password_resets_token_index` (`token`);

ALTER TABLE `roles`
  ADD UNIQUE KEY `roles_name_unique` (`name`);

INSERT INTO `roles` (`id`, `name`, `created_at`, `updated_at`) VALUES
(1, 'superuser', '2016-05-26 20:34:36', '2016-05-26 20:34:36'),
(2, 'admin', '2016-05-26 20:34:36', '2016-05-26 20:34:36'),
(3, 'manager', '2016-05-26 20:34:36', '2016-05-26 20:34:36'),
(4, 'agent', '2016-05-26 20:34:36', '2016-05-26 20:34:36'),
(5, 'manufacturer', '2016-07-07 22:00:00', NULL),
(6, 'accountant', '2016-07-24 22:00:00', NULL);

INSERT INTO `permissions` (`id`, `name`, `created_at`, `updated_at`) VALUES
(1, 'brands_edit', NULL, NULL),
(2, 'customers_see', NULL, NULL),
(3, 'customers_edit', NULL, NULL),
(4, 'orders_manage', NULL, NULL),
(5, 'orders_see', NULL, NULL),
(6, 'orders_create', NULL, NULL),
(7, 'orders_update', NULL, NULL),
(8, 'brands_manage_options', NULL, NULL),
(9, 'linesheet_see', NULL, NULL),
(10, 'invoice_create', NULL, NULL),
(11, 'invoice_see', NULL, NULL),
(12, 'users_manage', NULL, NULL),
(13, 'users_see', NULL, NULL),
(14, 'users_add', NULL, NULL),
(15, 'users_unlink', NULL, NULL),
(16, 'waybill_create', NULL, NULL),
(17, 'waybill_see', NULL, NULL),
(18, 'report_see_total', NULL, NULL),
(19, 'report_see_prices', NULL, NULL),
(20, 'report_see', NULL, NULL),
(21, 'products_see', NULL, NULL),
(22, 'products_create', NULL, NULL),
(23, 'products_edit', NULL, NULL);

INSERT INTO `permission_role` (`permission_id`, `role_id`) VALUES
(1, 1),
(1, 2),
(2, 1),
(2, 2),
(2, 3),
(2, 4),
(3, 1),
(3, 2),
(3, 3),
(3, 4),
(4, 1),
(4, 2),
(4, 3),
(5, 1),
(5, 2),
(5, 3),
(5, 4),
(6, 1),
(6, 2),
(6, 3),
(6, 4),
(7, 1),
(7, 2),
(7, 3),
(7, 4),
(8, 1),
(8, 2),
(8, 3),
(9, 1),
(9, 2),
(9, 3),
(9, 4),
(10, 1),
(10, 2),
(10, 6),
(11, 1),
(11, 2),
(11, 6),
(12, 1),
(12, 2),
(13, 1),
(13, 2),
(13, 3),
(14, 1),
(14, 2),
(14, 3),
(15, 1),
(15, 2),
(16, 1),
(16, 2),
(16, 6),
(17, 1),
(17, 2),
(17, 6),
(18, 1),
(18, 2),
(18, 3),
(18, 6),
(19, 1),
(19, 2),
(19, 3),
(19, 6),
(20, 1),
(20, 2),
(20, 3),
(20, 5),
(20, 6),
(21, 1),
(21, 2),
(21, 3),
(21, 4),
(21, 5),
(21, 6),
(22, 1),
(22, 2),
(22, 3),
(23, 1),
(23, 2),
(23, 3);