#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); $query = $ENV{'QUERY_STRING'}; @pairs = split (/&/, $query); foreach $pair (@pairs) { ($key, $value) = split(/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($urlquery{$key}) { $urlquery{$key} .= ", $value"; } else { $urlquery{$key} = $value; } } $args = $urlquery{'a'}; if($args eq "m"){ $printtemp = ""; &monthly; } elsif($args eq "h"){ $printtemp = ""; &howmuch; } elsif($args eq "d"){ $printtemp = ""; &duration; } elsif($args eq ""){ $printtemp = ""; &missing; } elsif($args eq "q"){ $printtemp = ""; &qualify; } elsif($args eq "b"){ $printtemp = ""; &balloon; } elsif($args eq "mi"){ $printtemp = ""; &million; } elsif($args eq "r"){ $printtemp = ""; &rdur; } elsif($args eq "re"){ $printtemp = ""; &retire; } elsif($args eq "s"){ $printtemp = ""; &savings; } elsif($args eq "l"){ $printtemp = ""; &lunch; } sub duration { print < How Much Will I Save by Prepaying Loan?
$printtemp
How Much Will I Save by Prepaying Loan?

Using this calculator, you can determine 3 different scenarios:
1.) Desired length of loan.
2.) Desired monthly payment. If your current payment is \$1000 and you want to see what would happen if you added \$200 per month. Then you would enter \$1200 as you new monthly payment.
3.) Enter "0" for credit card and other non-amortized lines of credit.

   
Loan Amount:
\$
Interest Rate:
%
Amortized Length of Mortgage:
(Enter "0" for credit card and other non-amortized lines of credit.)
Yrs
 
 
   
   
Results Shown Below
(This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!

Header $args = $ENV{'QUERY_STRING'}; $args =~ s/\+/ /g; $args =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; if (length($args) < 4) {} else { @f = split("&",$args); for ($i=0; $i<=$#f; $i++) { $av = @f[$i]; $av =~ s/[ ,+]//g; if ($av =~ /^amt/) { $amt = substr($av,4); } if ($av =~ /^int/) { $int = substr($av,4); } if ($av =~ /^len/) { $len = substr($av,4); } if ($av =~ /^opt/) { $opt = substr($av,4); } if ($av =~ /^ovl/) { $ovl = substr($av,4); } if ($av =~ /^out/) { $out = substr($av,4); } } if ($opt =~ /Length/) { $opt = "LENGTH"; } else { $opt = "AMOUNT"; } $thou = $amt/1000; #$int = $ir1 + $ir2; print "For a loan of \$ $amt at a interest rate of $int %\n"; print "for $len years\n"; $tt = $len * 12; $i = $int / 1200; if ($tt > 0) { if ($i > 0) { $paymt = $amt * $i / (1 - ((1 + $i) ** -$tt)); } else { $paymt = $amt / $tt; } printf("

Your original principal & interest payment is : \$ %9.2f

\n", $paymt); } else { $paymt = 0; } if ($opt eq "AMOUNT") { if ($ovl < $paymt) { print "

Sorry, you did not pay enough!

\n"; printf("

You entered \$ %9.2f, You need \$ %9.2f more

\n", $ovl, $paymt - $ovl); } else { printf("

You stated that you could afford to pay \$ %9.2f per month.

\n", $ovl); if ($paymt > 0) { printf("

That's an extra \$ %9.2f each month

\n", $ovl - $paymt); } if ($ovl < $amt * $i && $tt == 0) { printf("

But that's less than the interest of \$ %9.2f

", $amt * $i); exit; } $eti = $paymt * $tt - $amt; if ($out =~ /Full/) { print "\n
MonthPrincipalInterestBalanceTot Int\n"; } while($amt > 0 && $m < 1200) { $ti = $ti + $amt * $i; $ci = $amt * $i; $p = $ovl - $ci; $amt = $amt * (1 + $i) - $ovl; $m++; if ($out =~ /Full/) { printf("
%3d%9.2f%9.2f%9.2f%9.2f\n", $m,$p,$ci,$amt,$ti); } } if ($out =~ /Full/) { print "
\n"; } $y = $m/12; printf("

Your loan will be paid off in %3d months (%6.3f years)

\n", $m, $y); if ($tt > 0) { printf("
  • Expected total interest : \$ %10.2f\n",$eti); } printf("
  • Your total interest : \$ %10.2f\n",$ti); if ($tt > 0) { printf("
  • Total interest saved : \$ %10.2f\n",$eti - $ti); } } } else { if ($ovl > $len && $tt > 0) { print "

    Sorry, it can't take longer than the amortization

    "; print "

    That's called defaulting on your loan!

    "; } else { $dm = $ovl * 12; $dpt_l = $paymt; $dpt_h = 10 * $paymt; $m = 0; if ($dpt_h == 0) { $dpt_h = $amt; } while($dpt_h > $dpt_l + .01) { $dpt = ($dpt_l + $dpt_h) / 2; $m = 0; $amtt = $amt; while($amtt > 0 && $m < 1200) { $amtt = $amtt * (1 + $i) - $dpt; $m++; } if ($m < $dm) { $dpt_h = $dpt; } else { $dpt_l = $dpt; } } if ($out =~ /Full/) { print "\n"; print "
    MonthPrincipalInterestBalanceTot Int\n"; $amtt = $amt; while($amtt > 0 && $j < 1200) { $ci = $amtt * $i; $p = $dpt - $ci; $amtt = $amtt * (1 + $i) - $dpt; $j++; $ti = $ti + $ci; printf("
    %2d%9.2f%9.2f%9.2f%9.2f\n", $j, $p, $ci, $amtt, $ti); } print "
    \n"; } print "

    You've stated that you would like to pay off your loan in $ovl years.

    \n"; printf("

    Your new required monthly payment is: \$ %7.2f

    \n",$dpt); printf("

    That's an extra \$ %7.2f a month

    \n",$dpt - $paymt); $paid_interest = sprintf("%9.2f",$ovl * 12 * $dpt - $amt); $totl_interest = sprintf("%9.2f",$len * 12 * $paymt - $amt); printf("

    By choosing to prepay your loan, you have saved yourself: \$ %9.2f in interest payments!

    \n", $totl_interest - $paid_interest); } } } } sub missing { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); @v = split("&",$in); $tbl = "N"; for ($i=0; $i<=$#v; $i++) { ($key,$val) = split("=",@v[$i]); $val =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $val =~ s/,//g; $val =~ s/ //g; $aa{$key} = $val; if ($val < 1) { $zeroes++; $which = $key; } } if ($zeroes > 1) { # Too many zeroes! I'll use defaults $aa{LA} = 100000; $aa{AI}=8.00; $aa{NM} = 360; $aa{MP} = 0; $which = "MP"; } if ($which eq "MP") { $mi = $aa{AI}/1200; $aa{MP} = sprintf("%8.2f",$aa{LA} * $mi / (1 - (1 + $mi)** - $aa{NM})); $aa{MP} =~ s/ //g; } if ($which eq "LA") { $mi = $aa{AI}/1200; $aa{LA} = sprintf("%8.2f",$aa{MP} /( $mi / (1 - (1 + $mi)** - $aa{NM}))); $aa{LA} =~ s/ //g; } if ($which eq "NM") { $mi = $aa{AI}/1200; $nm_lo = 0 ; $nm_hi = 2000; while($nm_lo < $nm_hi + 0.01 && $mc < 500) { $nm = ($nm_lo + $nm_hi) / 2; $cmp = sprintf("%8.2f",$aa{LA} * $mi / (1 - (1 + $mi)** - $nm)); if ($cmp > $aa{MP}) { $nm_lo = $nm; } else { $nm_hi = $nm; } $mc++; } $aa{NM} = sprintf("%3d",$nm); $aa{NM} =~ s/ //g; if ($aa{NM} > 1999) { $needed_min = sprintf("%8.2f",$aa{LA} * $mi); $msg = "

    You will never pay off your loan, the required minimum is \$ $needed_min just to cover interest

    "; $aa{NM} = 0; } } if ($which eq "AI") { if ($aa{MP} * $aa{NM} < $aa{LA}) { $msg = "

    That payment is too low to ever pay off that loan

    "; } else { $ai_lo = 0 ; $ai_hi = 500; while($ai_lo < $ai_hi + 0.0001 && $mc < 500) { $ai = ($ai_lo + $ai_hi) / 2; $mi = $ai/1200; $cmp = sprintf("%8.2f",$aa{LA} * $mi / (1 - (1 + $mi)** - $aa{NM})); if ($cmp < $aa{MP}) { $ai_lo = $ai; } else { $ai_hi = $ai; } $mc++; } $aa{AI} = sprintf("%9.5f",$ai); $aa{AI} =~ s/ //g; if ($aa{AI} == 500) { $msg = "

    If you paid that much that long, you're paying annual interest over 500%

    "; $aa{AI} = 0; } } } $yrs = sprintf("%6.3f",$aa{NM}/12); print<How Much Will My Payments Be? EOF } sub qualify { print "Content-type: text/html\n\n"; print "Mortgage Qualifying Incomes\n"; print "\n"; $arglist = $ENV{'QUERY_STRING'}; @r = split("&","$arglist"); if ($#r < 4) { $paymt = $arglist; sprintf($spy,"%7.2f",$paymt); print < Monthly Payment & Income Requirement Calculator
    How Much Will My Payments Be?
    Using this calculator, you can find any missing variable for a loan. Just fill in any three fields to calculate the fourth.
     
    Loan Amount:
    Monthly Payment:
    Annual Interest:
    Number of Months:
    $msg
     
    Results Shown Above
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
     
    Monthly Payment & Income Requirement Calculator
    Using this calculator, you can estimate your monthly payment and the amount of income needed to purchase a home.
         
    Monthly Mortgage P&I:
    ( P&I = principal and interest)
    \$
    Annual Property Tax:
    \$
    Annual Homeowners Insurance:
    \$
    Total Monthly Debt:
    (car, credit cards and student loans, etc.)
    \$
    Sale Price of Home:
    \$
    Down Payment:
    \$
         
    $printtemp
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
    FormHead } else { print < Monthly Payment & Income Requirement Calculator
    Monthly Payment & Income Requirement Calculator
    Using this calculator, you can estimate your monthly payment and the amount of income needed to purchase a home.
         
    Monthly Mortgage P&I:
    ( P&I = principal and interest)
    \$
    Annual Property Tax:
    \$
    Annual Homeowners Insurance:
    \$
    Total Monthly Debt:
    (car, credit cards and student loans, etc.)
    \$
    Sale Price of Home:
    \$
    Down Payment:
    \$
         
    $printtemp
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!

    FormHead for ($i=0; $i<=$#r; $i++) { $av = @r[$i]; $av =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $av =~ s/[ ,+]//g; if ($av =~ /^pi=/) { $pi = substr($av,3); } if ($av =~ /^pt=/) { $pt = substr($av,3); } if ($av =~ /^hi=/) { $hi = substr($av,3); } if ($av =~ /^mi=/) { $mi = substr($av,3); } if ($av =~ /^hv=/) { $hv = substr($av,3); } if ($av =~ /^dp=/) { $dp = substr($av,3); } } $tpy = $pi + $mi + ($pt + $hi) / 12; $lpy = $pi + ($pt + $hi) / 12; printf("

    Total monthly lender (PITI) payment: \$ %7.2f

    ", $lpy); ("

    Total monthly debt payment: \$ %7.2f

    ", $tpy); if ($dp == 0) { if ($hv > 0) { $dp == $hv * .2; } else { $dp = 20000; } } else { if ($hv == 0) { $hv = $dp * 5; } } if ($hv == 0) { $hv = 100000; } if ($dp/$hv < .20 && $hv > 0) { # Impose PMI $pmi_r = .32; # Upto 20%? if ($dp/$hv <= .15) { $pmi_r = .52; } if ($dp/$hv <= .10) { $pmi_r = .78; } if ($dp/$hv <= .05) { $pmi_r = .90; } #if ($dp/$hv <= .15) { $pmi_r = .32; } #if ($dp/$hv <= .10) { $pmi_r = .52; } #if ($dp/$hv <= .05) { $pmi_r = .78; } #if ($dp/$hv <= .03) { $pmi_r = .90; } if ($dp/$hv >= 0.03) { $pmi = ($hv-$dp) * $pmi_r/1200; ("

    Total monthly PMI payment \$ %7.2f
    ( %4.2f %% a year on \$ %7.0f loan,
    since your downpayment was %5.2f %%)

    ", $pmi, $pmi_r, $hv - $dp, $dp/$hv*100); } else { printf("

    With a down payment of \$ %9d on a purchase of \$ %9d
    ", $dp,$hv); printf("That's a downpayment of only %5.3f %% !

    \n", $dp/$hv*100); print "

    Sorry, but unless you are eligible for a VA loan most lenders would require at least 3% down


    \n"; exit; } } else { $pmi = 0; } $i28 = (($pi + $pmi) * 12 + $pt + $hi ) / .28; $i36 = (($pi + $mi + $pmi) * 12 + $pt + $hi ) / .36; if ($i28 > $i36) { $req_inc = $i28; } else { $req_inc = $i36; } ("

    28%% Qualifying income: \$ %9.2f

    ",$i28); ("

    36%% Qualifying income: \$ %9.2f

    ",$i36); $req_inc_s = sprintf("%9.2f",$req_inc); print "

    The minimum qualifying income needed is: \$ $req_inc_s

    "; print< Convertible Balloon Mortgage Calculator
    Convertible Balloon Mortgage Calculator
    These days 5/25 and 7/23 convertible balloon mortgages are getting more popular since they provide lower rates than conventional 30 year mortgages while still giving a fixed payment schedule for 5 or more years. The risk, of course, is what happens after the initial fixed period is over and you have the possibility of converting your loan. Here is a calculator to try to answer those questions...
         
    Principle Balance:
    \$
    Type of Loan:
    Interest Rate:
    %
    Monthly Pre-Payment,
    if any:
    \$
    Output Type:
     
    $printtemp
         
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
    EOF } else { print< Convertible Balloon Mortgage Calculator
    Convertible Balloon Mortgage Calculator
    These days 5/25 and 7/23 convertible balloon mortgages are getting more popular since they provide lower rates than conventional 30 year mortgages while still giving a fixed payment schedule for 5 or more years. The risk, of course, is what happens after the initial fixed period is over and you have the possibility of converting your loan. Here is a calculator to try to answer those questions...
         
    Principle Balance:
    \$
    Type of Loan:
    Interest Rate:
    %
    Monthly Pre-Payment,
    if any:
    \$
    Output Type:
     
    $printtemp
         
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!

    EOF @v = split("&",$args); $tbl = "N"; for ($i=0; $i<=$#v; $i++) { ($key,$val) = split("=",@v[$i]); $aa{$key} = $val; if (($key =~ "out") && ($val =~ /HTML/)) { $tbl = "Y"; } } $bal = $aa{"bal"}; $init = substr($aa{"fxd"},0,1); if ($init eq "1") { $init = 10; } $int = $aa{"int"}; $prepay = $aa{"prepay"}; $tt = $init * 12; $ir = $int / 1200; $temp = (1 + $ir) ** -360; $paymt = ($bal * $ir) / (1 - $temp); printf ("

    Your Monthly Payment for %2d Years will be \$ %9.2f

    ", $init, $paymt); if ($prepay > 0) { printf("

    Plus \$ %7.2f monthly prepayment for \$ %7.2f total

    \n", $prepay,$paymt+$prepay); } print "

    Amortization Table for First $init Years

    "; if ($tbl eq "Y") { print "
    YrStart BalIntEnd Bal\n"; } else { print "
    \n  YR  Start Bal        Int       End Bal      \n"; 
       print "  ==  ==========  ==========  =========\n";
      }
      for ($i=1; $i<=$init; $i++)
      {
         $sbal = $bal; $ti = 0;
         for ($j=0; $j<12; $j++) # each month
         {
           $ci = $bal * $ir; $bal += $ci - $paymt - $prepay; $ti += $ci;
         }
         if ($tbl eq "Y")
         {
           printf("
    %2d%10.2f%10.2f%10.2f\n",$i,$sbal,$ti,$bal); } else { printf(" %2d %10.2f %10.2f %10.2f\n",$i,$sbal,$ti,$bal); } } if ($tbl eq "Y") { print "
    \n"; } else { print "\n
    \n"; } printf("

    After %2d Years Your Balance will be \$ %9.2f

    ", $init, $bal); $rest = 30 - $init; print "

    Let's see what happens in the next $rest years

    \n"; if ($tbl eq "Y") { print "
    RatePaymentTot Int\n"; print "RatePaymentTot Int\n"; } else { print "
    \n   Rate      Payment   Tot Int  ";
       print                 "   Rate      Payment   Tot Int\n";
       print                 "  ======  ==========  =========  ";
       print                 "  ======  ==========  =========\n";
      }
      for ($fi = 4; $fi <= 8; $fi += .25)
      {
        $ir = $fi/1200; $fi2 = $fi + 4;
        $temp = (1 + $ir) ** -($rest * 12);
        $np = ($bal * $ir) / (1 - $temp);
        $ti = ($rest * 12 * $np) - $bal;
    
        $ir2 = $fi2/1200;
        $temp = (1 + $ir2) ** -($rest * 12);
        $np2 = ($bal * $ir2) / (1 - $temp);
        $ti2 = ($rest * 12 * $np2) - $bal;
        if ($tbl eq "Y") 
        { printf("
    %6.2f%9.2f%9.2f\n",$fi,$np,$ti); printf("%6.2f%9.2f%9.2f\n",$fi2,$np2,$ti2); } else { printf(" %6.2f %9.2f %9.2f ",$fi,$np,$ti); printf(" %6.2f %9.2f %9.2f\n",$fi2,$np2,$ti2); } } if ($tbl eq "Y") { print "
    \n"; } else { print "\n\n"; } print<This shows what your new monthly payment will be as well as the total interest you will pay for the next $rest years depending what your new interest rate will be. Trailer } } sub million { # $args = $ENV{'QUERY_STRING'}; if (length($args) < 5) { print< When Will You Become a Millionaire? $printtemp
    When Will You Become a Millionaire?
    Using this calculator will help you find out how long it will take until you reach your goal (default = \$1,000,000). Of course that million won't be worth much in the future. Put in an inflation factor and it will show you what it's worth then.

    Enter your starting balance, your ending balance, monthly contribution and interest rate.
     
    Initial Amount:
    \$
    Monthly Deposit:
    \$
    Average Annual Return:
    %
    Average Annual Inflation:
    %
    Final Desired Amount:
    \$
     
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
    EOF } else { print< When Will You Become a Millionaire? $printtemp
    When Will You Become a Millionaire?
    Using this calculator will help you find out how long it will take until you reach your goal (default = \$1,000,000). Of course that million won't be worth much in the future. Put in an inflation factor and it will show you what it's worth then.

    Enter your starting balance, your ending balance, monthly contribution and interest rate.
     
    Initial Amount:
    \$
    Monthly Deposit:
    \$
    Average Annual Return:
    %
    Average Annual Inflation:
    %
    Final Desired Amount:
    \$
     
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
    EOF #($pmin,$pmax,$imin,$imax,$term) = split("&",$args); @v = split("&",$args); $tbl = "N"; for ($i=0; $i<=$#v; $i++) { ($key,$val) = split("=",@v[$i]); $val =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $val =~ s/,//g; $aa{$key} = $val; } $yld = $aa{"yld"}; $inf = $aa{"inf"}; $fin = $aa{"fin"}; $amt = $aa{"amt"}; $dep = $aa{"dep"}; $mi = $yld/1200; $tt = $yrs * $py; print "

    With your Yield of $yld % "; printf ("with monthly deposits of \$ %6.2f

    ",$dep); printf ("

    With an Initial Amount of \$ %9.2f:

    ",$amt); printf ("

    And a Final Amount of \$ %9.2f:

    ",$fin); $fact = 1; #print "
    \n";
      while($amt < $fin && $yrs < 100) 
      {
        $yrs++;
        for ($i=0; $i<12; $i++)
        {
          $amt = $amt * (1 + $mi) + $dep;
        }
        $fact = $fact * (1 + $inf/100);
      }
      #print "\n
    \n"; if ($yrs < 100) { printf ("

    You will reach your goal in %3d years, but due to $inf %% inflation your \$ %9d will only be worth \$ %9d in today's dollars

    \n", $yrs,$fin,$fin/$fact); print "
    \n"; } else { printf ("

    Sorry, even after 100 years, you will only have \$ %9d, worth
    \$ %9d in today's dollars.

    \n",$amt,$amt/$fact); } } } sub rdur { print < Retirement Payout Calculator $printtemp \n", $m,$pmt,$p,$ci,$aa{A},$ti); } } if ($aa{X} =~ /Full/) { print "
    Retirement Payout Calculator
    This calculator takes an account balance and interest rate and determines either how long you can withdraw a fixed amount of money from it, or how much you can withdraw over a fixed period of time. Confused? You won't be! Just enter some numbers and give it a try!
     
    Your Account Balance: \$
    Interest Rate: %
    Inflation on Payments: %
     
     
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
    Header $args = $ENV{'QUERY_STRING'}; $args =~ s/\+/ /g; $args =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; if (length($args) < 4) { print < 100) { $aa{I} = 100; } if ($aa{F} > 10) { $aa{F} = 10; } $mi = $aa{I}/1200; print "For an account of \$ $aa{A} at a interest rate of $aa{I} %\n"; print "with payments inflated at a rate of $aa{F} \% a year\n"; if ($opt eq "AMOUNT") { printf("

    You entered \$ %9.2f

    \n", $aa{V}); $pmt = $aa{V}; $ym = -1; if ($aa{X} =~ /Full/) { print "\n
    MonthPaymentPrincipalInterestBalanceTot Int\n"; } while($aa{A} > 0 && $m < 1200) { $ym++; if ($ym == 12) { $pmt = $pmt * (1 + $aa{F}/100); $ym = 0; } $ci = $aa{A} * $mi; $ti = $ti + $ci; $p = $pmt - $ci; #if ($p < 0) #{ #print "
    \n

    You are earning more than you are withdrawing"; #print "
    Your money will last forever

    \n"; $m = 1200; #} $aa{A} = $aa{A} + $ci - $pmt; $m++; if ($aa{X} =~ /Full/ && $m < 1200) { printf("
    %3d%9.2f%9.2f%9.2f%9.2f%9.2f
    \n"; } $y = $m/12; if ($y<100) { printf("

    Your money lasted %3d months (%6.3f years)

    \n", $m, $y); printf("
  • Your total earned interest : \$ %10.2f\n",$ti); } else { print "

    With those numbers your money would last over 100 year
    "; print "(i.e. essentially forever)

    \n"; } } else { $dm = $aa{V} * 12; $dpt_l = 0; $dpt_h = $aa{A}; $m = 0; while($dpt_h > $dpt_l + .01) { $dpt_mid = ($dpt_l + $dpt_h) / 2; $dpt = $dpt_mid; $m = 0; $amtt = $aa{A}; $ym= -1; while($amtt > 0 && $m < 1200) { $amtt = $amtt * (1 + $mi) - $dpt; $m++; $ym++; if ($ym == 12) { $dpt = $dpt * (1 + $aa{F}/100); $ym = 0; } } #print "
  • $m $dpt_mid $dpt"; if ($m < $dm) { $dpt_h = $dpt_mid; } else { $dpt_l = $dpt_mid; } } $dpt_o = $dpt_mid; # Original $dpt = $dpt_o; printf("

    Your Initial Monthly Payout : \$ %7.2f

    \n",$dpt_o); if ($aa{X} =~ /Full/) { $ym = -1; print "\n"; print "
    MonthPaymentPrincipalInterestBalanceTot Int\n"; $amtt = $aa{A}; while($amtt > 0 && $j < 1200) { $ym++; if ($ym == 12) { $dpt = $dpt * (1 + $aa{F}/100); $ym = 0; } $ci = $amtt * $mi; $p = $dpt - $ci; $amtt = $amtt * (1 + $mi) - $dpt; $j++; $ti = $ti + $ci; printf("
    %2d%9.2f%9.2f%9.2f%9.2f%9.2f\n", $j, $dpt, $p, $ci, $amtt, $ti); } print "
    \n"; } print "

    Over $aa{V} Years

    \n"; } print< TailEnd } sub retire { $args = $ENV{'QUERY_STRING'}; print < How Much Will You Need To Retire? "; $form; } sub get_data { local($string); # get data if ($ENV{'REQUEST_METHOD'} eq 'GET') { $_ = $string = $ENV{'QUERY_STRING'}; tr/\"~;/_/; $string = $_; } else { read(STDIN, $string, $ENV{'CONTENT_LENGTH'}); $_ = $string; $OK_CHARS='a-zA-Z0-9=&%\n\/_\-\.@'; tr/\"~;/_/; $string = $_; } # split data into name=value pairs @data = split(/&/, $string); # split into name=value pairs in associative array foreach (@data) { split(/=/, $_); $_[0] =~ s/\+/ /g; # plus to space $_[0] =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric $data{"$_[0]"} = $_[1]; } # translate special characters foreach (keys %data) { $data{"$_"} =~ s/\+/ /g; # plus to space $data{"$_"} =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric } %data; # return associative array of name=value } sub commify { local($val,$commify,$top,$bot,@top); $commify = "$_[0]"; ($top,$bot) = split(/\./, $commify); @top = split("", $top); for($i = 0; $i <= $#top; $i= $i + 3){ if ($#top - ($i+2) >= 0){ $val = ",$top[$#top - ($i + 2)]$top[$#top - ($i + 1)]$top[$#top - $i]$val"; } elsif($#top - ($i+1) >= 0){ $val = ",$top[$#top - ($i + 1)]$top[$#top - $i]$val"; } elsif($#top - ($i) >= 0){ $val = ",$top[$#top - $i]$val"; } } $val =~ s/,$//; $val =~ s/^,//; $val =~ s/^0+//; $val = "$val.$bot"; $val; } } }
    How Much Will You Need To Retire?
    This is a simple retirement calculator. It will show you how much you will need to save, to provide a certain income for a set number of years.
       
    Annual Income Required
    (In today's dollar)
    \$
    Number of Years Until Retirement:
    Number of Years Required
    After Retirement:
    Annual Inflation: %
    Average Annual Yield on Balance: %
     
    $printtemp
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
     
    FullForm } else { print < How Much Will You Need To Retire?
    How Much Will You Need To Retire?
    This is a simple retirement calculator. It will show you how much you will need to save, to provide a certain income for a set number of years.
       
    Annual Income Required
    (In today's dollar)
    \$
    Number of Years Until Retirement:
    Number of Years Required
    After Retirement:
    Annual Inflation: %
    Average Annual Yield on Balance: %
     
    $printtemp
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
     
    FullForm print "

    Retirement Estimations

    \n"; print "

    Inputs

    \n"; # Let's do the calculations! @va = split("&",$args); for ($i=0; $i<7; $i++) { @va[$i] = substr(@va[$i],5); } @va[$i] =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; @va[$i] =~ s/[ ,]//g; ($inc,$unt,$yrs,$inf,$yld,$ott) = @va; $irat = 1 + $inf/100; # inflation ratio $icf = sprintf("%10.2f",$inc * ( $irat ** $unt )); # future income if ($ott =~ /Plain/) { print "
  • Required Income: \$ $inc (Current Dollars)\n"; print "
  • Required Income: \$ $icf (Future Dollars)\n"; print "
  • Number of Years until retiring : $unt \n"; print "
  • Number of Years after retiring : $yrs \n"; print "
  • Annual Inflation : $inf %\n"; print "
  • Annual Yield on Balance: $yld % \n"; } else { print "\n"; print "
    Required Income (Current Dollars) \$ $inc \n"; print "
    Required Income (Future Dollars) \$ $icf \n"; print "
    Number of Years Until Retiring $unt \n"; print "
    Number of Years After Retiring $yrs \n"; print "
    Annual Inflation (on Required Income) $inf %\n"; print "
    Annual Yield on Balance$yld % \n"; print "
    \n"; } print "
    \n"; $iy = $yld/100; $oinc = $icf; if ($inf > 0) { $icf = $icf * ($irat ** $yrs); } for ($i=0; $i<$yrs; $i++) { if ($inf > 0) { $icf = $icf/ (1 + $inf/100); } $bal = $bal / (1 + $iy) + $icf; } printf("

    You will need \$ %10.2f

    \n",$bal); $icf = $oinc; printf("

    (\$ %10.2f invested today)

    \n", $bal / (1 + $iy) ** $unt); if ($ott =~ /HTML/) { print "\n"; print "
    YearBeg BalWithdrawInterestEnd Bal\n"; } for ($i=1; $i<=$yrs; $i++) { $bbal = $bal; $bal = $bal - $icf; $earn = $bal * $yld/100; $bal = $bal + $earn; if ($ott =~ /Plain/) { printf("
  • Year %2d : Beg Balance %10.2f Withdraw %9.2f Interest %9.2f End Balance %9.2f\n", $i, $bbal, $icf, $earn, $bal); } else { printf("
  • %2d %10.2f %9.2f %9.2f %9.2f\n", $i, $bbal, $icf, $earn, $bal); } if ($inf > 0) { $icf = $icf * (1 + $inf/100); } } if ($ott =~ /HTML/) { print "
    \n"; } print < Trailer } } sub savings { # $args = $ENV{'QUERY_STRING'}; if (length($args) < 4) { print< Simple Savings Calculator $printtemp
    Simple Savings Calculator
    This calculator doesn't deal with inflation or taxes. This is just a simple calculator that lets you start with a set amount of money and make regular monthly deposits, and see how much it grows.
     
    Initial Amount: \$
    Monthly Deposit: \$
    Annual Interest Compounded
    %
    Number of Years:  
     
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
     
    EOF } else { print< Simple Savings Calculator
    $printtemp $form $footer"; exit(); } # Get our HTML currency symbol: if($currency eq "yen" || $currency eq "pound" || $currency eq "cent"){ $currency = "&$currency;"; } else { $currency = "\$"; } # Now, we'll see if they entered an interest rate that is 0.075 or # .075 instead of 7.5 which they should have, and if so, multiply # it by 100 so that we get the value we want to calculate with. if($int =~ /^\./ || $int =~ /^0\./){ $int = $int * 100; } # Is the payment interval Biweekly or Monthly? $interval = "$data{'howoften'}"; # Note: for biweekly, calculate monthly payment first, then halve it. $freq = 12; $monthly_interest = $int / ($freq * 100); $numpayments = $len * $freq; $minusn = ($numpayments * (-1)); # And heeeeeere's the formula to calculate the payment: $pay = $prin * ($monthly_interest / (1 - (1 + $monthly_interest) ** ($minusn))); $payplus = $pay + ($tax / 12) + ($insure / 12); #biweekly payment $pay = $pay / 2 if $interval eq "Bi-Weekly"; $pay = sprintf("%.2f", $pay); $payplus = sprintf("%.2f", $payplus); # Generate the HTML form to be printed out so someone can do another # calculation immediately. $form = &get_form(); $realint = $monthly_interest; $realint = $int / (26 * 100) if $interval eq "Bi-Weekly"; if ($startmon eq "Jan") {$j = 1;} if ($startmon eq "Feb") {$j = 2;} if ($startmon eq "Mar") {$j = 3;} if ($startmon eq "Apr") {$j = 4;} if ($startmon eq "May") {$j = 5;} if ($startmon eq "Jun") {$j = 6;} if ($startmon eq "Jul") {$j = 7;} if ($startmon eq "Aug") {$j = 8;} if ($startmon eq "Sep") {$j = 9;} if ($startmon eq "Oct") {$j = 10;} if ($startmon eq "Nov") {$j = 11;} if ($startmon eq "Dec") {$j = 12;} $k = $j; $curyear = $startyr; $amort_html = " You have $yearsleft years $monthsleft months left on your loan.

    "; # Add some commas... $data{'prin'} =~ s/[^$money_chars]//g; $data{'prin'} = sprintf("%.2f", $data{'prin'}); $data{'prin'} = &commify("$data{'prin'}"); $totalint = sprintf("%.2f", $totalint); $totalint = &commify("$totalint"); $html = "
    Simple Savings Calculator
    This calculator doesn't deal with inflation or taxes. This is just a simple calculator that lets you start with a set amount of money and make regular monthly deposits, and see how much it grows.
     
    Initial Amount: \$
    Monthly Deposit: \$
    Annual Interest Compounded
    %
    Number of Years:  
     
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
     
    EOF #($pmin,$pmax,$imin,$imax,$term) = split("&",$args); @v = split("&",$args); $tbl = "N"; for ($i=0; $i<=$#v; $i++) { ($key,$val) = split("=",@v[$i]); $val =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $val =~ s/,//g; $aa{$key} = $val; } $yrs = $aa{"yrs"}; $int = $aa{"int"}; $amt = $aa{"amt"}; $dep = $aa{"dep"}; $cmp = $aa{"cmp"}; $py = 12; if ($cmp =~ /Q/) { $py = 4; } if ($cmp =~ /S/) { $py = 2; } if ($cmp =~ /A/) { $py = 1; } $tt = $yrs * $py; print "

    Your Monthly Deposit for $yrs Years "; printf ("of \$ %6.2f

    ",$dep); printf ("

    for an Interest Rate of %6.3f %% compounded %10s

    ", $int,$cmp); printf ("

    With an Initial Amount of \$ %9.2f:

    ",$amt); $mi = $int / ($py * 100); $sav = $amt; $tcont = $amt; print "\n
    YrMoEnding
    Balance\n"; print "
    Average
    Balance"; for ($i = 1; $i <= $yrs; $i++) { for ($j=0; $j<12; $j++) { #$sav = $sav * (1 + $mi) + $dep; $pnow = 0; if ($py == 12) { $sav = $sav * (1 + $mi); $asav = $sav; $pnow = 1; } if ($py == 4 && ($j == 2 | $j == 5 | $j == 8 | $j == 11)) { $asav = $tsav/3; $sav += $asav * $mi; $tsav = 0; $pnow = 1; } if ($py == 2 && ($j == 5 | $j == 11)) { $asav = $tsav/6; $sav += $asav * $mi; $tsav = 0; $pnow = 1; } if ($py == 1 && $j == 11) { $asav = $tsav/12; $sav += $asav * $mi; $tsav = 0; $pnow = 1; } $sav = $sav + $dep; $tcont += $dep; $tsav += $sav; if ($pnow == 1) { printf("
    %2d%2d%10.2f%10.2f\n",$i,$j+1,$sav,$asav); } } } printf ("
    \n

    Final Savings Balance: \$ %10.2f

    ",$sav); printf ("

    Initial Investment plus Monthly Contributions: \$ %10.2f

    ",$tcont); printf ("

    Total Interest Earned: \$ %10.2f

    ",$sav-$tcont); print "
    "; } } sub lunch { $in = $ENV{'QUERY_STRING'}; @vi = split("&",$in); for ($i=0; $i<5; $i++) { ($key,$val) = split("=",$vi[$i],2); $aa{$key} = $val; } # Limits and witty sayings! ;-) if ($aa{C} < .01) { $aa{C} = "1.50"; } if ($aa{C} > 3) { $sorry .= "

    A \$ $aa{C} lunch is not a cheap lunch in my book

    \n"; $aa{C} = 1.50; } if ($aa{X} < .01) { $aa{X} = "5.00"; } if ($aa{X} < 2) { $sorry .= "

    You cannot eat out for less than \$2!

    "; $aa{X} = "2.00"; } if ($aa{X} > 15 ) { $sorry .= "

    A $aa{X} lunch? Egads! Nobody should spend more than \$15/day on lunch!

    \n"; $aa{X} = 15.00; } if ($aa{X} <= $aa{C}) { $aa{C} = $aa{X} - 1; if ($aa{C} < .01) { $aa{C} = 1; } $sorry .= "

    Your cheap lunch must be less than the eating out lunch "; $sorry .= "price, I will set the cheap lunch price to \$ $aa{C}

    \n"; } if ($aa{D} < 1) { $aa{D} = 250; } if ($aa{D} > 366) { $aa{D} = 366; $sorry .= "

    Maximum of 366 days per year, nimwit

    \n"; } if ($aa{Y} < 1) { $aa{Y} = 10; } if ($aa{Y} > 50) { $aa{Y} = 50; $sorry .= "

    Maximum of 50 years

    \n"; } if ($aa{R} < 4 | $aa{R} > 50) { $aa{R} = 10.5; $sorry .= "

    Yield must be between 4 and 50 \% with default of 10.5\%

    \n"; } #$grow = $aa{W} - $aa{C}; #$start = sprintf("%7d",$aa{B} * (1 + $aa{Y}/100)** $grow); $rwrate = $aa{R}/100; print < Untitled Document
    Lunch Savings Calculator
    See how much money is saved by eating a cheap "brown bag" lunch, instead of eating out at a restaurant. Have fun!
     
    Cheap Home Lunch Price:
    \$
    Eating Out Lunch Price:
    \$
    Days Eaten Per Year:
    Years to Calculate:
    Investment Yield:
    (between 4 and 50%)
    %
     
    $printtemp
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!
     
    $sorry
    HHead $yearly = ($aa{X} - $aa{C}) * $aa{D}; for ($y=1; $y<=$aa{Y}; $y++) { $save = $yearly; $earn = $start * $aa{R}/100; $end = $start + $save + $earn; printf("\n", $y, $start, $earn, $save, $end); $start = $end; } print "
    YearStarting BalanceEarningsLunch Savings Ending Balance
    %3d%10.2f%8.2f%8.2f%10.2f
    \n"; exit; } sub howmuch { print "Content-type: text/html\n\n"; $arg = $ENV{'QUERY_STRING'}; if (length($arg) < 4) { print< How much house can you afford?
    How Much House Can You Afford?
    Using this calculator will help you determine the maximum sale price that you can afford. If you are a first time home buyer, change the "PITI Debt Ratio" to 29% and the "Total Debt Ratio" to 41%.
         
    Annual Household Income:
    \$
    Total Monthly Debt:
    (Car, Credit Cards, Student Loan payments, etc.)

    \$
    Cash for down payment:
    \$
    Property Tax:
    (leave if unsure)
    %
    Homeowners Insurance:
    (Leave if unsure)
    %
    Interest Rate:
    %
    Length of Loan:
    (years)
    PITI Debt Ratio:
    (Leave if unsure)
    %
    Total Debt Ratio:
    (leave if unsure)
    %
     
    $printtemp
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!

    FormInput } else { # Resulting output begins here print< How much house can you afford?
    How Much House Can You Afford?
    Using this calculator will help you determine the maximum sale price that you can afford. If you are a first time home buyer, change the "PITI Debt Ratio" to 29% and the "Total Debt Ratio" to 41%.
         
    Annual Household Income:
    \$
    Total Monthly Debt:
    (Car, Credit Cards, Student Loan payments, etc.)

    \$
    Cash for down payment:
    \$
    Property Tax:
    (leave if unsure)
    %
    Homeowners Insurance:
    (Leave if unsure)
    %
    Interest Rate:
    %
    Length of Loan:
    (years)
    PITI Debt Ratio:
    (Leave if unsure)
    %
    Total Debt Ratio:
    (leave if unsure)
    %
     
    $printtemp
     
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.) Copyright © 2003 Constant Image - All Rights Reserved!

    Here is an estimate of what you can afford.

    ResultHead @arga = split("&",$arg); for ($i=0; $i<=$#arga; $i++) { ($key,$val) = split("=",@arga[$i]); $aa{$key} = $val; } $r1 = $aa{pr}; #$r1 = 28; $r2 = $aa{dr}; #$r2 = 36; $mi = $aa{"ai"}/12; $c1 = $mi * $r1 / 100; $c2 = ($mi * $r2 / 100) - $aa{"md"}; if ($c1 < $c2) { ("\n\n\n"; printf("\n"; } DPTooLowTxt: #if ($dpp<3 && $aa{"ty"} =~ /Conv/ ) if ($dpp<3 ) { print< DPTooLo2 } print<

    We must use the %2d %% amount of \$%8.2f for PITI

    ", $r1, $c1); "
  • This is because this value is lower than the amount "; ("(\$%8.2f) calculated using the %2d %% monthly debt value", $c2, $r2); $piti = $c1; } else { ("
  • We must use the %2d %% amount of \$%8.2f for PITI

    ", $r2, $c2); "
  • This is because this value is lower than the amount "; ("(\$%8.2f) calculated using the %2d %% income only value", $c1, $r1); ("

    To use the lower %2d %% limit, try to keep your monthly", $r1); (" debt payments below \$ %8.2f (reduce them by \$ %8.2f)\n", $mi * ($r2 - $r1)/100, $aa{"md"} - $mi * ($r2 - $r1)/100); $piti = $c2; } print "

  • \n"; $j = $aa{"ir"}/1200; $yr = $aa{"yr"}; $amv = (1 - (1 + $j)**(-$yr * 12))/$j; ("

    Your interest rate of %5.2f %% over $yr years means ",$aa{"ir"}); ("every dollar you pay each month buys you \$ %7.2f of loan

    ",$amv); $piti_ov = $aa{"hi"} + $aa{"pt"}; ("

    You stated Tax and Insurance would total %5.2f %% the home value", $piti_ov); print "

    "; $dp = $aa{"dp"}; ("

    You have \$ %7.2f available to cover your down payment.

    \n",$dp); print "
    "; $house = 1000; $pmt = $piti; $loan = 1000; for ($i=0; $i<20; $i++) { $ti = $piti_ov/1200 * $house; $loan = ($piti - $ti) * $amv; $house = $loan + $dp; } $dpp = $dp/$house*100; $ltv = ($house-$dp)/$house*100; printf("
    Maximum House value: \$ %7d\n",$house); printf("
    Maximum Loan value: \$ %7d\n",$loan); printf("
    Monthly Principal and Interest: \$ %7.2f\n",$loan/$amv); printf("
    Monthly Prop Tax and Insurance: \$ %7.2f\n",$house*$piti_ov/1200); printf("
    Down Payment %5.2f %%\n",$dpp); printf("
    Loan To Value (LTV) %5.2f %%\n",$ltv); if ($ltv>80) { print "

    Since your down payment is less than 20%, you will be required to pay private mortgage insurance.(PMI)

    "; $house = 1000; $pmt = $piti; $loan = 1000; if ($aa{"ty"} =~ /Conv/) { $pmi = .32; if ($ltv>=85) { $pmi = .52; } if ($ltv>=90) { $pmi = .78; } if ($ltv>=95) { $pmi = .90; } if ($ltv>=97) { goto DPTooLowTxt; } } else { $pmi = .5; } printf ("

    This will cost you an extra %4.2f %% of your loan each year. Taking the PMI in to account, the maximum house you can afford is shown below.

    ",$pmi); $piti_ov += $pmi; for ($i=0; $i<20; $i++) { $ti = $piti_ov/1200 * $house; $loan = ($piti - $ti) * $amv; $house = $loan + $dp; } $dpp = $dp/$house*100; print "
    Maximum House value: \$ %7d\n",$house); printf("
    Maximum Loan value: \$ %7d\n",$loan); printf("
    Monthly Principal and Interest: \$ %7.2f\n",$loan/$amv); printf("
    Monthly Prop Tax and Insurance: \$ %7.2f\n", $house*($piti_ov-0.5)/1200); printf("
    Monthly PMI: \$ %7.2f\n",$house*$pmi/1200); printf("
    Down Payment %5.2f %%\n",$dpp); print "

    Sorry, your down payment is under 3%

    Since your down payment is so low, you should consider applying for an FHA or VA insured loan. There may also be local funding programs that can help you out too. For more information on those programs you should contact a realtor or mortgage broker in your area.

    You do not have to worry about your income qualifying you for your loan. What limits your house value is simply your downpayment of \$ $dp: DPTooLow $dpw20 = $dp * 5; if ($dpw20 > $house) { $dpw20 = $house; } $dpw10 = $dp * 10; if ($dpw10 > $house) { $dpw10 = $house; } $dpw5 = $dp * 20; if ($dpw5 > $house) { $dpw5 = $house; } $dpw3 = $dp * 33.3; if ($dpw3 > $house) { $dpw3 = $house; } printf("

    With 20%% down (80%% LTV) you can buy a \$ %7d house

    \n",$dpw20); printf("

    With 10%% down (90%% LTV) you can buy a \$ %7d house

    \n",$dpw10); printf("

    With 5%% down (95%% LTV) you can buy a \$ %7d house

    \n",$dpw5); printf("

    With 3%% down (97%% LTV) you can buy a \$ %7d house

    \n",$dpw3); print<

    The figures shown above do not include closing costs and any points your lender may charge.

    Trailer } } sub monthly { $args = $ENV{'QUERY_STRING'}; if (length($args) < 4) { print < Montly Payment Calculator
    Monthly Payment Calculator
    Using this calculator, you can figure your monthly PITI payment, and display an amortization schedule for the life of the loan. To display an amortization schedule, change the drop-down menu below.
     
    $printtemp Loan Amount:
    Interest Rate:
    Loan Term: (Years)
    Annual Property Taxes:
    Annual Insurance:
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.)
    Copyright © 2003 Constant Image - All Rights Reserved!


     
    Header } else { $| = 1; %data = &get_data(); print "Content-type: text/html\n\n"; $cgi_url = "$ENV{'SCRIPT_NAME'}"; $text_color = "000000"; $page_background_color = "FFFFFF"; $page_links_color = "0000FF"; $page_active_links_color = "FF0000"; $page_visited_links_color = "0000FF"; $table_background_color = "66FF66"; $table_background_color2 = "CCCCCC"; # $header is the HTML header that will be generated by the results page # of the program. You may **CHANGE** this to any HTML code you like. # The caveats here are as follows: First, any of the following # characters: # " % @ $ \ # must have a backslash (\) in front of them like this: # \" \% \@ \$ \\ # or the program will not work. ONLY change between the lines that # say and # You may also leave this as it is. $header = " Monthly Payment Calculator "; # $footer is the HTML code that will go at the bottom of pages # generated by the program. The same rules apply as to $header # above. You may also leave this as it is, and it will work fine. # Again, ONLY change between the lines that say # and $footer = "
    Monthly Payment Calculator
    Using this calculator, you can figure your monthly PITI payment, and display an amortization schedule for the life of the loan. To display an amortization schedule, change the drop-down menu below.
     
     
    "; # yen # cent (centime) # pound (British pound) # **CHANGE** $currency=""; to one of the following: # $currency = "yen"; # $currency = "cent"; # $currency = "pound"; $currency = ""; # First, we get the data submitted on the form into variables we can use. $prin = "$data{'prin'}"; $int = "$data{'int'}"; $len = "$data{'years'}"; $tax = "$data{'tax'}"; $insure = "$data{'insure'}"; $startmon = "$data{'startmon'}"; $startday = "$data{'startday'}"; $startyr = "$data{'startyr'}"; ($second,$minute,$hour,$month_day, $month,$year,$weekday,$IsDST) = (localtime)[0,1,2,3,4,5,6,8]; $year += 1900; $month++; if ($startmon eq "Jan") {$startmonth = 1;} if ($startmon eq "Feb") {$startmonth = 2;} if ($startmon eq "Mar") {$startmonth = 3;} if ($startmon eq "Apr") {$startmonth = 4;} if ($startmon eq "May") {$startmonth = 5;} if ($startmon eq "Jun") {$startmonth = 6;} if ($startmon eq "Jul") {$startmonth = 7;} if ($startmon eq "Aug") {$startmonth = 8;} if ($startmon eq "Sep") {$startmonth = 9;} if ($startmon eq "Oct") {$startmonth = 10;} if ($startmon eq "Nov") {$startmonth = 11;} if ($startmon eq "Dec") {$startmonth = 12;} $monthsleft = $startmonth - $month; $yearsleft = $startyr + $len - $year; if ($monthsleft < 0) {$monthsleft += 12;} if ($startmonth < $month) {$yearsleft--;} if ($yearsleft < 0) {$yearsleft = "N/A"; $monthsleft = "N/A";} # Strip out non-money characters $money_chars = '0-9\.'; $prin =~ s/[^$money_chars]//g; # check and make sure that we got something entered for these # items, and that the value of the loan, interest, and loan term # is greater than 0. if($prin eq "" || $prin <= 0 || $int eq "" || $int <= 0 || $len eq "" || $len <= 0 || $tax eq "" || $tax <= 0 || $insure eq "" || $insure <= 0 || $startyr eq "" || $startyr <= 0){ $form = &get_form; print "$header
    Please make sure all fields are filled and contain appropriate figures.
     
    "; for ($i = $prin; $i > 0; $i = $bal){ if ($k eq 13) {$k = 1; $curyear++;} if ($k eq 1) {$startmon2 = "Jan";} if ($k eq 2) {$startmon2 = "Feb";} if ($k eq 3) {$startmon2 = "Mar";} if ($k eq 4) {$startmon2 = "Apr";} if ($k eq 5) {$startmon2 = "May";} if ($k eq 6) {$startmon2 = "Jun";} if ($k eq 7) {$startmon2 = "Jul";} if ($k eq 8) {$startmon2 = "Aug";} if ($k eq 9) {$startmon2 = "Sep";} if ($k eq 10) {$startmon2 = "Oct";} if ($k eq 11) {$startmon2 = "Nov";} if ($k eq 12) {$startmon2 = "Dec";} $curint = $i * $realint; $p_curint = sprintf("%.2f", $curint); $curprin = $pay - $curint; $p_curprin = sprintf("%.2f", $curprin); $bal = $i - $curprin; $p_bal = sprintf("%.2f", $bal); $printbal = &commify($p_bal); $totalint += $curint; $amort_html .= "\n" if $bal > 0; $k++; } $amort_html .= "
    Month Principal Paid Interest Paid Loan Balance
    $startmon2 $curyear$currency$p_curprin$currency$p_curint$currency$printbal

    Your monthly PITI (Principal, Interest, Taxes and Insurance) payment will be $currency$payplus

    "; $loan = " Total interest paid over life of loan is $currency$totalint

    "; if($data{'show_amort'} eq "Yes" && $data{'howoften'} ne "Bi-Weekly"){ print "$header $form $html $loan $amort_html $footer"; } elsif($data{'show_amort'} eq "Yes" && $data{'howoften'} eq "Bi-Weekly"){ print "$header
    Note: Amortization table not available for Bi-Weekly payments.

    $html
  • $form
    $footer"; } else{ print "$header $form $html $footer"; } sub get_form { if($data{'show_amort'} eq "Yes") { $vis = "visible"; } if($data{'show_amort'} eq "No") { $vis = "hidden"; } $form = "
    $printtemp Loan Amount:
    Interest Rate:
    Loan Term: (Years)
    Annual Property Taxes:
    Annual Insurance:
    Loan Started On: ,
    Results Shown Below
    (This calculator is considered reliable, but not guaranteed.)
    Copyright © 2003 Constant Image - All Rights Reserved