Skip to content
Closed
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
43 changes: 37 additions & 6 deletions app/controllers/state_file/questions/w2_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module StateFile
module Questions
class W2Controller < QuestionsController
before_action :load_w2
before_action :load_box_14_codes
before_action :load_w2, only: [:show, :edit, :update]
helper_method :box_14_codes_and_values, :state_wages_invalid?

def self.show?(intake) # only accessed via button, not navigator
Expand All @@ -12,6 +13,27 @@ def prev_path
StateFile::Questions::IncomeReviewController.to_path_helper(return_to_review: params[:return_to_review])
end

def edit_all
if params.include? current_intake.class.name.underscore
current_intake.assign_attributes(all_w2_form_params)
end
current_intake.state_file_w2s.each do |w2|
w2.valid?(:state_file_edit)
end
end

def update_all
current_intake.assign_attributes(all_w2_form_params)
current_intake.state_file_w2s.each { |w2| w2.check_box14_limits = true }
if current_intake.valid?(context: :state_file_edit)
current_intake.state_file_w2s.each { |w2| w2.box14_ui_hc_wd = nil }
current_intake.save(context: :state_file_edit)
redirect_to(StateFile::Questions::IncomeReviewController.to_path_helper(return_to_review: params[:return_to_review]))
else
render :edit_all
end
end

def edit
if StateFile::StateInformationService.check_box_16(current_state_code) && !current_intake.confirmed_w2_ids.include?(@w2.id)
current_intake.confirmed_w2_ids.append(@w2.id)
Expand All @@ -36,28 +58,37 @@ def update
end
end

def all_w2_form_params
params.require(current_intake.class.name.underscore)
.permit(state_file_w2s_attributes: StateFileW2.attribute_names)
end

def form_params
params.require(StateFileW2.name.underscore)
.except(:state_file_intake_id, :state_file_intake_type)
.permit(*StateFileW2.attribute_names)
end

def box_14_codes_and_values
def box_14_codes_and_values(w2)
@box14_codes.map do |code|
code_name = code['name'].downcase
field_name = "box14_#{code_name}"
value = code_name == "uiwfswf" ? @w2.get_box14_ui_overwrite : @w2.send(field_name)
value = code_name == "uiwfswf" ? w2.get_box14_ui_overwrite : w2.send(field_name)
{ code_name:, field_name:, value: }
end
end

def state_wages_invalid?
StateFile::StateInformationService.check_box_16(current_state_code) && current_intake.state_wages_invalid?(@w2)
def state_wages_invalid?(state_file_w2 = nil)
state_file_w2 ||= @w2
StateFile::StateInformationService.check_box_16(current_state_code) && current_intake.state_wages_invalid?(state_file_w2)
end

def load_box_14_codes
@box14_codes = StateFile::StateInformationService.w2_supported_box14_codes(current_state_code)
end

def load_w2
@w2 = current_intake.state_file_w2s.find(params[:id])
@box14_codes = StateFile::StateInformationService.w2_supported_box14_codes(current_state_code)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/state_file_base_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class StateFileBaseIntake < ApplicationRecord
belongs_to :spouse_state_id, class_name: "StateId", optional: true
accepts_nested_attributes_for :primary_state_id, :spouse_state_id
accepts_nested_attributes_for :dependents, update_only: true
accepts_nested_attributes_for :state_file_w2s, update_only: true

validates :email_address, 'valid_email_2/email': true
validates :phone_number, allow_blank: true, e164_phone: true
Expand Down
4 changes: 2 additions & 2 deletions app/views/state_file/questions/w2/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<p class="text--bold spacing-below-5"><%= @w2.employee_name %></p>
<p class="spacing-below-25"><%= @w2.employer_name %></p>

<% if box_14_codes_and_values.present? %>
<% if box_14_codes_and_values(@w2).present? %>
<% box14_intro_key = "state_file.questions.w2.edit.box14_intro_#{current_state_code}_html" %>
<% if I18n.exists?(box14_intro_key) %>
<p><%= t(box14_intro_key) %></p>
<% end %>
<fieldset>
<legend class="spacing-below-5"><%= t(".box14_html") %></legend>
<% box_14_codes_and_values.each do |box_14_item| %>
<% box_14_codes_and_values(@w2).each do |box_14_item| %>
<% box_14_item => { code_name:, field_name:, value: } %>
<div class="form-question spacing-below-25">
<%= f.vita_min_money_field(
Expand Down
71 changes: 71 additions & 0 deletions app/views/state_file/questions/w2/edit_all.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<% content_for :card do %>
<h1 class="form-question"><%= t(".instructions_1") %></h1>
<%= form_with model: current_intake, url: { action: :update_all }, method: :patch, local: true, builder: VitaMinFormBuilder, html: { class: 'form-card form-card--long' } do |f| %>
<%= f.fields_for :state_file_w2s, current_intake.state_file_w2s do |ff| %>
<div class="white-group">
<p class="text--bold spacing-below-5"><%= ff.object.employee_name %></p>
<p class="spacing-below-25"><%= ff.object.employer_name %></p>

<% if box_14_codes_and_values(ff.object).present? %>
<% box14_intro_key = "state_file.questions.w2.edit.box14_intro_#{current_state_code}_html" %>
<% if I18n.exists?(box14_intro_key) %>
<p><%= t(box14_intro_key) %></p>
<% end %>
<fieldset>
<legend class="spacing-below-5"><%= t("state_file.questions.w2.edit.box14_html") %></legend>
<% box_14_codes_and_values(ff.object).each do |box_14_item| %>
<% box_14_item => { code_name:, field_name:, value: } %>
<div class="form-question spacing-below-25">
<%= ff.vita_min_money_field(
field_name.to_sym,
t("state_file.questions.w2.edit.box14_#{code_name}_html"),
options: { value: value },
classes: ["form-width--long"],
help_text: t("state_file.questions.w2.edit.box14_#{code_name}_help_text_html", year: MultiTenantService.statefile.current_tax_year, default: nil)
) %>
</div>
<% end %>
</fieldset>
<% end %>
<div class="form-question spacing-below-25">
<%= ff.cfa_input_field(:employer_state_id_num, t("state_file.questions.w2.edit.box15_html"), classes: ["form-width--long"]) %>
</div>
<div class="form-question spacing-below-25">
<%= ff.vita_min_money_field(:state_wages_amount, t("state_file.questions.w2.edit.box16_html"), classes: ["form-width--long"]) %>
</div>
<% if state_wages_invalid?(ff.object) %>
<div class="notice--warning spacing-above-5">
<p><%= t("state_file.questions.w2.edit.box16_warning_nj") %></p>
</div>
<% end %>
<div class="form-question spacing-below-25">
<%= ff.vita_min_money_field(:state_income_tax_amount, t("state_file.questions.w2.edit.box17_html"), classes: ["form-width--long"]) %>
</div>
<% if StateFile::StateInformationService.w2_include_local_income_boxes(current_state_code) %>
<div class="form-question spacing-below-25">
<%= ff.vita_min_money_field(:local_wages_and_tips_amount, t("state_file.questions.w2.edit.box18_html"), classes: ["form-width--long"]) %>
</div>
<div class="form-question spacing-below-25">
<%= ff.vita_min_money_field(:local_income_tax_amount, t("state_file.questions.w2.edit.box19_html"), classes: ["form-width--long"]) %>
</div>
<div class="form-question spacing-below-25 ny-w2-locality-nm">
<%= ff.cfa_input_field(:locality_nm, t("state_file.questions.w2.edit.box20_locality_name_html"), classes: ["form-width--long"]) %>
</div>
<% end %>
</div>
<% end %>

<% explanation_key = ".box14_explanation_#{current_state_code}_html" %>
<% explanation_text = t(explanation_key, year: MultiTenantService.statefile.current_tax_year, default: nil) %>
<% if explanation_text %>
<div class="reveal spacing-above-35">
<button href="#" class="reveal__button"><%= t(".what_is_box14_#{current_state_code}") %></button>
<div class="reveal__content">
<%= explanation_text %>
</div>
</div>
<% end %>

<%= f.continue %>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/state_file/questions/w2/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<p class="spacing-below-25"><%= @w2.employer_name %></p>

<dl>
<% if box_14_codes_and_values.present? %>
<% if box_14_codes_and_values(@w2).present? %>
<p class="text--small spacing-below-0"><%= t("state_file.questions.w2.edit.box14_html") %></p>
<ul>
<% box_14_codes_and_values.each do |box_14_item| %>
<% box_14_codes_and_values(@w2).each do |box_14_item| %>
<% box_14_item => { code_name:, field_name:, value: } %>
<li class="list--padded unbulleted">
<div class="spacing-below-25">
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4390,6 +4390,8 @@ en:
wages_amt_error: Total income tax cannot be greater than $%{wages_amount}
what_is_box14_md: What could be in Box 14?
what_is_box14_nj: What should I put in these Box 14 fields?
edit_all:
instructions_1: Please review your job (W-2) details
waiting_to_load_data:
edit:
subtitle_html: This usually takes a few minutes. Don’t close this page.<br><br> We’ll use your federal tax return information to complete sections of your state return.
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4375,6 +4375,8 @@ es:
wages_amt_error: El impuesto sobre la renta total no puede ser mas de $%{wages_amount}
what_is_box14_md: "¿Qué podría aparecer en la casilla 14?"
what_is_box14_nj: "¿Qué debo poner en los casilleros 14?"
edit_all:
instructions_1: Por favor revisa los detalles de tu trabajo (W-2)
waiting_to_load_data:
edit:
subtitle_html: Esto suele tardar unos minutos. No cierres esta página.<br><br> Usaremos la información de tu declaración de impuestos federales para completar algunas secciones de tu declaración estatal.
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,12 @@ def scoped_navigation_routes(context, navigation)

match("/questions/pending-federal-return", action: :edit, controller: "state_file/questions/pending_federal_return", via: :get)
match("/questions/pending_federal_return", action: :edit, controller: "state_file/questions/pending_federal_return", via: :get)
resources :w2, only: [:edit, :update], module: 'state_file/questions', path: 'questions/w2'
resources :w2, only: [:edit, :update], module: 'state_file/questions', path: 'questions/w2' do
collection do
get "edit_all"
patch "update_all"
end
end

active_state_codes.each do |code|
navigation_class = StateFile::StateInformationService.navigation_class(code)
Expand Down
Loading