Skip to content

Commit

Permalink
epf etf calculation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dilumn committed Dec 23, 2022
1 parent b23281e commit 9f825ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 9 additions & 3 deletions app/controllers/thetax_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class ThetaxController < ApplicationController

def index
@tax = Tax.new(
current_salary: session[:current_salary],
basic_salary: session[:basic_salary],
allowance: session[:allowance],
tax_amount: session[:tax_amount],
epf: session[:epf],
etf: session[:etf],
Expand All @@ -13,8 +14,13 @@ def index
end

def calculate
calculated_tax = Tax.new(current_salary: params[:tax][:current_salary].to_i).calculate
session[:current_salary] = calculated_tax.current_salary
calculated_tax = Tax.new(
basic_salary: params[:tax][:basic_salary].to_i,
allowance: params[:tax][:allowance].to_i
).calculate

session[:basic_salary] = calculated_tax.basic_salary
session[:allowance] = calculated_tax.allowance
session[:tax_amount] = calculated_tax.tax_amount
session[:epf] = calculated_tax.epf
session[:etf] = calculated_tax.etf
Expand Down
9 changes: 4 additions & 5 deletions app/models/tax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ class Tax
EPF_RATE = 0.08
ETF_RATE = 0.03

attr_accessor :current_salary, :tax_amount, :epf, :etf, :take_home
attr_accessor :basic_salary, :allowance, :tax_amount, :epf, :etf, :take_home

def calculate
current_salary = basic_salary + allowance
annual_salary = current_salary * 12
epf = annual_salary * EPF_RATE
annual_etf = annual_salary * ETF_RATE
remaining_taxable = annual_salary - TAX_FREE_LIMIT

calculated_tax = 0
Expand All @@ -38,8 +37,8 @@ def calculate


self.tax_amount = monthly_calculated_tax
self.epf = current_salary * EPF_RATE
self.etf = current_salary * ETF_RATE
self.epf = basic_salary * EPF_RATE
self.etf = basic_salary * ETF_RATE
self.take_home = (current_salary - self.tax_amount - self.epf - self.etf)
self
end
Expand Down
11 changes: 9 additions & 2 deletions app/views/thetax/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
<%= form_with model: @tax, url: tax_calculate_path, :html => {:method => :post}, class: 'pt-3 pb-3' do |f| %>
<div class="row">
<div class="col-12 col-md-6 pb-3">
<%= f.label :current_salary, "Salary amount (Monthly) in LKR", class: "required" %>
<%= f.number_field :current_salary, required: true, class: "form-control col-4" %>
<%= f.label :basic_salary, "Basic Salary amount (Monthly) in LKR", class: "required" %>
<%= f.number_field :basic_salary, required: true, class: "form-control col-4" %>
</div>
</div>

<div class="row">
<div class="col-12 col-md-6 pb-3">
<%= f.label :allowance, "Allowance amount (Monthly) in LKR" %>
<%= f.number_field :allowance, class: "form-control col-4" %>
</div>
</div>

Expand Down

0 comments on commit 9f825ca

Please sign in to comment.