-- Remove Create Invoice button from Case Management modal Invoices tab
UPDATE ui_modals
SET config = jsonb_set(
  config,
  '{body,0,tabs}',
  (
    SELECT jsonb_agg(
      CASE
        WHEN tab->>'label' = 'Invoices'
          THEN jsonb_build_object(
            'label','Invoices',
            'elements', (
              SELECT jsonb_agg(elem)
              FROM jsonb_array_elements(tab->'elements') elem
              WHERE elem->>'type' <> 'button'
            )
          )
        ELSE tab
      END
    )
    FROM jsonb_array_elements(config->'body'->0->'tabs') tab
  )
)
WHERE name = 'Case Management';
