Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
4.0 KiB

CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
module Csv
class SchemeCsvService
include SchemesHelper
include LocationsHelper
def initialize(download_type:)
@download_type = download_type
end
def prepare_csv(schemes)
CSV.generate(headers: true) do |csv|
csv << attributes
case @download_type
when "schemes"
schemes.find_each do |scheme|
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) }
end
when "locations"
schemes.find_each do |scheme|
scheme.locations.find_each do |location|
csv << [scheme.id_to_display] + location_attributes.map { |attribute| location_value(attribute, location) }
end
end
when "combined"
schemes.find_each do |scheme|
scheme.locations.find_each do |location|
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } + location_attributes.map { |attribute| location_value(attribute, location) }
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
end
end
end
end
end
private
SCHEME_FIELD_FROM_ATTRIBUTE = {
"scheme_code" => "id_to_display",
"scheme_service_name" => "service_name",
"scheme_status" => "status",
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
"scheme_confidential" => "sensitive",
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
"scheme_registered_under_care_act" => "registered_under_care_act",
"scheme_support_services_provided_by" => "arrangement_type",
"scheme_primary_client_group" => "primary_client_group",
"scheme_has_other_client_group" => "has_other_client_group",
"scheme_secondary_client_group" => "secondary_client_group",
"scheme_support_type" => "support_type",
"scheme_intended_stay" => "intended_stay",
"scheme_created_at" => "created_at",
}.freeze
LOCATION_FIELD_FROM_ATTRIBUTE = {
"location_code" => "id",
"location_postcode" => "postcode",
"location_name" => "name",
"location_status" => "status",
"location_local_authority" => "location_admin_district",
"location_units" => "units",
"location_type_of_unit" => "type_of_unit",
"location_mobility_type" => "mobility_type",
}.freeze
CUSTOM_CALL_CHAINS = {
scheme_owning_organisation_name: %i[owning_organisation name],
}.freeze
SYSTEM_DATE_FIELDS = %w[
created_at
].freeze
def scheme_value(attribute, scheme)
attribute = SCHEME_FIELD_FROM_ATTRIBUTE.fetch(attribute, attribute)
if attribute == "scheme_active_dates"
scheme_availability(scheme).gsub("\n", ", ").to_s
elsif CUSTOM_CALL_CHAINS.key? attribute.to_sym
call_chain = CUSTOM_CALL_CHAINS[attribute.to_sym]
call_chain.reduce(scheme) { |object, next_call| object&.public_send(next_call) }
elsif SYSTEM_DATE_FIELDS.include? attribute
scheme.public_send(attribute)&.iso8601
else
scheme.public_send(attribute)
end
end
def location_value(attribute, location)
attribute = LOCATION_FIELD_FROM_ATTRIBUTE.fetch(attribute, attribute)
if attribute == "location_active_dates"
location_availability(location).gsub("\n", ", ").to_s
else
location.public_send(attribute)
end
end
def scheme_attributes
CLDC-3438 Update log csv download flow (#2403) * Filter out empty options from selected filters * Redirect to year filter if it is not selected * Add remaining filter questions * Display lettings filters CYA * Add cancel, conditionally display send email * Refactor * Add removed tests * Update method name * Add sales logs filters * Update tests * Set label size on filter questions * Refactor * Deduplicate filter views * Rename methods * Authenticate pages * Update filtering per organisation * Update routing from CYA * lint * Refactor check_your_answers_filters_list * Redirect if year is not given for sales csv * Update formatted organisations methods * Update missing and wrong copy * Update cancel and back buttons * CLDC-3442 Download logs csv per year (#2404) * Specify year in lettings csv download service * Specify year in sales csv download service * Define non_question_fields per year * Tidy up missing fields and tests * Fix request tests * Refactor * Add missing param * CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) * CLDC-2586 Rename scheme sensitive (#2405) * Rename scheme sensitive in lettings csv * Rename scheme sensitive in schemes csv * CLDC-3347 Show soft validations in support CSVs only (#2406) * Show soft validations in support csvs only * CLDC-3352 Update lettings CSV address order (#2409) * Update lettings support csv address ordering * Refactor * CLDC-3415/3421/3422 Add lettings CSV updates (#2415) * Add first_time_property_let_as_social_housing to coordinators csv * Update lettings CSV user fields order * Remove new_old from lettings CSV * Remove duplicate rent value check from CSV (#2423) * Refactor CSV service (#2425) * Extract and move lettings methods * Extract and more sales methods
7 months ago
%w[scheme_code scheme_service_name scheme_status scheme_confidential scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates]
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
end
def location_attributes
%w[location_code location_postcode location_name location_status location_local_authority location_units location_type_of_unit location_mobility_type location_active_dates]
end
def attributes
case @download_type
when "schemes"
scheme_attributes
when "locations"
%w[scheme_code] + location_attributes
when "combined"
scheme_attributes + location_attributes
end
end
end
end