From 1c4129de4015cdb6ba6c0ddcd81a030c8b9547f5 Mon Sep 17 00:00:00 2001 From: Em Barnard-Shao Date: Fri, 19 Apr 2024 12:39:29 -0400 Subject: [PATCH] WIP: submit on hidden field instead --- app/controllers/application_controller.rb | 9 +++++++ .../questions/taxes_owed_controller.rb | 6 +++++ app/forms/state_file/taxes_owed_form.rb | 27 ++++++++++++++++++- app/helpers/application_time_helper.rb | 27 +++++++++++++++++++ .../tax_refund/_bank_details.html.erb | 20 +++++++++++++- .../application_controller_spec.rb | 21 +++++++++++++++ 6 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 app/helpers/application_time_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2c65f1b7f4..5931efab09 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -430,6 +430,15 @@ def before_withdrawal_date_deadline? end helper_method :before_withdrawal_date_deadline? + def withdrawal_date_post_deadline + if params[:us_state] == 'ny' + app_time.in_time_zone('America/New_York') + else + app_time.in_time_zone('America/Phoenix') + end + end + helper_method :withdrawal_date_post_deadline + private def locale diff --git a/app/controllers/state_file/questions/taxes_owed_controller.rb b/app/controllers/state_file/questions/taxes_owed_controller.rb index 76c2827117..ac76c36abe 100644 --- a/app/controllers/state_file/questions/taxes_owed_controller.rb +++ b/app/controllers/state_file/questions/taxes_owed_controller.rb @@ -34,9 +34,15 @@ def pay_mail_online_text end helper_method :pay_mail_online_text + #find where we initialize the form and pass it to the form through there private + # def initialized_update_form + # form_class.new(current_resource, form_params) + # end + #instead of validating on the form we should just put the date in as a hidden param + def card_postscript; end end diff --git a/app/forms/state_file/taxes_owed_form.rb b/app/forms/state_file/taxes_owed_form.rb index bb50b8c0c0..2edbe95167 100644 --- a/app/forms/state_file/taxes_owed_form.rb +++ b/app/forms/state_file/taxes_owed_form.rb @@ -37,7 +37,7 @@ def self.existing_attributes(intake) private def date_electronic_withdrawal - if app_time.before?(withdrawal_date_deadline) + if before_withdrawal_date_deadline? parse_date_params(date_electronic_withdrawal_year, date_electronic_withdrawal_month, date_electronic_withdrawal_day) else if params[:us_state] == 'ny' @@ -67,5 +67,30 @@ def withdrawal_date_before_deadline self.errors.add(:date_electronic_withdrawal, I18n.t("forms.errors.taxes_owed.withdrawal_date_deadline", year: withdrawal_date_deadline.year)) end end + + + def withdrawal_date_deadline + # binding.pry + case params[:us_state] + when 'ny' + Rails.configuration.state_file_withdrawal_date_deadline_ny + else + # Arizona's withdrawal date deadline is the same as the end-new-intakes date which is set in PDT, + # if this was during daylight-savings, it would be different except in the Navajo Nation + Rails.configuration.state_file_end_of_new_intakes + end + end + + def before_withdrawal_date_deadline? + app_time < withdrawal_date_deadline + end + + def app_time + if Rails.env.production? + Time.current + else + SessionToggle.new(session, 'app_time').value || Time.current + end + end end end diff --git a/app/helpers/application_time_helper.rb b/app/helpers/application_time_helper.rb new file mode 100644 index 0000000000..63f7a2497c --- /dev/null +++ b/app/helpers/application_time_helper.rb @@ -0,0 +1,27 @@ +module ApplicationTimeHelper + def app_time + if Rails.env.production? + Time.current + else + SessionToggle.new(session, 'app_time').value || Time.current + end + end + + + def withdrawal_date_deadline + # binding.pry + case params[:us_state] + when 'ny' + Rails.configuration.state_file_withdrawal_date_deadline_ny + else + # Arizona's withdrawal date deadline is the same as the end-new-intakes date which is set in PDT, + # if this was during daylight-savings, it would be different except in the Navajo Nation + Rails.configuration.state_file_end_of_new_intakes + end + end + + def before_withdrawal_date_deadline? + app_time < withdrawal_date_deadline + end + +end \ No newline at end of file diff --git a/app/views/state_file/questions/tax_refund/_bank_details.html.erb b/app/views/state_file/questions/tax_refund/_bank_details.html.erb index cd10360ad0..ac4a0f5068 100644 --- a/app/views/state_file/questions/tax_refund/_bank_details.html.erb +++ b/app/views/state_file/questions/tax_refund/_bank_details.html.erb @@ -2,8 +2,26 @@

<%= t(".bank_title") %>

<%= t(".foreign_accounts") %>

- <% if owe_taxes && before_withdrawal_date_deadline? %> + <% if owe_taxes %> <%= form.cfa_input_field(:withdraw_amount, t('.withdraw_amount', owed_amount: taxes_owed), classes: ["form-width--long"]) %> + <% if before_withdrawal_date_deadline? %> + # if its the time of transmission really we should be doing these checks when we submit + # could put hidden value, could overwrite it in the model, could do it when we transmit and bundle?? + # hidden value and transmission? +
+ <% year = MultiTenantService.new(:statefile).current_tax_year + 1 %> + <%= form.cfa_date_select( + :date_electronic_withdrawal, + t(".date_withdraw_text"), + options: { + start_year: year, + end_year: year, + } + ) %> +
+ <% else %> + <%= form.hidden_field :date_electronic_withdrawal, value: withdrawal_date_post_deadline %> + <% end %> <% end %> <%= form.cfa_input_field(:bank_name, t("views.questions.bank_details.bank_name"), classes: ["form-width--long"]) %> diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index ccea5eb60a..f0600419fd 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -1408,6 +1408,27 @@ def index end end + describe "#withdrawal_date_deadline" do + let(:state) { "ny" } + before { @params = { us_state: state } } + + context "for a New York return" do + it "returns the NY withdrawal date deadline" do + get :index, params: @params + expect(subject.withdrawal_date_deadline).to eq Rails.configuration.state_file_withdrawal_date_deadline_ny + end + end + + context "for an Arizona return" do + let(:state) { "az" } + + it "returns the AZ withdrawal date deadline" do + get :index, params: @params + expect(subject.withdrawal_date_deadline).to eq Rails.configuration.state_file_end_of_new_intakes + end + end + end + context "when receiving invalid requests from robots" do before do allow(DatadogApi).to receive(:increment)