-- Slice 8i-DocNumbers · perms
-- Read: anyone who might want to preview numbering. Write (saveAj): Admin only.

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

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