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.

184 lines
4.3 KiB

module DerivedVariables::SalesLogVariables
include DerivedVariables::SharedLogic
def set_derived_fields!
reset_invalidated_derived_values!(DEPENDENCIES)
self.ethnic = 17 if ethnic_refused?
self.mscharge = nil if no_monthly_leasehold_charges?
Cldc 1776 sales information sections (#1106) * Mark subsection as completed if it is not displayed in the tasklist and hide it from the UI * Add sale_information section * add sales information subsections * Cldc 1531 staircasing (#1109) * Add staircase field to sales_logs table * Add staircase question and page * add staircase page to the shared ownership scheme subsection fix file name * Cldc 1539 previous bedrooms (#1108) * add frombeds field * Add previous_bedrooms page and question * add Previous Bedrooms page to the shared ownership subsection * Cldc 1532 about staircasing (#1110) * Add stairboughts and stairowned fields to the database * Add about staircasing page and questions * Add about staircasing page to the shared wnership scheme subsection * Add a space before percent * Cldc 1546 monthly rent (#1111) * Add monthly rent column to sales logs table * Add monthly rent question and page * Add monthly rent page to the shared ownership scheme subsection * Cldc 1535 exchange contracts (#1112) * Add exdate to sales logs table * Add exchange date page and question * Add exchange contracts page to the shared ownership subsection * derive exday, exmonth and exyear, tests and lint * rebase tests * Cldc 1538 la nominations (#1115) * Add la nominations column to sales logs table * Add La nominations page and questions * Add la nominations to the shared ownership subsection * Add accidentally removed files * Cldc 1545 about the deposit (#1113) * feat: add question(s) without depends_on behaviour * feat: separate ids for diff sections * test: update tests * test: add tests * tests: test tweaks * refactor: linting * Cldc 1538 la nominations (#1115) * Add la nominations column to sales logs table * Add La nominations page and questions * Add la nominations to the shared ownership subsection * Add accidentally removed files * feat: add question(s) without depends_on behaviour Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> * Cldc 1533 is resale (#1118) * feat: add resale question and page * tests: add new tests * test: update previous tests * refactor: linting * refactor: linting * Cldc 1576 buyer prp (#1117) * Add soctenant field to sales logs * Add buyer previous page and question * Add buyer previous page to shared ownership scheme subsection * rebase migrate * rebase too * Cldc 1540 about price (#1121) * add price fields to the sales logs table * Add about proce questions * add about proce pages * Add about price pages to sale information sections * rebase changes * happy new year * Switch the order of sales log sections * Cldc 1540 fixes (#1130) * Update order of pages and remove wrong id's * Add spacing to the hint text * Cldc 1521 living before purchase (#1129) * feat: add new page and question and update db * test: add and update tests * feat: reset db * Only display from beds for social housing (#1131) * Cldc 1544 mortgage amount (#1136) * feat: add sales log seeds * feat: add question and page and update db * tests: add and update tests * Cldc 1540 fixes part two (#1135) * Change about_price_social_housing to about_price_shared_ownership and display it in all shared ownership cases * Change about_price to purchase_price and display it for outright sale * lint * Move exchange contracts date page (#1143) * feat: PO fix and tests (#1144) * feat: PO fix and tests * feat: simmplification * refactor: linting * feat: copy tweak Co-authored-by: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Co-authored-by: natdeanlewissoftwire <nat.dean-lewis@softwire.com>
2 years ago
if exdate.present?
self.exday = exdate.day
self.exmonth = exdate.month
self.exyear = exdate.year
end
if hodate.present?
self.hoday = hodate.day
self.homonth = hodate.month
self.hoyear = hodate.year
end
self.deposit = value if outright_sale? && mortgage_not_used?
if saledate && form.start_year_after_2024? && discounted_ownership_sale?
self.ppostcode_full = postcode_full
self.ppcodenk = 0 if postcode_full.present?
self.prevloc = la
self.is_previous_la_inferred = is_la_inferred
self.previous_la_known = la_known
end
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
1 year ago
self.pcode1, self.pcode2 = postcode_full.split if postcode_full.present?
self.ppostc1, self.ppostc2 = ppostcode_full.split if ppostcode_full.present?
self.totchild = total_child
self.totadult = total_adult + total_elder
self.hhmemb = number_of_household_members
self.hhtype = household_type
if saledate && form.start_year_after_2024?
self.soctenant = soctenant_from_prevten_values
end
self.uprn_known = 0 if address_answered_without_uprn?
if uprn_known&.zero?
self.uprn = nil
end
if uprn_confirmed&.zero?
self.uprn = nil
self.uprn_known = 0
end
self.nationality_all = nationality_all_group if nationality_uk_or_prefers_not_to_say?
self.nationality_all_buyer2 = nationality_all_buyer2_group if nationality2_uk_or_prefers_not_to_say?
set_encoded_derived_values!(DEPENDENCIES)
end
private
DEPENDENCIES = [
{
conditions: {
buylivein: 2,
},
derived_values: {
buy1livein: 2,
},
},
{
conditions: {
buylivein: 2,
jointpur: 1,
},
derived_values: {
buy1livein: 2,
buy2livein: 2,
},
},
{
conditions: {
buylivein: 1,
jointpur: 2,
},
derived_values: {
buy1livein: 1,
},
},
{
conditions: {
mortgageused: 2,
},
derived_values: {
mortgage: 0,
},
},
].freeze
def number_of_household_members
return unless hholdcount.present? && jointpur.present?
number_of_buyers = joint_purchase? ? 2 : 1
hholdcount + number_of_buyers
end
def total_elder
ages = [age1, age2, age3, age4, age5, age6]
ages.count { |age| age.present? && age >= 60 }
end
def total_child
(2..6).count do |i|
age = public_send("age#{i}")
relat = public_send("relat#{i}")
age.present? && (age < 20 && %w[C].include?(relat) || age < 18)
end
end
def total_adult
total = age1.present? && age1.between?(16, 59) ? 1 : 0
total + (2..6).count do |i|
age = public_send("age#{i}")
relat = public_send("relat#{i}")
age.present? && (age.between?(20, 59) || age.between?(18, 19) && relat != "C")
end
end
def household_type
return unless total_elder && total_adult && totchild
if only_one_elder?
1
elsif only_two_elders?
2
elsif only_one_adult?
3
elsif only_two_adults?
4
elsif one_adult_with_at_least_one_child?
5
elsif at_least_two_adults_with_at_least_one_child?
6
else
9
end
end
def at_least_two_adults_with_at_least_one_child?
total_elder.zero? && total_adult >= 2 && totchild >= 1
end
def one_adult_with_at_least_one_child?
total_elder.zero? && total_adult == 1 && totchild >= 1
end
def only_two_adults?
total_elder.zero? && total_adult == 2 && totchild.zero?
end
def only_one_adult?
total_elder.zero? && total_adult == 1 && totchild.zero?
end
def only_two_elders?
total_elder == 2 && total_adult.zero? && totchild.zero?
end
def only_one_elder?
total_elder == 1 && total_adult.zero? && totchild.zero?
end
def address_answered_without_uprn?
[address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023
end
def soctenant_from_prevten_values
return unless prevten && shared_ownership_scheme?
prevten_was_social_housing? ? 1 : 2
end
def prevten_was_social_housing?
[1, 2].include?(prevten) || [1, 2].include?(prevtenbuy2)
end
end