Created
February 17, 2019 21:36
-
-
Save SGTMcClain/d73896f0248ba4a793876b9e04f209be to your computer and use it in GitHub Desktop.
income_tax_v2.php
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
<?php | |
define('TAX_BRACKETS', array(10, 15, 25, 28, 33, 35, 39.6)); | |
define('SINGLE_RANGES', array(0, 9275, 37650, 91150, 190150, 413350, 415050)); | |
define('JOINT_RANGES', array(0, 18550, 75300, 151900, 231450, 413350, 466950)); | |
define('SEPERATE_RANGES', array(0, 9275, 37650, 75950, 115725, 206675, 233475)); | |
define('HEAD_RANGES', array(0, 13250, 50400, 130150, 210800, 413350, 441000)); | |
define('TAX_RATES', | |
array( | |
'Single' => array ( | |
'Rates' => TAX_BRACKETS, | |
'Ranges' => SINGLE_RANGES, | |
'MinTax' => createMinTaxArray(SINGLE_RANGES), | |
), | |
'Married_Jointly' => array( | |
'Rates' => TAX_BRACKETS, | |
'Ranges' => JOINT_RANGES, | |
'MinTax' => createMinTaxArray(JOINT_RANGES), | |
), | |
'Married_Separately' => array( | |
'Rates' => TAX_BRACKETS, | |
'Ranges' => SEPERATE_RANGES, | |
'MinTax' => createMinTaxArray(SEPERATE_RANGES), | |
), | |
'Head_Household' => array( | |
'Rates' => TAX_BRACKETS, | |
'Ranges' => HEAD_RANGES, | |
'MinTax' => createMinTaxArray(HEAD_RANGES), | |
), | |
) | |
); | |
$tableTaxRateStrings = array( | |
'10%', | |
' plus 15% of the amount over ', | |
' plus 25% of the amount over ', | |
' plus 28% of the amount over ', | |
' plus 33% of the amount over ', | |
' plus 35% of the amount over ', | |
' plus 39.6% of the amount over ', | |
); | |
function generateTaxableIncomeTableStrings($ranges){ | |
$tableRangesStrings = array( | |
$range[0] . ' - ' . $range[1], | |
$range[1] + 1 . ' - ' . $range[2], | |
$range[2] + 1 . ' - ' . $range[3], | |
$range[3] + 1 . ' - ' . $range[4], | |
$range[4] + 1 . ' - ' . $range[5], | |
$range[5] + 1 . ' - ' . $range[6], | |
$range[6] + 1 . ' - or more', | |
); | |
return $tableRangesStrings; | |
} | |
function incomeTax($taxableIncome, $filingStatus){ | |
} | |
function getPercent($taxBracket){ | |
return $taxBracket / 100; | |
} | |
function createMinTaxArray($rangeArray){ | |
$minTaxArray = array( | |
0, | |
$rangeArray[1] * getPercent(TAX_BRACKETS[0]), | |
(($rangeArray[2] - $rangeArray[1]) * getPercent(TAX_BRACKETS[1])) + $minTaxArray[1], | |
(($rangeArray[3] - $rangeArray[2]) * getPercent(TAX_BRACKETS[2])) + $minTaxArray[2], | |
(($rangeArray[4] - $rangeArray[3]) * getPercent(TAX_BRACKETS[3])) + $minTaxArray[3], | |
(($rangeArray[5] - $rangeArray[4]) * getPercent(TAX_BRACKETS[4])) + $minTaxArray[4], | |
(($rangeArray[6] - $rangeArray[5]) * getPercent(TAX_BRACKETS[5])) + $minTaxArray[5] | |
); | |
return $minTaxArray; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Tax Rate Calculation</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" type="text/css" media="screen" href="main.css"> | |
<link rel="stylesheet" type="text/css" media="screen" href="bootstrap.css"> | |
<script src="main.js"></script> | |
</head> | |
<body> | |
<main> | |
<h1>Marginal Tax Rate Calculation</h1> | |
<form action="income_tax_v1.php" method="post"> | |
<div id="data"> | |
<label>Your Gross Annual Income:</label> | |
<input type="text" name="net_income"><br> | |
</div> | |
<div id="buttons"> | |
<label> </label> | |
<input type="submit" value="Calculate Tax"><br> | |
</div> | |
</form> | |
<!-- Start If to hide this section until there is an income submitted --> | |
<span>With a net taxable income of: <?php echo "$".number_format($net_income,2) ?></span> | |
<div class="table-responsive"> | |
<table class="table table-condensed"> | |
<thead> | |
<tr> | |
<th>Status</th> | |
<th>Tax</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td>Single</td> | |
<td><?php echo $singleTax; ?></td> | |
</tr> | |
<tr> | |
<td>Married Filing Jointly</td> | |
<td><?php echo $jointTax; ?></td> | |
</tr> | |
<tr> | |
<td>Married Filing Separately</td> | |
<td><?php echo $seperateTax; ?></td> | |
</tr> | |
<tr> | |
<td>Head of Household</td> | |
<td><?php echo $headOfHouseholdTax; ?></td> | |
</tr> | |
</tbody> | |
<tfooter> | |
<tr> | |
<td></td> | |
</tr> | |
</tfooter> | |
</table> | |
</div> | |
<!-- End IF --> | |
<div>2016 Tax Tables</div> | |
<!-- Single Table should be created with a for loop--> | |
<?php | |
foreach(TAX_RATES as $status){ | |
echo "<div>" . $status . "</div>"; | |
echo "<div class=\"table-responsive\">"; | |
echo "<table class=\"table table-condensed\">"; | |
echo "<thead>"; | |
echo "<tr>"; | |
echo "<th>Taxable Income</th>"; | |
echo "<th>Tax Rates</th>"; | |
echo "</tr>"; | |
#<!-- Start Inner Table loop here --> | |
foreach($status['Ranges'] as $thisRange){ | |
$i = 0; | |
echo "<tr>"; | |
echo "<td>" . generateTaxableIncomeTableStrings($thisRange[$i]) . "</td>"; | |
echo "<td></td>"; | |
echo "</tr>"; | |
$i++; | |
} | |
echo "</thead>"; | |
echo "</table>"; | |
echo "</div>"; | |
} | |
?> | |
</main> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment