Simple loan simulation on WordPress
Insert following code on function.php on your theme.
function kpr() {
ob_start(); ?>
<div class="kpr-frame">
<form>
<label>Harga</label>
<input type="number" class="form-control mb-2" id="harga" placeholder="Contoh: 250000000" required>
<label>DP</label>
<input type="number" class="form-control mb-2" id="dp" placeholder="Contoh: 25000000" required>
<label>Jangka Waktu (Tahun) </label>
<input type="number" class="form-control mb-2" id="tenor" placeholder="Contoh: 10" required>
<label>Suku Bunga /tahun (%)</label>
<input type="number" class="form-control" id="bunga" placeholder="Contoh: 2" required>
<label></label>
<button id="hitungsimulasi" class="btn btn-outline-primary btn-lg btn-block">Hitung</button>
</form>
<script>
jQuery(function($) {
function convertToRupiah(angka)
{
var rupiah = '';
var angkarev = angka.toString().split('').reverse().join('');
for(var i = 0; i < angkarev.length; i++) if(i%3 == 0) rupiah += angkarev.substr(i,3)+'.';
return 'Rp. '+rupiah.split('',rupiah.length-1).reverse().join('');
}
$("#hitungsimulasi").click(function(event) {
var harga = $('#harga').val();
var tenor = $('#tenor').val();
var tenortahun = tenor*12;
var bunga = $('#bunga').val();
var dp = $('#dp').val();
var kurang = +harga - +dp;
var cicilpokok = +kurang / tenortahun;
var rpbunga = +kurang*((bunga/100)/12);
var bungadibayar = +kurang*((bunga*tenor)/100);
var angsuran = (kurang+bungadibayar)/tenortahun;
var totaldp = + dp + +angsuran;
var tpinjaman = '<<br><br>div class="alert alert-dark" role="alert"> Total Pinjaman: '+ convertToRupiah(Math.round(kurang)) +'</div>';
var cicilanpokok = '<div class="alert alert-dark" role="alert"> Cicilan Pokok: '+ convertToRupiah(Math.round(cicilpokok)) +'</div>';
var bungarp = '<div class="alert alert-dark" role="alert">Bunga: '+convertToRupiah(Math.round(rpbunga))+'</div>';
var tuangmuka = '<div class="alert alert-dark" role="alert">Total DP + Cicilan Pertama: '+convertToRupiah(Math.round(totaldp))+'</div>';
var tangsuran = '<div class="alert alert-info" role="alert">Angsuran per bulan<br><b>'+convertToRupiah(Math.round(angsuran))+'</b> <small> *selama '+tenor+' tahun ('+tenortahun+' Bulan)</small></div>';
if(!harga){
$('.hasilhitung').html('<div class="alert alert-warning" role="alert">Harga belum Diisi.</div>');
} else if (!dp){
$('.hasilhitung').html('<div class="alert alert-warning" role="alert">Tentukan DP. Contoh 25.000.000</div>');
} else if (!bunga) {
$('.hasilhitung').html('<div class="alert alert-warning" role="alert">Tentukan Bunga. Contoh 10</div>');
} else {
$('.hasilhitung').html('<div class="">'+ tpinjaman + cicilanpokok + bungarp + tuangmuka + tangsuran + '</div>');
}
event.preventDefault();
});
});
</script>
<div class="hasilhitung mt-3"></div>
</div>
<?php return ob_get_clean();
}
add_shortcode('kpr', 'kpr');
This is flat loan simulation with following formula:
a = loan principal
b = interest per tahun
c = time in year
d = downpayment
so,
installment per month = (a-d) / c
interest per month = (a-d) x b / 12
TotalĀ installament per month = (a-d) x b / 12 x c
for using this simulation using this shortcode:
[kpr]