|
|
|
@ -10,6 +10,9 @@ function parseField(id, isInt) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function round(num) { |
|
|
|
|
if (num == null) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return parseFloat(num.toFixed(2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -111,8 +114,11 @@ jQuery(function($){
|
|
|
|
|
let yearly_sum = PMT(0.01*interest, term, -(price - payment_absolute)); |
|
|
|
|
let monthly_sum = PMT(0.01*interest/12, term*12, -(price - payment_absolute)); |
|
|
|
|
let month = new Date().getMonth() + 1; // current month
|
|
|
|
|
let pay_month = undefined; |
|
|
|
|
let months = 1; |
|
|
|
|
for (let i = 0; i < term; i++) { |
|
|
|
|
let i = 0; |
|
|
|
|
let total = 0; |
|
|
|
|
while(months < term * 12) { |
|
|
|
|
let year_cur = year + i; |
|
|
|
|
if (payments[year_cur] === undefined) { |
|
|
|
|
payments[year_cur] = {} |
|
|
|
@ -120,31 +126,37 @@ jQuery(function($){
|
|
|
|
|
payments[year_cur].principal = 0; |
|
|
|
|
payments[year_cur].interest = 0; |
|
|
|
|
payments[year_cur].tax = insurance + tax; |
|
|
|
|
while(month <= 12) { |
|
|
|
|
while(months < term * 12 && month <= 12) { |
|
|
|
|
let principal_monthly = round(PPMT(interest*0.01/12, months, term*12, -(price - payment_absolute))); |
|
|
|
|
let interest_monthly = round(monthly_sum - round(PPMT(interest*0.01/12, months, term*12, -(price - payment_absolute)))); |
|
|
|
|
let pmi_monthly = round(pmi*0.01*due/12); |
|
|
|
|
payments[year_cur].principal += principal_monthly; |
|
|
|
|
payments[year_cur].interest += interest_monthly; |
|
|
|
|
due = due - principal_monthly; |
|
|
|
|
total += round(principal_monthly); |
|
|
|
|
total += round(interest_monthly); |
|
|
|
|
total += round(tax / 12); |
|
|
|
|
total += round(insurance / 12); |
|
|
|
|
if (due / (price - payment_absolute) > 0.8) { // there's still PMI
|
|
|
|
|
payments[year_cur].tax += pmi_monthly; |
|
|
|
|
} |
|
|
|
|
if (year_cur === 2018) { |
|
|
|
|
console.log(""+months+"-"+principal_monthly+"-"+interest_monthly+"-"+pmi_monthly); |
|
|
|
|
total += round(pmi_monthly); |
|
|
|
|
} else { |
|
|
|
|
if (pay_month === undefined) { |
|
|
|
|
pay_month = new Date(year_cur, month, 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
month++; |
|
|
|
|
months++; |
|
|
|
|
} |
|
|
|
|
month = 1; |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
console.log(payments); |
|
|
|
|
// Compiling a nice visual table
|
|
|
|
|
let html = "<thead><th>Year</th><th>Principal</th><th>Interest</th><th>Tax, PMI, Insurance</th><th class='hidden-sm-down'>Remaining due</th></thead><tbody>"; |
|
|
|
|
let html = "<thead><th>Date</th><th>Principal</th><th>Interest</th><th class='tax'>Tax, PMI, Insurance</th><th class='hidden-sm-down'>Balance</th></thead><tbody>"; |
|
|
|
|
let pay = price * (1 - 0.01*payment); |
|
|
|
|
for (let i = 0; i < term; i++) { |
|
|
|
|
let year_cur = year + i; |
|
|
|
|
pay = pay - payments[year_cur].principal; |
|
|
|
|
pay = pay - round(payments[year_cur].principal); |
|
|
|
|
html += "<tr>"; |
|
|
|
|
html += "<td>"+year_cur+"</td>"; |
|
|
|
|
html += "<td>"+round(payments[year_cur].principal)+"</td>"; |
|
|
|
@ -153,12 +165,20 @@ jQuery(function($){
|
|
|
|
|
html += "<td class='hidden-sm-down'>"+round(pay)+"</td>"; |
|
|
|
|
html += "</tr>"; |
|
|
|
|
} |
|
|
|
|
jQuery("#total-payments").text(months); |
|
|
|
|
jQuery("#total").text("$"+total.toLocaleString()); |
|
|
|
|
let shortmonth = new Date("2000", new Date().getMonth(), 0).toLocaleString("en-us", { month: "short" }); |
|
|
|
|
jQuery("#payoff").text(shortmonth+". "+(year + term)); |
|
|
|
|
jQuery("#cost-after").text("$"+round(monthly_sum + tax/12 + insurance/12).toLocaleString()); |
|
|
|
|
html += "</tbody>"; |
|
|
|
|
jQuery("#paymentdetails").html(html); |
|
|
|
|
let monthly = PMT(0.01*interest/12, term*12, -(price - payment_absolute)); |
|
|
|
|
monthly += pmi*0.01*(price-payment_absolute)/12; |
|
|
|
|
monthly += insurance/12 + tax/12; |
|
|
|
|
jQuery("#calculated-cost").text("$" + monthly.toLocaleString()); |
|
|
|
|
jQuery(".pay-month").text(pay_month.toLocaleString("en-us", { |
|
|
|
|
month: "long" |
|
|
|
|
})+", "+pay_month.getFullYear()); |
|
|
|
|
jQuery("#estimations").modal(); |
|
|
|
|
}); |
|
|
|
|
updatePrice(); |
|
|
|
@ -206,4 +226,10 @@ jQuery(function($){
|
|
|
|
|
'phone': phone |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
jQuery(".mod-more").on('click', function(){ |
|
|
|
|
jQuery(".mod-more").slideUp(); |
|
|
|
|
jQuery("#initial-cost-card").addClass('narrow'); |
|
|
|
|
jQuery(".cost-card").removeClass('hidden'); |
|
|
|
|
jQuery(".pay-month").parent().removeClass("hidden"); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|