Skip to content

Commit

Permalink
Merge pull request #2954 from bitzesty/fy-end-qa
Browse files Browse the repository at this point in the history
Set latest financial year after year end input
  • Loading branch information
TheDancingClown authored May 24, 2024
2 parents 4c54492 + fcc9e37 commit 5ece888
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
21 changes: 18 additions & 3 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ getLatestFinancialYearParts = () ->
if (parseInt(fy_month, 10) == 9 && parseInt(fy_day, 10) >= 7) || parseInt(fy_month, 10) > 9
fy_year = parseInt(fy_year, 10) - 1

if $(".js-most-recent-financial-year input:checked").val() && $(".js-most-recent-financial-year .js-conditional-question").hasClass("show-question")
if $(".js-most-recent-financial-year input:checked").val()
fy_year = parseInt($(".js-most-recent-financial-year input:checked").val())

return [fy_day, fy_month, fy_year]
Expand Down Expand Up @@ -328,7 +328,7 @@ jQuery ->

# overriding financial year with the selected radio button value
# also check if the question is visible
if $(".js-most-recent-financial-year input:checked").val() && $(".js-most-recent-financial-year .js-conditional-question").hasClass("show-question")
if $(".js-most-recent-financial-year input:checked").val()
fy_year = parseInt($(".js-most-recent-financial-year input:checked").val())

# Updates the latest changed financial year input
Expand All @@ -350,7 +350,22 @@ jQuery ->
# We should change the last year date regardless if it's present or not
fy_latest_changed_input.find("input.js-fy-year").val(fy_year)

updateYearEnd()
# If the latest financial year is not set, we set it
if $('input:radio[name="form\\[most_recent_financial_year\\]"]:checked').size() == 0
# If day and month entered are valid, we set the latest financial year
fy_date = new Date(fy_year + "-" + fy_month + "-" + fy_day)
if fy_date instanceof Date && !isNaN(fy_date.getTime())
setDefaultRecentFinancialYear()
updateYearEnd()

# Update the recent financial year end
setDefaultRecentFinancialYear = () ->
[fy_day, fy_month, fy_year] = getLatestFinancialYearParts()
$(".js-most-recent-financial-year-options input").each ->
if $(this).val() == fy_year.toString()
$(this).prop("checked", true)
else
$(this).prop("checked", false)

# Update the financial year labels
updateYearEnd = () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.govuk-radios
- for answer in question.options do
.govuk-radios__item
input.js-trigger-autosave.govuk-radios__input type="radio" id="#{question.input_name}_#{answer.value.to_s.parameterize}" name=question.input_name value=answer.value checked=(answer.value.to_s == (question.input_value || '').to_s || (question.input_value.blank? && question.default_option.to_s == answer.value.to_s)) aria-describedby="#{question.input_name}_#{answer.value.to_s.parameterize}_hint" *possible_read_only_ops
input.js-trigger-autosave.govuk-radios__input type="radio" id="#{question.input_name}_#{answer.value.to_s.parameterize}" name=question.input_name value=answer.value checked=(answer.value.to_s == (question.input_value || '').to_s) aria-describedby="#{question.input_name}_#{answer.value.to_s.parameterize}_hint" *possible_read_only_ops
label.govuk-label.govuk-radios__label for="#{question.input_name}_#{answer.value.to_s.parameterize}"
= answer.text.html_safe
span.question-context id="#{question.input_name}_#{answer.value.to_s.parameterize}_hint"
Expand Down
9 changes: 0 additions & 9 deletions forms/award_years/v2025/innovation/innovation_step4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ def innovation_step4
required
option (AwardYear.current.year - 2).to_s, (AwardYear.current.year - 2).to_s
option (AwardYear.current.year - 1).to_s, (AwardYear.current.year - 1).to_s
default_option (AwardYear.current.year - 1).to_s

classes "js-most-recent-financial-year fs-trackable fs-two-trackable"
context %(
<p>
Answer this question if your dates in question D1 range between #{Settings.current_award_year_switch_date.decorate.formatted_trigger_date} to #{Settings.current_submission_deadline.decorate.formatted_trigger_date}.
</p>
)

conditional :financial_year_date, :day_month_range, range: AwardYear.fy_date_range_threshold(minmax: true), disable_pdf_conditional_hints: true, data: { value: AwardYear.fy_date_range_threshold(minmax: true, format: true), type: :range }
end

options :financial_year_date_changed, "Did your year-end date change during your <span class='js-entry-period-subtext'>five</span> most recent financial years that you will be providing figures for?" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,7 @@ def trade_step4
required
option (AwardYear.current.year - 2).to_s, (AwardYear.current.year - 2).to_s
option (AwardYear.current.year - 1).to_s, (AwardYear.current.year - 1).to_s
default_option (AwardYear.current.year - 1).to_s

classes "js-most-recent-financial-year"
context %(
<p>
Answer this question if your dates in question D2 range between #{Settings.current_award_year_switch_date.decorate.formatted_trigger_date} to #{Settings.current_submission_deadline.decorate.formatted_trigger_date}.
</p>
)

conditional :financial_year_date, :day_month_range, range: AwardYear.fy_date_range_threshold(minmax: true), data: { value: AwardYear.fy_date_range_threshold(minmax: true, format: true), type: :range }
end

options :financial_year_date_changed, "Did your year-end date change during your <span class='js-entry-period-subtext'>three or six</span>-year entry period that you will be providing figures for?" do
Expand Down

0 comments on commit 5ece888

Please sign in to comment.