Skip to content

Commit

Permalink
Move read/write from old integer columns to new decimal columns (#4797)
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsinaislam authored Sep 30, 2024
1 parent 1dd3a39 commit 863dbad
Show file tree
Hide file tree
Showing 46 changed files with 264 additions and 523 deletions.
4 changes: 0 additions & 4 deletions app/controllers/flows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,9 @@ def self.ny_attributes(first_name: 'Testuser', last_name: 'Testuser', filing_sta
def self.az_attributes(first_name: 'Testuser', last_name: 'Testuser', filing_status: :single)
base_attributes = common_attributes.merge(
armed_forces_member: "yes",
armed_forces_wages: 100,
armed_forces_wages_amount: 100,
charitable_cash: 123,
charitable_cash_amount: 123,
charitable_contributions: "yes",
charitable_noncash: 123,
charitable_noncash_amount: 123,
contact_preference: "email",
eligibility_529_for_non_qual_expense: "no",
Expand All @@ -649,7 +646,6 @@ def self.az_attributes(first_name: 'Testuser', last_name: 'Testuser', filing_sta
primary_last_name: last_name,
prior_last_names: "Jordan, Pippen, Rodman",
tribal_member: "yes",
tribal_wages: 100,
tribal_wages_amount: 100,
primary_was_incarcerated: "no",
spouse_was_incarcerated: "no",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.show?(intake)

def form_params
params.require(:state_file_az_subtractions_form).permit(
[:armed_forces_member, :armed_forces_wages, :tribal_member, :tribal_wages]
[:armed_forces_member, :armed_forces_wages_amount, :tribal_member, :tribal_wages_amount]
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def state_file1099_params
:payer_street_address,
:payer_tin,
:payer_zip,
:federal_income_tax_withheld,
:state_income_tax_withheld,
:unemployment_compensation,
:federal_income_tax_withheld_amount,
:state_income_tax_withheld_amount,
:unemployment_compensation_amount,
:recipient_city,
:recipient_street_address,
:recipient_street_address_apartment,
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/state_file/questions/w2_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def self.w2s_for_intake(intake)
state_file_intake: intake,
w2_index: index,
employer_state_id_num: df_w2.EmployerStateIdNum,
state_wages_amt: df_w2.StateWagesAmt,
state_income_tax_amt: df_w2.StateIncomeTaxAmt,
local_wages_and_tips_amt: df_w2.LocalWagesAndTipsAmt,
local_income_tax_amt: df_w2.LocalIncomeTaxAmt,
state_wages_amount: df_w2.StateWagesAmt,
state_income_tax_amount: df_w2.StateIncomeTaxAmt,
local_wages_and_tips_amount: df_w2.LocalWagesAndTipsAmt,
local_income_tax_amount: df_w2.LocalIncomeTaxAmt,
locality_nm: df_w2.LocalityNm
)
end
Expand Down
12 changes: 4 additions & 8 deletions app/forms/state_file/az_charitable_contributions_form.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
module StateFile
class AzCharitableContributionsForm < QuestionsForm
set_attributes_for :intake, :charitable_contributions, :charitable_cash, :charitable_noncash, :charitable_cash_amount, :charitable_noncash_amount
set_attributes_for :intake, :charitable_contributions, :charitable_cash_amount, :charitable_noncash_amount

validates :charitable_contributions, inclusion: { in: %w[yes no], message: :blank }
validates_numericality_of :charitable_cash, only_integer: true, message: :whole_number, if: -> { charitable_contributions == "yes" }
validates :charitable_cash, presence: true, numericality: { greater_than_or_equal_to: 0 }, allow_blank: false, if: -> { charitable_contributions == "yes" }
validates_numericality_of :charitable_noncash, only_integer: true, message: :whole_number, if: -> { charitable_contributions == "yes" }
validates :charitable_noncash, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 500 }, allow_blank: false, if: -> { charitable_contributions == "yes" }
validates :charitable_cash_amount, presence: true, numericality: { greater_than_or_equal_to: 0 }, allow_blank: false, if: -> { charitable_contributions == "yes" }
validates :charitable_noncash_amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 500 }, allow_blank: false, if: -> { charitable_contributions == "yes" }


def save
if charitable_contributions == "no"
@intake.update(charitable_contributions: "no", charitable_cash: nil, charitable_noncash: nil, charitable_cash_amount: nil, charitable_noncash_amount: nil)
@intake.update(charitable_contributions: "no", charitable_cash_amount: nil, charitable_noncash_amount: nil)
else
@intake.update(attributes_for(:intake))
additional_attributes = { charitable_cash_amount: charitable_cash, charitable_noncash_amount: charitable_noncash }
@intake.update(attributes_for(:intake).merge(additional_attributes))
end
end
end
Expand Down
12 changes: 3 additions & 9 deletions app/forms/state_file/az_excise_credit_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@ class AzExciseCreditForm < QuestionsForm
:spouse_was_incarcerated,
:ssn_no_employment,
:household_excise_credit_claimed,
:household_excise_credit_claimed_amt,
:household_excise_credit_claimed_amount

validates :primary_was_incarcerated, inclusion: { in: %w[yes no], message: :blank }
validates :spouse_was_incarcerated, inclusion: { in: %w[yes no], message: :blank }, if: -> { intake.filing_status_mfj? }
validates :ssn_no_employment, inclusion: { in: %w[yes no], message: :blank }
validates :household_excise_credit_claimed, inclusion: { in: %w[yes no], message: :blank }
validates_presence_of :household_excise_credit_claimed_amt, if: -> { household_excise_credit_claimed == "yes" }
validates :household_excise_credit_claimed_amt, numericality: { only_integer: true, greater_than: 0, message: ->(_object, _data) { I18n.t('validators.must_enter_amount') } }, allow_blank: true
validates_presence_of :household_excise_credit_claimed_amount, if: -> { household_excise_credit_claimed == "yes" }
validates :household_excise_credit_claimed_amount, numericality: { greater_than: 0, message: ->(_object, _data) { I18n.t('validators.must_enter_amount') } }, allow_blank: true

def save
attributes = attributes_for(:intake)
if household_excise_credit_claimed == "no"
attributes = attributes.merge(household_excise_credit_claimed_amt: nil, household_excise_credit_claimed_amount: nil)
else
attributes = attributes.merge(
household_excise_credit_claimed_amount: household_excise_credit_claimed_amt
)
attributes = attributes.merge(household_excise_credit_claimed_amount: nil)
end

@intake.update(attributes)
end
end
Expand Down
33 changes: 9 additions & 24 deletions app/forms/state_file/az_subtractions_form.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
module StateFile
class AzSubtractionsForm < QuestionsForm
set_attributes_for :intake, :tribal_member, :tribal_wages, :armed_forces_member, :armed_forces_wages, :tribal_wages_amount, :armed_forces_wages_amount
set_attributes_for :intake, :tribal_member, :armed_forces_member, :tribal_wages_amount, :armed_forces_wages_amount

validates_numericality_of :tribal_wages, only_integer: true, message: :whole_number, if: -> { tribal_member == "yes" }
validates :tribal_wages, presence: true, allow_blank: false, numericality: { greater_than_or_equal_to: 1 }, if: -> { tribal_member == "yes" }
validates_numericality_of :armed_forces_wages, only_integer: true, message: :whole_number, if: -> { armed_forces_member == "yes" }
validates :armed_forces_wages, presence: true, allow_blank: false, numericality: { greater_than_or_equal_to: 1 }, if: -> { armed_forces_member == "yes" }
validate :below_1040_amount, if: -> { tribal_wages.present? || armed_forces_wages.present? }
validates :tribal_wages_amount, presence: true, allow_blank: false, numericality: { greater_than_or_equal_to: 1 }, if: -> { tribal_member == "yes" }
validates :armed_forces_wages_amount, presence: true, allow_blank: false, numericality: { greater_than_or_equal_to: 1 }, if: -> { armed_forces_member == "yes" }
validate :below_1040_amount, if: -> { tribal_wages_amount.present? || armed_forces_wages_amount.present? }

def save
attributes_to_save = attributes_for(:intake)

if tribal_member == "no"
attributes_to_save[:tribal_wages] = nil
attributes_to_save[:tribal_wages_amount] = nil
else
attributes_to_save[:tribal_wages_amount] = tribal_wages
end

if armed_forces_member == "no"
attributes_to_save[:armed_forces_wages] = nil
attributes_to_save[:armed_forces_wages_amount] = nil
else
attributes_to_save[:armed_forces_wages_amount] = armed_forces_wages
end

attributes_to_save[:tribal_wages_amount] = nil if tribal_member == "no"
attributes_to_save[:armed_forces_wages_amount] = nil if armed_forces_member == "no"
@intake.update(attributes_to_save)
end

private

def below_1040_amount
amount_limit = @intake.direct_file_data.fed_wages_salaries_tips
total = self.tribal_wages.to_i + self.armed_forces_wages.to_i
total = self.tribal_wages_amount.to_d.round + self.armed_forces_wages_amount.to_d.round
if total > amount_limit
errors.add(:base, I18n.t("forms.errors.state_credit.exceeds_limit", limit: amount_limit))
errors.add(:tribal_wages, "")
errors.add(:armed_forces_wages, "")
errors.add(:tribal_wages_amount, "")
errors.add(:armed_forces_wages_amount, "")
end
end
end
Expand Down
20 changes: 14 additions & 6 deletions app/lib/efile/az/az140_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def initialize(year:, intake:, include_source: false)
end

def calculate
set_line(:AZ140_CCWS_LINE_1c, @intake, :charitable_cash)
set_line(:AZ140_CCWS_LINE_2c, @intake, :charitable_noncash)
set_line(:AZ140_CCWS_LINE_1c, :calculate_line_1c)
set_line(:AZ140_CCWS_LINE_2c, :calculate_line_2c)
set_line(:AZ140_CCWS_LINE_3c, -> { 0 })
set_line(:AZ140_CCWS_LINE_4c, :calculate_ccws_line_4c)
set_line(:AZ140_CCWS_LINE_5c, -> { 0 })
Expand Down Expand Up @@ -94,6 +94,14 @@ def analytics_attrs

private

def calculate_line_1c
@intake.charitable_cash_amount&.round
end

def calculate_line_2c
@intake.charitable_noncash_amount&.round
end

def calculate_line_14
line_or_zero(:AZ140_LINE_12)
end
Expand All @@ -120,11 +128,11 @@ def calculate_line_29B
end

def calculate_line_31
@intake.tribal_member_yes? ? @intake.tribal_wages : 0
@intake.tribal_member_yes? ? @intake.tribal_wages_amount&.round : 0
end

def calculate_line_32
@intake.armed_forces_member_yes? ? @intake.armed_forces_wages : 0
@intake.armed_forces_member_yes? ? @intake.armed_forces_wages_amount&.round : 0
end

def calculate_line_35
Expand Down Expand Up @@ -255,7 +263,7 @@ def calculate_line_53
# AZ income tax withheld
# sum of tax withheld from all income documents: W-2, 1099-R, 1099-G, 1099-INT
@direct_file_data.total_w2_state_tax_withheld +
@intake.state_file1099_gs.sum(&:state_income_tax_withheld) +
@intake.state_file1099_gs.sum { |item| item.state_income_tax_withheld_amount.round } +
@direct_file_data.total_1099r_state_tax_withheld
end

Expand All @@ -269,7 +277,7 @@ def calculate_line_56
wrksht_line_4 = (@dependent_count + wrksht_line_2) * 25

max_credit = 100
max_credit -= @intake.household_excise_credit_claimed_amt if @intake.household_excise_credit_claimed_yes? && @intake.household_excise_credit_claimed_amt.is_a?(Integer)
max_credit -= @intake.household_excise_credit_claimed_amount&.round if @intake.household_excise_credit_claimed_yes?

[wrksht_line_4, max_credit].min
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/efile/ny/it201.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def calculate_line_72
# NY income tax withheld
# sum of tax withheld from all income documents
@direct_file_data.total_w2_state_tax_withheld +
@intake.state_file1099_gs.sum(&:state_income_tax_withheld)
@intake.state_file1099_gs.sum { |item| item.state_income_tax_withheld_amount.round }
end

def calculate_line_73
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def document
xml.StateAbbreviationCd "AZ"
xml.ZIPCd sanitize_for_xml(form1099g.recipient_zip)
end
xml.UnemploymentCompensation form1099g.unemployment_compensation
xml.FederalTaxWithheld form1099g.federal_income_tax_withheld
xml.UnemploymentCompensation form1099g.unemployment_compensation_amount&.round
xml.FederalTaxWithheld form1099g.federal_income_tax_withheld_amount&.round
xml.State1099GStateLocalTaxGrp do
xml.StateTaxWithheldAmt form1099g.state_income_tax_withheld
xml.StateTaxWithheldAmt form1099g.state_income_tax_withheld_amount&.round
xml.StateAbbreviationCd "AZ"
if form1099g.state_identification_number && form1099g.state_identification_number != ''
xml.PayerStateIdNumber form1099g.state_identification_number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def document
xml.StateAbbreviationCd "NY"
xml.ZIPCd form1099g.recipient_zip if form1099g.recipient_zip.present?
end
xml.UnemploymentCompensation form1099g.unemployment_compensation if form1099g.unemployment_compensation.present?
xml.FederalTaxWithheld form1099g.federal_income_tax_withheld if form1099g.federal_income_tax_withheld.present?
xml.UnemploymentCompensation form1099g.unemployment_compensation_amount.round if form1099g.unemployment_compensation_amount.present?
xml.FederalTaxWithheld form1099g.federal_income_tax_withheld_amount.round if form1099g.federal_income_tax_withheld_amount.present?
xml.State1099GStateLocalTaxGrp do
xml.StateTaxWithheldAmt form1099g.state_income_tax_withheld if form1099g.state_income_tax_withheld.present?
xml.StateTaxWithheldAmt form1099g.state_income_tax_withheld_amount.round if form1099g.state_income_tax_withheld_amount.present?
xml.StateAbbreviationCd "NY"
if form1099g.state_identification_number && form1099g.state_identification_number != ''
xml.PayerStateIdNumber form1099g.state_identification_number
Expand Down
20 changes: 4 additions & 16 deletions app/models/state_file1099_g.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# id :bigint not null, primary key
# address_confirmation :integer default("unfilled"), not null
# federal_income_tax_withheld :integer
# federal_income_tax_withheld_amount :decimal(12, 2)
# had_box_11 :integer default("unfilled"), not null
# intake_type :string not null
Expand All @@ -19,9 +18,7 @@
# recipient_street_address_apartment :string
# recipient_zip :string
# state_identification_number :string
# state_income_tax_withheld :integer
# state_income_tax_withheld_amount :decimal(12, 2)
# unemployment_compensation :integer
# unemployment_compensation_amount :decimal(12, 2)
# created_at :datetime not null
# updated_at :datetime not null
Expand All @@ -32,9 +29,9 @@
# index_state_file1099_gs_on_intake (intake_type,intake_id)
#
class StateFile1099G < ApplicationRecord
self.ignored_columns = %w[unemployment_compensation federal_income_tax_withheld state_income_tax_withheld]
belongs_to :intake, polymorphic: true
before_validation :update_conditional_attributes
before_save :sync_amount_columns

enum address_confirmation: { unfilled: 0, yes: 1, no: 2 }, _prefix: :address_confirmation
enum had_box_11: { unfilled: 0, yes: 1, no: 2 }, _prefix: :had_box_11
Expand All @@ -50,20 +47,11 @@ class StateFile1099G < ApplicationRecord
validates :recipient_street_address_apartment, format: { :with => /\A[a-zA-Z0-9\/\s-]+\z/.freeze, message: ->(_object, _data) { I18n.t("errors.attributes.address.street_address.invalid") }}, allow_blank: true
validates :recipient_city, presence: true, format: { with: /\A[a-zA-Z\s]+\z/.freeze, message: ->(_object, _data) { I18n.t("errors.attributes.address.city.invalid") }}
validates :recipient_zip, zip_code: { zip_code_lengths: [5, 9, 12].freeze }
validates_numericality_of :unemployment_compensation, only_integer: true, message: :whole_number
validates :unemployment_compensation, numericality: { greater_than_or_equal_to: 1 }
validates_numericality_of :federal_income_tax_withheld, only_integer: true, message: :whole_number
validates :federal_income_tax_withheld, numericality: { greater_than_or_equal_to: 0}
validates_numericality_of :state_income_tax_withheld, only_integer: true, message: :whole_number
validates :state_income_tax_withheld, numericality: { greater_than_or_equal_to: 0}
validates :unemployment_compensation_amount, numericality: { greater_than_or_equal_to: 1 }
validates :federal_income_tax_withheld_amount, numericality: { greater_than_or_equal_to: 0}
validates :state_income_tax_withheld_amount, numericality: { greater_than_or_equal_to: 0}
validate :state_specific_validation

def sync_amount_columns
self.unemployment_compensation_amount = unemployment_compensation if unemployment_compensation.present?
self.federal_income_tax_withheld_amount = federal_income_tax_withheld if federal_income_tax_withheld.present?
self.state_income_tax_withheld_amount = state_income_tax_withheld if state_income_tax_withheld.present?
end

def update_conditional_attributes
if address_confirmation_yes?
self.recipient_city = intake.direct_file_data.mailing_city
Expand Down
6 changes: 1 addition & 5 deletions app/models/state_file_az_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
# account_number :string
# account_type :integer
# armed_forces_member :integer default("unfilled"), not null
# armed_forces_wages :integer
# armed_forces_wages_amount :decimal(12, 2)
# bank_name :string
# charitable_cash :integer default(0)
# charitable_cash_amount :decimal(12, 2)
# charitable_contributions :integer default("unfilled"), not null
# charitable_noncash :integer default(0)
# charitable_noncash_amount :decimal(12, 2)
# consented_to_terms_and_conditions :integer default("unfilled"), not null
# contact_preference :integer default("unfilled"), not null
Expand All @@ -34,7 +31,6 @@
# hashed_ssn :string
# household_excise_credit_claimed :integer default("unfilled"), not null
# household_excise_credit_claimed_amount :decimal(12, 2)
# household_excise_credit_claimed_amt :integer
# last_sign_in_at :datetime
# last_sign_in_ip :inet
# locale :string default("en")
Expand Down Expand Up @@ -75,7 +71,6 @@
# spouse_was_incarcerated :integer default("unfilled"), not null
# ssn_no_employment :integer default("unfilled"), not null
# tribal_member :integer default("unfilled"), not null
# tribal_wages :integer
# tribal_wages_amount :decimal(12, 2)
# unfinished_intake_ids :text default([]), is an Array
# unsubscribed_from_email :boolean default(FALSE), not null
Expand All @@ -96,6 +91,7 @@
# index_state_file_az_intakes_on_spouse_state_id_id (spouse_state_id_id)
#
class StateFileAzIntake < StateFileBaseIntake
self.ignored_columns = %w[charitable_cash charitable_noncash household_excise_credit_claimed_amt tribal_wages armed_forces_wages]
encrypts :account_number, :routing_number, :raw_direct_file_data, :raw_direct_file_intake_data

has_many :az322_contributions, dependent: :destroy
Expand Down
Loading

0 comments on commit 863dbad

Please sign in to comment.