-- Migration: Add date range filter to Payroll module
-- Date: 2025-10-08
-- Description: Adds a filter-date-range component to the Payroll module header
--              to allow filtering worked hours and payslips by pay period dates

UPDATE modules 
SET config = $json$ {
  "title": "Payroll",
  "header": [
    {
      "type": "filter-date-range",
      "options": {
        "data_column": "start_date",
        "label": "Pay Period"
      }
    },
    { "type": "button", "label": "Generate Pay", "onClick": "generatePayForEmployees" }
  ],
  "body": [
    {
      "type": "tabs",
      "tabs": [
        {
          "label": "Worked Hours",
          "elements": [
            {
              "type": "table",
              "options": {
                "tableName": "time_clock_aggregates",
                "showGlobalSearch": false,
                "addButton": false,
                "filterField": "start_date",
                "listenColumn": "start_date",
                "columnsToShow": ["name", "start_date", "end_date", "total_net_minutes", "total_overtime_minutes", "total_regular_minutes", "total_payable_minutes", "total_days_worked"]
              }
            }
          ]
        },
        {
          "label": "Payslips",
          "elements": [
            {
              "type": "table",
              "options": {
                "tableName": "generated_payslips",
                "showGlobalSearch": false,
                "addButton": false,
                "filterField": "start_date",
                "listenColumn": "start_date",
                "columnsToShow": ["user_name", "org_name", "gross_pay", "net_pay", "start_date", "end_date"]
              }
            }
          ]
        }
      ]
    }
  ],
  "footer": [
    { "type": "button", "label": "Close", "onClick": "closeModal" }
  ]
} $json$::jsonb,
aria_label = 'Payroll',
description = 'Manage payroll and timesheets',
icon = 'fa-money-check-dollar'
WHERE module_id = '018e3f0a-12d3-7c45-b89a-2f3c4e1d5b6c'::uuid;
