Amortization Loan Calculator Using PHP

infoslearning

Amortization of Loan

Amortization refers to the process of paying off debt over time in regular installments of interest and principal sufficient to repay the loan in full by its maturity date. Amortization is the process of reducing asset value or the loan balance by a periodic amount. The formulas used in amortization calculation can be kind of confusing.

In this tutorial, we will use PHP to create a loan calculator using the amortization formula. The following PHP code is used to find loan payments. You can just copy, and paste this PHP code and use it to find the loan payment.

Create a file called ‘index.php’ and write the following code.

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Loan Calculator, Using Amortization Method in PHP </title>

	<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
	
</head>
<body>
	<br>
	<br>
<div class="container">
  <h1 align="center">Loan Calculator Amortization</h1>
	<form method="POST" action="">
  <div class="form-group" >
    <label for="exampleInputEmail1">Loan Amount</label>
    <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="e.g. 100000" name="amount" required="true">
  
  </div>
    <div class="form-group">
    <label for="exampleInputEmail1">Interest (Per Month)</label>
    <input type="number" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="e.g. 1.5" name="interest_rate" step="any" required="true">
   
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Period (Months)</label>
    <input type="number" class="form-control" id="exampleInputPassword1" placeholder="e.g. 12" name="period" required="true">
  </div>

  <button type="submit" name="submit" class="btn btn-primary">Calculate</button>
</form>

<br>

  <table id="example1" class="table table-bordered table-striped">             

  <thead >
<?php
$loan_amount=$interest_rate=$period=NULL;

$total_interest=$total_payable=$monthly_payable=0;

if(isset($_POST['submit'])){

	$loan_amount=$_POST['amount'];

    $interest_rate=$_POST['interest_rate'];

	$period=$_POST['period'];

	
   //Amortization

    $value1 = $interest_rate * pow((1 + $interest_rate), $period);
    $value2 = pow((1 + $interest_rate), $period) - 1;
    $pmt_per_month = $loan_amount * ($value1 / $value2);

    $total_payable=$pmt_per_month*$period;
    $total_interest=$total_payable - $loan_amount;

}          
  ?>

   

          
                 <tr>                  
                  <th width="40%" class="text-right">Loan Amount</th>
                  <td ><?=number_format($loan_amount, 2);?></td>
                </tr>
				 <tr>                  
                  <th width="40%" class="text-right">Interest</th>
                  <td ><?=number_format($interest_rate, 2);?></td>
                </tr>
                 <tr>                  
                  <th width="40%" class="text-right">Total Interest</th>
                  <td ><?=number_format($total_interest, 2);?> </td>
                </tr>
                  <tr>
                  
                  <th width="40%" class="text-right">Total Loan (Principal + Interest)</th>
                  <td><?=number_format($total_payable, 2);?></td>
                </tr>                 
                   <tr>
                  
                  <th width="40%" class="text-right">Monthly Payment</th>
                  <td><?=number_format($pmt_per_month, 2);?></td>
                </tr>

                </thead>

  </table>
  
	</body>
</html>

The principal is the original loan amount or the balance that you must pay off. By making regular periodic payments, the principal gradually decreases, and when it reaches zero, you have to completely pay off your debt.


Other Recommended for you

  • .Firebase Realtime Database vs Firestore.
  • .What is an Intent in Android? Types of Intent
  • .What is Firebase?
  • .How to Get Number of Remaining Days Between Two Date in PHP