From b7210b2f530589fa5c665d201431d7998c09b226 Mon Sep 17 00:00:00 2001 From: Benjamin Randolph Date: Wed, 11 Sep 2024 07:22:54 -0600 Subject: [PATCH] Create filing status federal tax table types. --- app/models/federal_tax_bracket.rb | 33 ++++++++---- app/models/federal_tax_table_type.rb | 15 ++++++ db/data/20240711124610_create_tax_tables.rb | 14 +++--- .../20240910125100_create_tax_table_types.rb | 50 +++++++++++++++++++ db/data_schema.rb | 2 +- ...11123818_create_federal_tax_table_types.rb | 11 ++++ db/schema.rb | 11 +++- spec/factories/federal_tax_brackets.rb | 31 ++++++++---- spec/factories/federal_tax_table_types.rb | 14 ++++++ spec/models/federal_tax_bracket_spec.rb | 31 ++++++++---- spec/models/federal_tax_table_type_spec.rb | 14 ++++++ 11 files changed, 184 insertions(+), 42 deletions(-) create mode 100644 app/models/federal_tax_table_type.rb create mode 100644 db/data/20240910125100_create_tax_table_types.rb create mode 100644 db/migrate/20240911123818_create_federal_tax_table_types.rb create mode 100644 spec/factories/federal_tax_table_types.rb create mode 100644 spec/models/federal_tax_table_type_spec.rb diff --git a/app/models/federal_tax_bracket.rb b/app/models/federal_tax_bracket.rb index 4459a84..efb3fa7 100644 --- a/app/models/federal_tax_bracket.rb +++ b/app/models/federal_tax_bracket.rb @@ -2,19 +2,30 @@ # # Table name: federal_tax_brackets # -# id :bigint not null, primary key -# bottom_range_cents :integer default(0), not null -# bottom_range_currency :string default("USD"), not null -# cumulative_cents :integer default(0), not null -# cumulative_currency :string default("USD"), not null -# rate :float -# tier :string -# top_range_cents :integer default(0), not null -# top_range_currency :string default("USD"), not null -# created_at :datetime not null -# updated_at :datetime not null +# id :bigint not null, primary key +# bottom_range_cents :integer default(0), not null +# bottom_range_currency :string default("USD"), not null +# cumulative_cents :integer default(0), not null +# cumulative_currency :string default("USD"), not null +# rate :float +# tier :string +# top_range_cents :integer default(0), not null +# top_range_currency :string default("USD"), not null +# created_at :datetime not null +# updated_at :datetime not null +# federal_tax_table_type_id :bigint +# +# Indexes +# +# index_federal_tax_brackets_on_federal_tax_table_type_id (federal_tax_table_type_id) +# +# Foreign Keys +# +# fk_rails_... (federal_tax_table_type_id => federal_tax_table_types.id) # class FederalTaxBracket < ApplicationRecord + belongs_to :federal_tax_table_type + monetize :bottom_range_cents monetize :top_range_cents monetize :cumulative_cents diff --git a/app/models/federal_tax_table_type.rb b/app/models/federal_tax_table_type.rb new file mode 100644 index 0000000..1bff1ce --- /dev/null +++ b/app/models/federal_tax_table_type.rb @@ -0,0 +1,15 @@ +# == Schema Information +# +# Table name: federal_tax_table_types +# +# id :bigint not null, primary key +# filing_status :string +# created_at :datetime not null +# updated_at :datetime not null +# +class FederalTaxTableType < ApplicationRecord + has_many :federal_tax_brackets + + FILING_TYPES = %w(single married_filing_jointly married_filing_separately head_of_household) + validates :filing_status, presence: true, inclusion: FILING_TYPES +end diff --git a/db/data/20240711124610_create_tax_tables.rb b/db/data/20240711124610_create_tax_tables.rb index bcc5dbd..253397e 100644 --- a/db/data/20240711124610_create_tax_tables.rb +++ b/db/data/20240711124610_create_tax_tables.rb @@ -3,13 +3,13 @@ class CreateTaxTables < ActiveRecord::Migration[7.0] def up # Federal tax brackets for single filers in 2024 - FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 11_600, rate: 0.1, cumulative: 0) - FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160) - FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426) - FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5) - FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5) - FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 609_350, rate: 0.35, cumulative: 55_678.5) - FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 183_647.25) + # FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 11_600, rate: 0.1, cumulative: 0) + # FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160) + # FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426) + # FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5) + # FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5) + # FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 609_350, rate: 0.35, cumulative: 55_678.5) + # FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 183_647.25) end def down diff --git a/db/data/20240910125100_create_tax_table_types.rb b/db/data/20240910125100_create_tax_table_types.rb new file mode 100644 index 0000000..22545c5 --- /dev/null +++ b/db/data/20240910125100_create_tax_table_types.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +class CreateTaxTableTypes < ActiveRecord::Migration[7.0] + def up + FederalTaxTableType.create(filing_status: "single") + FederalTaxTableType.create(filing_status: "married_filing_jointly") + FederalTaxTableType.create(filing_status: "married_filing_separately") + FederalTaxTableType.create(filing_status: "head_of_household") + + # Federal tax brackets for single filers in 2024 + FederalTaxBracket.create!(tier: "Tier 1", bottom_range: 0, top_range: 11_600, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 609_350, rate: 0.35, cumulative: 55_678.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 183_647.25, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id) + + # Federal tax brackets for married joint filers in 2024 + FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 23_200, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + FederalTaxBracket.create(tier: "Tier 2", bottom_range: 23_201, top_range: 94_300, rate: 0.12, cumulative: 2_320, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + FederalTaxBracket.create(tier: "Tier 3", bottom_range: 94_301, top_range: 201_050, rate: 0.22, cumulative: 10_852, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + FederalTaxBracket.create(tier: "Tier 4", bottom_range: 201_051, top_range: 383_900, rate: 0.24, cumulative: 34_337, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + FederalTaxBracket.create(tier: "Tier 5", bottom_range: 383_901, top_range: 487_450, rate: 0.32, cumulative: 78_221, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + FederalTaxBracket.create(tier: "Tier 6", bottom_range: 487_451, top_range: 731_200, rate: 0.35, cumulative: 111_357, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + FederalTaxBracket.create(tier: "Tier 7", bottom_range: 731_201, top_range: 10_000_000, rate: 0.35, cumulative: 196_669.50, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id) + + # Federal tax brackets for married separate filers in 2024 + FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 11_600, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 365_600, rate: 0.35, cumulative: 55_678.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + FederalTaxBracket.create(tier: "Tier 7", bottom_range: 365_601, top_range: 10_000_000, rate: 0.35, cumulative: 98_334.75, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id) + + # Federal tax brackets for head of household filers in 2024 + FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 16_550, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + FederalTaxBracket.create(tier: "Tier 2", bottom_range: 16_551, top_range: 63_100, rate: 0.12, cumulative: 1_655, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + FederalTaxBracket.create(tier: "Tier 3", bottom_range: 63_101, top_range: 100_500, rate: 0.22, cumulative: 7_241, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_501, top_range: 191_950, rate: 0.24, cumulative: 15_469, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_700, rate: 0.32, cumulative: 37_417, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_701, top_range: 609_350, rate: 0.35, cumulative: 53_977, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 181_954.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id) + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/data_schema.rb b/db/data_schema.rb index 61248fe..6f1aa4d 100644 --- a/db/data_schema.rb +++ b/db/data_schema.rb @@ -1 +1 @@ -DataMigrate::Data.define(version: 20240715131425) +DataMigrate::Data.define(version: 20240910125100) diff --git a/db/migrate/20240911123818_create_federal_tax_table_types.rb b/db/migrate/20240911123818_create_federal_tax_table_types.rb new file mode 100644 index 0000000..c8e406d --- /dev/null +++ b/db/migrate/20240911123818_create_federal_tax_table_types.rb @@ -0,0 +1,11 @@ +class CreateFederalTaxTableTypes < ActiveRecord::Migration[7.0] + def change + create_table :federal_tax_table_types do |t| + t.string :filing_status + + t.timestamps + end + + add_reference :federal_tax_brackets, :federal_tax_table_type, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3e19000..4134b3d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_07_15_131211) do +ActiveRecord::Schema[7.0].define(version: 2024_09_11_123818) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -28,6 +28,14 @@ t.string "cumulative_currency", default: "USD", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "federal_tax_table_type_id" + t.index ["federal_tax_table_type_id"], name: "index_federal_tax_brackets_on_federal_tax_table_type_id" + end + + create_table "federal_tax_table_types", force: :cascade do |t| + t.string "filing_status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "fixed_expenses", force: :cascade do |t| @@ -67,4 +75,5 @@ t.datetime "updated_at", null: false end + add_foreign_key "federal_tax_brackets", "federal_tax_table_types" end diff --git a/spec/factories/federal_tax_brackets.rb b/spec/factories/federal_tax_brackets.rb index 991b9fe..84f45c7 100644 --- a/spec/factories/federal_tax_brackets.rb +++ b/spec/factories/federal_tax_brackets.rb @@ -2,17 +2,26 @@ # # Table name: federal_tax_brackets # -# id :bigint not null, primary key -# bottom_range_cents :integer default(0), not null -# bottom_range_currency :string default("USD"), not null -# cumulative_cents :integer default(0), not null -# cumulative_currency :string default("USD"), not null -# rate :float -# tier :string -# top_range_cents :integer default(0), not null -# top_range_currency :string default("USD"), not null -# created_at :datetime not null -# updated_at :datetime not null +# id :bigint not null, primary key +# bottom_range_cents :integer default(0), not null +# bottom_range_currency :string default("USD"), not null +# cumulative_cents :integer default(0), not null +# cumulative_currency :string default("USD"), not null +# rate :float +# tier :string +# top_range_cents :integer default(0), not null +# top_range_currency :string default("USD"), not null +# created_at :datetime not null +# updated_at :datetime not null +# federal_tax_table_type_id :bigint +# +# Indexes +# +# index_federal_tax_brackets_on_federal_tax_table_type_id (federal_tax_table_type_id) +# +# Foreign Keys +# +# fk_rails_... (federal_tax_table_type_id => federal_tax_table_types.id) # FactoryBot.define do # tax_brackets = 10% on first $1,000, 15% from $1,001 to $100,000, 25% from $100,001 to $500,000 diff --git a/spec/factories/federal_tax_table_types.rb b/spec/factories/federal_tax_table_types.rb new file mode 100644 index 0000000..e21ed93 --- /dev/null +++ b/spec/factories/federal_tax_table_types.rb @@ -0,0 +1,14 @@ +# == Schema Information +# +# Table name: federal_tax_table_types +# +# id :bigint not null, primary key +# filing_status :string +# created_at :datetime not null +# updated_at :datetime not null +# +FactoryBot.define do + factory :federal_tax_table_type do + + end +end diff --git a/spec/models/federal_tax_bracket_spec.rb b/spec/models/federal_tax_bracket_spec.rb index 65d8c2e..19fa5b9 100644 --- a/spec/models/federal_tax_bracket_spec.rb +++ b/spec/models/federal_tax_bracket_spec.rb @@ -2,17 +2,26 @@ # # Table name: federal_tax_brackets # -# id :bigint not null, primary key -# bottom_range_cents :integer default(0), not null -# bottom_range_currency :string default("USD"), not null -# cumulative_cents :integer default(0), not null -# cumulative_currency :string default("USD"), not null -# rate :float -# tier :string -# top_range_cents :integer default(0), not null -# top_range_currency :string default("USD"), not null -# created_at :datetime not null -# updated_at :datetime not null +# id :bigint not null, primary key +# bottom_range_cents :integer default(0), not null +# bottom_range_currency :string default("USD"), not null +# cumulative_cents :integer default(0), not null +# cumulative_currency :string default("USD"), not null +# rate :float +# tier :string +# top_range_cents :integer default(0), not null +# top_range_currency :string default("USD"), not null +# created_at :datetime not null +# updated_at :datetime not null +# federal_tax_table_type_id :bigint +# +# Indexes +# +# index_federal_tax_brackets_on_federal_tax_table_type_id (federal_tax_table_type_id) +# +# Foreign Keys +# +# fk_rails_... (federal_tax_table_type_id => federal_tax_table_types.id) # require "rails_helper" diff --git a/spec/models/federal_tax_table_type_spec.rb b/spec/models/federal_tax_table_type_spec.rb new file mode 100644 index 0000000..cfd8033 --- /dev/null +++ b/spec/models/federal_tax_table_type_spec.rb @@ -0,0 +1,14 @@ +# == Schema Information +# +# Table name: federal_tax_table_types +# +# id :bigint not null, primary key +# filing_status :string +# created_at :datetime not null +# updated_at :datetime not null +# +require 'rails_helper' + +RSpec.describe FederalTaxTableType, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end