-- Slice 8P-TenderDetailsEdit · perms
-- Allow CRM (primary) + Administrator + Executive to edit the Details tab in-place.
-- Non-editable fields (project_type, tender_no) stay locked; only the details-tab surface is exposed.

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