-- Migration: Add date/time columns to Case Management and Time Entries & Expenses modules
-- Date: 2025-10-04
-- Description: Updates module configurations to display date/time columns in all relevant tabs

-- Update time_entries_expenses module to show date column in all tabs
UPDATE modules
SET config = jsonb_set(
  jsonb_set(
    jsonb_set(
      config,
      '{body,0,tabs,0,elements,0,options,columnsToShow}',
      '["date", "counsel", "client_name", "case_name", "hours", "total", "description", "billable", "approved", "approval_comment"]'::jsonb
    ),
    '{body,0,tabs,1,elements,0,options,columnsToShow}',
    '["date", "counsel", "client_name", "case_name", "amount", "description", "billable", "approved", "approval_comment"]'::jsonb
  ),
  '{body,0,tabs,2,elements,0,options,columnsToShow}',
  '["date", "counsel", "client_name", "case_name", "amount", "description", "billable", "approved", "comments"]'::jsonb
)
WHERE name = 'time_entries_expenses';

-- Update Case Management module Invoices tab to show sent_at column
UPDATE modules
SET config = jsonb_set(
  config,
  '{body,0,tabs,6,elements,0,options,columnsToShow}',
  '["invoice_date", "sent_at", "invoice_number", "amount", "amount_paid", "balance"]'::jsonb
)
WHERE name = 'Case Management';

-- Update Case Management module Payments tab to show payment_date and other columns
UPDATE modules
SET config = jsonb_set(
  config,
  '{body,0,tabs,7,elements,0,options,columnsToShow}',
  '["payment_date", "total_amount", "payment_method", "status", "notes"]'::jsonb
)
WHERE name = 'Case Management';
