File "loan_calculator.php"
Full path: /home/fsibplc/public_html/fsib/loan_calculator.php
File
size: 6.37 B (6.37 KB bytes)
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
include('./includes/config.php');
$page_title = "First Security Islami Bank PLC.";
//echo $page_title;
//echo $data[0]['value'];
$meta_description = "First Security Islami Bank PLC. Home page description";
$meta_keywords = "First Security Islami Bank PLC., Bank, Website";
include('includes/header.php');
include('includes/navbar.php');
//include('includes/slider.php');
?>
<!-- ++++++++++++++++++++++++++Start Body Tag++++++++++++++++++++++++++ -->
<style>
th,
td {
color: #d9ffe3;
}
table {
border: 1px solid #085e1f !important;
}
</style>
<div class="container">
<h4 class="tab_title mt-5">EMI Calculator</h4>
<div class="calculator_wrapper">
<div class="card loan_calculator">
<div class="mb-3 row">
<label for="disbursement_date" class="form-label">Disbursement Date</label>
<input type="date" id="dis_date" class="form-control">
</div>
<div class="mb-3 row">
<label for="loan_amount" class="form-label">Loan Amount</label>
<input type="number" id="principal" class="form-control" placeholder="">
</div>
<div class="mb-3 row">
<label for="total_month" class="form-label">Total Years</label>
<input type="number" id="tenure" placeholder="" class="form-control">
</div>
<div class="mb-3 row">
<label for="rate" class="form-label">Rate(%)</label>
<input type="number" id="interest" placeholder="" class="form-control">
</div>
<button onclick="calculateLoan()" class="btn btn-success">Find Your EMI</button>
</div>
<div class="card output_card">
<table class="table table-bordered table-responsive mt-5">
<thead>
<th style="color:#bbbdfc;text-align:center" colspan="2">Loan Information</th>
</thead>
<tbody>
<tr>
<td><strong>Monthly Installment :</strong></td>
<td id="emi_amount"></td>
</tr>
<tr>
<td>Disbursement Date :</td>
<td id="disbursement_date"></td>
</tr>
<tr>
<td>Loan Amount :</td>
<td id="principal_amount"></td>
</tr>
<tr>
<td>Number of Month :</td>
<td id="total_month"></td>
</tr>
<tr>
<td>Rate(%) :</td>
<td id="rate"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- ++++++++++++++++++++++++++Start Footer Section++++++++++++++++++++++++++ -->
<?php include('includes/footer.php'); ?>
<script>
function calculateLoan() {
// Step 1: Fetch values from input fields
let principal = parseFloat(document.getElementById('principal').value);
let annualInterest = parseFloat(document.getElementById('interest').value);
let tenureYears = parseFloat(document.getElementById('tenure').value);
let disbursementDate = document.getElementById('dis_date').value;
// Step 2: Validate if all fields are filled with valid numbers
if (isNaN(principal) || isNaN(annualInterest) || isNaN(tenureYears) || annualInterest < 0 || annualInterest > 100 || principal < 0 || annualInterest < 0 || tenureYears <= 0) {
alert("Please fill out all fields with valid numbers!");
return;
}
// Step 3: Calculate Monthly Interest and Tenure in Months
let monthlyInterest = (annualInterest / 100) / 12;
let tenureMonths = tenureYears * 12;
// Step 4: Calculate EMI with Interest and Total Interest
// let emiWithInterest = principal * monthlyInterest / (1 - Math.pow(1 + monthlyInterest, -tenureMonths));
// let totalInterest = emiWithInterest * tenureMonths - principal;
// Step 5: Calculate Monthly Interest Amount
// let monthlyInterestAmount = (emiWithInterest - principal / tenureMonths).toFixed(2);
// Step 6: Calculate Total Loan Amount with Interest
// let totalLoanAmountWithInterest = (emiWithInterest * tenureMonths).toFixed(2);
// Step 7: Display the calculated results on the page
let monthlyInterestAmount = (principal * monthlyInterest * ((Math.pow(1 + monthlyInterest, tenureMonths)) / ((Math.pow(1 + monthlyInterest, tenureMonths)) - 1))).toFixed(2);
// let powerMath = (Math.pow(1 + monthlyInterest, tenureMonths));
document.getElementById('emi_amount').innerHTML = monthlyInterestAmount;
document.getElementById('disbursement_date').innerHTML = disbursementDate;
document.getElementById('principal_amount').innerHTML = principal;
document.getElementById('total_month').innerHTML = tenureMonths;
document.getElementById('rate').innerHTML = annualInterest;
}
// function submitForm() {
// const form = document.getElementById('myForm');
// form.addEventListener('submit', (event) => {
// event.preventDefault();
// let dis_date = document.getElementById("dis_date").value;
// var principal = document.getElementById("loan_amount").value;
// var time = document.getElementById("total_month").value;
// var rate = document.getElementById("total_rate").value;
// var EMI = principal*(rate/(100*12))*((power(1+(rate/(100*12))),time)/((power(1+(rate/(100*12))),time)-1));
// alert("EMI = "+EMI);
// });
// form.submit();
// }
</script>