$(document).ready(function(){ // var intRate = document.getElementById("uRate").value; var loanAmount = document.getElementById("loanamount").value; var rateOfInterest = document.getElementById("uRate").value; var numberofYears = document.getElementById("loanTenureValue").value; var moratorium = 0; if (moratorium) { moratorium = moratorium; } var emi; calculateForm() $("#uRate_slider").slider({ range: "min", value: uRate.value, step: 0.1, min: 4, max: 24, slide: function( event, ui ) { $( "#uRate" ).val( ui.value ); rateOfInterest = ui.value ; calculateForm() } }); $("#uRate").change(function() { var value = this.value; if(value < 4 || value>24){ alert("Please enter the value within 4 to 24") $("#uRate").val(6); } $("#uRate_slider").slider("value", $(this).val()); rateOfInterest = this.value; calculateForm() }); $("#loanamount_slider").slider({ range: "min", value: loanamount.value, step: 100000, min: 100000, max: 25000000, slide: function( event, ui ) { $( "#loanamount" ).val( ui.value ); loanAmount= ui.value calculateForm() } }); $("#loanamount").change(function() { var value = this.value; if(value < 100000 || value>25000000){ alert("Please enter the value within 100000 to 25000000"); $("#loanamount").val(5000000); } $("#loanamount_slider").slider("value", $(this).val()); loanAmount=this.value; calculateForm() }); $("#loanTenureValue_slider").slider({ range: "min", value: loanTenureValue.value, step: 1, min: 1, max: 55, slide: function( event, ui ) { $( "#loanTenureValue" ).val( ui.value ); numberofYears=ui.value; calculateForm() } }); $("#loanTenureValue").change(function() { var value = this.value; if(value>55){ alert("Please enter the value with in 1 to 55"); $("#loanTenureValue").val(25); } $("#loanTenureValue_slider").slider("value", $(this).val()); numberofYears=this.value; calculateForm() }); function calculateForm(){ var numberOfMonths = numberofYears*12; var monthlyInterestRatio = (rateOfInterest / 100) / 12; var months = numberOfMonths; if (moratorium != 0) months =numberOfMonths - moratorium; var top = Math.pow((1 + monthlyInterestRatio), months); var bottom = top - 1; var sp = top / bottom; emi = ((loanAmount * monthlyInterestRatio) * sp); var full = numberOfMonths * emi; interest = full - loanAmount; var int_pge = (interest / full) * 100; var detailDesc var bb = parseInt(loanAmount), int_dd = 0, pre_dd = 0, end_dd = 0, emiAndInt = 0, totalInterestPreEmiLP = 0, totalPayOfLoan = 0; jsonInt = []; jsonPl = []; labels = []; emis = []; for (var j = 1; j <= numberOfMonths; j++) { monthlyInterst = ""; MonthlyPrincipal = ""; if (moratorium != 0 && moratorium >= j) { emiAndInt = PMT(rateOfInterest / 12, numberOfMonths, loanAmount, 0, 0) totalInterestPreEmiLP = totalInterestPreEmiLP + emiAndInt; totalPayOfLoan = totalPayOfLoan + emiAndInt; // labels.push(j); jsonInt.push(Math.round(emiAndInt)); jsonPl.push(parseInt(0)); emis.push(Math.round(emi)); } else { int_dd = bb * ((rateOfInterest / 100) / 12); pre_dd = emi - int_dd; end_dd = bb - pre_dd; // labels.push(j); jsonInt.push(Math.round(int_dd)); jsonPl.push(Math.round(pre_dd)); emis.push(Math.round(emi)); bb = bb - pre_dd; totalInterestPreEmiLP = totalInterestPreEmiLP + int_dd; totalPayOfLoan = totalPayOfLoan + emi; } } var totalInterestPreEmiMP = Math.round(emiAndInt * moratorium); $("#emi").html( Math.round(emi)); $("#maturity").html( Math.round(totalInterestPreEmiLP) ); chartgenerator(labels, jsonInt, jsonPl, emis) } function chartgenerator(labels, jsonInt, jsonPl, emis) { Highcharts.chart('emi_chart', { title: { text: 'EMI Chart' }, credits: { enabled: false }, xAxis: { tickInterval: 12, gridLineWidth: 1, title: { text: 'Loan Tenure(in Months)' } }, yAxis: { min: 0, gridLineWidth: 1, title: { text: 'Amount (Rs)' } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'middle' }, plotOptions: { series: { label: { connectorAllowed: false }, marker: { enabled: false }, } }, series: [{ name: 'Interest', color:'#ffd100', data:jsonInt }, { name: ' Principal', color:'#280071', data: jsonPl }, {name: 'EMI', color: '#12a8e0', data: emis }], responsive: { rules: [{ condition: { maxWidth: 1000 }, chartOptions: { legend: { layout: 'horizontal', align: 'center', verticalAlign: 'bottom' } } }] } }); } function inrFormat(inputStrng) { return parseFloat(inputStrng).toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","); } function addCommas(str) { var amount = new String(str); amount = amount.split("").reverse(); var output = ""; for (var i = 0; i <= amount.length - 1; i++) { output = amount[i] + output; if (i == 2 && (amount.length - 1) !== i) output = ',' + output; if (i == 4 && (amount.length - 1) !== i) output = ',' + output; if (i == 6 && (amount.length - 1) !== i) output = ',' + output; //alert(output); } return output; } $('.re_calc').on('click',function(){ clearForm(); }) function clearForm(){ loanTenureValue.value = 25; uRate.value = 6; loanamount.value = 5000000; $("#uRate_slider").slider("value",6); $("#loanTenureValue_slider").slider("value",25); $("#loanamount_slider").slider("value",5000000); calculateForm(); } $.fn.scrollView = function () { return this.each(function () { $('html, body').animate({ scrollTop: $(this).offset().top }, 1000); }); } $('.emi_chart').on('click',function(){ var scrollBottom = $('.calc_area').scrollTop() + $('.calc_area').height(); $('#emi_chart').css('display','flex'); var scrollHeight = $('.calc_area').prop("scrollHeight"); $('.calc_area').animate({scrollTop : 120},800); }); (function(jQuery) { jQuery.fn.inputFilter = function(inputFilter) { return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() { if (inputFilter(this.value)) { this.oldValue = this.value; this.oldSelectionStart = this.selectionStart; this.oldSelectionEnd = this.selectionEnd; } else if (this.hasOwnProperty("oldValue")) { this.value = this.oldValue; this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd); } }); }; }(jQuery)); jQuery("#loanamount").inputFilter(function(value) { return /^\d*$/.test(value); }); jQuery("#loanTenureValue").inputFilter(function(value) { return /^\d*$/.test(value); }); jQuery("#uRate").inputFilter(function(value) { return /^\d*\.?\d*$/.test(value); }); });