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

Refactor withdrawal date things and pull state time #4503

Merged
merged 4 commits into from May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -413,6 +413,32 @@ def before_state_file_launch?
end
helper_method :before_state_file_launch?

def withdrawal_date_deadline
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
helper_method :withdrawal_date_deadline

def before_withdrawal_date_deadline?
app_time < withdrawal_date_deadline
end
helper_method :before_withdrawal_date_deadline?

def post_deadline_withdrawal_date
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 :post_deadline_withdrawal_date

private

def locale
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/session_toggles_controller.rb
Expand Up @@ -23,8 +23,9 @@ def index
service_url: url_for(host: MultiTenantService.new(:statefile).host, controller: :session_toggles),
times: [
SessionToggleTime.new(name: 'Start of open intake', property: :state_file_start_of_open_intake),
SessionToggleTime.new(name: 'End of New intake', property: :state_file_end_of_new_intakes),
SessionToggleTime.new(name: 'End of In Progress Intakes', property: :state_file_end_of_in_progress_intakes),
SessionToggleTime.new(name: 'Withdrawal date deadline for New York', property: :state_file_withdrawal_date_deadline_ny),
SessionToggleTime.new(name: 'End of new intakes', property: :state_file_end_of_new_intakes),
SessionToggleTime.new(name: 'End of in-progress intakes', property: :state_file_end_of_in_progress_intakes),
]
},
{
Expand Down
Expand Up @@ -34,7 +34,6 @@ def pay_mail_online_text
end
helper_method :pay_mail_online_text


private

def card_postscript; end
Expand Down
34 changes: 27 additions & 7 deletions app/forms/state_file/taxes_owed_form.rb
Expand Up @@ -10,11 +10,16 @@ class TaxesOwedForm < TaxRefundForm
:withdraw_amount

set_attributes_for :confirmation, :routing_number_confirmation, :account_number_confirmation
set_attributes_for :date, :date_electronic_withdrawal_month, :date_electronic_withdrawal_year, :date_electronic_withdrawal_day
set_attributes_for :date,
:date_electronic_withdrawal_month,
:date_electronic_withdrawal_year,
:date_electronic_withdrawal_day,
:post_deadline_withdrawal_date,
:app_time

with_options unless: -> { payment_or_deposit_type == "mail" } do
# validate :date_electronic_withdrawal_is_valid_date
# validate :withdrawal_date_before_deadline, if: -> { date_electronic_withdrawal.present? }
validate :date_electronic_withdrawal_is_valid_date
validate :withdrawal_date_before_deadline, if: -> { date_electronic_withdrawal.present? && !post_deadline_withdrawal_date.present? }
validates :withdraw_amount, presence: true, numericality: { greater_than: 0 }
validate :withdraw_amount_higher_than_owed?
end
Expand All @@ -37,11 +42,26 @@ def self.existing_attributes(intake)
private

def date_electronic_withdrawal
Time.now.in_time_zone('Eastern Time (US & Canada)').to_date
if post_deadline_withdrawal_date.present?
date_electronic_withdrawal_post_deadline
else
parse_date_params(date_electronic_withdrawal_year, date_electronic_withdrawal_month, date_electronic_withdrawal_day)
end
end

def date_electronic_withdrawal_post_deadline
Date.parse(post_deadline_withdrawal_date)
end

def date_electronic_withdrawal_is_valid_date
valid_text_date(Time.now.year.to_s, Time.now.month.to_s, Time.now.day.to_s, :date_electronic_withdrawal)
if post_deadline_withdrawal_date.present?
date_electronic_withdrawal_post_deadline
else
valid_text_date(date_electronic_withdrawal_year,
date_electronic_withdrawal_month,
date_electronic_withdrawal_day,
:date_electronic_withdrawal)
end
end

def withdraw_amount_higher_than_owed?
Expand All @@ -55,13 +75,13 @@ def withdraw_amount_higher_than_owed?
end

def withdrawal_date_before_deadline
unless date_electronic_withdrawal.between?(DateTime.current.to_date, withdrawal_date_deadline)
unless date_electronic_withdrawal.between?(Date.parse(app_time), withdrawal_date_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
DateTime.parse("April 15th, #{MultiTenantService.new(:statefile).current_tax_year + 1}")
Date.parse("April 15th, #{MultiTenantService.new(:statefile).current_tax_year + 1}")
end
end
end
6 changes: 5 additions & 1 deletion app/views/shared/_environment_warning.html.erb
Expand Up @@ -16,7 +16,11 @@
<div class="grid">
<div class="grid__item">
<strong>Active Session Toggles:</strong>
<div><%= session[:session_toggles] %></div>
<div><%= session[:session_toggles] %> UTC</div>
<% if state_file? %>
<div><%= app_time.in_time_zone('America/New_York').strftime("%A %m-%d-%Y %l:%M%P") %> EST</div>
<div><%= app_time.in_time_zone('America/Phoenix').strftime("%A %m-%d-%Y %l:%M%P") %> MST</div>
<% end %>
</div>
</div>
</div>
Expand Down
27 changes: 25 additions & 2 deletions app/views/state_file/questions/tax_refund/_bank_details.html.erb
Expand Up @@ -3,8 +3,25 @@
<p class="text--small"><%= t(".foreign_accounts") %></p>
<div class="form-group-tight">
<% if owe_taxes %>
<%= form.hidden_field :app_time, value: app_time %>
<%= form.cfa_input_field(:withdraw_amount, t('.withdraw_amount', owed_amount: taxes_owed), classes: ["form-width--long"]) %>

<% if before_withdrawal_date_deadline? %>
<div class="date-select">
<% year = MultiTenantService.new(:statefile).current_tax_year + 1 %>
<%= form.cfa_date_select(
:date_electronic_withdrawal,
t(".date_withdraw_text",
withdrawal_deadline_date: I18n.l(withdrawal_date_deadline.to_date, format: :medium, locale: locale),
with_drawal_deadline_year: withdrawal_date_deadline.year),
options: {
start_year: year,
end_year: year,
}
) %>
</div>
<% else %>
<%= form.hidden_field :post_deadline_withdrawal_date, value: post_deadline_withdrawal_date %>
<% end %>
<% end %>

<%= form.cfa_input_field(:bank_name, t("views.questions.bank_details.bank_name"), classes: ["form-width--long"]) %>
Expand All @@ -23,5 +40,11 @@
<%= form.cfa_input_field(:account_number_confirmation, t(".confirm_account_number"), classes: ["form-width--long", "disablepaste", "disablecopy"]) %>
</div>
<p><strong><%= t(".disclaimer") %></strong></p>
<p><strong><%= t(".after-deadline-default-withdrawl-info") %></strong></p>
<% if owe_taxes && !before_withdrawal_date_deadline? %>
<p>
<%= t(".after_deadline_default_withdrawal_info",
withdrawal_deadline_date: I18n.l(withdrawal_date_deadline.to_date, format: :medium, locale: locale),
with_drawal_deadline_year: withdrawal_date_deadline.year) %>
</p>
<% end %>
</div>
1 change: 1 addition & 0 deletions config/application.rb
Expand Up @@ -108,6 +108,7 @@ class Application < Rails::Application
# StateFile
config.state_file_start_of_open_intake = Time.find_zone('America/New_York').parse('2024-02-08 09:00:00')
config.state_file_end_of_new_intakes = Time.find_zone('America/Los_Angeles').parse('2024-04-15 23:59:59')
config.state_file_withdrawal_date_deadline_ny = Time.find_zone('America/New_York').parse('2024-04-15 23:59:59')
config.state_file_end_of_in_progress_intakes = Time.find_zone('America/Los_Angeles').parse('2024-04-25 23:59:59')

config.allow_magic_verification_code = (Rails.env.demo? || Rails.env.development? || Rails.env.heroku?)
Expand Down
5 changes: 3 additions & 2 deletions config/locales/en.yml
Expand Up @@ -258,7 +258,7 @@ en:
is_hsa: is HSA
taxes_owed:
withdraw_amount_higher_than_owed: Please enter in an amount less than or equal to %{owed_amount}
withdrawal_date_deadline: Please enter a date on or before April 15, %{year}
withdrawal_date_deadline: Please enter a date between today and on or before April 15, %{year}
general:
NA: N/A
about: About
Expand Down Expand Up @@ -2667,10 +2667,11 @@ en:
tax_refund:
bank_details:
account_number: Account Number
after-deadline-default-withdrawl-info: Because you are submitting your return on or after April 15, 2024, the state will withdraw your payment as soon as they process your return.
after_deadline_default_withdrawal_info: Because you are submitting your return on or after %{withdrawal_deadline_date}, %{with_drawal_deadline_year}, the state will withdraw your payment as soon as they process your return.
bank_title: 'Please provide your bank details:'
confirm_account_number: Confirm Account Number
confirm_routing_number: Confirm Routing Number
date_withdraw_text: 'When would you like the funds withdrawn from your account? (Must be on or before %{withdrawal_deadline_date}, %{with_drawal_deadline_year}):'
disclaimer: Check to make sure your bank information is correct. You won’t be able to correct this after you submit your return.
foreign_accounts: "(Foreign accounts are not accepted)"
routing_number: Routing Number
Expand Down
5 changes: 3 additions & 2 deletions config/locales/es.yml
Expand Up @@ -259,7 +259,7 @@ es:
is_hsa: es HSA
taxes_owed:
withdraw_amount_higher_than_owed: Ingresa una cantidad menor o igual a %{owed_amount}
withdrawal_date_deadline: Introduce una fecha en o antes del 15 de Abril, %{year}
withdrawal_date_deadline: Ingrese una fecha entre hoy y el 15 de abril de %{year} o antes
general:
NA: N/A
about: Acerca de nosotros
Expand Down Expand Up @@ -2647,10 +2647,11 @@ es:
tax_refund:
bank_details:
account_number: Número de cuenta
after-deadline-default-withdrawl-info: Debido al hecho de que estás enviando tu declaración el 15 de abril o después, el estado retirará tu pago tan pronto como se procese tu declaración.
after_deadline_default_withdrawal_info: Debido al hecho de que estás enviando tu declaración el %{withdrawal_deadline_date} de %{with_drawal_deadline_year} o después, el estado retirará tu pago tan pronto como se procese tu declaración.
bank_title: 'Comparte los detalles de tu cuenta bancaria:'
confirm_account_number: Confirma el número de cuenta
confirm_routing_number: Confirma el número de ruta bancaria (routing number)
date_withdraw_text: "¿Cuándo te gustaría que se retiren los fondos de tu cuenta? (debe ser antes o en el dia del %{withdrawal_deadline_date} de %{with_drawal_deadline_year}):"
disclaimer: Verifica que la información de tu banco sea correcta. No podrás corregirla después de enviar tu declaración.
foreign_accounts: "(Las cuentas extranjeras no son aceptadas)"
routing_number: Número de ruta bancaria (routing number)
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/application_controller_spec.rb
Expand Up @@ -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)
Expand Down