34 lines
1.8 KiB
JavaScript
34 lines
1.8 KiB
JavaScript
function calculate() {
|
|
const gross = parseFloat(document.getElementById('grossPay').value) || 0;
|
|
const freq = parseInt(document.getElementById('payFreq').value);
|
|
const status = document.getElementById('filingStatus').value;
|
|
const stateCode = document.getElementById('state').value;
|
|
const retPct = parseFloat(document.getElementById('retPct').value) / 100;
|
|
const preTax = (parseFloat(document.getElementById('preTaxPay').value) || 0) * freq;
|
|
const postTax = (parseFloat(document.getElementById('postTaxPay').value) || 0) * freq;
|
|
const other = (parseFloat(document.getElementById('otherPay').value) || 0) * freq;
|
|
const cityPct = (parseFloat(document.getElementById('cityTax').value) / 100) || 0;
|
|
|
|
const stdDed = STD_DEDUCTIONS[status];
|
|
document.getElementById('stdDedLabel').textContent = '$' + stdDed.toLocaleString();
|
|
|
|
const retirement = gross * retPct;
|
|
const preTaxTotal = retirement + preTax;
|
|
const fedtaxable = Math.max(0, gross - stdDed - preTaxTotal);
|
|
const taxable = Math.max(0, gross - preTaxTotal);
|
|
|
|
const fed = calcBracketTax(fedtaxable, FED_BRACKETS[status]);
|
|
const ss = Math.min(gross, SS_BASE) * SS_RATE;
|
|
const med = gross * MED_RATE;
|
|
const addMed = gross > ADD_MED_THRESH[status] ? (gross - ADD_MED_THRESH[status]) * 0.009 : 0;
|
|
const fica = ss + med + addMed;
|
|
const stTax = calcStateTax(taxable, stateCode);
|
|
const ctTax = Math.max(0,taxable * cityPct);
|
|
const totalTax = fed + fica + stTax + ctTax;
|
|
const totalDeductions = preTaxTotal + postTax + other + totalTax;
|
|
const net = gross - totalDeductions;
|
|
const netPer = net / freq;
|
|
|
|
currentData = { gross, retPct, retirement, preTax, preTaxTotal, postTax, other, fed, ss, med, addMed, fica, stTax, ctTax, totalTax, net, netPer, taxable, stdDed, freq, status, stateCode };
|
|
renderResults(currentData);
|
|
} |