-- Pacific Logistics · slice 40 · Fleet Analytics deep-drill grants
--
-- New actions on FleetAnalyticsController:
--   matrix — every truck × every metric in a sortable matrix
--   truck  — single-truck deep-drill (monthly trend, fuel, trips, WOs, incidents)
--
-- Grants for the same 6 roles that already see the other Fleet Analytics
-- actions.

INSERT IGNORE INTO user_groups_perms (user_group_id, controller_allowed, action_allowed, created_by, created_on) VALUES
(1,  'FleetAnalytics', 'matrix', 1, NOW()), (1,  'FleetAnalytics', 'truck', 1, NOW()),
(2,  'FleetAnalytics', 'matrix', 1, NOW()), (2,  'FleetAnalytics', 'truck', 1, NOW()),
(10, 'FleetAnalytics', 'matrix', 1, NOW()), (10, 'FleetAnalytics', 'truck', 1, NOW()),
(20, 'FleetAnalytics', 'matrix', 1, NOW()), (20, 'FleetAnalytics', 'truck', 1, NOW()),
(21, 'FleetAnalytics', 'matrix', 1, NOW()), (21, 'FleetAnalytics', 'truck', 1, NOW()),
(22, 'FleetAnalytics', 'matrix', 1, NOW()), (22, 'FleetAnalytics', 'truck', 1, NOW());

SELECT ug.user_group_name, GROUP_CONCAT(ugp.action_allowed ORDER BY ugp.action_allowed) AS actions
  FROM user_groups_perms ugp
  JOIN user_groups ug ON ug.c0d = ugp.user_group_id
 WHERE ugp.controller_allowed = 'FleetAnalytics'
 GROUP BY ug.c0d, ug.user_group_name;
