diff --git a/app/models/form/sales/pages/person1_age.rb b/app/models/form/sales/pages/person1_age.rb deleted file mode 100644 index d669c76eb..000000000 --- a/app/models/form/sales/pages/person1_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person1Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_1_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_1" => 1, "jointpur" => 2 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person1AgeKnown.new("age2_known", nil, self), - Form::Sales::Questions::Person1Age.new("age2", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person1_age_joint_purchase.rb b/app/models/form/sales/pages/person1_age_joint_purchase.rb deleted file mode 100644 index fa40a59f1..000000000 --- a/app/models/form/sales/pages/person1_age_joint_purchase.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person1AgeJointPurchase < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_1_age_joint_purchase" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_1" => 1, "jointpur" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person1AgeKnown.new("age3_known", nil, self), - Form::Sales::Questions::Person1Age.new("age3", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person2_age.rb b/app/models/form/sales/pages/person2_age.rb deleted file mode 100644 index bee287c18..000000000 --- a/app/models/form/sales/pages/person2_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person2Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_2_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_2" => 1, "jointpur" => 2 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person2AgeKnown.new("age3_known", nil, self), - Form::Sales::Questions::Person2Age.new("age3", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person2_age_joint_purchase.rb b/app/models/form/sales/pages/person2_age_joint_purchase.rb deleted file mode 100644 index 96d6d61ec..000000000 --- a/app/models/form/sales/pages/person2_age_joint_purchase.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person2AgeJointPurchase < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_2_age_joint_purchase" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_2" => 1, "jointpur" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person2AgeKnown.new("age4_known", nil, self), - Form::Sales::Questions::Person2Age.new("age4", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person3_age.rb b/app/models/form/sales/pages/person3_age.rb deleted file mode 100644 index 9156ae831..000000000 --- a/app/models/form/sales/pages/person3_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person3Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_3_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_3" => 1, "jointpur" => 2 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person3AgeKnown.new("age4_known", nil, self), - Form::Sales::Questions::Person3Age.new("age4", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person3_age_joint_purchase.rb b/app/models/form/sales/pages/person3_age_joint_purchase.rb deleted file mode 100644 index 5cad52685..000000000 --- a/app/models/form/sales/pages/person3_age_joint_purchase.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person3AgeJointPurchase < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_3_age_joint_purchase" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_3" => 1, "jointpur" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person3AgeKnown.new("age5_known", nil, self), - Form::Sales::Questions::Person3Age.new("age5", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person4_age.rb b/app/models/form/sales/pages/person4_age.rb deleted file mode 100644 index 0e24128be..000000000 --- a/app/models/form/sales/pages/person4_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person4Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_4_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_4" => 1, "jointpur" => 2 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person4AgeKnown.new("age5_known", nil, self), - Form::Sales::Questions::Person4Age.new("age5", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person4_age_joint_purchase.rb b/app/models/form/sales/pages/person4_age_joint_purchase.rb deleted file mode 100644 index e3e6a2ce1..000000000 --- a/app/models/form/sales/pages/person4_age_joint_purchase.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person4AgeJointPurchase < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_4_age_joint_purchase" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_4" => 1, "jointpur" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person4AgeKnown.new("age6_known", nil, self), - Form::Sales::Questions::Person4Age.new("age6", nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person_age.rb b/app/models/form/sales/pages/person_age.rb new file mode 100644 index 000000000..ef0113ada --- /dev/null +++ b/app/models/form/sales/pages/person_age.rb @@ -0,0 +1,41 @@ +class Form::Sales::Pages::PersonAge < ::Form::Page + def initialize(id, hsh, subsection) + super + @header = "" + @description = "" + @subsection = subsection + @depends_on = [ + { "details_known_#{person_display_number}" => 1, "jointpur" => joint_purchase? ? 1 : 2 }, + ] + end + + def questions + @questions ||= [ + Form::Sales::Questions::PersonAgeKnown.new("age#{person_database_number}_known", nil, self), + Form::Sales::Questions::PersonAge.new("age#{person_database_number}", nil, self), + ] + end + + def person_database_number + PERSON_INDEX[id] + end + + def person_display_number + joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1 + end + + def joint_purchase? + id.include?("_joint_purchase") + end + + PERSON_INDEX = { + "person_1_age" => 2, + "person_2_age" => 3, + "person_3_age" => 4, + "person_4_age" => 5, + "person_1_age_joint_purchase" => 3, + "person_2_age_joint_purchase" => 4, + "person_3_age_joint_purchase" => 5, + "person_4_age_joint_purchase" => 6, + }.freeze +end diff --git a/app/models/form/sales/questions/person1_age.rb b/app/models/form/sales/questions/person1_age.rb deleted file mode 100644 index 501a45fe5..000000000 --- a/app/models/form/sales/questions/person1_age.rb +++ /dev/null @@ -1,21 +0,0 @@ -class Form::Sales::Questions::Person1Age < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 1’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = if id == "age2" - { "condition" => { "age2_known" => 1 }, "value" => "Not known" } - else - { "condition" => { "age3_known" => 1 }, "value" => "Not known" } - end - @hidden_in_check_answers = if id == "age2" - { "depends_on" => [{ "jointpur" => 1 }] } - else - { "depends_on" => [{ "jointpur" => 2 }] } - end - @check_answers_card_number = id == "age2" ? 2 : 3 - end -end diff --git a/app/models/form/sales/questions/person1_age_known.rb b/app/models/form/sales/questions/person1_age_known.rb deleted file mode 100644 index 610ad1aec..000000000 --- a/app/models/form/sales/questions/person1_age_known.rb +++ /dev/null @@ -1,49 +0,0 @@ -class Form::Sales::Questions::Person1AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 1’s age known?" - @header = "Do you know person 1’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = if id == "age2_known" - { - "age2" => [0], - } - else - { - "age3" => [0], - } - end - @hidden_in_check_answers = if id == "age2_known" - { - "depends_on" => [ - { - "age2_known" => 0, - }, - { - "age2_known" => 1, - }, - ], - } - else - { - "depends_on" => [ - { - "age3_known" => 0, - }, - { - "age3_known" => 1, - }, - ], - } - end - @check_answers_card_number = id == "age2_known" ? 2 : 3 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person2_age.rb b/app/models/form/sales/questions/person2_age.rb deleted file mode 100644 index 93c455149..000000000 --- a/app/models/form/sales/questions/person2_age.rb +++ /dev/null @@ -1,21 +0,0 @@ -class Form::Sales::Questions::Person2Age < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 2’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = if id == "age3" - { "condition" => { "age3_known" => 1 }, "value" => "Not known" } - else - { "condition" => { "age4_known" => 1 }, "value" => "Not known" } - end - @hidden_in_check_answers = if id == "age3" - { "depends_on" => [{ "jointpur" => 1 }] } - else - { "depends_on" => [{ "jointpur" => 2 }] } - end - @check_answers_card_number = id == "age3" ? 3 : 4 - end -end diff --git a/app/models/form/sales/questions/person2_age_known.rb b/app/models/form/sales/questions/person2_age_known.rb deleted file mode 100644 index ac87e3aac..000000000 --- a/app/models/form/sales/questions/person2_age_known.rb +++ /dev/null @@ -1,49 +0,0 @@ -class Form::Sales::Questions::Person2AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 2’s age known?" - @header = "Do you know person 2’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = if id == "age3_known" - { - "age3" => [0], - } - else - { - "age4" => [0], - } - end - @hidden_in_check_answers = if id == "age3_known" - { - "depends_on" => [ - { - "age3_known" => 0, - }, - { - "age3_known" => 1, - }, - ], - } - else - { - "depends_on" => [ - { - "age4_known" => 0, - }, - { - "age4_known" => 1, - }, - ], - } - end - @check_answers_card_number = id == "age3_known" ? 3 : 4 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person3_age.rb b/app/models/form/sales/questions/person3_age.rb deleted file mode 100644 index b376a1d6d..000000000 --- a/app/models/form/sales/questions/person3_age.rb +++ /dev/null @@ -1,21 +0,0 @@ -class Form::Sales::Questions::Person3Age < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 3’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = if id == "age4" - { "condition" => { "age4_known" => 1 }, "value" => "Not known" } - else - { "condition" => { "age5_known" => 1 }, "value" => "Not known" } - end - @hidden_in_check_answers = if id == "age4" - { "depends_on" => [{ "jointpur" => 1 }] } - else - { "depends_on" => [{ "jointpur" => 2 }] } - end - @check_answers_card_number = id == "age4" ? 4 : 5 - end -end diff --git a/app/models/form/sales/questions/person3_age_known.rb b/app/models/form/sales/questions/person3_age_known.rb deleted file mode 100644 index 08e41b686..000000000 --- a/app/models/form/sales/questions/person3_age_known.rb +++ /dev/null @@ -1,49 +0,0 @@ -class Form::Sales::Questions::Person3AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 3’s age known?" - @header = "Do you know person 3’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = if id == "age4_known" - { - "age4" => [0], - } - else - { - "age5" => [0], - } - end - @hidden_in_check_answers = if id == "age4_known" - { - "depends_on" => [ - { - "age4_known" => 0, - }, - { - "age4_known" => 1, - }, - ], - } - else - { - "depends_on" => [ - { - "age5_known" => 0, - }, - { - "age5_known" => 1, - }, - ], - } - end - @check_answers_card_number = id == "age4_known" ? 4 : 5 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person4_age.rb b/app/models/form/sales/questions/person4_age.rb deleted file mode 100644 index fa59a4916..000000000 --- a/app/models/form/sales/questions/person4_age.rb +++ /dev/null @@ -1,21 +0,0 @@ -class Form::Sales::Questions::Person4Age < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 4’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = if id == "age5" - { "condition" => { "age5_known" => 1 }, "value" => "Not known" } - else - { "condition" => { "age6_known" => 1 }, "value" => "Not known" } - end - @hidden_in_check_answers = if id == "age5" - { "depends_on" => [{ "jointpur" => 1 }] } - else - { "depends_on" => [{ "jointpur" => 2 }] } - end - @check_answers_card_number = id == "age5" ? 5 : 6 - end -end diff --git a/app/models/form/sales/questions/person4_age_known.rb b/app/models/form/sales/questions/person4_age_known.rb deleted file mode 100644 index fd8c14ae7..000000000 --- a/app/models/form/sales/questions/person4_age_known.rb +++ /dev/null @@ -1,49 +0,0 @@ -class Form::Sales::Questions::Person4AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @check_answer_label = "Person 4’s age known?" - @header = "Do you know person 4’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = if id == "age5_known" - { - "age5" => [0], - } - else - { - "age6" => [0], - } - end - @hidden_in_check_answers = if id == "age5_known" - { - "depends_on" => [ - { - "age5_known" => 0, - }, - { - "age5_known" => 1, - }, - ], - } - else - { - "depends_on" => [ - { - "age6_known" => 0, - }, - { - "age6_known" => 1, - }, - ], - } - end - @check_answers_card_number = id == "age5_known" ? 5 : 6 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person_age.rb b/app/models/form/sales/questions/person_age.rb new file mode 100644 index 000000000..84c2b214d --- /dev/null +++ b/app/models/form/sales/questions/person_age.rb @@ -0,0 +1,32 @@ +class Form::Sales::Questions::PersonAge < ::Form::Question + def initialize(id, hsh, page) + super + @check_answer_label = "Person #{person_display_number}’s age" + @header = "Age" + @type = "numeric" + @page = page + @width = 3 + @inferred_check_answers_value = { "condition" => { "age#{PERSON_INDEX[id]}_known" => 1 }, "value" => "Not known" } + @check_answers_card_number = person_database_number + end + + def person_database_number + PERSON_INDEX[id] + end + + PERSON_INDEX = { + "age2" => 2, + "age3" => 3, + "age4" => 4, + "age5" => 5, + "age6" => 6, + }.freeze + + def person_display_number + joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1 + end + + def joint_purchase? + page.id.include?("_joint_purchase") + end +end diff --git a/app/models/form/sales/questions/person_age_known.rb b/app/models/form/sales/questions/person_age_known.rb new file mode 100644 index 000000000..23c58b262 --- /dev/null +++ b/app/models/form/sales/questions/person_age_known.rb @@ -0,0 +1,48 @@ +class Form::Sales::Questions::PersonAgeKnown < ::Form::Question + def initialize(id, hsh, page) + super + @check_answer_label = "Person #{person_display_number}’s age known?" + @header = "Do you know person #{person_display_number}’s age?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @hint_text = "" + @conditional_for = { "age#{PERSON_INDEX[id]}" => [0] } + @hidden_in_check_answers = { + "depends_on" => [ + { + "age#{PERSON_INDEX[id]}_known" => 0, + }, + { + "age#{PERSON_INDEX[id]}_known" => 1, + }, + ], + } + @check_answers_card_number = PERSON_INDEX[id] + end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze + + def person_database_number + PERSON_INDEX[id] + end + + PERSON_INDEX = { + "age2_known" => 2, + "age3_known" => 3, + "age4_known" => 4, + "age5_known" => 5, + "age6_known" => 6, + }.freeze + + def person_display_number + joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1 + end + + def joint_purchase? + page.id.include?("_joint_purchase") + end +end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 1c928c88e..d820a291f 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -33,22 +33,22 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Person1KnownJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person1RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::Person1RelationshipToBuyer1JointPurchase.new(nil, nil, self), - Form::Sales::Pages::Person1Age.new(nil, nil, self), - Form::Sales::Pages::Person1AgeJointPurchase.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_1_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_1_age_joint_purchase", nil, self), Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person2Known.new(nil, nil, self), Form::Sales::Pages::Person2KnownJointPurchase.new(nil, nil, self), - Form::Sales::Pages::Person2Age.new(nil, nil, self), - Form::Sales::Pages::Person2AgeJointPurchase.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_2_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self), Form::Sales::Pages::Person3Known.new(nil, nil, self), Form::Sales::Pages::Person3KnownJointPurchase.new(nil, nil, self), - Form::Sales::Pages::Person3Age.new(nil, nil, self), - Form::Sales::Pages::Person3AgeJointPurchase.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_3_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self), Form::Sales::Pages::Person4Known.new(nil, nil, self), Form::Sales::Pages::Person4KnownJointPurchase.new(nil, nil, self), - Form::Sales::Pages::Person4Age.new(nil, nil, self), - Form::Sales::Pages::Person4AgeJointPurchase.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_4_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_4_age_joint_purchase", nil, self), ] end end