-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Federal Tax Rates and test * Lint Federal Tax Rates * Add method and poro for calculating taxes on incomes * Add tax brackets and taxed incomes to dashboard * Display taxed incomes with turbo * Update income form select box to display income type * Lint * Update test suit * Lint
- Loading branch information
Showing
36 changed files
with
781 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
class DashboardController < ApplicationController | ||
def index | ||
@incomes = Income.all | ||
@incomes = Income.order_by_type | ||
@fixed_expenses = FixedExpense.get_ordered | ||
@totals = FixedExpense.total_costs | ||
@federal_tax_brackets = FederalTaxBracket.order_by_range | ||
@salary_taxed = Income.tax_on_income(income_type: "Salary") | ||
@hourly_taxed = Income.tax_on_income(income_type: "Hourly") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class FederalTaxBracketsController < ApplicationController | ||
before_action :set_federal_tax_bracket, only: %i[show edit update destroy] | ||
|
||
# GET /federal_tax_brackets or /federal_tax_brackets.json | ||
def index | ||
@federal_tax_brackets = FederalTaxBracket.order_by_range | ||
end | ||
|
||
# GET /federal_tax_brackets/1 or /federal_tax_brackets/1.json | ||
def show | ||
end | ||
|
||
# GET /federal_tax_brackets/new | ||
def new | ||
@federal_tax_bracket = FederalTaxBracket.new | ||
end | ||
|
||
# GET /federal_tax_brackets/1/edit | ||
def edit | ||
end | ||
|
||
# POST /federal_tax_brackets or /federal_tax_brackets.json | ||
def create | ||
@federal_tax_bracket = FederalTaxBracket.new(federal_tax_bracket_params) | ||
@federal_tax_bracket.update_rate(rate: params[:rate]) | ||
|
||
respond_to do |format| | ||
if @federal_tax_bracket.save | ||
format.html { redirect_to federal_tax_bracket_url(@federal_tax_bracket), notice: "Federal tax bracket was successfully created." } | ||
format.json { render :show, status: :created, location: @federal_tax_bracket } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @federal_tax_bracket.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /federal_tax_brackets/1 or /federal_tax_brackets/1.json | ||
def update | ||
respond_to do |format| | ||
if @federal_tax_bracket.update(federal_tax_bracket_params) | ||
format.html { redirect_to federal_tax_bracket_url(@federal_tax_bracket), notice: "Federal tax bracket was successfully updated." } | ||
# format.json { render :show, status: :ok, location: @federal_tax_bracket } | ||
format.turbo_stream { render turbo_stream: turbo_stream.update(@federal_tax_bracket) } | ||
|
||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @federal_tax_bracket.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /federal_tax_brackets/1 or /federal_tax_brackets/1.json | ||
def destroy | ||
@federal_tax_bracket.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to federal_tax_brackets_url, notice: "Federal tax bracket was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_federal_tax_bracket | ||
@federal_tax_bracket = FederalTaxBracket.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def federal_tax_bracket_params | ||
params.require(:federal_tax_bracket).permit(:tier, :bottom_range, :top_range, :rate, :cumulative) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FederalTaxBracketsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# == Schema Information | ||
# | ||
# 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 | ||
# | ||
class FederalTaxBracket < ApplicationRecord | ||
monetize :bottom_range_cents | ||
monetize :top_range_cents | ||
monetize :cumulative_cents | ||
|
||
def self.order_by_range | ||
all.order(:bottom_range_cents) | ||
end | ||
|
||
def update_rate(rate:) | ||
update( | ||
rate: rate / 100 | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class IncomeTaxCalculator | ||
attr_reader :income, | ||
:annual_income, | ||
:federal_tax, | ||
:net_after_fed_tax, | ||
:state_tax, | ||
:total_net_income, | ||
:bi_weekly_net_income | ||
|
||
def initialize(income:) | ||
@income = income | ||
@annual_income = income.weekly_income_cents * 52 | ||
@federal_tax = nil | ||
@net_after_fed_tax = nil | ||
@state_tax = nil | ||
@total_net_income = nil | ||
@bi_weekly_net_income = nil | ||
end | ||
|
||
def calculate_taxes | ||
@federal_tax = calculate_fed_tax | ||
@net_after_fed_tax = calculate_net_after_fed_tax | ||
@state_tax = calculate_state_tax | ||
@total_net_income = calculate_total_net_income | ||
@bi_weekly_net_income = calculate_bi_weekly_income | ||
end | ||
|
||
private | ||
|
||
def calculate_fed_tax | ||
bracket = FederalTaxBracket.where("bottom_range_cents <= ?", @annual_income).order(:bottom_range_cents).last | ||
rated = bracket.rate * @annual_income | ||
Money.new(rated + bracket.cumulative_cents, "USD") | ||
end | ||
|
||
def calculate_state_tax | ||
state_tax = (@net_after_fed_tax.fractional * 0.0463).to_i | ||
Money.new(state_tax, "USD") | ||
end | ||
|
||
def calculate_net_after_fed_tax | ||
Money.new(@annual_income - @federal_tax.fractional, "USD") | ||
end | ||
|
||
def calculate_total_net_income | ||
Money.new(@net_after_fed_tax.fractional - @state_tax.fractional, "USD") | ||
end | ||
|
||
def calculate_bi_weekly_income | ||
Money.new(@total_net_income.fractional / 26) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= turbo_frame_tag dom_id(federal_tax_bracket) do %> | ||
<div class="grid grid-cols-6"> | ||
<% attributes = federal_tax_bracket.tier, humanized_money_with_symbol(federal_tax_bracket.bottom_range), humanized_money_with_symbol(federal_tax_bracket.top_range), number_to_percentage(federal_tax_bracket.rate * 100, precision: 1), humanized_money_with_symbol(federal_tax_bracket.cumulative) %> | ||
<% attributes.each do |attribute| %> | ||
<div class="px-5 py-1"><%= attribute %></div> | ||
<% end %> | ||
<div class="px-5 py-1"><%= link_to 'Edit', edit_federal_tax_bracket_path(federal_tax_bracket), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %></div> | ||
</div> | ||
<% end %> |
2 changes: 2 additions & 0 deletions
2
app/views/federal_tax_brackets/_federal_tax_bracket.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! federal_tax_bracket, :id, :tier, :bottom_range, :top_range, :rate, :cumulative, :created_at, :updated_at | ||
json.url federal_tax_bracket_url(federal_tax_bracket, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<%= form_with(model: federal_tax_bracket, class: "contents") do |form| %> | ||
<% if federal_tax_bracket.errors.any? %> | ||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3"> | ||
<h2><%= pluralize(federal_tax_bracket.errors.count, "error") %> prohibited this federal_tax_bracket from being saved:</h2> | ||
|
||
<ul> | ||
<% federal_tax_bracket.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<div class="flex-container"> | ||
<div class="my-5"> | ||
<%= form.label :tier %> | ||
<%= form.text_field :tier, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :bottom_range %> | ||
<%= form.number_field :bottom_range, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :top_range %> | ||
<%= form.number_field :top_range, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :rate %> | ||
<%= form.text_field :rate, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :cumulative %> | ||
<%= form.number_field :cumulative, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full", step: :any %> | ||
</div> | ||
|
||
<div class="inline"> | ||
<%= form.submit class: "rounded-lg py-1 px-4 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
<div> | ||
<%= link_to "Cancel", fixed_expenses_path, class: "rounded-lg py-1 px-4 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="grid grid-cols-6"> | ||
<% tax_headings = %w[Tier From To Rate Cumulative] %> | ||
<% tax_headings.each do |tax_heading| %> | ||
<div class="px-5"><strong><%= tax_heading %></strong></div> | ||
<% end %> | ||
</div> | ||
<%= turbo_frame_tag :federal_tax_brackets do %> | ||
<%= render @federal_tax_brackets %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="mx-auto md:w-2/3 w-full"> | ||
<h1 class="font-bold text-4xl">Editing federal tax bracket</h1> | ||
|
||
<%= turbo_frame_tag @federal_tax_bracket do %> | ||
<%= render "form", federal_tax_bracket: @federal_tax_bracket %> | ||
<% end %> | ||
|
||
<%= link_to "Show this federal tax bracket", @federal_tax_bracket, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%= link_to "Back to federal tax brackets", federal_tax_brackets_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="w-full"> | ||
<% if notice.present? %> | ||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> | ||
<% end %> | ||
|
||
<div class="flex justify-between items-center"> | ||
<h1 class="font-bold text-4xl">Federal Tax Brackets</h1> | ||
<%= link_to 'New federal tax bracket', new_federal_tax_bracket_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> | ||
</div> | ||
|
||
<div class="min-w-full"> | ||
<%= render "federal_tax_brackets/index" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @federal_tax_brackets, partial: "federal_tax_brackets/federal_tax_bracket", as: :federal_tax_bracket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="mx-auto md:w-2/3 w-full"> | ||
<h1 class="font-bold text-4xl">New federal tax bracket</h1> | ||
|
||
<%= render "form", federal_tax_bracket: @federal_tax_bracket %> | ||
|
||
<%= link_to 'Back to federal tax brackets', federal_tax_brackets_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="mx-auto md:w-2/3 w-full flex"> | ||
<div class="mx-auto"> | ||
<% if notice.present? %> | ||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> | ||
<% end %> | ||
|
||
<%= render @federal_tax_bracket %> | ||
|
||
<%= link_to 'Edit this federal_tax_bracket', edit_federal_tax_bracket_path(@federal_tax_bracket), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<div class="inline-block ml-2"> | ||
<%= button_to 'Destroy this federal_tax_bracket', federal_tax_bracket_path(@federal_tax_bracket), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> | ||
</div> | ||
<%= link_to 'Back to federal_tax_brackets', federal_tax_brackets_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "federal_tax_brackets/federal_tax_bracket", federal_tax_bracket: @federal_tax_bracket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= turbo_stream.update @income %> | ||
|
||
<%= turbo_stream.replace "taxed_incomes" do %> | ||
<%= render partial: "shared/taxed_incomes", locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed } %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="px-5"><%= humanized_money_with_symbol(taxed_income.federal_tax) %></div> | ||
<div class="px-5"><%= humanized_money_with_symbol(taxed_income.state_tax) %></div> | ||
<div class="px-5"><%= humanized_money_with_symbol(taxed_income.total_net_income) %></div> | ||
<div class="px-5"><%= humanized_money_with_symbol(taxed_income.bi_weekly_net_income) %></div> |
Oops, something went wrong.