Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back previous logic when displaying C section #2226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,18 @@ jQuery ->
fy_latest_changed_input.find("input.js-fy-day").val(fy_day)
fy_latest_changed_input.find("input.js-fy-month").val(fy_month)

# disabled for 2021
# Auto fill the year for previous years
# $(".js-financial-year-changed-dates .js-fy-entries").each ->
# if $(this).find("input.js-fy-year").val() == ""
# parent_fy = $(this).parent().find(".js-fy-entries")
# this_year = fy_year - (parent_fy.size() - parent_fy.index($(this)) - 1)
# $(this).find("input.js-fy-year").val(this_year)
$(".js-financial-year-changed-dates .js-fy-entries").each ->
if $(this).find("input.js-fy-year").val() == ""
parent_fy = $(this).parent().find(".js-fy-entries")
this_year = fy_year - (parent_fy.size() - parent_fy.index($(this)) - 1)
$(this).find("input.js-fy-year").val(this_year)

# fy_latest_changed_input.find("input").attr("disabled", "disabled")
# $(".js-financial-year-changed-dates").attr("data-year", fy_year)
fy_latest_changed_input.find("input").attr("disabled", "disabled")
$(".js-financial-year-changed-dates").attr("data-year", fy_year)

# 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)
fy_latest_changed_input.find("input.js-fy-year").val(fy_year)

updateYearEnd()

Expand Down
8 changes: 1 addition & 7 deletions app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,11 @@ window.FormValidation =
else
complexDateString = day + "/" + month + "/" + year
date = @toDate(complexDateString)
currentDate = new Date()

if not date.isValid()
@logThis(question, "validateDateByYears", "Not a valid date")
@appendMessage(qParent, "Not a valid date")
@addErrorClass(question)
# temporary condition
else if parseInt(year) > 2022 || parseInt(year) < 2014
@logThis(question, "validateDateByYears", "the year must be from 2014 to 2022")
@appendMessage(qParent, "the year must be from 2014 to 2022")
@addErrorClass(question)

validateInnovationFinancialDate: (question) ->

Expand Down Expand Up @@ -613,7 +607,7 @@ window.FormValidation =
@validateMoneyByYears(question)

if question.hasClass("question-date-by-years") &&
(question.hasClass("one-option-by-years") || question.find(".show-question").length == (question.find(".js-conditional-question").length - 1))
question.find(".show-question").length == (question.find(".js-conditional-question").length - 1)
@validateDateByYears(question)

if question.find(".match").length
Expand Down
30 changes: 3 additions & 27 deletions app/form_pointers/financial_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,11 @@ def get_audit_data(key)
res.present? ? res[key.to_sym] : financial_empty_values
end

# pre COVID logic
# def financial_table_headers
# if financial_year_changed_dates?
# financial_table_changed_dates_headers
# elsif (financial_date_day.to_i > 0 && financial_date_month.to_i > 0)
# financial_table_pointer_headers
# else
# financial_table_default_headers
# end
# end

# COVID period logic:
# If all the dates are present just render them
# Instead of making any changes to years
def financial_table_headers
if financial_year_dates_filled_in?
if financial_year_changed_dates?
financial_table_changed_dates_headers
elsif (financial_date_day.to_i > 0 && financial_date_month.to_i > 0)
financial_table_pointer_headers
else
financial_table_default_headers
end
Expand All @@ -42,18 +30,6 @@ def financial_table_changed_dates_headers
end
end

def financial_year_dates_filled_in?
res = financial_data(
:financial_year_changed_dates,
get_audit_data(:financial_year_changed_dates)
)

res.any? && res.all? do |entry|
date_array = entry.to_s.split("/")
date_array.any? && date_array.all?(&:present?)
end
end

def correct_date_headers(res)
corrected_result = []
last_year = res.last.split("/")[2].to_i
Expand Down
1 change: 1 addition & 0 deletions app/forms/award_years/v2024/innovation/innovation_step3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def innovation_step3
by_year_condition :innovation_performance_years, "2 to 4", 2
by_year_condition :innovation_performance_years, "5 plus", 5
conditional :innovation_performance_years, :true
conditional :financial_year_date_changed, :yes
end

by_years :employees, "Enter the number of people employed by your organisation in the UK in each year of your entry." do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def trade_step3
by_year_condition :trade_commercial_success, "3 to 5", 3
by_year_condition :trade_commercial_success, "6 plus", 6
conditional :trade_commercial_success, :true
conditional :financial_year_date_changed, "yes"
end

textarea :financial_year_date_changed_explaination, "Please explain why your year-end date changed." do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def mobility_step3
)
type :date
label ->(y) { "Financial year #{y}" }
conditional :financial_year_date_changed, :yes
end

upload :supporting_financials, "To support your figures, please upload your financial statements for the years entered in question C2.2." do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def development_step3
end

one_option_by_years_label :financial_year_changed_dates, "Please enter your year-end dates for each financial year." do
classes "sub-question one-option-by-years"
classes "sub-question"
sub_ref "C 2.2"

context %(
Expand All @@ -106,6 +106,7 @@ def development_step3
required
type :date
label ->(y) { "Financial year #{y}" }
conditional :financial_year_date_changed, :yes
end

upload :supporting_financials, "To support your figures, please upload your financial statements for the years entered in question C2.2." do
Expand Down
6 changes: 3 additions & 3 deletions app/pdf_generators/qae_pdf_forms/custom_questions/by_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def financial_dates_changed_year_headers

financial_table_headers.each_with_index do |item, placement|
header_item = "#{FINANCIAL_YEAR_PREFIX} #{placement + 1}"
header_item += " (last)" if size == (placement + 1)
header_item += " (current)" if size == (placement + 1)

res << header_item
end
Expand All @@ -81,14 +81,14 @@ def financial_dates_not_changed_year_headers

if form_pdf.pdf_blank_mode.present? # BLANK FOR MODE
financial_table_default_headers.map.with_index do |item, index|
financial_table_default_headers.size == (index + 1) ? "#{item} (last)" : item
financial_table_default_headers.size == (index + 1) ? "#{item} (current)" : item
end
else
size = financial_table_headers.size

financial_table_headers.map.with_index do |item, index|
item = "#{prefix} #{item}"
size == (index.to_i + 1) && item.include?(FINANCIAL_YEAR_PREFIX) ? "#{item} (last)" : item
size == (index.to_i + 1) && item.include?(FINANCIAL_YEAR_PREFIX) ? "#{item} (current)" : item
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/qae_form/_by_years_label_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ div role="group" id="q_#{question.key}"
span.js-year-default class="govuk-body govuk-!-font-size-19 govuk-!-margin-bottom-0 govuk-!-margin-top-5"
= question.format_label(y)
- if y == c.years
' (last)
' (current)
span.govuk-error-message class="govuk-!-margin-bottom-0 govuk-!-margin-top-1"
.govuk-date-input
.govuk-date-input__item
Expand Down
2 changes: 1 addition & 1 deletion app/views/qae_form/_by_years_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
' Financial year
= y
- if y == c.years
' (last)
' (current)
span.js-year-text
span.govuk-error-message class="govuk-!-margin-bottom-0 govuk-!-margin-top-1"
span class="#{'govuk-input__wrapper' if question.type == :money}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.js-financial-year-changed-dates role="group" id="q_#{question.key}"
.js-fy-entry-container.show-question
.js-fy-entry-container
.if-js-hide
label.govuk-label
strong
Expand All @@ -11,7 +11,7 @@
label.js-year-default.govuk-label class="govuk-!-margin-bottom-0 govuk-!-margin-top-5"
= question.format_label(y)
- if y == 3
' (last)
' (current)
br
span.govuk-error-message class="govuk-!-margin-bottom-0 govuk-!-margin-top-1"
.govuk-date-input
Expand Down
2 changes: 1 addition & 1 deletion app/views/qae_form/_one_option_by_years_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
' Financial year
= y
- if y == 3
' (last)
' (current)
span.js-year-text
span.govuk-error-message class="govuk-!-margin-bottom-0 govuk-!-margin-top-1"
span class="#{'govuk-input__wrapper' if question.type == :money}"
Expand Down