Created
June 23, 2011 19:31
-
-
Save wjlafrance/1043418 to your computer and use it in GitHub Desktop.
Script to calculate taxes for biweekly paychecks
This file contains hidden or 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
#! /usr/bin/ruby | |
BUSINESS_TAX_SOCIAL_SECURITY = 0.062 | |
EMPLOYEE_TAX_SOCIAL_SECURITY = 0.042 | |
BUSINESS_TAX_MEDICARE = 0.0145 | |
EMPLOYEE_TAX_MEDICARE = 0.0145 | |
EMPLOYEE_TAX_INCOME_STATE = 0.05 | |
MONEY_FORMAT_STRING = "$%07.2f" | |
$employee_names = Array.new | |
$employee_gross_payments = Array.new | |
$employee_social_security_tax_payments = Array.new | |
$employee_medicare_tax_payments = Array.new | |
$employee_state_income_tax_payments = Array.new | |
$employee_federal_income_tax_payments = Array.new | |
$employee_net_payments = Array.new | |
$business_medicare_payment = 0 | |
$business_social_security_payment = 0 | |
def run | |
print "Business net income over period (after paying bills): " | |
net_income = gets.chomp.to_f | |
print "Number of employees: " | |
employee_count = gets.chomp.to_f | |
(1..employee_count).each do | i | | |
print "Employee's name: " | |
$employee_names += [gets.chomp] | |
print "Gross pay: " | |
$employee_gross_payments += [gets.chomp.to_f] | |
end | |
# Calculate total amount going to employees / staying in business | |
gross_payment = 0 | |
$employee_gross_payments.each do | employee_pay | | |
gross_payment += employee_pay | |
end | |
net_income -= gross_payment # take gross payment away from net_income | |
puts "Total gross pay is $#{gross_payment}, leaving $#{net_income}." | |
$employee_gross_payments.each_index do | i | | |
# puts "Employee #{i+1} earns #{employee_gross_pay[i]} gross pay." | |
employee_pay = $employee_gross_payments[i] | |
$employee_social_security_tax_payments += [employee_pay * EMPLOYEE_TAX_SOCIAL_SECURITY] | |
$employee_medicare_tax_payments += [employee_pay * EMPLOYEE_TAX_MEDICARE] | |
$employee_state_income_tax_payments += [employee_pay * EMPLOYEE_TAX_INCOME_STATE] | |
$employee_federal_income_tax_payments += [biweeklyFederalIncomeTax(:gross=>employee_pay, :isMarried=>false)] | |
$employee_net_payments += [employee_pay - | |
$employee_social_security_tax_payments[i] - | |
$employee_medicare_tax_payments[i] - | |
$employee_state_income_tax_payments[i] - | |
$employee_federal_income_tax_payments[i]] | |
$business_social_security_payment += employee_pay * BUSINESS_TAX_SOCIAL_SECURITY | |
$business_medicare_payment += employee_pay * BUSINESS_TAX_MEDICARE | |
end | |
net_income -= $business_social_security_payment | |
net_income -= $business_medicare_payment | |
puts | |
puts | |
$employee_gross_payments.each_index do | i | | |
puts "#{$employee_names[i]}" | |
puts " Gross: #{sprintf(MONEY_FORMAT_STRING, $employee_gross_payments[i])}" | |
puts " Social Security: #{sprintf(MONEY_FORMAT_STRING, $employee_social_security_tax_payments[i])}" | |
puts " Medicare: #{sprintf(MONEY_FORMAT_STRING, $employee_medicare_tax_payments[i])}" | |
puts " State Income Tax: #{sprintf(MONEY_FORMAT_STRING, $employee_state_income_tax_payments[i])}" | |
puts " Federal Income Tax: #{sprintf(MONEY_FORMAT_STRING, $employee_federal_income_tax_payments[i])}" | |
puts " Net: #{sprintf(MONEY_FORMAT_STRING, $employee_net_payments[i])}" | |
puts | |
end | |
puts "BUSINESS:" | |
puts " Social Security: #{sprintf(MONEY_FORMAT_STRING, $business_social_security_payment)}" | |
puts " Medicare: #{sprintf(MONEY_FORMAT_STRING, $business_medicare_payment)}" | |
puts " Remaining: #{sprintf(MONEY_FORMAT_STRING, net_income)}" | |
end | |
def weeklyFederalIncomeTax(params) | |
gross = params[:gross] | |
isMarried = params[:isMarried] | |
if isMarried | |
return 0.00 if gross < 152.00 | |
return 0.00 + (gross - 152) * 0.10 if gross >= 152.00 and gross < 179.00 | |
return 32.70 + (gross - 479) * 0.15 if gross >= 479.00 and gross < 1479.00 | |
return 182.70 + (gross - 1479) * 0.25 if gross >= 1479.00 and gross < 1479.00 | |
return 520.95 + (gross - 2832) * 0.28 if gross >= 2832.00 and gross < 1479.00 | |
return 913.79 + (gross - 4235) * 0.33 if gross >= 4235.00 and gross < 1479.00 | |
return 1972.43 + (gross - 7443) * 0.35 if gross >= 7443.00 | |
else | |
return 0.00 if gross < 40.00 | |
return 0.00 + (gross - 40) * 0.10 if gross >= 40.00 and gross < 204.00 | |
return 16.40 + (gross - 204) * 0.15 if gross >= 204.00 and gross < 704.00 | |
return 91.40 + (gross - 704) * 0.25 if gross >= 704.00 and gross < 1648.00 | |
return 327.40 + (gross - 1648) * 0.28 if gross >= 1648.00 and gross < 3394.00 | |
return 816.28 + (gross - 3394) * 0.33 if gross >= 3394.00 and gross < 7332.00 | |
return 2115.82 + (gross - 7332) * 0.35 if gross >= 7332.00 | |
end | |
end | |
def biweeklyFederalIncomeTax(params) | |
gross = params[:gross] | |
isMarried = params[:isMarried] | |
if isMarried | |
return 0.00 if gross < 304.00 | |
return 0.00 + (gross - 304) * 0.10 if gross >= 304.00 and gross < 958.00 | |
return 65.40 + (gross - 958) * 0.15 if gross >= 958.00 and gross < 2958.00 | |
return 365.40 + (gross - 2958) * 0.25 if gross >= 2958.00 and gross < 5663.00 | |
return 1041.65 + (gross - 5663) * 0.28 if gross >= 5663.00 and gross < 8469.00 | |
return 1827.33 + (gross - 8469) * 0.33 if gross >= 8469.00 and gross < 14887.00 | |
return 3945.27 + (gross - 14887) * 0.35 if gross >= 14887.00 | |
else | |
return 0.00 if gross < 81.00 | |
return 0.00 + (gross - 81) * 0.10 if gross >= 81.00 and gross < 408.00 | |
return 32.70 + (gross - 408) * 0.15 if gross >= 408.00 and gross < 1408.00 | |
return 182.70 + (gross - 1408) * 0.25 if gross >= 1408.00 and gross < 3296.00 | |
return 654.70 + (gross - 3296) * 0.28 if gross >= 3296.00 and gross < 6788.00 | |
return 1632.46 + (gross - 6788) * 0.33 if gross >= 6788.00 and gross < 14663.00 | |
return 4231.21 + (gross - 14663) * 0.35 if gross >= 14663.00 | |
end | |
end | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment