diff --git a/app/services/exports/lettings_log_export_constants.rb b/app/services/exports/lettings_log_export_constants.rb index b6897dbe6..1456f9d68 100644 --- a/app/services/exports/lettings_log_export_constants.rb +++ b/app/services/exports/lettings_log_export_constants.rb @@ -7,19 +7,17 @@ module Exports::LettingsLogExportConstants csv: 2, }.freeze - EXPORT_FIELDS = Set[ + ALL_YEAR_EXPORT_FIELDS = Set[ "armedforces", "beds", "benefits", "brent", - "builtype", "cap", "cbl", - "chcharge", "chr", "cligrp1", "cligrp2", - "createddate", # New metadata coming from our system + "createddate", "creation_method", "confidential", "discarded_at", @@ -53,12 +51,10 @@ module Exports::LettingsLogExportConstants "mantype", "mobstand", "mrcdate", - "national", "needstype", "new_old", "newprop", "nocharge", - "offered", "owningorgid", "owningorgname", "period", @@ -102,7 +98,7 @@ module Exports::LettingsLogExportConstants "startertenancy", "supcharg", "support", - "status", # New metadata coming from our system + "status", "tcharge", "tshortfall", "tenancy", @@ -138,6 +134,49 @@ module Exports::LettingsLogExportConstants "location_status", "amended_by", "duplicate_set_id", + "assigned_to", + "created_by", + ] + + (1..8).each do |index| + ALL_YEAR_EXPORT_FIELDS << "age#{index}" + ALL_YEAR_EXPORT_FIELDS << "ecstat#{index}" + ALL_YEAR_EXPORT_FIELDS << "sex#{index}" + end + (2..8).each do |index| + ALL_YEAR_EXPORT_FIELDS << "relat#{index}" + end + (1..10).each do |index| + ALL_YEAR_EXPORT_FIELDS << "illness_type_#{index}" + end + %w[a b c d e f g h].each do |letter| + ALL_YEAR_EXPORT_FIELDS << "housingneeds_#{letter}" + end + + YEAR_2021_EXPORT_FIELDS = Set[ + "builtype", + "chcharge", + "national", + "offered", + ] + + YEAR_2022_EXPORT_FIELDS = Set[ + "builtype", + "chcharge", + "national", + "offered", + ] + + YEAR_2023_EXPORT_FIELDS = Set[ + "builtype", + "chcharge", + "national", + "offered", + ] + + YEAR_2024_EXPORT_FIELDS = Set[ + "builtype", + "chcharge", "accessible_register", "nationality_all", "bulk_upload_id", @@ -153,27 +192,10 @@ module Exports::LettingsLogExportConstants "pscharge_value_check", "supcharg_value_check", "carehome_charges_value_check", - "assigned_to", - "created_by", ] - (1..8).each do |index| - EXPORT_FIELDS << "age#{index}" - EXPORT_FIELDS << "ecstat#{index}" - EXPORT_FIELDS << "sex#{index}" - EXPORT_FIELDS << "sexrab#{index}" - end - (2..8).each do |index| - EXPORT_FIELDS << "relat#{index}" - end - (1..10).each do |index| - EXPORT_FIELDS << "illness_type_#{index}" - end - %w[a b c d e f g h].each do |letter| - EXPORT_FIELDS << "housingneeds_#{letter}" - end - - POST_2024_EXPORT_FIELDS = Set[ + YEAR_2025_EXPORT_FIELDS = Set[ + "builtype", "accessible_register", "nationality_all", "bulk_upload_id", @@ -188,25 +210,26 @@ module Exports::LettingsLogExportConstants "scharge_value_check", "pscharge_value_check", "supcharg_value_check", - "carehome_charges_value_check", - ] - - PRE_2024_EXPORT_FIELDS = Set[ - "national", - "offered" -] - - PRE_2025_EXPORT_FIELDS = Set[ - "carehome_charges_value_check", - "chcharge" ] - PRE_2026_EXPORT_FIELDS = Set[ - "builtype" + YEAR_2026_EXPORT_FIELDS = Set[ + "accessible_register", + "nationality_all", + "bulk_upload_id", + "address_line1_as_entered", + "address_line2_as_entered", + "town_or_city_as_entered", + "county_as_entered", + "postcode_full_as_entered", + "la_as_entered", + "net_income_value_check", + "rent_value_check", + "scharge_value_check", + "pscharge_value_check", + "supcharg_value_check", ] - POST_2026_EXPORT_FIELDS = Set[] (1..8).each do |index| - POST_2026_EXPORT_FIELDS << "sexrab#{index}" + YEAR_2026_EXPORT_FIELDS << "sexrab#{index}" end end diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index cd92fadab..bfae9fe99 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/app/services/exports/lettings_log_export_service.rb @@ -171,24 +171,26 @@ module Exports pattern_age = /age\d_known/ details_known_prefix = "details_known_" included_fields = Set[] - included_fields.merge(EXPORT_FIELDS) - - if lettings_log.form.start_year_2024_or_later? - included_fields.subtract(PRE_2024_EXPORT_FIELDS) - else - included_fields.subtract(POST_2024_EXPORT_FIELDS) - end - - if lettings_log.form.start_year_2025_or_later? - included_fields.subtract(PRE_2025_EXPORT_FIELDS) - end - - if lettings_log.form.start_year_2026_or_later? - included_fields.subtract(PRE_2026_EXPORT_FIELDS) - else - included_fields.subtract(POST_2026_EXPORT_FIELDS) - end - + included_fields.merge(ALL_YEAR_EXPORT_FIELDS) + + year_fields = case lettings_log.collection_start_year + when 2021 + YEAR_2021_EXPORT_FIELDS + when 2022 + YEAR_2022_EXPORT_FIELDS + when 2023 + YEAR_2023_EXPORT_FIELDS + when 2024 + YEAR_2024_EXPORT_FIELDS + when 2025 + YEAR_2025_EXPORT_FIELDS + when 2026 + YEAR_2026_EXPORT_FIELDS + else + Set[] + end + + included_fields.merge(year_fields) included_fields.reject! { |field| field.starts_with?(details_known_prefix) || pattern_age.match(field) } included_fields