-- Slice 8V-CompanyProfile · perms
-- index (view): CRM, Executive, Administrator, plus Finance Manager (needs the bank + tax details for docs)
-- saveAj  (write): CRM, Executive, Administrator — model enforces field-level RBAC per group.
INSERT INTO user_groups_perms (user_group_id, controller_allowed, action_allowed, created_by, created_on)
SELECT g.c0d, 'CompanyProfile', 'index', 0, NOW()
FROM user_groups g
WHERE g.user_group_name IN ('CRM','Executive','Administrator','Finance Manager')
  AND NOT EXISTS (
    SELECT 1 FROM user_groups_perms p
    WHERE p.user_group_id = g.c0d AND p.controller_allowed='CompanyProfile' AND p.action_allowed='index'
  );

INSERT INTO user_groups_perms (user_group_id, controller_allowed, action_allowed, created_by, created_on)
SELECT g.c0d, 'CompanyProfile', 'saveAj', 0, NOW()
FROM user_groups g
WHERE g.user_group_name IN ('CRM','Executive','Administrator')
  AND NOT EXISTS (
    SELECT 1 FROM user_groups_perms p
    WHERE p.user_group_id = g.c0d AND p.controller_allowed='CompanyProfile' AND p.action_allowed='saveAj'
  );
