-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `statsmain_main`
--

-- --------------------------------------------------------

--
-- Table structure for table `custom_page_layouts`
--

CREATE TABLE `custom_page_layouts` (
  `id` int(11) NOT NULL,
  `slug` varchar(64) NOT NULL,
  `title` varchar(200) DEFAULT NULL,
  `view_permission_key` varchar(80) DEFAULT NULL,
  `layout_json` text NOT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `gp_thresholds`
--

CREATE TABLE `gp_thresholds` (
  `id` int(11) NOT NULL,
  `department_type` varchar(50) NOT NULL,
  `green_min` float NOT NULL,
  `yellow_min` float NOT NULL,
  `yellow_max` float NOT NULL,
  `red_max` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `gp_thresholds`
--

INSERT INTO `gp_thresholds` (`id`, `department_type`, `green_min`, `yellow_min`, `yellow_max`, `red_max`) VALUES
(1, 'electrical', 55, 40, 55, 40),
(2, 'commercial', 55, 40, 55, 40),
(3, 'air', 40, 35, 40, 35),
(4, 'solar', 40, 35, 40, 35),
(5, 'residential', 55, 40, 55, 40);

-- --------------------------------------------------------

--
-- Table structure for table `invoices`
--

CREATE TABLE `invoices` (
  `id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `branch_id` varchar(50) NOT NULL,
  `company_id` int(11) NOT NULL,
  `company_name` varchar(100) NOT NULL,
  `date_issued` datetime NOT NULL,
  `total_ex_tax` float NOT NULL,
  `is_paid` tinyint(1) DEFAULT NULL,
  `customer` text DEFAULT NULL,
  `jobs` text DEFAULT NULL,
  `stage` varchar(100) DEFAULT NULL,
  `status` varchar(100) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `kpi_target_overrides`
--

CREATE TABLE `kpi_target_overrides` (
  `id` int(11) NOT NULL,
  `branch` varchar(80) NOT NULL,
  `department` varchar(80) NOT NULL,
  `metric_key` varchar(80) NOT NULL,
  `target` float DEFAULT NULL,
  `weight` float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `kpi_target_overrides`
--

INSERT INTO `kpi_target_overrides` (`id`, `branch`, `department`, `metric_key`, `target`, `weight`) VALUES
(1, 'Busselton', 'Air', 'quoteConversion', 50, NULL),
(2, 'Bunbury', 'Air', 'quoteConversion', 50, NULL),
(3, 'Mandurah', 'Air', 'quoteConversion', 50, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `permissions`
--

CREATE TABLE `permissions` (
  `id` int(11) NOT NULL,
  `key` varchar(80) NOT NULL,
  `name` varchar(120) NOT NULL,
  `category` varchar(40) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `permissions`
--

INSERT INTO `permissions` (`id`, `key`, `name`, `category`) VALUES
(1, 'admin.access', 'Access Admin page', 'Admin'),
(2, 'admin.revenue_targets', 'Revenue targets (admin)', 'Admin'),
(3, 'admin.gp_thresholds', 'GP thresholds (admin)', 'Admin'),
(4, 'admin.kpi_targets', 'KPI targets (admin)', 'Admin'),
(5, 'admin.connections', 'Connections (admin)', 'Admin'),
(6, 'admin.users', 'Users list & create (admin)', 'Admin'),
(7, 'admin.manage_roles', 'Manage roles & permissions (admin)', 'Admin'),
(8, 'directors.access', 'Access Directors page', 'Directors'),
(9, 'branch.overview', 'Overview (company)', 'Branches'),
(10, 'branch.branch1', 'Busselton branch', 'Branches'),
(11, 'branch.branch2', 'Bunbury branch', 'Branches'),
(12, 'branch.branch3', 'Mandurah branch', 'Branches'),
(13, 'department.branch1_electrical', 'Busselton Electrical', 'Departments'),
(14, 'department.branch1_air', 'Busselton Air', 'Departments'),
(15, 'department.branch2_residential', 'Bunbury Residential', 'Departments'),
(16, 'department.branch2_air', 'Bunbury Air', 'Departments'),
(17, 'department.branch2_solar', 'Bunbury Solar', 'Departments'),
(18, 'department.branch2_commercial', 'Bunbury Commercial', 'Departments'),
(19, 'department.branch3_electrical', 'Mandurah Electrical', 'Departments'),
(20, 'department.branch3_air', 'Mandurah Air', 'Departments'),
(21, 'kpi.branch1', 'Busselton KPIs only', 'KPIs'),
(22, 'kpi.branch2', 'Bunbury KPIs only', 'KPIs'),
(23, 'kpi.branch3', 'Mandurah KPIs only', 'KPIs'),
(24, 'performance.access', 'Access Performance Monitor', 'Performance'),
(25, 'admin.custom_pages', 'Custom page builder', 'Admin');

-- --------------------------------------------------------

--
-- Table structure for table `revenue_targets`
--

CREATE TABLE `revenue_targets` (
  `id` int(11) NOT NULL,
  `branch_id` varchar(50) NOT NULL,
  `company_id` int(11) NOT NULL,
  `target` int(11) DEFAULT NULL,
  `breakeven` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `roles`
--

CREATE TABLE `roles` (
  `id` int(11) NOT NULL,
  `name` varchar(60) NOT NULL,
  `slug` varchar(20) DEFAULT NULL,
  `is_system` tinyint(1) NOT NULL,
  `created_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `roles`
--

INSERT INTO `roles` (`id`, `name`, `slug`, `is_system`, `created_at`) VALUES
(1, 'User', 'user', 1, '2026-02-17 22:18:11'),
(2, 'Admin', 'admin', 1, '2026-02-17 22:18:11'),
(3, 'Director', 'director', 1, '2026-02-17 22:18:11'),
(5, 'Ops Manager Busselton', NULL, 0, '2026-02-23 00:47:05'),
(6, 'Ops Manager Bunbury Air', NULL, 0, '2026-02-23 01:08:56'),
(7, 'Ops Manager Bunbury Electrical', NULL, 0, '2026-02-23 01:11:56'),
(8, 'Ops Manager Bunbury Commercial', NULL, 0, '2026-02-23 01:12:40'),
(9, 'Nixon Directors', NULL, 0, '2026-02-23 01:25:14'),
(10, 'Ops Manager Bunbury Solar', NULL, 0, '2026-02-23 01:31:51'),
(11, 'Ops Manager Mandurah Air', NULL, 0, '2026-02-23 01:32:32'),
(12, 'Ops Manager Mandurah Electrical', NULL, 0, '2026-02-23 01:33:01'),
(13, 'Mandurah Director', NULL, 0, '2026-02-23 01:33:49'),
(14, 'Ops Manager Bunbury Residential', NULL, 0, '2026-02-23 01:37:56'),
(15, 'Office Manager', NULL, 0, '2026-02-23 01:46:13'),
(16, 'adam', NULL, 0, '2026-02-23 03:05:40');

-- --------------------------------------------------------

--
-- Table structure for table `role_permissions`
--

CREATE TABLE `role_permissions` (
  `role_id` int(11) NOT NULL,
  `permission_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `role_permissions`
--

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

-- --------------------------------------------------------

--
-- Table structure for table `sessions`
--

CREATE TABLE `sessions` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `token` varchar(64) NOT NULL,
  `expires_at` datetime NOT NULL,
  `remember_me` tinyint(1) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `otp_verified_at` datetime DEFAULT NULL,
  `otp_code_hash` varchar(255) DEFAULT NULL,
  `otp_expires_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `sessions`
--

INSERT INTO `sessions` (`id`, `user_id`, `token`, `expires_at`, `remember_me`, `created_at`, `otp_verified_at`, `otp_code_hash`, `otp_expires_at`) VALUES
(5, 2, 'kxe08MFFrMAcMUbxbmwR_5eJ4y0SptZMtD2wR3KYJ_U', '2026-03-20 00:52:15', 1, '2026-02-18 00:52:15', NULL, NULL, NULL),
(7, 2, '9Hq0J3mVJYFB75kAduTm_aqiV50w_7EpsCsab5s7oZI', '2026-02-26 02:08:19', 0, '2026-02-19 02:08:19', NULL, NULL, NULL),
(9, 2, 'THvXmjibc95Ig4i1_pw8mk8c3E0KSnoMUHbBUgRM7wA', '2026-02-26 03:22:11', 0, '2026-02-19 03:22:11', NULL, NULL, NULL),
(10, 2, 'sHxl6YPnRRteadrf9--m5HimJ_PlA_gDNISCyWJ9xGw', '2026-02-26 22:13:10', 0, '2026-02-19 22:13:10', '2026-02-24 01:28:19', NULL, NULL),
(11, 2, 'mg1VOecHDTg6-b8xpaigkqM81LHO5jrbvG207s8Ev5U', '2026-03-02 02:01:00', 0, '2026-02-23 02:01:00', NULL, NULL, NULL),
(48, 2, 'Q6HjrVi29EeloeXSN-3yRIe6G7Q6DHxxZHcPZw56ZTo', '2026-03-03 03:04:32', 0, '2026-02-24 03:04:32', '2026-02-24 03:04:32', NULL, NULL),
(54, 28, '5La3Jtx1CVQoD4R3MvQKHESEas8F0Ghv4FhsI0h879Y', '2026-03-03 03:27:33', 0, '2026-02-24 03:27:33', '2026-02-24 03:27:33', NULL, NULL),
(58, 30, 'pftHzodJsRnqVIbwsIEx1XSfotUZdsd_7GHnxcncyco', '2026-03-03 03:51:20', 0, '2026-02-24 03:51:20', '2026-02-24 03:51:20', NULL, NULL),
(60, 21, 'JsluuUoBgRdl9w9c7t5xQqFSTrTZBRDMOjRm4m0fSsA', '2026-03-03 04:24:24', 0, '2026-02-24 04:24:24', '2026-02-24 04:24:24', NULL, NULL),
(61, 29, 'Uu_fbNLNe4oEXicCv3E2hhHfILvVc9tZcQMXpmHaac0', '2026-03-26 04:25:04', 1, '2026-02-24 04:25:04', '2026-02-24 04:25:04', '$2b$12$ZQ56E6yp6oF0x1FrVCmYCeftLScoj8knbBsnh/eKgpODasnavUNdu', '2026-03-13 01:18:18'),
(63, 25, 'okPUAPUhJHpYszf5fB3AMfloP0ssG-VhKL1d8e8hhoE', '2026-03-03 05:21:35', 0, '2026-02-24 05:21:35', '2026-02-24 05:21:35', NULL, NULL),
(68, 33, 'ozMuskDSyFP5CaOIsJQQRU7KNLnfv5-l5-BqC3wJWMM', '2026-03-27 09:37:13', 1, '2026-02-25 09:37:13', '2026-02-25 09:37:13', NULL, NULL),
(69, 22, 'V3l_FLHBYMJKL-01kMlp_zLXfkXiIAJx5AfJfBlrdEE', '2026-03-04 23:33:15', 0, '2026-02-25 23:33:15', '2026-02-25 23:33:15', NULL, NULL),
(78, 12, 'iBzv_U7lR-Zghpo3aCR91Dru6U0kJ_N3FWpnyaj14Kg', '2026-03-05 04:05:33', 0, '2026-02-26 04:05:33', '2026-02-26 04:05:33', NULL, NULL),
(83, 12, 'QgZ4Boel9iP2nBCSMYcX1Y-zTygsIJauWh--ounKP1Q', '2026-03-05 17:37:27', 0, '2026-02-26 17:37:27', '2026-02-26 17:37:27', NULL, NULL),
(85, 24, '9a9RqTxuSM00aw8CPQ8Ec3Vmvc67NwpwohgxPftslKY', '2026-03-05 23:10:46', 0, '2026-02-26 23:10:46', '2026-02-26 23:10:46', NULL, NULL),
(87, 22, 'IFjLiAmgif5DAXJs9wsPgmdqiavUtDHL8L9gAocgPwY', '2026-03-06 02:47:17', 0, '2026-02-27 02:47:17', '2026-02-27 02:47:17', NULL, NULL),
(88, 2, 'gDSVMBsnZgV9plFTowKdKlacWgPnu92t_Ue3Y-9Kn4s', '2026-03-29 03:33:38', 1, '2026-02-27 03:33:38', '2026-02-27 03:33:38', '$2b$12$CtJGSnrQJctiii3EPrAIAur06aMwvrfuM8E2WgEj3U5yFC.pJEy9W', '2026-03-06 03:58:08'),
(91, 32, 'KB-dsvHbtyAd_1ZL02BooOz1r7FToCfJy7AIuJW4VEU', '2026-03-06 06:14:52', 0, '2026-02-27 06:14:52', '2026-02-27 06:14:52', NULL, NULL),
(93, 23, 'ww5ag8bSgv49Jnb9G16WAw_MVEvJDt771xejRHWGX5U', '2026-03-29 07:28:50', 1, '2026-02-27 07:28:50', '2026-02-27 07:28:50', NULL, NULL),
(94, 33, 'jgon0iL0NE9VP98-DzG91ubzPQejqcj3tkKTIy4z_PY', '2026-03-31 23:36:16', 1, '2026-03-01 23:36:16', '2026-03-01 23:36:16', NULL, NULL),
(97, 28, 'Q7YPRrcnG0YDPpIT2rrjrRwt6ILuYxysKg8bIlMALP4', '2026-03-10 03:31:53', 0, '2026-03-03 03:31:53', '2026-03-03 03:31:53', NULL, NULL),
(98, 33, 'xWvPJm9LIM3JhSexct69QSae7kAKOKgjEMHWcK2hTB4', '2026-03-10 22:15:12', 0, '2026-03-03 22:15:12', '2026-03-03 22:15:12', NULL, NULL),
(100, 36, 'VgJOqWLXURM3dDsHuE3bqdvLNDFEbrVzIdcIkZOTvvE', '2026-03-11 00:31:05', 0, '2026-03-04 00:31:05', '2026-03-04 00:31:05', NULL, NULL),
(101, 36, 'BmFVMX3fQuS087WEObyHG0SzWW_dRIw0LKke9bQI_KM', '2026-03-11 00:36:53', 0, '2026-03-04 00:36:53', '2026-03-04 00:36:53', NULL, NULL),
(104, 34, 'dlJg57iGvRZm1MVv4Nocn7B8W_HxpbVRyLVxJRv_9jY', '2026-03-11 02:56:03', 0, '2026-03-04 02:56:03', '2026-03-04 02:56:03', NULL, NULL),
(106, 12, 'pxgSY10u3WeAcaDzGmI05erQ-atnXSCSY-QfJ31Hnyc', '2026-04-04 06:49:15', 1, '2026-03-05 06:49:15', '2026-03-05 06:49:15', NULL, NULL),
(107, 2, 'fo7GwqsaMtrHui-F3LbI6SKul1FEure8KxErLSaPmMM', '2026-03-12 07:30:29', 0, '2026-03-05 07:30:29', '2026-03-05 07:30:29', NULL, NULL),
(110, 2, 'b_w_8cPsLCVp6uzBLw-iacpr8FgruJsQRAkpwTx9New', '2026-04-05 03:48:54', 1, '2026-03-06 03:48:54', '2026-03-06 03:48:54', NULL, NULL),
(111, 2, 'ptlqJZQv-s8hl8WrcyL9rjYHkLKA7ilb79UTfkekxi0', '2026-04-05 03:50:26', 1, '2026-03-06 03:50:26', '2026-03-06 03:50:26', NULL, NULL),
(113, 28, 'vm8xSLQRYmNdAsBf5Dhyc5x5ACPGaFFahDAyn2ZQ3gI', '2026-03-13 08:21:50', 0, '2026-03-06 08:21:50', '2026-03-06 08:21:50', NULL, NULL),
(114, 2, '80I3t1plZS4i6RFzYaW3FvLbPsbxCM15s2gQ2uBxg-o', '2026-04-08 03:02:15', 1, '2026-03-09 03:02:15', '2026-03-09 03:02:15', '$2b$12$HtxD9tvXPCXwdQR7HD2ru.QHTlPRVCwjOzlw1aaAD15wwFrrEAJfu', '2026-03-17 00:45:42'),
(116, 28, 'XRxTLmWaMk3UwMyNFE3Tt_iYhr-qcWZmdAW6envpiKg', '2026-03-16 03:47:10', 0, '2026-03-09 03:47:10', '2026-03-09 03:47:10', NULL, NULL),
(119, 24, 'LhA9nF_6L-8kdRbCs-zUVk3WCTXU2qIjBaTlL0NO3Os', '2026-03-16 22:38:01', 0, '2026-03-09 22:38:01', '2026-03-09 22:38:01', NULL, NULL),
(120, 22, 'z09Nr1p6KxA-6GNwMIqcQG767vUGY0JfEtiEZ55wFRw', '2026-03-16 23:33:14', 0, '2026-03-09 23:33:14', '2026-03-09 23:33:14', NULL, NULL),
(125, 2, 'SJvE2rLPKGaVJztcbI2OyQjM9L-eMb1vJN7OeGrHi5g', '2026-04-10 06:42:37', 1, '2026-03-11 06:42:37', '2026-03-11 06:42:37', NULL, NULL),
(126, 33, 'zO7M8Y52mKgdrxIGcvsN8i5hosduKzgDEN-CkAvJuCs', '2026-03-18 10:57:24', 0, '2026-03-11 10:57:24', '2026-03-11 10:57:24', NULL, NULL),
(127, 2, 'mu1qozT3lEcr-tCpRI-7xV_kuxcaOMMCdtyGnnhVs9I', '2026-04-10 22:49:17', 1, '2026-03-11 22:49:17', '2026-03-11 22:49:17', NULL, NULL),
(128, 22, 'Sm-MGr1yGNBFgHewu9XrctAKzPXR3Mcl6RM-rOwx9go', '2026-03-18 23:13:06', 0, '2026-03-11 23:13:06', '2026-03-11 23:13:06', NULL, NULL),
(130, 20, 'VE1AFd-yyvSw8yK9OC3wt4pzPhUyG9ZhoQIpFZ5sAww', '2026-03-19 01:56:14', 0, '2026-03-12 01:56:14', '2026-03-12 01:56:14', NULL, NULL),
(131, 34, '_dVBlt4498utToWQ2HzqAQQcQb3YN8siuRS50JYhy-4', '2026-03-19 02:51:14', 0, '2026-03-12 02:51:14', '2026-03-12 02:51:14', NULL, NULL),
(137, 28, 'c0BeQN02M-LFNyRA_KyCuGhhiLjy4T3OhFZs724UQMc', '2026-03-20 10:55:52', 0, '2026-03-13 10:55:52', '2026-03-13 10:55:52', NULL, NULL),
(144, 12, 'aOdr9J8YcgzeVjoAs4xzqTNpdzLIBUE48BqZEvg7Tz0', '2026-03-24 03:00:56', 0, '2026-03-17 03:00:56', '2026-03-17 03:00:56', NULL, NULL),
(145, 28, 'W2Dv4aHWnYQBnUCrXPxgZJYR5SbGtYJ1yNhzpHwF8_c', '2026-03-24 04:49:53', 0, '2026-03-17 04:49:53', '2026-03-17 04:49:53', NULL, NULL),
(147, 24, 'QLvv971OERv356tbFBVSznlWE0MU8FhiQFeeMxT-WxE', '2026-03-24 22:23:02', 0, '2026-03-17 22:23:02', '2026-03-17 22:23:02', NULL, NULL),
(148, 35, 'OaP5Z4KvziEJHZ_MlTMHxgRjZRlkSbNy0qh0iu6_acw', '2026-04-16 23:17:46', 1, '2026-03-17 23:17:46', '2026-03-17 23:17:46', NULL, NULL),
(149, 32, 'BJQm-VdhVsekxDrDgYkGoV9CKeaxXzIMAKoquHBvT3g', '2026-03-25 03:14:08', 0, '2026-03-18 03:14:08', '2026-03-18 03:14:08', NULL, NULL),
(152, 33, 'WqHykXrUY7s0eJnCtMWXDmm3vtLw3p_CMxzHVeirO_c', '2026-03-25 22:52:53', 0, '2026-03-18 22:52:53', '2026-03-18 22:52:53', NULL, NULL),
(156, 28, 'UUsFJDHQhkYfl9fZZ6tLW4sDDCXY3e_g8uoKIfo89fs', '2026-03-26 01:46:23', 0, '2026-03-19 01:46:23', '2026-03-19 01:46:23', NULL, NULL),
(157, 2, 'yBrmTQW5IFfCYvsS6KflhZNjypqclSF5QUEW1Jc7SOk', '2026-04-18 11:37:05', 1, '2026-03-19 11:37:05', '2026-03-19 11:37:05', NULL, NULL),
(160, 27, 'c3srYrwilaR_z-6-AB3TmAtg-b4eAJ1XWwG75l-KZrM', '2026-03-27 03:17:22', 0, '2026-03-20 03:17:22', '2026-03-20 03:17:22', NULL, NULL),
(161, 34, 'hlkmaIJOBnSsaIPVCskLanHRDMNlhZX7jGDcma6Ncek', '2026-03-27 04:01:20', 0, '2026-03-20 04:01:20', '2026-03-20 04:01:20', NULL, NULL),
(165, 27, '_blQ0r6soyw2zXO1OuH7w86lVrAwKLjf6QHuhPjHr0k', '2026-03-30 05:36:47', 0, '2026-03-23 05:36:47', '2026-03-23 05:36:47', NULL, NULL),
(166, 27, 'zGWaBwtDBf_1ElMxb7LfJgHe02UFsIcWwh9RWVk_9uo', '2026-03-30 07:48:02', 0, '2026-03-23 07:48:02', '2026-03-23 07:48:02', NULL, NULL),
(167, 31, 'AdmbW4mKH9M3Hz0Z1sCT6NN0ev5hzDRqFD-pl3nikDE', '2026-03-30 22:51:36', 0, '2026-03-23 22:51:36', '2026-03-23 22:51:36', NULL, NULL),
(169, 21, '09D3w804fkOE9FynNnTHr9OfeK5BXhlR88JV5cb7XEM', '2026-03-30 23:27:05', 0, '2026-03-23 23:27:05', '2026-03-23 23:27:05', NULL, NULL),
(170, 2, 'DPnSDKFf-s9IZlTYo1Bf-YmEiRXQtYYFs9SvdT0s8NM', '2026-04-23 00:21:43', 1, '2026-03-24 00:21:43', '2026-03-24 00:21:43', NULL, NULL),
(171, 12, 'iqeYgomD8IW93CJDZ003cX9LgiCpT4TUyuM8oU0HwcY', '2026-03-31 03:35:15', 0, '2026-03-24 03:35:15', '2026-03-24 03:35:15', NULL, NULL),
(172, 27, 'kuTOPMeUBr5IcoZeBGemNvAklbkuAFebQYrnTQq7hzU', '2026-03-31 04:55:18', 0, '2026-03-24 04:55:18', '2026-03-24 04:55:18', NULL, NULL),
(175, 2, 'pg9EFz2035MdSiqQMV8ToTGz8yHJ8OZIO4d3LE109IY', '2026-04-01 04:40:54', 0, '2026-03-25 04:40:54', '2026-03-25 04:40:54', NULL, NULL),
(176, 28, 'b1rLE2i4n7-vYfzuXvMpDcRxhQ_P7KKgPU3krLEeneU', '2026-04-01 21:14:27', 0, '2026-03-25 21:14:27', '2026-03-25 21:14:27', NULL, NULL),
(178, 24, '2VD--9fLgbPlxkmu57uMe0PyE2m2fk7WYGCapRuJtbo', '2026-04-01 22:15:27', 0, '2026-03-25 22:15:27', '2026-03-25 22:15:27', NULL, NULL),
(180, 33, '4YNAeu9HRVPA1dUb3mDnk-61ceaPPI_sHSKxTQeGwyA', '2026-04-02 00:59:36', 0, '2026-03-26 00:59:36', '2026-03-26 00:59:36', NULL, NULL),
(181, 28, '0C6BRcaMyAuoZxODu4V6cV0KvYVRMRzqxlYjZQ0fs_0', '2026-04-02 02:01:03', 0, '2026-03-26 02:01:03', '2026-03-26 02:01:03', NULL, NULL),
(187, 29, '-TA5ca0JQuoJ7WzNBZMaA1h0kD9f-57W5UhcD3gFR6o', '2026-04-03 01:39:50', 0, '2026-03-27 01:39:50', '2026-03-27 01:39:50', NULL, NULL),
(188, 37, 'UNMfXr94a7iHce69_KYOHOHoXt6B5Ylt7lL1m9Wut5k', '2026-04-03 01:45:49', 0, '2026-03-27 01:45:49', '2026-03-27 01:45:49', NULL, NULL),
(189, 30, '5aTeU-c15owMRq3xqpRmMkqrGML0iOLKRUHWOhzErRM', '2026-04-03 03:43:46', 0, '2026-03-27 03:43:46', '2026-03-27 03:43:46', NULL, NULL),
(190, 28, 'khhg91HoI5fcbHRF1-JJODpUCxPIzmBdujinYmYRXW4', '2026-04-03 22:26:49', 0, '2026-03-27 22:26:49', '2026-03-27 22:26:49', NULL, NULL),
(191, 28, 'I7PFiTspiBAvFQRLrlKh4nRPeCHsrSGXmu5MEcrTAr0', '2026-04-04 04:33:27', 0, '2026-03-28 04:33:27', '2026-03-28 04:33:27', NULL, NULL),
(198, 32, 'Tntgel0TM9QEsTfHjcd6nyGtcnAvb2xsDCqhAPD8jm4', '2026-04-29 22:49:57', 1, '2026-03-30 22:49:57', '2026-03-30 22:49:57', NULL, NULL),
(200, 2, 'pLJS6mxS6put3K04pfzFTi-7ppsGJs0Sibn1SwCiWNQ', '2026-04-30 02:19:52', 1, '2026-03-31 02:19:52', '2026-03-31 02:19:52', NULL, NULL),
(202, 12, 'S1slaS12OYkgx2NWO7BgYnEp9DLC8I-IogaHCqNPq4s', '2026-04-07 03:41:03', 0, '2026-03-31 03:41:03', '2026-03-31 03:41:03', NULL, NULL),
(204, 27, '8z8L1Cah35n0lEFo1sUgW_HmO3QNMJAJXmIEcVWdi0o', '2026-04-07 07:42:13', 0, '2026-03-31 07:42:13', '2026-03-31 07:42:13', NULL, NULL),
(209, 2, 'VYuo6gGfDHwApBkmbkGNRAdnwSKqmpNtm8RHow1m9q0', '2026-05-01 02:24:28', 1, '2026-04-01 02:24:28', '2026-04-01 02:24:28', NULL, NULL),
(212, 34, 'bX5-YS_L-vQ7BYAiYTggTW72YS0GqbdeQs_TX_A21vI', '2026-04-08 06:05:54', 0, '2026-04-01 06:05:54', '2026-04-01 06:05:54', NULL, NULL),
(216, 31, 'evjaulT-rSfxdLoMKxzW3I7Oozw4uhHwr-_C7wx1MZU', '2026-04-08 10:13:03', 0, '2026-04-01 10:13:03', '2026-04-01 10:13:03', NULL, NULL),
(218, 28, 'MiipEPDBqVWSYVIshLZEVlIoHG67QPJOhT-dBibA1Bw', '2026-04-09 08:06:29', 0, '2026-04-02 08:06:29', '2026-04-02 08:06:29', NULL, NULL),
(222, 31, '8nvLlPtm9DO-xHdrHmau3xXBAV_a5mFiDkmKa5-s0dM', '2026-04-14 00:04:48', 0, '2026-04-07 00:04:48', '2026-04-07 00:04:48', NULL, NULL),
(223, 12, 'JMPAoaZjkDYQDfazMjq1Y6aswxo_hEd7ihNGOMDhWeY', '2026-04-14 22:12:31', 0, '2026-04-07 22:12:31', '2026-04-07 22:12:31', NULL, NULL),
(224, 29, '7tMnJ1GCX7iHL3wkfYEy_G1NX-ntf5fFB8qUIqKyIP8', '2026-04-15 02:45:17', 0, '2026-04-08 02:45:17', '2026-04-08 02:45:17', NULL, NULL),
(225, 30, 'tiLjtx6qC5QsdorddzleiA3ZfclbxgErbRRZUIiiGKY', '2026-04-15 07:08:12', 0, '2026-04-08 07:08:12', '2026-04-08 07:08:12', NULL, NULL),
(226, 29, '9sa3d18pxCkOWA7Rhhv71-FL4xT0XBI_f6KTW54qRuo', '2026-05-08 12:41:04', 1, '2026-04-08 12:41:04', '2026-04-08 12:41:04', NULL, NULL),
(228, 35, '8IJWHyciOYqUetselHFhZwlR6LmFe-XT3P4ttJMVKY0', '2026-04-15 21:56:49', 0, '2026-04-08 21:56:49', '2026-04-08 21:56:49', NULL, NULL),
(230, 34, 'MtZUDeI1dj7_YVl1Sc-TmDUf8RcjDiMECyoLPJfhaNY', '2026-04-16 00:28:42', 0, '2026-04-09 00:28:42', '2026-04-09 00:28:42', NULL, NULL),
(232, 29, '0VGpHFPmRzel8QvTUVkJo86uOIhidwNwk1oG47Lu5SA', '2026-04-16 03:56:06', 0, '2026-04-09 03:56:06', '2026-04-09 03:56:06', NULL, NULL),
(234, 33, 'mVC1d0_w5kGh7q6WnOC6pOjLPZUBfHQxwWMMGsWsxcc', '2026-05-13 04:50:43', 1, '2026-04-13 04:50:43', '2026-04-13 04:50:43', NULL, NULL),
(236, 28, 'N8OZkeNUVdZP5hwDuzufOsfJDNPRNlkSVA0H4VEMDFY', '2026-04-21 06:36:47', 0, '2026-04-14 06:36:47', '2026-04-14 06:36:47', NULL, NULL),
(237, 28, 'O7wwmAQPTHGvoxANPQM6QP-HrYengW2s1dgQQt7GV_k', '2026-04-21 22:46:25', 0, '2026-04-14 22:46:25', '2026-04-14 22:46:25', NULL, NULL),
(238, 27, 'lC-VT47nlkemTO4XH36_WbY8ClD4AjSsHXc6-T4mtIo', '2026-04-22 06:41:01', 0, '2026-04-15 06:41:01', '2026-04-15 06:41:01', NULL, NULL),
(239, 32, 'NZw_HjWQlA8cOtn6BPT__nG67zxM_RJx2TD2t85lo-4', '2026-04-22 16:47:11', 0, '2026-04-15 16:47:11', '2026-04-15 16:47:11', NULL, NULL),
(241, 22, 'ZJ7pUXAWMPIjYt4_OOMIx_x3WVXA-b7PpfnshzFWTf0', '2026-04-22 23:28:44', 0, '2026-04-15 23:28:44', '2026-04-15 23:28:44', NULL, NULL),
(243, 35, 'zNrv4O3pQwWBuSSFMZtVRZdoK_hbeMXTeU7odlWzGLw', '2026-05-16 04:33:55', 1, '2026-04-16 04:33:55', '2026-04-16 04:33:55', NULL, NULL),
(244, 31, 'mz61tVyE1ewsBucZUJSe1tgAi3zem9ukZAoqEcEKnJk', '2026-04-23 07:37:04', 0, '2026-04-16 07:37:04', '2026-04-16 07:37:04', NULL, NULL),
(247, 21, 'hqGPyEm4j_LDRfDkNx7rv998fsfNtyuAvzoT_HxVD34', '2026-04-24 04:54:23', 0, '2026-04-17 04:54:23', '2026-04-17 04:54:23', NULL, NULL),
(248, 29, 'STiIhtflDkSszMA8Oht97ayPCq-e9yFjCzQIFwCrSMg', '2026-04-24 05:49:46', 0, '2026-04-17 05:49:46', '2026-04-17 05:49:46', NULL, NULL),
(249, 12, 'uGZ7IXy6Q8zcrXLDf12BAUcZQiSxogfJZcFthEl74nI', '2026-04-26 23:31:45', 0, '2026-04-19 23:31:45', '2026-04-19 23:31:45', NULL, NULL),
(251, 34, 'IjVmetE2p2jMa9a01i6cpiM5jgJiXObPGfi_W6BUUwY', '2026-04-30 01:34:08', 0, '2026-04-23 01:34:08', '2026-04-23 01:34:08', NULL, NULL),
(255, 30, 'E81UZwjIIlCPaKShdJba7cJqFNbymWXrqjmVtfppL_w', '2026-05-01 06:11:03', 0, '2026-04-24 06:11:03', '2026-04-24 06:11:03', NULL, NULL),
(256, 29, 'MstPmpGE7b4V1zofvpXIOGvnh0vD9l5tXVxXuKsHUVc', '2026-05-01 21:52:59', 0, '2026-04-24 21:52:59', '2026-04-24 21:52:59', NULL, NULL),
(258, 12, '8_xtWTBjoV0vllN2dDWE5CRvRxP0OHN8mFGzTyAazPc', '2026-05-04 23:00:09', 0, '2026-04-27 23:00:09', '2026-04-27 23:00:09', NULL, NULL),
(260, 2, 'P_-PC-kb2TxNp4BGBZgnunr2_uOZFoE97aWueDCUJzQ', '2026-05-28 00:18:53', 1, '2026-04-28 00:18:53', '2026-04-28 00:18:53', NULL, NULL),
(261, 12, '3TTdU_E015HaX_pwAebdKavn-7DAhAhvtauIwb59V2U', '2026-05-05 00:25:32', 0, '2026-04-28 00:25:32', '2026-04-28 00:25:32', NULL, NULL),
(263, 31, 'Tvj2uxXe-0eID_N3N8FmHCaYXMtH8oz1pPmftmlDgYA', '2026-05-05 02:17:18', 0, '2026-04-28 02:17:18', '2026-04-28 02:17:18', NULL, NULL),
(264, 2, '7gjSMCoM6WsLzcxPXzd_ie8zl4CJSkhdY-2AicntQBM', '2026-05-05 05:05:16', 0, '2026-04-28 05:05:16', '2026-04-28 05:05:16', NULL, NULL),
(265, 39, 'enXkPqIRWvqa5cVK4xetDGzrr-GZEq2zKJSRh4e-b8U', '2026-05-28 05:12:03', 1, '2026-04-28 05:12:03', '2026-04-28 05:12:03', NULL, NULL),
(267, 27, 'zzBqJB2Xtg_XjP5EuvMQtpctNELNY4TMdm7wiDW3Xzs', '2026-05-05 07:46:28', 0, '2026-04-28 07:46:28', '2026-04-28 07:46:28', NULL, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `sync_metadata`
--

CREATE TABLE `sync_metadata` (
  `id` int(11) NOT NULL,
  `branch_id` varchar(50) NOT NULL,
  `company_id` int(11) NOT NULL,
  `last_sync_date` datetime DEFAULT NULL,
  `last_sync_timestamp` datetime NOT NULL,
  `invoice_count` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(80) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `role` varchar(20) NOT NULL,
  `role_id` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `invite_token` varchar(64) DEFAULT NULL,
  `invite_expires_at` datetime DEFAULT NULL,
  `reset_token` varchar(64) DEFAULT NULL,
  `reset_expires_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password_hash`, `role`, `role_id`, `created_at`, `invite_token`, `invite_expires_at`, `reset_token`, `reset_expires_at`) VALUES
(2, 'dylan@nixonlive.com.au', '$2a$12$Hi5UV/bQYZx0LnGA9xFdHu.ml3F5tIvvwKOTsPLB/XzLCzNDb5Yza', 'director', 3, NULL, NULL, NULL, NULL, NULL),
(12, 'adam@nixonlive.com.au', '$2b$12$WM4pBeD3lcvblAB1/m9EdObsp1tuzB3W2IWGuZBXKCGJ06Scwa9vK', 'user', 1, '2026-02-24 01:26:39', NULL, NULL, NULL, NULL),
(17, 'rachel@nixonlive.com.au', '$2b$12$QYeO7l75EZO4732Zyg.u9.sMKbd6pykyKDQzXnq8NtpuN4NAdNa4.', 'user', 1, '2026-02-24 02:59:12', NULL, NULL, NULL, NULL),
(18, 'test', '$2b$12$K4TwLg5F/5xO9gqHFSu0JeqUaqUhBnbpkWSvHl6Dm6sfbdTSXkrwK', 'user', 1, '2026-02-24 03:05:16', NULL, NULL, NULL, NULL),
(20, 'hayden@nixonlive.com.au', '$2b$12$91Z2uqz52GrPPHrc5KJLTuMlAQAgcKTVT9.IjUUdwRN5hgVXnYCEC', 'user', 1, '2026-02-24 03:11:08', NULL, NULL, NULL, NULL),
(21, 'ryan@nixonlive.com.au', '$2b$12$jD4NKwwTJhSzIVjxrXW8o.FneH4n2x6ZkQ3Z7tSYAxPIV4yxIZYEG', 'user', 1, '2026-02-24 03:11:35', NULL, NULL, NULL, NULL),
(22, 'tom@nixonlive.com.au', '$2b$12$idNbgBQ86zsMS1.Ymm9KYujIEU6m72zEIfI.NNiexI///4TpsRKPy', 'user', 1, '2026-02-24 03:11:51', NULL, NULL, NULL, NULL),
(23, 'tony@nixonlive.com.au', '$2b$12$mwnrAL/cNAtuXkDtRIvrrOG5ohgmJqMAivR8fWwbLv0p5oXh/8cIq', 'user', 1, '2026-02-24 03:12:13', NULL, NULL, NULL, NULL),
(24, 'sean.browne@nixonlive.com.au', '$2b$12$dNxSHuXDx4.Dl7g0YlxnpOAascGBa53mFyqbolLJQIaorV6n0X7bu', 'user', 1, '2026-02-24 03:12:32', NULL, NULL, NULL, NULL),
(25, 'jamie@nixonlive.com.au', '$2b$12$wQtVPygr4.ytHQa0mTPggez6jQ/w7zqlC95NoWDRIbqb1srhWNtxu', 'user', 1, '2026-02-24 03:12:52', NULL, NULL, NULL, NULL),
(27, 'keegan@nixonlive.com.au', '$2b$12$4Xl2kLYfhrhJwDJOYr6Qr.R5dsgqExZMWMsFhwoAZ6/LJKGZ3MZvS', 'user', 1, '2026-02-24 03:13:44', NULL, NULL, NULL, NULL),
(28, 'dave@nixonlive.com.au', '$2b$12$DMlCxIWhZiM5ykuuhv6GCusYYIUWJaDzHq2ycTX2GT5xrWhMBkHqi', 'user', 1, '2026-02-24 03:14:42', NULL, NULL, NULL, NULL),
(29, 'jay@nixonlive.com.au', '$2b$12$wq01ZIMS1P1gg5zWONW.beUQP6qV6m19DN2cPkg.6mJnKs8UiypzW', 'user', 1, '2026-02-24 03:15:39', NULL, NULL, NULL, NULL),
(30, 'mitch@nixonlive.com.au', '$2b$12$WFQCOOtYcf9gSzzLwk7su.2SkA0.H1GQZFubMbw5mOUU9J3Lhoab.', 'user', 1, '2026-02-24 03:16:21', NULL, NULL, NULL, NULL),
(31, 'tristan@nixonlive.com.au', '$2b$12$sptBXpzQX8x0vLJRnujgeelEPLFgt8lK45LmSP2j/VDnd2c2OqINW', 'user', 1, '2026-02-24 03:16:53', NULL, NULL, NULL, NULL),
(32, 'teneale@nixonlive.com.au', '$2b$12$2bsKqBAKYo0VF1Sd8HXGDeSQt2EQx5rfRZS3f9tsuvjUfuOZMLSm.', 'user', 1, '2026-02-24 03:17:49', NULL, NULL, NULL, NULL),
(33, 'andrewm@the-entourage.com', '$2b$12$KpWhCCJeF7.E7moEx89vGul3J1qKtgHVF64x8AHiQ6kfQYO7zQRsW', 'user', 1, '2026-02-25 06:13:35', NULL, NULL, NULL, NULL),
(34, 'darren@nixonlive.com.au', '$2b$12$fB9fqm8PcbBQAxl7slhbMeyNliGXmeGhCZfmx7LV3DdCCvPnw14Ea', 'user', 1, '2026-02-25 07:21:20', NULL, NULL, NULL, NULL),
(35, 'busselton@nixonlive.com.au', '$2b$12$z88BAuKvxh5kPvQ1Y/6ZGue9tyZS1WQJn9hQJhlv6VbYWBtomDOxS', 'user', 1, '2026-02-26 04:13:23', NULL, NULL, NULL, NULL),
(36, 'bunbury@nixonlive.com.au', '$2b$12$c2f6fQbf6uNcTLI19eq57ejk.epESFsg1ufyefdmNE1paYNhyqKW6', 'user', 1, '2026-02-26 04:14:39', NULL, NULL, NULL, NULL),
(37, 'mandurah@nixonlive.com.au', '$2b$12$fHjQBNdH1NjvJmM5CO7rPehc.KfUemurv6lHCoZEqrV1KoGNLME6u', 'user', 1, '2026-02-26 04:15:16', NULL, NULL, NULL, NULL),
(39, 'cherrie@nixonlive.com.au', '$2b$12$PM9VulPA142aTYGLjaoYN./k3/fsyeXhis7a0EOzhXAqpWvn9Qija', 'user', NULL, '2026-04-28 05:07:28', NULL, NULL, NULL, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `user_permissions`
--

CREATE TABLE `user_permissions` (
  `user_id` int(11) NOT NULL,
  `permission_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `user_permissions`
--

INSERT INTO `user_permissions` (`user_id`, `permission_id`) VALUES
(2, 1),
(2, 2),
(2, 3),
(2, 4),
(2, 5),
(2, 6),
(2, 7),
(2, 8),
(2, 9),
(2, 10),
(2, 11),
(2, 12),
(2, 13),
(2, 14),
(2, 15),
(2, 16),
(2, 17),
(2, 18),
(2, 19),
(2, 20),
(12, 1),
(12, 2),
(12, 3),
(12, 4),
(12, 5),
(12, 6),
(12, 7),
(12, 8),
(12, 9),
(12, 10),
(12, 11),
(12, 12),
(12, 13),
(12, 14),
(12, 15),
(12, 16),
(12, 17),
(12, 18),
(12, 19),
(12, 20),
(17, 10),
(17, 14),
(18, 10),
(18, 21),
(20, 10),
(20, 13),
(20, 14),
(21, 11),
(21, 15),
(22, 11),
(22, 16),
(23, 11),
(23, 18),
(24, 12),
(24, 19),
(25, 12),
(25, 20),
(27, 11),
(27, 18),
(28, 8),
(28, 9),
(28, 10),
(28, 11),
(28, 12),
(28, 13),
(28, 14),
(28, 15),
(28, 16),
(28, 17),
(28, 18),
(28, 19),
(28, 20),
(29, 8),
(29, 9),
(29, 10),
(29, 11),
(29, 12),
(29, 13),
(29, 14),
(29, 15),
(29, 16),
(29, 17),
(29, 18),
(29, 19),
(29, 20),
(30, 8),
(30, 9),
(30, 10),
(30, 11),
(30, 12),
(30, 13),
(30, 14),
(30, 15),
(30, 16),
(30, 17),
(30, 18),
(30, 19),
(30, 20),
(31, 12),
(31, 19),
(31, 20),
(32, 11),
(32, 15),
(32, 16),
(32, 17),
(32, 18),
(33, 8),
(33, 9),
(33, 10),
(33, 11),
(33, 12),
(33, 13),
(33, 14),
(33, 15),
(33, 16),
(33, 17),
(33, 18),
(33, 19),
(33, 20),
(34, 11),
(34, 17),
(35, 10),
(35, 21),
(36, 11),
(36, 22),
(37, 12),
(37, 23),
(39, 11),
(39, 17);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `custom_page_layouts`
--
ALTER TABLE `custom_page_layouts`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `ix_custom_page_layouts_slug` (`slug`),
  ADD KEY `ix_custom_page_layouts_view_permission_key` (`view_permission_key`);

--
-- Indexes for table `gp_thresholds`
--
ALTER TABLE `gp_thresholds`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `department_type` (`department_type`),
  ADD UNIQUE KEY `idx_gp_thresholds_dept` (`department_type`);

--
-- Indexes for table `invoices`
--
ALTER TABLE `invoices`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_unique_invoice` (`branch_id`,`company_id`,`invoice_id`),
  ADD KEY `ix_invoices_invoice_id` (`invoice_id`),
  ADD KEY `idx_branch_company_date` (`branch_id`,`company_id`,`date_issued`),
  ADD KEY `ix_invoices_branch_id` (`branch_id`),
  ADD KEY `ix_invoices_company_id` (`company_id`),
  ADD KEY `ix_invoices_date_issued` (`date_issued`);

--
-- Indexes for table `kpi_target_overrides`
--
ALTER TABLE `kpi_target_overrides`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_kpi_overrides_branch_dept_metric` (`branch`,`department`,`metric_key`);

--
-- Indexes for table `permissions`
--
ALTER TABLE `permissions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `ix_permissions_key` (`key`);

--
-- Indexes for table `revenue_targets`
--
ALTER TABLE `revenue_targets`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_revenue_targets_branch_company` (`branch_id`,`company_id`);

--
-- Indexes for table `roles`
--
ALTER TABLE `roles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `ix_roles_slug` (`slug`);

--
-- Indexes for table `role_permissions`
--
ALTER TABLE `role_permissions`
  ADD PRIMARY KEY (`role_id`,`permission_id`),
  ADD KEY `permission_id` (`permission_id`);

--
-- Indexes for table `sessions`
--
ALTER TABLE `sessions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `ix_sessions_token` (`token`),
  ADD KEY `ix_sessions_user_id` (`user_id`),
  ADD KEY `idx_sessions_token` (`token`);

--
-- Indexes for table `sync_metadata`
--
ALTER TABLE `sync_metadata`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_branch_company_sync` (`branch_id`,`company_id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `ix_users_username` (`username`),
  ADD KEY `ix_users_role_id` (`role_id`);

--
-- Indexes for table `user_permissions`
--
ALTER TABLE `user_permissions`
  ADD PRIMARY KEY (`user_id`,`permission_id`),
  ADD KEY `permission_id` (`permission_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `custom_page_layouts`
--
ALTER TABLE `custom_page_layouts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `gp_thresholds`
--
ALTER TABLE `gp_thresholds`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `invoices`
--
ALTER TABLE `invoices`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `kpi_target_overrides`
--
ALTER TABLE `kpi_target_overrides`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `permissions`
--
ALTER TABLE `permissions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;

--
-- AUTO_INCREMENT for table `revenue_targets`
--
ALTER TABLE `revenue_targets`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `roles`
--
ALTER TABLE `roles`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

--
-- AUTO_INCREMENT for table `sessions`
--
ALTER TABLE `sessions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=268;

--
-- AUTO_INCREMENT for table `sync_metadata`
--
ALTER TABLE `sync_metadata`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `role_permissions`
--
ALTER TABLE `role_permissions`
  ADD CONSTRAINT `role_permissions_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `role_permissions_ibfk_2` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sessions`
--
ALTER TABLE `sessions`
  ADD CONSTRAINT `sessions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `user_permissions`
--
ALTER TABLE `user_permissions`
  ADD CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE;
COMMIT;

