PHP Classes

PHP Mortgage Calculator: Calculate monthly payments for mortgage

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 83 All time: 10,027 This week: 571Up
Version License PHP version Categories
mortgage 1.0.0GNU General Publi...5PHP 5, Finances
Description 

Author

This class can calculate monthly payments for mortgage.

It can take as parameters the loan amount, the fixed interest rate amount and the number of years to pay.

The class returns an array that has the values of amortization to pay the mortgage loan.

Picture of Adeola Odusola
  Performance   Level  
Name: Adeola Odusola is available for providing paid consulting. Contact Adeola Odusola .
Classes: 2 packages by
Country: United States United States
Age: ???
All time rank: 4309546 in United States United States
Week rank: 416 Up46 in United States United States Up
Innovation award
Innovation award
Nominee: 1x

Recommendations

What is the best PHP amortization calculation class?
Credit card amortization debt calculator

Example

<?php
/**
 * @author Adeola Odusola
 *
 * The following program calculates monthly mortgage for fixed interest rate.
 * The user inputs the original loan amount, interest rate, and number of years.
 */
?>

<!DOCTYPE html>
<html>
    <head>
        <style>
             table.my_table {
                font-family: verdana,arial,sans-serif;
                color:#333333;
                border-width: 1px;
                border-color: #999999;
                border-collapse: collapse;
            }
            table.my_table th {
                font-size:10px;
                background:#b5cfd2;
                border-width: 1px;
                padding: 3px;
                border-style: solid;
                border-color: #999999;
            }
            table.my_table tr{
                 -webkit-print-color-adjust: exact;
            }
            table.my_table tr:nth-child(odd) {
                background: #f2f2f2;
            }
            table.my_table tr:hover {
                background-color: #ffff00;
            }
            table.my_table td {
                font-size:10px;
                border-width: 1px;
                padding: 2px;
                border-style: solid;
                border-color: #999999;
            }
        </style>
        <title>
            Mortgage calculator and amortization table generator
        </title>
    </head>
    <body>
        <form method="post" action="">
            <table>
                <tr>
                    <td>
                        <label for="loan">Loan: $</label>
                    </td>
                    <td>
                        <input type="text" name="loan" value="" pattern="\d+((\.)\d{2})?" required>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="rate">Rate: </label>
                    </td>
                    <td>
                        <input type="text" name="rate" value="" pattern="\d+((\.)\d{1,})?" required>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="years">Years: </label>
                    </td>
                    <td>
                        <select name="years" required>
                            <option value="">select...</option>
                            <option value="5">5</option>
                            <option value="10">10</option>
                            <option value="15">15</option>
                            <option value="20">20</option>
                            <option value="25">25</option>
                            <option value="30">30</option>
                            <option value="40">40</option>
                            <option value="50">50</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                       <input type="submit" name="compute" value="calculate mortgage">
                    </td>
                </tr>
            </table>
        </form>


<?php
if (isset($_POST['compute'])){
    require_once
'Mortgage.php';
   
//input values
   
$loanAmount=$_POST['loan'];
   
$rawRate=$_POST['rate'];
   
$numberOfYears=$_POST['years'];
   
   
// get results
   
$mort=new Mortgage($loanAmount, $rawRate, $numberOfYears);
   
$results=$mort->getResults();
   
$summary=$results["summary"];
   
$amortization=$results["amortization"];
   
   
// display mortgage summary
   
echo "<div>Mortgage Summary</div>";
    echo
"<table class=\"my_table\">";
    echo
"<tr><td>Home Value: </td><td>$".$summary["homeValue"]."</td></tr>";
    echo
"<tr><td>Monthly Mortgage: </td><td>$".$summary["monthlyMortgage"]."</td></tr>";
    echo
"<tr><td>Total Payment: </td><td>$".$summary["totalPayment"]."</td></tr>";
    echo
"<tr><td>Total Interest: </td><td>$".$summary["totalInterest"]."</td></tr>";
    echo
"</table><br>";
       
   
// display amortization table
   
echo "<div>Amortization Schedule</div>";
    echo
"<table class=\"my_table\">";
    echo
"<tr><th>Month #</th><th>Mortgage</th><th>Principal</th><th>Interest</th><th>Balance</th></tr>";
    foreach (
$amortization as $row){
        echo
"<tr>";
        echo
"<td>".$row["monthNumber"]."</td>";
        echo
"<td>".$row["mortgage"]."</td>";
        echo
"<td>".$row["principal"]."</td>";
        echo
"<td>".$row["interest"]."</td>";
        echo
"<td>".$row["balance"]."</td>";
        echo
"</tr>";
        if (
$row["monthNumber"]%12==0 && $row["monthNumber"]!=($numberOfYears*12) ){
           
// redisplay header
           
echo "<tr><th>Month #</th><th>Mortgage</th><th>Principal</th><th>Interest</th><th>Balance</th></tr>";
        }
    }
    echo
"</table>";
}
?>

       
    </body>
</html>


Details

The following program calculates monthly mortgage for fixed interest rate. The user inputs the original loan amount, interest rate, and number of years. Subsequently, the mortgage summary and amortization table are displayed.

  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example example
Accessible without login Plain text file Mortgage.php Class Mortgage and Amortization generator
Accessible without login Plain text file readme.md Doc. documentation

 Version Control Unique User Downloads Download Rankings  
 0%
Total:83
This week:0
All time:10,027
This week:571Up