Social Security Benefit Calculator
$value) { // print($year." ". $value. "\n"); //} } echo "
\n
\n"; if(isset($_POST["IndexFactorStr"])) { $IndexFactorStr= $_POST["IndexFactorStr"]; // composed of year and index. $IndexFactorStr = preg_replace('/[\s\t\n\r]+/', ' ', $IndexFactorStr); $IndexFactors= explode(" ",$IndexFactorStr); // turn into an array; $index_factor= array(); for($i=0;$i
\n"); //} $adjusted_earnings= array(); foreach($salary as $year => $value) { if(isset($index_factor[$year])) { $factor= $index_factor[$year]; $adjusted= $factor*$value; $adjusted_earnings[$year]= $adjusted; } } arsort($adjusted_earnings,SORT_NUMERIC); $used_earnings= array_slice($adjusted_earnings,0,35,$preserve_keys = true); // take only the top 35 } $ErrorMsg= ""; if(isset($_POST["BirthDate"])) { $BirthDate= $_POST["BirthDate"]; $Birth= explode("/",$BirthDate); if(count($Birth)<2) { $ErrorMsg= "Please enter Birth Month and Year in the correct format: (mm/yyyy)"; } else { $BirthMonth= $Birth[0]; $BirthYear= $Birth[1]; if(($BirthMonth<1)||($BirthMonth>12)) { $ErrorMsg= "Invalid Birth Month."; } else if(($BirthYear<1900)||($BirthYear>2100)) { $ErrorMsg= "Invalid Birth Year."; } } } else { $BirthDate=""; $ErrorMsg= "Your Birth Month and Year is required"; } $ErrorMsg= ""; if(isset($_POST["StartDate"])) { $StartDate= $_POST["StartDate"]; $Start= explode("/",$StartDate); if(count($Start)<2) { $ErrorMsg= "Please enter Start Month and Year in the correct format: (mm/yyyy)"; } else { $StartMonth= $Start[0]; $StartYear= $Start[1]; if(($StartMonth<1)||($StartMonth>12)) { $ErrorMsg= "Invalid Start Month."; } else if(($StartYear<1900)||($StartYear>2100)) { $ErrorMsg= "Invalid Start Year."; } } } else { $StartDate=""; $ErrorMsg= "Your Start Month and Year is required"; } if(!empty($ErrorMsg)) { print("
$ErrorMsg>"); } echo '
--RESULTS--"; echo "Your birth month and year: $BirthMonth,$BirthYear\n"; echo "The first month and year when you started receiving benefits: $StartMonth,$StartYear
\n"; echo "Only the highest 35 years of indexed earnings are used in calculation of the AIME (Average Indexed Monthly Earnings).
\n"; echo "The following table list your indexed earnings history from highest to lowest years. Only the black entries are used in the calculation:
\n"; if(isset($_POST["IndexFactorStr"])) { print("
Year | Earnings | Index Factor | Adjusted Earnings |
---|---|---|---|
".$year." | ". $value. " | ".$factor ." | ");
printf("%.0f | \n",$adjusted);
print("
"); print("
\n"); print("
\n"); $AIME = array_sum($used_earnings)/count($used_earnings)/12; echo "AIME (Average Indexed Monthly Earnings): "; printf("\$%.0f
\n",$AIME); print("
\n"); print("
\n"); if($AIME<=885) { $benefit= 0.9*$AIME; } else if($AIME<=5336) { $benefit= 0.9*885+ 0.32*($AIME-885); } else { $benefit= 0.9*885+ 0.32*5336 + 0.15*($AIME-5336); } printf("Estimated Normal Benefit: \$%.0f
\n",$benefit); $StartYear = 2012; $CurrentYear= 2017; $months= 60; if($months>60) $months=60; //Cost of Living Adjustments // adjustments only go to 2016 and need to be updated. $COLA= array(1975=>8.0,1976=>6.4,1977=>5.9,1978=>6.5,1979=>9.9,1980=>14.3,1981=>11.2,1982=>7.4,1983=>3.5,1984=>3.5, 1985=>3.1,1986=>1.3,1987=>4.2,1988=>4.0,1989=>4.7,1990=>5.4,1991=>3.7,1992=>3.0,1993=>2.6,1994=>2.8, 1995=>2.6,1996=>2.9,1997=>2.1,1998=>1.3,1999=>2.5,2000=>3.5,2001=>2.6,2002=>1.4,2003=>2.1,2004=>2.7, 2005=>4.1,2006=>3.3,2007=>2.3,2008=>5.8,2009=>0.0,2010=>0.0,2011=>3.6,2012=>1.7,2013=>1.5,2014=>1.7, 2015=>0.0,2016=>0.3,2017=>0.0,2018=>0.0,2019=>0.0,2020=>0.0,2021=>0.0,2022=>0.0,2023=>0.0,2024=>0.0 ); $cola_benefit= $benefit; for($key=$StartYear;$key<=$CurrentYear;$key++) { $cola_benefit= (1.00+$COLA[$key]/100)*$cola_benefit; } printf("Estimated Cost of Living Adjusted Benefit \$%.2f
\n",$cola_benefit); if($months<=36) { $reduction= 5/9*$months; } else { $reduction= 5/9*36+ 5/12*($months-36); } printf("Estimated Reduction Percentage: %.2f %%
\n",$reduction); $adj_benefit= (1-$reduction/100)*$cola_benefit; printf("Estimated Adjusted Benefit: \$%.0f
\n",$adj_benefit); } ?>